Added global toggle [partially]. Need to fix removing global prefix when no Guild Prefix is defined.
This commit is contained in:
1 parent
7a868c8ce8
commit
cb75dc1f5a
2 files changed
+41
-21
No files matched your search
@@ -22,7 +22,7 @@ using System.Threading;
|
|||||||
|
|
||||||
namespace StarsiegeBot
|
namespace StarsiegeBot
|
||||||
{
|
{
|
||||||
[Group("ex")]
|
[Group("bot")]
|
||||||
class BotSettings : BaseCommandModule
|
class BotSettings : BaseCommandModule
|
||||||
{
|
{
|
||||||
public static Dictionary<string, GuildSettings> GuildSettings;
|
public static Dictionary<string, GuildSettings> GuildSettings;
|
||||||
@@ -47,8 +47,10 @@ namespace StarsiegeBot
|
|||||||
item.Prefixes.Add(">");
|
item.Prefixes.Add(">");
|
||||||
// this line... is a test line.
|
// this line... is a test line.
|
||||||
|
|
||||||
GuildSettings = new Dictionary<string, GuildSettings>();
|
GuildSettings = new Dictionary<string, GuildSettings>
|
||||||
GuildSettings.Add("default", item);
|
{
|
||||||
|
{ "default", item }
|
||||||
|
};
|
||||||
|
|
||||||
string output = JsonConvert.SerializeObject(GuildSettings);
|
string output = JsonConvert.SerializeObject(GuildSettings);
|
||||||
File.WriteAllTextAsync("guildSettings.json", output);
|
File.WriteAllTextAsync("guildSettings.json", output);
|
||||||
@@ -108,6 +110,15 @@ namespace StarsiegeBot
|
|||||||
GuildSettings.Remove(prefix);
|
GuildSettings.Remove(prefix);
|
||||||
await ctx.RespondAsync($"Removed `{prefix}` as a command 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
@@ -184,7 +184,8 @@ namespace StarsiegeBot
|
|||||||
//{
|
//{
|
||||||
this.Commands.RegisterCommands<Quickchat>();
|
this.Commands.RegisterCommands<Quickchat>();
|
||||||
this.Commands.RegisterCommands<Functions>();
|
this.Commands.RegisterCommands<Functions>();
|
||||||
this.Commands.RegisterCommands<DeathMessages>();
|
this.Commands.RegisterCommands<DeathMessages>();
|
||||||
|
this.Commands.RegisterCommands<StarsiegeCommands>();
|
||||||
//}
|
//}
|
||||||
Task thisTimer = StartTimer(new CancellationToken());
|
Task thisTimer = StartTimer(new CancellationToken());
|
||||||
|
|
||||||
@@ -197,6 +198,7 @@ namespace StarsiegeBot
|
|||||||
// and this is to prevent premature quitting
|
// and this is to prevent premature quitting
|
||||||
await Task.Delay(-1);
|
await Task.Delay(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task Event_MessageCreated(DiscordClient d, MessageCreateEventArgs e)
|
private Task Event_MessageCreated(DiscordClient d, MessageCreateEventArgs e)
|
||||||
{
|
{
|
||||||
d.Logger.LogDebug(BotEventId, "Event_MessageCreated.");
|
d.Logger.LogDebug(BotEventId, "Event_MessageCreated.");
|
||||||
@@ -276,11 +278,11 @@ namespace StarsiegeBot
|
|||||||
return Task.CompletedTask;
|
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
|
// 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);
|
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)
|
private Task Event_InteractionCreated(DiscordClient d, InteractionCreateEventArgs e)
|
||||||
@@ -343,22 +345,29 @@ namespace StarsiegeBot
|
|||||||
{
|
{
|
||||||
string gId = e.Guild.Id.ToString();
|
string gId = e.Guild.Id.ToString();
|
||||||
// this guild doesnt have settings, make a skel set for them.
|
// 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;
|
else
|
||||||
item.UseGlobalPrefix = true;
|
{
|
||||||
item.UseLevelRoles = false;
|
if (!BotSettings.GuildSettings.ContainsKey(gId))
|
||||||
item.UseLevels = false;
|
{
|
||||||
item.UseSelfRoles = false;
|
Console.WriteLine("making config");
|
||||||
item.AllowRolesPurchase = false;
|
GuildSettings item = new GuildSettings();
|
||||||
item.UseAutoRoles = false;
|
item.UseAutoRoles = false;
|
||||||
item.LevelRoles = new Dictionary<string, int>();
|
item.UseGlobalPrefix = true;
|
||||||
item.Prefixes = new List<string>();
|
item.UseLevelRoles = false;
|
||||||
item.SelfRoles = new Dictionary<string, int>();
|
item.UseLevels = false;
|
||||||
// this line... is a test line.
|
item.UseSelfRoles = false;
|
||||||
BotSettings.GuildSettings.Add(gId, item);
|
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
|
// let's log the name of the guild that was just
|
||||||
|
|||||||
Reference in new issue
Block a user