diff --git a/StarsiegeBot/BotSettings.cs b/StarsiegeBot/BotSettings.cs index bfff479..e00d4a6 100644 --- a/StarsiegeBot/BotSettings.cs +++ b/StarsiegeBot/BotSettings.cs @@ -87,9 +87,6 @@ namespace StarsiegeBot public List Prefixes { get; set; } public Dictionary> SelfRoles { get; set; } public Dictionary> LevelRoles { get; set; } - public DiscordChannel WelcomeChannel { get; set; } - public bool useWelcomeMessage { get; set; } - public List HiddenRolesList { get; set; } public DiscordChannel WelcomeChannel { get; set; } public bool UseWelcome { get; set; } diff --git a/StarsiegeBot/EventTriggers.cs b/StarsiegeBot/EventTriggers.cs index a23723b..77b1bee 100644 --- a/StarsiegeBot/EventTriggers.cs +++ b/StarsiegeBot/EventTriggers.cs @@ -110,8 +110,6 @@ namespace StarsiegeBot public Task 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 ?? ""}' but it errored: {e.Exception.GetType()}: {e.Exception.Message ?? ""}", DateTime.Now); return Task.CompletedTask; } @@ -177,9 +175,7 @@ namespace StarsiegeBot string gId = e.Guild.Id.ToString(); // this guild doesnt have settings, make a skel set for them. if (BotSettings.GuildSettings is null) - { - - } + { } else { if (!BotSettings.GuildSettings.ContainsKey(gId)) @@ -251,13 +247,16 @@ namespace StarsiegeBot public Task GuildMemberAdded(DiscordClient d, GuildMemberAddEventArgs e) { d.Logger.LogDebug(BotEventId, $"GuildMemberAdded.{e.Guild.Name}"); + if (e.Member.IsBot) + { + return Task.CompletedTask; + } + string gId = e.Guild.Id.ToString(); if (BotSettings.GuildSettings[gId].UseWelcome) { if (BotSettings.GuildSettings[gId].WelcomeChannel is null) - { - - } + { } else { if (BotSettings.GuildSettings[gId].WelcomeMessage is null) @@ -269,7 +268,6 @@ namespace StarsiegeBot } } - return Task.CompletedTask; } public Task GuildMemberRemoved(DiscordClient d, GuildMemberRemoveEventArgs e) diff --git a/StarsiegeBot/Starsiege/DeathMessages.cs b/StarsiegeBot/Starsiege/DeathMessages.cs index be6da3f..fa2c5bf 100644 --- a/StarsiegeBot/Starsiege/DeathMessages.cs +++ b/StarsiegeBot/Starsiege/DeathMessages.cs @@ -26,7 +26,7 @@ namespace StarsiegeBot class DeathMessages : BaseCommandModule { private readonly Random rnd = new Random(); - private readonly DeathMessageLines dmLines; + private DeathMessageLines dmLines; private bool DeathMessagesEnabled; public DeathMessages() @@ -54,9 +54,35 @@ namespace StarsiegeBot } } + [Command("load")] + public async Task LoadDeathMessages(CommandContext ctx) + { + await ctx.TriggerTypingAsync(); + if (File.Exists("DeathMessages.json")) + { + // set some JSON text to blank. + var json = ""; + using (var fs = File.OpenRead("DeathMessages.json")) + using (var sr = new StreamReader(fs, new UTF8Encoding(false))) + json = sr.ReadToEnd(); + // Decode the JSON and set it to dmLines. + dmLines = JsonConvert.DeserializeObject(json); + // Enable all the commands. + DeathMessagesEnabled = true; + await ctx.RespondAsync("Loading Death Messages successul."); + } + else + { + // Echo out that we're missing a file. Disable the commands due to that. + await ctx.RespondAsync("Can't load Death Messages. File missing."); + DeathMessagesEnabled = false; + } + } + + [Command("toggle"), Aliases("t")] [RequireOwner] - public async Task ToggleQC(CommandContext ctx, [RemainingText] string isEnabled = null) + public async Task ToggleDM(CommandContext ctx, [RemainingText] string isEnabled = null) { await ctx.TriggerTypingAsync(); diff --git a/StarsiegeBot/Starsiege/Functions.cs b/StarsiegeBot/Starsiege/Functions.cs index ccb5568..ef76239 100644 --- a/StarsiegeBot/Starsiege/Functions.cs +++ b/StarsiegeBot/Starsiege/Functions.cs @@ -30,7 +30,7 @@ namespace StarsiegeBot DiscordColor.Rose, DiscordColor.SapGreen, DiscordColor.Sienna, DiscordColor.SpringGreen, DiscordColor.Teal, DiscordColor.Turquoise, DiscordColor.VeryDarkGray, DiscordColor.Violet, DiscordColor.Wheat, DiscordColor.White, DiscordColor.Yellow }; private readonly Random rnd = new Random(); - private readonly Dictionary ssFunctions; + private Dictionary ssFunctions; private bool FunctionsEnabled; public Functions() @@ -138,7 +138,7 @@ namespace StarsiegeBot [Command("toggle"), Aliases("t")] [RequireOwner] - public async Task ToggleQC(CommandContext ctx, [RemainingText] string isEnabled = null) + public async Task ToggleFunctions(CommandContext ctx, [RemainingText] string isEnabled = null) { await ctx.TriggerTypingAsync(); @@ -172,6 +172,29 @@ namespace StarsiegeBot } await ctx.RespondAsync(output); } + [Command("load"), RequireOwner] + public async Task LoadFunctions(CommandContext ctx) + { + await ctx.TriggerTypingAsync(); + + // Check for file, if not there, disable commands. + if (File.Exists("functions.json")) + { + // Load the Functions JSON file. Has all information regarding Starsiege in-game Functions. + var json = ""; + using (var fs = File.OpenRead("functions.json")) + using (var sr = new StreamReader(fs, new UTF8Encoding(false))) + json = sr.ReadToEnd(); + ssFunctions = JsonConvert.DeserializeObject>(json); + FunctionsEnabled = true; + await ctx.RespondAsync("Loading Quick Chats successul."); + } + else + { + FunctionsEnabled = false; + await ctx.RespondAsync("Loading Functions failed. File does not exist."); + } + } } public class SSFunction diff --git a/StarsiegeBot/Starsiege/Quickchat.cs b/StarsiegeBot/Starsiege/Quickchat.cs index fd4518b..fd8140f 100644 --- a/StarsiegeBot/Starsiege/Quickchat.cs +++ b/StarsiegeBot/Starsiege/Quickchat.cs @@ -22,7 +22,7 @@ namespace StarsiegeBot [Aliases("qc"), Group("quickchat")] class Quickchat : BaseCommandModule { - private readonly List Quickchats; + private List Quickchats; private readonly Random rnd = new Random(); private bool QuickChatsEnabled; @@ -51,6 +51,32 @@ namespace StarsiegeBot } } + [Command("load"), RequireOwner] + public async Task LoadQuickChats(CommandContext ctx) + { + await ctx.TriggerTypingAsync(); + if (File.Exists("quickchats.json")) + { + // Load the JSON file. + var json = ""; + using (var fs = File.OpenRead("quickchats.json")) + using (var sr = new StreamReader(fs, new UTF8Encoding(false))) + json = sr.ReadToEnd(); + Dictionary tempQC = JsonConvert.DeserializeObject>(json); + // set the Quick Chat object. + Quickchats = Enumerable.ToList(tempQC.Values); + // enable the commands. + QuickChatsEnabled = true; + await ctx.RespondAsync("Loading Quick Chats successul."); + } + else + { + QuickChatsEnabled = false; + await ctx.RespondAsync("Loading Quick Chats failed. File does not exist."); + } + } + + [Command("script")] [Description("Gives the `say()` for use in the Quickchat.cs file.")] public async Task GetQuickChatScript(CommandContext ctx, [Description("ID of Quick chat to get script for.")] int index) @@ -239,7 +265,6 @@ namespace StarsiegeBot QuickChatsEnabled = false; output = "QuickChats.json file is missing, and it can not be enabled."; } - await ctx.RespondAsync(output); } } diff --git a/StarsiegeBot/WelcomeMessage.cs b/StarsiegeBot/WelcomeMessage.cs index 048f3e2..3d62dc1 100644 --- a/StarsiegeBot/WelcomeMessage.cs +++ b/StarsiegeBot/WelcomeMessage.cs @@ -24,6 +24,7 @@ using System.Threading; namespace StarsiegeBot { [Group("welcome")] + [RequireGuild, RequirePermissions(Permissions.ManageChannels)] class WelcomeMessage : BotSettings { [Command("enable")] @@ -43,7 +44,7 @@ namespace StarsiegeBot await ctx.TriggerTypingAsync(); string gId = ctx.Guild.Id.ToString(); GuildSettings[gId].WelcomeChannel = ctx.Channel; - await ctx.RespondAsync("This channel is the welcome channle now!"); + await ctx.RespondAsync("This channel is the welcome channel now!"); } [Command("Message")] @@ -54,6 +55,5 @@ namespace StarsiegeBot GuildSettings[gId].WelcomeMessage = msg; await ctx.RespondAsync("welcome message set."); } - } }