Merge branch 'main' of github.com:cmd276/DiscordBot into main
This commit is contained in:
commit
147c165e62
28 files changed
+1741
-1466
No files matched your search
@@ -1,21 +1,15 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.VoiceNext;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext.Exceptions;
|
||||
using DSharpPlus.EventArgs;
|
||||
using DSharpPlus.VoiceNext.Codec;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StarsiegeBot
|
||||
{
|
||||
@@ -27,17 +21,18 @@ namespace StarsiegeBot
|
||||
{
|
||||
private DeathMessageLines dmLines;
|
||||
private bool DeathMessagesEnabled;
|
||||
private static readonly string fileName = "Json/deathmessages.json";
|
||||
|
||||
public DeathMessages()
|
||||
{
|
||||
Console.WriteLine("Death Message Commands Loaded.");
|
||||
// If the DeathMessages file exists, load it. And enable the commands.
|
||||
// Otherwise disable all the commands.
|
||||
if (File.Exists("DeathMessages.json"))
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
// set some JSON text to blank.
|
||||
var json = "";
|
||||
using (var fs = File.OpenRead("DeathMessages.json"))
|
||||
using (var fs = File.OpenRead(fileName))
|
||||
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
|
||||
json = sr.ReadToEnd();
|
||||
// Decode the JSON and set it to dmLines.
|
||||
@@ -48,7 +43,7 @@ namespace StarsiegeBot
|
||||
else
|
||||
{
|
||||
// Echo out that we're missing a file. Disable the commands due to that.
|
||||
Console.WriteLine(" --- --- --- --- DeathMessages.json is missing");
|
||||
Console.WriteLine($" --- --- --- --- {fileName} is missing");
|
||||
DeathMessagesEnabled = false;
|
||||
}
|
||||
}
|
||||
@@ -58,11 +53,11 @@ namespace StarsiegeBot
|
||||
public async Task LoadDeathMessages(CommandContext ctx)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
if (File.Exists("DeathMessages.json"))
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
// set some JSON text to blank.
|
||||
var json = "";
|
||||
using (var fs = File.OpenRead("DeathMessages.json"))
|
||||
using (var fs = File.OpenRead(fileName))
|
||||
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
|
||||
json = sr.ReadToEnd();
|
||||
// Decode the JSON and set it to dmLines.
|
||||
@@ -92,7 +87,7 @@ namespace StarsiegeBot
|
||||
string[] turnOn = { "on", "true", "1" };
|
||||
string[] turnOff = { "off", "false", "0" };
|
||||
|
||||
if (File.Exists("DeathMessages.json"))
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
if (turnOn.Contains(isEnabled))
|
||||
{
|
||||
@@ -111,13 +106,13 @@ namespace StarsiegeBot
|
||||
else
|
||||
{
|
||||
DeathMessagesEnabled = false;
|
||||
output = "DeathMessages.json file is missing, and it can not be enabled.";
|
||||
output = $"{fileName} file is missing, and it can not be enabled.";
|
||||
}
|
||||
await ctx.RespondAsync(output);
|
||||
}
|
||||
|
||||
[GroupCommand]
|
||||
public async Task DeathMessage(CommandContext ctx, [Description("Optional. Person you want to see kill you. If blank, will show generic death message.")]DiscordMember target = null)
|
||||
public async Task DeathMessage(CommandContext ctx, [Description("Optional. Person you want to see kill you. If blank, will show generic death message.")] DiscordMember target = null)
|
||||
{
|
||||
// We're typing! (In all honesty, this is just used to avoid the 'async task not using await' messages I get.
|
||||
await ctx.TriggerTypingAsync();
|
||||
@@ -129,7 +124,7 @@ namespace StarsiegeBot
|
||||
await ctx.RespondAsync("Death Messages Commands have been disabled. Please contact the bot owners.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// set some basic output incase something goes south.
|
||||
string line = "Something went wrong.";
|
||||
// if there is no target, we're going to "kill" the author.
|
||||
@@ -182,7 +177,7 @@ namespace StarsiegeBot
|
||||
[Command("Add")]
|
||||
[Description("Adds a message to the Pending Death Message Queue. Generic Death Messages require just a [Killed] while any other death message requires both a [Killed] and a [Killer] tags. These will be replaced with the correct information in game, and in the usage of random DM generation.")]
|
||||
[Cooldown(1, 2, CooldownBucketType.Guild)]
|
||||
public async Task DeathMessageNew(CommandContext ctx, [RemainingText,Description("The Death Message you want added. See help section.")] string msg)
|
||||
public async Task DeathMessageNew(CommandContext ctx, [RemainingText, Description("The Death Message you want added. See help section.")] string msg)
|
||||
{
|
||||
// IF we're missing the Death Messages dot JSON file, we're going to get disabled... Check for that.
|
||||
// If disabled, let the person know the command set is disabled, and return.
|
||||
@@ -265,7 +260,7 @@ namespace StarsiegeBot
|
||||
// Tell DSharp that we want to upload this file.
|
||||
msg.WithFile("deathmessages.cs", sound);
|
||||
// Add some content so its not a blank file.
|
||||
msg.Content ="Here is your request for a death message script.";
|
||||
msg.Content = "Here is your request for a death message script.";
|
||||
// send that message.
|
||||
await ctx.RespondAsync(msg);
|
||||
// We're done with the file, so close access to it.
|
||||
@@ -275,7 +270,7 @@ namespace StarsiegeBot
|
||||
private async Task StoreDeathMessages()
|
||||
{
|
||||
string output = JsonConvert.SerializeObject(dmLines);
|
||||
await File.WriteAllTextAsync("DeathMessages.json", output);
|
||||
await File.WriteAllTextAsync(fileName, output);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.VoiceNext;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext.Exceptions;
|
||||
using DSharpPlus.EventArgs;
|
||||
using DSharpPlus.VoiceNext.Codec;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StarsiegeBot
|
||||
{
|
||||
@@ -24,17 +18,17 @@ namespace StarsiegeBot
|
||||
{
|
||||
private Dictionary<string, SSFunction> ssFunctions;
|
||||
private bool FunctionsEnabled;
|
||||
|
||||
private static readonly string fileName = "Json/functions.json";
|
||||
public Functions()
|
||||
{
|
||||
Console.WriteLine("Starsiege Function Commands Loaded");
|
||||
|
||||
// Check for file, if not there, disable commands.
|
||||
if (File.Exists("functions.json"))
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
// Load the Functions JSON file. Has all information regarding Starsiege in-game Functions.
|
||||
var json = "";
|
||||
using (var fs = File.OpenRead("functions.json"))
|
||||
using (var fs = File.OpenRead(fileName))
|
||||
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
|
||||
json = sr.ReadToEnd();
|
||||
ssFunctions = JsonConvert.DeserializeObject<Dictionary<string, SSFunction>>(json);
|
||||
@@ -141,7 +135,7 @@ namespace StarsiegeBot
|
||||
string[] turnOn = { "on", "true", "1" };
|
||||
string[] turnOff = { "off", "false", "0" };
|
||||
|
||||
if (File.Exists("functions.json"))
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
if (turnOn.Contains(isEnabled))
|
||||
{
|
||||
@@ -160,7 +154,7 @@ namespace StarsiegeBot
|
||||
else
|
||||
{
|
||||
FunctionsEnabled = false;
|
||||
output = "Functions.json file is missing, and it can not be enabled.";
|
||||
output = $"{fileName} file is missing, and it can not be enabled.";
|
||||
}
|
||||
await ctx.RespondAsync(output);
|
||||
}
|
||||
@@ -170,11 +164,11 @@ namespace StarsiegeBot
|
||||
await ctx.TriggerTypingAsync();
|
||||
|
||||
// Check for file, if not there, disable commands.
|
||||
if (File.Exists("functions.json"))
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
// Load the Functions JSON file. Has all information regarding Starsiege in-game Functions.
|
||||
var json = "";
|
||||
using (var fs = File.OpenRead("functions.json"))
|
||||
using (var fs = File.OpenRead(fileName))
|
||||
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
|
||||
json = sr.ReadToEnd();
|
||||
ssFunctions = JsonConvert.DeserializeObject<Dictionary<string, SSFunction>>(json);
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.VoiceNext;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext.Exceptions;
|
||||
using DSharpPlus.EventArgs;
|
||||
using DSharpPlus.VoiceNext.Codec;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StarsiegeBot
|
||||
{
|
||||
@@ -50,7 +40,7 @@ namespace StarsiegeBot
|
||||
}
|
||||
}
|
||||
[GroupCommand]
|
||||
public async Task Overview (CommandContext ctx)
|
||||
public async Task Overview(CommandContext ctx)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
Update();
|
||||
@@ -70,9 +60,9 @@ namespace StarsiegeBot
|
||||
Title = "Master|Game Server Overview",
|
||||
Description = "Number of Master, and Game servers. Along with number of errors."
|
||||
};
|
||||
embed.AddField("Masters", gameData.Masters.Length.ToString(),true);
|
||||
embed.AddField("Games", gameData.Games.Length.ToString(),true);
|
||||
embed.AddField("Errors", gameData.Errors.Length.ToString(),true);
|
||||
embed.AddField("Masters", gameData.Masters.Length.ToString(), true);
|
||||
embed.AddField("Games", gameData.Games.Length.ToString(), true);
|
||||
embed.AddField("Errors", gameData.Errors.Length.ToString(), true);
|
||||
await ctx.RespondAsync(embed);
|
||||
}
|
||||
|
||||
@@ -106,7 +96,7 @@ namespace StarsiegeBot
|
||||
|
||||
[Command("Masters"), Aliases("m")]
|
||||
[Description("Gives all the master servers as a script to be improted into `master.cs`.")]
|
||||
public async Task MasterServers (CommandContext ctx)
|
||||
public async Task MasterServers(CommandContext ctx)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
Update();
|
||||
@@ -137,7 +127,7 @@ namespace StarsiegeBot
|
||||
|
||||
[Command("games"), Aliases("g")]
|
||||
[Description("Currently: Lists games that have been started (Player dropped in). End Result: Lists all games that have a player in the server (either dropped in or not)")]
|
||||
public async Task GameServers(CommandContext ctx, [Description("Number of players you want to check for. Game servers will need at least this meaning or more to be listed.")]int playerCount = 1)
|
||||
public async Task GameServers(CommandContext ctx, [Description("Number of players you want to check for. Game servers will need at least this meaning or more to be listed.")] int playerCount = 1)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
Update();
|
||||
@@ -145,7 +135,7 @@ namespace StarsiegeBot
|
||||
// setup an exit point check.
|
||||
bool exit = false;
|
||||
// if its null, we're going to exit.
|
||||
if(gameData is null || gameData.Games is null)
|
||||
if (gameData is null || gameData.Games is null)
|
||||
{
|
||||
exit = true;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.VoiceNext;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext.Exceptions;
|
||||
using DSharpPlus.EventArgs;
|
||||
using DSharpPlus.VoiceNext.Codec;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StarsiegeBot
|
||||
{
|
||||
@@ -24,6 +18,8 @@ namespace StarsiegeBot
|
||||
{
|
||||
private Dictionary<string, Quickchat> quickchats;
|
||||
private bool IsEnabled;
|
||||
private readonly string fileName = "Json/quickchats.json";
|
||||
|
||||
|
||||
public QuickchatHandler()
|
||||
{
|
||||
@@ -38,13 +34,13 @@ namespace StarsiegeBot
|
||||
private bool LoadQuickChatsImpl()
|
||||
{
|
||||
// Check to see if the file exists...
|
||||
if (File.Exists("quickchats.json"))
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
// Load the JSON file.
|
||||
var json = "";
|
||||
using (var fs = File.OpenRead("quickchats.json"))
|
||||
using (var fs = File.OpenRead(fileName))
|
||||
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
|
||||
json = sr.ReadToEnd();
|
||||
json = sr.ReadToEnd();
|
||||
quickchats = JsonConvert.DeserializeObject<Dictionary<string, Quickchat>>(json);
|
||||
// enable the commands.
|
||||
return true;
|
||||
@@ -82,15 +78,13 @@ namespace StarsiegeBot
|
||||
[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)
|
||||
{
|
||||
// trigger some typing on discord's side.
|
||||
await ctx.TriggerTypingAsync();
|
||||
|
||||
// If we're disabled, let them know. And exit out.
|
||||
if (!IsEnabled)
|
||||
{
|
||||
await ctx.RespondAsync("Quick Chat Commands have been disabled. Please contact the bot owners.");
|
||||
return;
|
||||
}
|
||||
// trigger some typing on discord's side.
|
||||
await ctx.TriggerTypingAsync();
|
||||
|
||||
// We're good to go... If we have an index, pull it up.
|
||||
index = Math.Abs(index);
|
||||
@@ -194,7 +188,7 @@ namespace StarsiegeBot
|
||||
{
|
||||
// Open the file.
|
||||
FileStream sound = new FileStream($"./qc/{chat.soundFile}", FileMode.Open, FileAccess.Read);
|
||||
|
||||
|
||||
// feed it to the Message Builder.
|
||||
msg.WithFile(chat.soundFile, sound);
|
||||
}
|
||||
@@ -205,9 +199,9 @@ namespace StarsiegeBot
|
||||
}
|
||||
|
||||
[Command("search"), Aliases("s")]
|
||||
[Cooldown(1,5,CooldownBucketType.Global)]
|
||||
[Cooldown(1, 5, CooldownBucketType.Global)]
|
||||
[Description("Searches all the [T]ext and [S]ound file names for the Search input.")]
|
||||
public async Task SearchQuickChats(CommandContext ctx, [RemainingText,Description("What to search for.")] string toSearch)
|
||||
public async Task SearchQuickChats(CommandContext ctx, [RemainingText, Description("What to search for.")] string toSearch)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
string output;
|
||||
@@ -223,7 +217,7 @@ namespace StarsiegeBot
|
||||
StringBuilder sb = new StringBuilder();
|
||||
DiscordMessageBuilder msg = new DiscordMessageBuilder();
|
||||
int count = 0;
|
||||
|
||||
|
||||
// We're going to search each QC for the stuff in toSearch.
|
||||
foreach (KeyValuePair<string, Quickchat> qc in quickchats)
|
||||
{
|
||||
@@ -261,8 +255,8 @@ namespace StarsiegeBot
|
||||
|
||||
[Command("toggle"), Aliases("t")]
|
||||
[RequireOwner]
|
||||
[Description("[Owner only] Enables or disables, or checks status of QuickChats.")]
|
||||
public async Task ToggleQC (CommandContext ctx, [RemainingText] string isEnabled = null)
|
||||
[Description("[Owner only] Enables or disables, or checks status of QuickChats.\r\nTo turn the feature on, use `TRUE`, `ON`, or `1`\r\nTo turn off, use `FALSE`, `OFF`, or `0`")]
|
||||
public async Task ToggleQC(CommandContext ctx, [RemainingText] string isEnabled = null)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
isEnabled = isEnabled.ToLower();
|
||||
@@ -270,7 +264,7 @@ namespace StarsiegeBot
|
||||
string[] turnOn = { "on", "true", "1" };
|
||||
string[] turnOff = { "off", "false", "0" };
|
||||
|
||||
if (File.Exists("quickchats.json"))
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
if (turnOn.Contains(isEnabled))
|
||||
{
|
||||
@@ -281,12 +275,12 @@ namespace StarsiegeBot
|
||||
IsEnabled = false;
|
||||
}
|
||||
|
||||
output = $"Quickchats {(IsEnabled ? "Enabled":"Disabled")}";
|
||||
output = $"Quickchats {(IsEnabled ? "Enabled" : "Disabled")}";
|
||||
}
|
||||
else
|
||||
{
|
||||
IsEnabled = false;
|
||||
output = "QuickChats.json file is missing, and it can not be enabled.";
|
||||
output = $"{fileName} file is missing, and it can not be enabled.";
|
||||
}
|
||||
await ctx.RespondAsync(output);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user