From aa79a30956642752612f08e481f160498a31ce20 Mon Sep 17 00:00:00 2001 From: Chris Darnell Date: Tue, 20 Apr 2021 20:11:00 -0700 Subject: [PATCH] Added Group Role functionality for Add and Remove. --- StarsiegeBot/BotSettings.cs | 17 ++++++----------- StarsiegeBot/Commands.cs | 3 --- StarsiegeBot/GroupManagement.cs | 33 +++++++++++++++++++++++++++++++++ StarsiegeBot/Program.cs | 3 --- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/StarsiegeBot/BotSettings.cs b/StarsiegeBot/BotSettings.cs index fab7e33..a88de6c 100644 --- a/StarsiegeBot/BotSettings.cs +++ b/StarsiegeBot/BotSettings.cs @@ -1,24 +1,13 @@ using System; -using System.Diagnostics; using System.IO; using System.Threading.Tasks; using DSharpPlus.CommandsNext; using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; -using DSharpPlus.VoiceNext; using System.Text.RegularExpressions; -using System.Linq; using System.Collections.Generic; using Newtonsoft.Json; using System.Text; -using DSharpPlus; -using DSharpPlus.CommandsNext.Exceptions; -using DSharpPlus.EventArgs; -using DSharpPlus.VoiceNext.Codec; -using Microsoft.Extensions.Logging; -using DSharpPlus.Interactivity; -using DSharpPlus.Interactivity.Extensions; -using System.Threading; namespace StarsiegeBot { @@ -32,6 +21,12 @@ namespace StarsiegeBot public BotSettings() { Console.WriteLine("Bot Setting Commands Loaded"); + + if (!(GuildSettings is null)) + { + // guild settings have already been set... stop resetting it. + return; + } // Check for guild settings file. If it doesnt exist, create it. if (!File.Exists("guildSettings.json")) { diff --git a/StarsiegeBot/Commands.cs b/StarsiegeBot/Commands.cs index 1c4ede7..35c512b 100644 --- a/StarsiegeBot/Commands.cs +++ b/StarsiegeBot/Commands.cs @@ -1,11 +1,8 @@ using System; -using System.Diagnostics; -using System.IO; using System.Threading.Tasks; using DSharpPlus.CommandsNext; using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; -using DSharpPlus.VoiceNext; using System.Text.RegularExpressions; using System.Linq; diff --git a/StarsiegeBot/GroupManagement.cs b/StarsiegeBot/GroupManagement.cs index 11b5759..7f98213 100644 --- a/StarsiegeBot/GroupManagement.cs +++ b/StarsiegeBot/GroupManagement.cs @@ -34,12 +34,33 @@ namespace StarsiegeBot public async Task ListGroups(CommandContext ctx) { await ctx.TriggerTypingAsync(); + string gId = ctx.Guild.Id.ToString(); + DiscordEmbedBuilder embed = new DiscordEmbedBuilder(); + + embed.WithTitle($"{ctx.Guild.Name} Groups"); + embed.WithDescription("An overview of all role groups."); + foreach (KeyValuePair> item in GuildSettings[gId].SelfRoles) + { + embed.AddField(item.Key, item.Value.Count.ToString()); + } + await ctx.RespondAsync(embed); } [Command("add")] public async Task AddGroup(CommandContext ctx, [RemainingText] string groupName) { await ctx.TriggerTypingAsync(); + string gId = ctx.Guild.Id.ToString(); + if (GuildSettings[gId].SelfRoles.ContainsKey(groupName)) + { + await ctx.RespondAsync($"The group `{groupName}` already exists."); + } + else + { + var temp = new Dictionary(); + GuildSettings[gId].SelfRoles.Add(groupName, temp); + await ctx.RespondAsync($"The group `{groupName}` was added."); + } } // TODO: Delete all roles or assign new group? @@ -47,12 +68,24 @@ namespace StarsiegeBot public async Task RemoveGroup(CommandContext ctx, [RemainingText] string groupName) { await ctx.TriggerTypingAsync(); + string gId = ctx.Guild.Id.ToString(); + if (GuildSettings[gId].SelfRoles.ContainsKey(groupName)) + { + GuildSettings[gId].SelfRoles.Remove(groupName); + await ctx.RespondAsync($"Group `{groupName}` removed."); + } + else + { + await ctx.RespondAsync($"The group `{groupName}` doesn't exist."); + } } [Command("edit")] public async Task EditGroup(CommandContext ctx, [RemainingText] string groupInfo) { await ctx.TriggerTypingAsync(); + string gId = ctx.Guild.Id.ToString(); + } } } diff --git a/StarsiegeBot/Program.cs b/StarsiegeBot/Program.cs index 14f3899..272fe8b 100644 --- a/StarsiegeBot/Program.cs +++ b/StarsiegeBot/Program.cs @@ -2,19 +2,16 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; using DSharpPlus; using DSharpPlus.CommandsNext; -using DSharpPlus.CommandsNext.Exceptions; using DSharpPlus.Entities; using DSharpPlus.EventArgs; using DSharpPlus.Interactivity; using DSharpPlus.Interactivity.Enums; using DSharpPlus.Interactivity.Extensions; using DSharpPlus.VoiceNext; -using DSharpPlus.VoiceNext.Codec; using Microsoft.Extensions.Logging; using Newtonsoft.Json;