Added Group Role functionality for Add and Remove.
This commit is contained in:
1 parent
cb5d2b7e85
commit
aa79a30956
4 files changed
+39
-17
No files matched your search
@@ -1,24 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
using DSharpPlus.CommandsNext;
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
using DSharpPlus.CommandsNext.Attributes;
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.VoiceNext;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Linq;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Text;
|
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
|
namespace StarsiegeBot
|
||||||
{
|
{
|
||||||
@@ -32,6 +21,12 @@ namespace StarsiegeBot
|
|||||||
public BotSettings()
|
public BotSettings()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Bot Setting Commands Loaded");
|
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.
|
// Check for guild settings file. If it doesnt exist, create it.
|
||||||
if (!File.Exists("guildSettings.json"))
|
if (!File.Exists("guildSettings.json"))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
using DSharpPlus.CommandsNext;
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
using DSharpPlus.CommandsNext.Attributes;
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.VoiceNext;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
|
|||||||
@@ -34,12 +34,33 @@ namespace StarsiegeBot
|
|||||||
public async Task ListGroups(CommandContext ctx)
|
public async Task ListGroups(CommandContext ctx)
|
||||||
{
|
{
|
||||||
await ctx.TriggerTypingAsync();
|
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")]
|
[Command("add")]
|
||||||
public async Task AddGroup(CommandContext ctx, [RemainingText] string groupName)
|
public async Task AddGroup(CommandContext ctx, [RemainingText] string groupName)
|
||||||
{
|
{
|
||||||
await ctx.TriggerTypingAsync();
|
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?
|
// TODO: Delete all roles or assign new group?
|
||||||
@@ -47,12 +68,24 @@ namespace StarsiegeBot
|
|||||||
public async Task RemoveGroup(CommandContext ctx, [RemainingText] string groupName)
|
public async Task RemoveGroup(CommandContext ctx, [RemainingText] string groupName)
|
||||||
{
|
{
|
||||||
await ctx.TriggerTypingAsync();
|
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")]
|
[Command("edit")]
|
||||||
public async Task EditGroup(CommandContext ctx, [RemainingText] string groupInfo)
|
public async Task EditGroup(CommandContext ctx, [RemainingText] string groupInfo)
|
||||||
{
|
{
|
||||||
await ctx.TriggerTypingAsync();
|
await ctx.TriggerTypingAsync();
|
||||||
|
string gId = ctx.Guild.Id.ToString();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,19 +2,16 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus;
|
using DSharpPlus;
|
||||||
using DSharpPlus.CommandsNext;
|
using DSharpPlus.CommandsNext;
|
||||||
using DSharpPlus.CommandsNext.Exceptions;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.EventArgs;
|
using DSharpPlus.EventArgs;
|
||||||
using DSharpPlus.Interactivity;
|
using DSharpPlus.Interactivity;
|
||||||
using DSharpPlus.Interactivity.Enums;
|
using DSharpPlus.Interactivity.Enums;
|
||||||
using DSharpPlus.Interactivity.Extensions;
|
using DSharpPlus.Interactivity.Extensions;
|
||||||
using DSharpPlus.VoiceNext;
|
using DSharpPlus.VoiceNext;
|
||||||
using DSharpPlus.VoiceNext.Codec;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user