Added Group Role functionality for Add and Remove.

This commit is contained in:
Chris Darnell committed 2021-04-20 20:11:00 -07:00
1 parent cb5d2b7e85
commit aa79a30956
4 files changed
+39 -17

No files matched your search

+6 -11
View File
@@ -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"))
{
-3
View File
@@ -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;
+33
View File
@@ -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<string, Dictionary<string, int>> 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<string, int>();
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();
}
}
}
-3
View File
@@ -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;