Added Load and Toggle sub commands to [DeathMessages|Functions|QuickChats] commands.
This commit is contained in:
1 parent
177a689989
commit
b2d6cff5ed
6 files changed
+89
-20
No files matched your search
@@ -87,9 +87,6 @@ namespace StarsiegeBot
|
||||
public List<String> Prefixes { get; set; }
|
||||
public Dictionary<string,Dictionary<string,int>> SelfRoles { get; set; }
|
||||
public Dictionary<int,List<DiscordRole>> LevelRoles { get; set; }
|
||||
public DiscordChannel WelcomeChannel { get; set; }
|
||||
public bool useWelcomeMessage { get; set; }
|
||||
|
||||
public List<DiscordRole> HiddenRolesList { get; set; }
|
||||
public DiscordChannel WelcomeChannel { get; set; }
|
||||
public bool UseWelcome { get; set; }
|
||||
|
||||
@@ -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 ?? "<unknown command>"}' but it errored: {e.Exception.GetType()}: {e.Exception.Message ?? "<no 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)
|
||||
|
||||
@@ -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<DeathMessageLines>(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();
|
||||
|
||||
|
||||
@@ -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<string, SSFunction> ssFunctions;
|
||||
private Dictionary<string, SSFunction> 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<Dictionary<string, SSFunction>>(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
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace StarsiegeBot
|
||||
[Aliases("qc"), Group("quickchat")]
|
||||
class Quickchat : BaseCommandModule
|
||||
{
|
||||
private readonly List<Quickchats> Quickchats;
|
||||
private List<Quickchats> 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<string, Quickchats> tempQC = JsonConvert.DeserializeObject<Dictionary<string, Quickchats>>(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user