chore: format with csharpier
This commit is contained in:
parent
2f516dcb73
commit
4f54077c68
59 changed files with 2000 additions and 942 deletions
|
|
@ -22,41 +22,52 @@ public class KeyRoleCommands(
|
|||
ContextInjectionService contextInjection,
|
||||
IFeedbackService feedbackService,
|
||||
GuildCache guildCache,
|
||||
RoleCache roleCache) : CommandGroup
|
||||
RoleCache roleCache
|
||||
) : CommandGroup
|
||||
{
|
||||
[Command("list")]
|
||||
[Description("List this server's key roles.")]
|
||||
public async Task<IResult> ListKeyRolesAsync()
|
||||
{
|
||||
var (_, guildId) = contextInjection.GetUserAndGuild();
|
||||
if (!guildCache.TryGet(guildId, out var guild)) throw new CataloggerError("Guild not in cache");
|
||||
if (!guildCache.TryGet(guildId, out var guild))
|
||||
throw new CataloggerError("Guild not in cache");
|
||||
var guildRoles = roleCache.GuildRoles(guildId).ToList();
|
||||
var guildConfig = await db.GetGuildAsync(guildId);
|
||||
|
||||
if (guildConfig.KeyRoles.Count == 0)
|
||||
return await feedbackService.SendContextualAsync(
|
||||
"There are no key roles to list. Add some with `/key-roles add`.");
|
||||
"There are no key roles to list. Add some with `/key-roles add`."
|
||||
);
|
||||
|
||||
var description = string.Join("\n", guildConfig.KeyRoles.Select(id =>
|
||||
{
|
||||
var role = guildRoles.FirstOrDefault(r => r.ID.Value == id);
|
||||
return role != null ? $"- {role.Name} <@&{role.ID}>" : $"- unknown role {id}";
|
||||
}));
|
||||
var description = string.Join(
|
||||
"\n",
|
||||
guildConfig.KeyRoles.Select(id =>
|
||||
{
|
||||
var role = guildRoles.FirstOrDefault(r => r.ID.Value == id);
|
||||
return role != null ? $"- {role.Name} <@&{role.ID}>" : $"- unknown role {id}";
|
||||
})
|
||||
);
|
||||
|
||||
return await feedbackService.SendContextualEmbedAsync(new Embed(
|
||||
Title: $"Key roles for {guild.Name}",
|
||||
Description: description,
|
||||
Colour: DiscordUtils.Purple));
|
||||
return await feedbackService.SendContextualEmbedAsync(
|
||||
new Embed(
|
||||
Title: $"Key roles for {guild.Name}",
|
||||
Description: description,
|
||||
Colour: DiscordUtils.Purple
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
[Command("add")]
|
||||
[Description("Add a new key role.")]
|
||||
public async Task<IResult> AddKeyRoleAsync(
|
||||
[Description("The role to add.")] [DiscordTypeHint(TypeHint.Role)] Snowflake roleId)
|
||||
[Description("The role to add.")] [DiscordTypeHint(TypeHint.Role)] Snowflake roleId
|
||||
)
|
||||
{
|
||||
var (_, guildId) = contextInjection.GetUserAndGuild();
|
||||
var role = roleCache.GuildRoles(guildId).FirstOrDefault(r => r.ID == roleId);
|
||||
if (role == null) throw new CataloggerError("Role is not cached");
|
||||
if (role == null)
|
||||
throw new CataloggerError("Role is not cached");
|
||||
|
||||
var guildConfig = await db.GetGuildAsync(guildId);
|
||||
if (guildConfig.KeyRoles.Any(id => role.ID == id))
|
||||
|
|
@ -66,27 +77,34 @@ public class KeyRoleCommands(
|
|||
db.Update(guildConfig);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return await feedbackService.SendContextualAsync($"Added {role.Name} to this server's key roles!");
|
||||
return await feedbackService.SendContextualAsync(
|
||||
$"Added {role.Name} to this server's key roles!"
|
||||
);
|
||||
}
|
||||
|
||||
[Command("remove")]
|
||||
[Description("Remove a key role.")]
|
||||
public async Task<IResult> RemoveKeyRoleAsync(
|
||||
[Description("The role to remove.")] [DiscordTypeHint(TypeHint.Role)]
|
||||
Snowflake roleId)
|
||||
[Description("The role to remove.")] [DiscordTypeHint(TypeHint.Role)] Snowflake roleId
|
||||
)
|
||||
{
|
||||
var (_, guildId) = contextInjection.GetUserAndGuild();
|
||||
var role = roleCache.GuildRoles(guildId).FirstOrDefault(r => r.ID == roleId);
|
||||
if (role == null) throw new CataloggerError("Role is not cached");
|
||||
if (role == null)
|
||||
throw new CataloggerError("Role is not cached");
|
||||
|
||||
var guildConfig = await db.GetGuildAsync(guildId);
|
||||
if (guildConfig.KeyRoles.All(id => role.ID != id))
|
||||
return await feedbackService.SendContextualAsync($"{role.Name} is already not a key role.");
|
||||
return await feedbackService.SendContextualAsync(
|
||||
$"{role.Name} is already not a key role."
|
||||
);
|
||||
|
||||
guildConfig.KeyRoles.Remove(role.ID.Value);
|
||||
db.Update(guildConfig);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return await feedbackService.SendContextualAsync($"Removed {role.Name} from this server's key roles!");
|
||||
return await feedbackService.SendContextualAsync(
|
||||
$"Removed {role.Name} from this server's key roles!"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue