Merge branch 'main' of github.com:cmd276/DiscordBot into main

This commit is contained in:
Christopher Darnell committed 2021-05-02 14:42:13 -07:00
commit 147c165e62
28 files changed
+1741 -1466

No files matched your search

+23 -29
View File
@@ -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);
}