Added commands for allowing bot to talk on specific channels.

This commit is contained in:
Chris Darnell committed 2021-05-09 08:36:27 -07:00
1 parent c8095f3ba6
commit c9bf08c230
1 file changed
+94 -9
+94 -9
View File
@@ -23,18 +23,92 @@ namespace StarsiegeBot
Console.WriteLine("Channel Management Module loaded."); Console.WriteLine("Channel Management Module loaded.");
} }
[Command("Allow")] [Group("allow")]
public async Task AllowChannels(CommandContext ctx, [Description("List of discord channels to allow the bot to respond on.")]params DiscordChannel[] discordChannels) class Allow
{
[Command("add")]
public async Task AddAllowedChannels(CommandContext ctx, [Description("List of discord channels to allow the bot to respond on.")] params DiscordChannel[] discordChannels)
{
string gId = ctx.Guild.Id.ToString();
// string output = "Added the following channel(s) to the allow list:";
string output = "";
foreach (DiscordChannel channel in discordChannels)
{ {
} GuildSettings[gId].AllowChannels.Add(channel.Id.ToString());
[Command("Allow")] if (!GuildSettings[gId].AllowChannels.Contains(channel.Id.ToString()))
public async Task AllowChannels(CommandContext ctx, string discordChannels = "")
{ {
if (output == "")
{
output = channel.Mention;
}
else
{
output += $", {channel.Mention}";
}
}
} }
[Command("deny")] if (output == "")
{
output = "There was an error adding your channel(s) to the allow list.";
}
else
{
output = "Added the following channel(s) to the allow list: " + output;
}
await ctx.RespondAsync(StartEmbed(output));
}
[Command("remove")]
public async Task RemoveAllowedChannel(CommandContext ctx, params DiscordChannel[] discordChannels)
{
string success = "";
string failed = "";
string output = "";
string gId = ctx.Guild.Id.ToString();
foreach (DiscordChannel channel in discordChannels)
{
string chanId = channel.Id.ToString();
if (GuildSettings[gId].AllowChannels.Remove(chanId))
{
if (success == "")
{
success = channel.Mention;
}
else
{
success += $", {channel.Mention}";
}
}
else
{
if (failed == "")
{
failed = channel.Mention;
}
else
{
failed += $", {channel.Mention}";
}
}
}
if (success != "")
{
output += "Successfully removed from allowed channel(s): " + success;
}
if (failed != "")
{
if (output != "") output += "\r\n";
output += "Failed to removed from allowed channel(s): " + failed;
}
await ctx.RespondAsync(StartEmbed(output));
}
}
[Group("deny")]
class Deny
{
[Command("add")]
public async Task DenyChannels(CommandContext ctx, params DiscordChannel[] discordChannels) public async Task DenyChannels(CommandContext ctx, params DiscordChannel[] discordChannels)
{ {
foreach (DiscordChannel chan in discordChannels) foreach (DiscordChannel chan in discordChannels)
@@ -42,10 +116,21 @@ namespace StarsiegeBot
Console.WriteLine(chan.Id.ToString()); Console.WriteLine(chan.Id.ToString());
} }
} }
}
[Command("deny")] [Command("deny")]
public async Task DenyChannels(CommandContext ctx, [Description("List of discord channels to deny the bot to respond on.")] string discordChannels = "")
private static DiscordEmbedBuilder StartEmbed(string desc)
{ {
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Description = desc,
Color = Program.colours[^2]
};
return embed;
}
} }
} }
}