Added global toggle [partially]. Need to fix removing global prefix when no Guild Prefix is defined.

This commit is contained in:
Christopher Darnell committed 2021-04-19 16:43:16 -07:00
1 parent 7a868c8ce8
commit cb75dc1f5a
2 files changed
+41 -21

No files matched your search

+14 -3
View File
@@ -22,7 +22,7 @@ using System.Threading;
namespace StarsiegeBot
{
[Group("ex")]
[Group("bot")]
class BotSettings : BaseCommandModule
{
public static Dictionary<string, GuildSettings> GuildSettings;
@@ -47,8 +47,10 @@ namespace StarsiegeBot
item.Prefixes.Add(">");
// this line... is a test line.
GuildSettings = new Dictionary<string, GuildSettings>();
GuildSettings.Add("default", item);
GuildSettings = new Dictionary<string, GuildSettings>
{
{ "default", item }
};
string output = JsonConvert.SerializeObject(GuildSettings);
File.WriteAllTextAsync("guildSettings.json", output);
@@ -108,6 +110,15 @@ namespace StarsiegeBot
GuildSettings.Remove(prefix);
await ctx.RespondAsync($"Removed `{prefix}` as a command prefix.");
}
[Command("global"), Aliases("g")]
public async Task UseGlobalPrefixes(CommandContext ctx, bool isEnabled)
{
await ctx.TriggerTypingAsync();
GuildSettings[ctx.Guild.Id.ToString()].UseGlobalPrefix = isEnabled;
await ctx.RespondAsync($"Global Prefix usage has been turned **{(isEnabled ? "on":"off")}**");
}
}
}
+27 -18
View File
@@ -184,7 +184,8 @@ namespace StarsiegeBot
//{
this.Commands.RegisterCommands<Quickchat>();
this.Commands.RegisterCommands<Functions>();
this.Commands.RegisterCommands<DeathMessages>();
this.Commands.RegisterCommands<DeathMessages>();
this.Commands.RegisterCommands<StarsiegeCommands>();
//}
Task thisTimer = StartTimer(new CancellationToken());
@@ -197,6 +198,7 @@ namespace StarsiegeBot
// and this is to prevent premature quitting
await Task.Delay(-1);
}
private Task Event_MessageCreated(DiscordClient d, MessageCreateEventArgs e)
{
d.Logger.LogDebug(BotEventId, "Event_MessageCreated.");
@@ -276,11 +278,11 @@ namespace StarsiegeBot
return Task.CompletedTask;
}
private async Task Event_CommandErrored(CommandsNextExtension ext, CommandErrorEventArgs e)
private Task Event_CommandErrored(CommandsNextExtension ext, CommandErrorEventArgs e)
{
// let's log the error details
e.Context.Client.Logger.LogError(BotEventId, $"{e.Context.User.Username} tried executing '{e.Command?.QualifiedName ?? "<unknown command>"}' but it errored: {e.Exception.GetType()}: {e.Exception.Message ?? "<no message>"}", DateTime.Now);
return Task.CompletedTask;
}
private Task Event_InteractionCreated(DiscordClient d, InteractionCreateEventArgs e)
@@ -343,22 +345,29 @@ namespace StarsiegeBot
{
string gId = e.Guild.Id.ToString();
// this guild doesnt have settings, make a skel set for them.
if (!BotSettings.GuildSettings.ContainsKey(gId))
if (BotSettings.GuildSettings is null)
{
Console.WriteLine("making config");
GuildSettings item = new GuildSettings();
item.UseAutoRoles = false;
item.UseGlobalPrefix = true;
item.UseLevelRoles = false;
item.UseLevels = false;
item.UseSelfRoles = false;
item.AllowRolesPurchase = false;
item.UseAutoRoles = false;
item.LevelRoles = new Dictionary<string, int>();
item.Prefixes = new List<string>();
item.SelfRoles = new Dictionary<string, int>();
// this line... is a test line.
BotSettings.GuildSettings.Add(gId, item);
}
else
{
if (!BotSettings.GuildSettings.ContainsKey(gId))
{
Console.WriteLine("making config");
GuildSettings item = new GuildSettings();
item.UseAutoRoles = false;
item.UseGlobalPrefix = true;
item.UseLevelRoles = false;
item.UseLevels = false;
item.UseSelfRoles = false;
item.AllowRolesPurchase = false;
item.UseAutoRoles = false;
item.LevelRoles = new Dictionary<string, int>();
item.Prefixes = new List<string>();
item.SelfRoles = new Dictionary<string, int>();
// this line... is a test line.
BotSettings.GuildSettings.Add(gId, item);
}
}
// let's log the name of the guild that was just