Reworked NotFacts.cs to match Snapple.cs. Small refactor on GameCommands.cs
This commit is contained in:
1 parent
965b972e0c
commit
cf036c534f
4 files changed
+143
-84
No files matched your search
@@ -28,6 +28,7 @@ namespace StarsiegeBot
|
||||
Console.WriteLine("Basic Commands Loaded");
|
||||
InsultCopy = InsultMaster.ToList<string>();
|
||||
}
|
||||
|
||||
[Command("8ball"), Aliases(new String[] { "ball", "8" })]
|
||||
[Description("The Magic 8-Ball is a fortune-telling or seeking advice")]
|
||||
public async Task Eightball(CommandContext ctx, [RemainingText, Description("Your question to the 8 ball")] String remainingText = "")
|
||||
@@ -36,12 +37,7 @@ namespace StarsiegeBot
|
||||
// Load all the traditional 8-Ball answers into an array.
|
||||
string[] results = new string[] { "It is certain.", "It is decidedly so.", "Without a doubt.", "Yes - definitely.", "You may rely on it.", "As I see it, yes.", "Most likely.", "Outlook good.", "Yes.", "Signs point to yes.", "Reply hazy, try again", "Ask again later.", "Better not tell you now.", "Cannot predict now.", "Concentrate and ask again.", "Don't count on it.", "My reply is no.", "My sources say no", "Outlook not so good.", "Very doubtful." };
|
||||
// give the end user the randomly choosen result.
|
||||
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Description = results[Program.rnd.Next(0, results.Length)],
|
||||
Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
|
||||
};
|
||||
await ctx.RespondAsync(embed);
|
||||
await ctx.RespondAsync(StartEmbed(results[Program.rnd.Next(0, results.Length)]));
|
||||
}
|
||||
[Command("about")]
|
||||
[Description("Gives some basic info about the bot")]
|
||||
@@ -81,12 +77,7 @@ namespace StarsiegeBot
|
||||
// We're going to randomly select heads or tails and then give it to the user.
|
||||
await ctx.TriggerTypingAsync();
|
||||
string[] choices = { "heads", "tails" };
|
||||
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Description = "The coin landed on... " + choices[Program.rnd.Next(0, choices.Length)],
|
||||
Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
|
||||
};
|
||||
await ctx.RespondAsync(embed);
|
||||
await ctx.RespondAsync(StartEmbed($"The coin landed on... {choices[Program.rnd.Next(0, choices.Length)]}"));
|
||||
}
|
||||
[Command("credits")]
|
||||
[Description("Shows all those that have helped with my bot(s) over the years!")]
|
||||
@@ -196,24 +187,14 @@ namespace StarsiegeBot
|
||||
int i = Math.Min(min, max);
|
||||
int a = Math.Max(min, max) + 1;
|
||||
// output the results
|
||||
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Description = $"🎲 Your random number is: {Program.rnd.Next(i, a)}",
|
||||
Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
|
||||
};
|
||||
await ctx.RespondAsync(embed);
|
||||
await ctx.RespondAsync(StartEmbed($"🎲 Your random number is: {Program.rnd.Next(i, a)}"));
|
||||
}
|
||||
[Command("random")]
|
||||
public async Task Random(CommandContext ctx)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
// some one didn't read the HELP file on Random. Explain it to them.
|
||||
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Description = $"Gives you a random number between <Option 1> and <Option 2> Try someething like `random 3 30`!",
|
||||
Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
|
||||
};
|
||||
await ctx.RespondAsync(embed);
|
||||
await ctx.RespondAsync(StartEmbed($"Gives you a random number between <Option 1> and <Option 2> Try someething like `random 3 30`!"));
|
||||
}
|
||||
[Command("rps")]
|
||||
[Description("Rock Paper Scissors")]
|
||||
@@ -243,12 +224,7 @@ namespace StarsiegeBot
|
||||
result += " set of child proof scissors.";
|
||||
break;
|
||||
}
|
||||
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Description = result,
|
||||
Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
|
||||
};
|
||||
await ctx.RespondAsync(embed);
|
||||
await ctx.RespondAsync(StartEmbed(result));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -273,12 +249,7 @@ namespace StarsiegeBot
|
||||
{
|
||||
result = "Please pick a valid option! Options: " + String.Join(", ", choices);
|
||||
}
|
||||
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Description = result,
|
||||
Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
|
||||
};
|
||||
await ctx.RespondAsync(embed);
|
||||
await ctx.RespondAsync(StartEmbed(result));
|
||||
}
|
||||
}
|
||||
[Command("rpsls")]
|
||||
@@ -318,12 +289,7 @@ namespace StarsiegeBot
|
||||
break;
|
||||
}
|
||||
// tell the user we're giving them a thing.
|
||||
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Description = result,
|
||||
Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
|
||||
};
|
||||
await ctx.RespondAsync(embed);
|
||||
await ctx.RespondAsync(StartEmbed(result));
|
||||
}
|
||||
// the end user actually wants to throw down... Lets go!
|
||||
else
|
||||
@@ -361,12 +327,7 @@ namespace StarsiegeBot
|
||||
result = "Please pick a valid option! Options: " + String.Join(", ", choices);
|
||||
}
|
||||
// Actually send out all our info now.
|
||||
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Description = result,
|
||||
Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
|
||||
};
|
||||
await ctx.RespondAsync(embed);
|
||||
await ctx.RespondAsync(StartEmbed(result));
|
||||
}
|
||||
}
|
||||
[Command("say")]
|
||||
@@ -383,12 +344,7 @@ namespace StarsiegeBot
|
||||
result = msg;
|
||||
else
|
||||
result = "I need something to say...";
|
||||
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Description = result,
|
||||
Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
|
||||
};
|
||||
await ctx.RespondAsync(embed);
|
||||
await ctx.RespondAsync(StartEmbed(result));
|
||||
}
|
||||
[Command("slap")]
|
||||
public async Task Slap(CommandContext ctx, DiscordMember user = null)
|
||||
@@ -414,17 +370,23 @@ namespace StarsiegeBot
|
||||
// pick a random insult, and populate the names correctly.
|
||||
int randInt = Program.rnd.Next(0, InsultCopy.Count);
|
||||
|
||||
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Description = string.Format(InsultCopy[randInt], user1, user2),
|
||||
Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
|
||||
};
|
||||
await ctx.RespondAsync(embed);
|
||||
await ctx.RespondAsync(StartEmbed(string.Format(InsultCopy[randInt], user1, user2)));
|
||||
InsultCopy.RemoveAt(randInt);
|
||||
if (InsultCopy.Count == 0)
|
||||
{
|
||||
InsultCopy = InsultMaster.ToList<string>();
|
||||
}
|
||||
}
|
||||
|
||||
private DiscordEmbedBuilder StartEmbed(string desc)
|
||||
{
|
||||
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Description = desc,
|
||||
Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
|
||||
};
|
||||
return embed;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+106
-10
@@ -1,28 +1,34 @@
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace StarsiegeBot
|
||||
{
|
||||
[Group("notfact")]
|
||||
class NotFacts : BaseCommandModule
|
||||
{
|
||||
private readonly List<string> notfacts;
|
||||
private List<string> notfacts;
|
||||
private bool IsEnabled;
|
||||
private readonly string fileName = "notfacts.json";
|
||||
|
||||
public NotFacts()
|
||||
{
|
||||
Console.WriteLine("NotFacts Command Loaded");
|
||||
string json = File.ReadAllText("notfacts.json");
|
||||
notfacts = JsonConvert.DeserializeObject<List<string>>(json);
|
||||
IsEnabled = Load();
|
||||
}
|
||||
|
||||
[Command("notfact"), Description("Get a NotFact")]
|
||||
public async Task Snapplefact(CommandContext ctx, [Description("[Optional] A NotFact ID")] int notFactID = 0)
|
||||
[GroupCommand, Description("Get a NotFact")]
|
||||
public async Task NotFact(CommandContext ctx, [Description("[Optional] A NotFact ID")] int notFactID = 0)
|
||||
{
|
||||
if (!IsEnabled)
|
||||
return;
|
||||
await ctx.TriggerTypingAsync();
|
||||
|
||||
notFactID--;
|
||||
@@ -35,16 +41,106 @@ namespace StarsiegeBot
|
||||
{
|
||||
await ctx.RespondAsync(notfacts[Program.rnd.Next(0, notfacts.Count)]);
|
||||
}
|
||||
|
||||
// await ctx.RespondAsync("**Warning:** The Id's used here are arbitrary");
|
||||
}
|
||||
|
||||
[Command("notfactcount"), Description("Get a count of the NotFacts")]
|
||||
public async Task SnappleCount(CommandContext ctx)
|
||||
[Command("count"), Aliases("c"), Description("Get a count of the NotFacts")]
|
||||
public async Task NotFactCount(CommandContext ctx)
|
||||
{
|
||||
if (!IsEnabled)
|
||||
return;
|
||||
await ctx.TriggerTypingAsync();
|
||||
await ctx.RespondAsync(notfacts.Count + " NotFacts in the NotFacts Bank");
|
||||
await ctx.RespondAsync(StartEmbed(notfacts.Count + " NotFacts in the NotFacts Bank"));
|
||||
}
|
||||
|
||||
[Command("load"), RequireOwner, Aliases("l")]
|
||||
public async Task Load(CommandContext ctx)
|
||||
{
|
||||
// trigger the typing.
|
||||
await ctx.TriggerTypingAsync();
|
||||
// start the response.
|
||||
DiscordEmbedBuilder embed = StartEmbed("Reloading NotFacts");
|
||||
// our old setting...
|
||||
embed.AddField("Old", (IsEnabled ? "Enabled" : "Disabled"));
|
||||
// run this, we dont care about its actual results.
|
||||
_ = Load();
|
||||
// report our new setting.
|
||||
embed.AddField("New", (IsEnabled ? "Enabled" : "Disabled"));
|
||||
// since the only thing that *should* go wrong is a missing file, report it if thats the case.
|
||||
if (!File.Exists(fileName))
|
||||
embed.WithFooter($":warning: {fileName} file is missing.");
|
||||
// send our results.
|
||||
await ctx.RespondAsync(embed);
|
||||
}
|
||||
|
||||
[Command("toggle"), RequireOwner, Aliases("t")]
|
||||
public async Task Enable(CommandContext ctx, [RemainingText] string isEnabled = null)
|
||||
{
|
||||
// trigger the typing.
|
||||
await ctx.TriggerTypingAsync();
|
||||
// lower case teh input.
|
||||
isEnabled = isEnabled.ToLower();
|
||||
string[] turnOn = { "on", "true", "1" };
|
||||
string[] turnOff = { "off", "false", "0" };
|
||||
//start our response.
|
||||
DiscordEmbedBuilder embed = StartEmbed("NotFact Toggle");
|
||||
embed.AddField("Old", (IsEnabled ? "Enabled" : "Disabled"));
|
||||
// check for file.
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
// compare desired input against on or off values.
|
||||
if (turnOn.Contains(isEnabled))
|
||||
{
|
||||
IsEnabled = true;
|
||||
embed.AddField("New", (IsEnabled ? "Enabled" : "Disabled"));
|
||||
}
|
||||
else if (turnOff.Contains(isEnabled))
|
||||
{
|
||||
IsEnabled = false;
|
||||
embed.AddField("New", (IsEnabled ? "Enabled" : "Disabled"));
|
||||
}
|
||||
else
|
||||
{
|
||||
// we dont know what they were trying to do, throw an error in the footer with a :warning: emote.
|
||||
embed.AddField("New", (IsEnabled ? "Enabled" : "Disabled"));
|
||||
embed.WithFooter(":warning: Invalid command given?");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// file is missing, disable this, regardless of their desires. Report the file is missing in the footer with a :warning:
|
||||
IsEnabled = false;
|
||||
embed.AddField("New", (IsEnabled ? "Enabled" : "Disabled"));
|
||||
embed.WithFooter($":warning: {fileName} file is missing, and it can not be enabled.");
|
||||
}
|
||||
await ctx.RespondAsync(embed);
|
||||
}
|
||||
|
||||
|
||||
private DiscordEmbedBuilder StartEmbed(string desc)
|
||||
{
|
||||
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Description = desc,
|
||||
Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
|
||||
};
|
||||
return embed;
|
||||
}
|
||||
|
||||
private bool Load()
|
||||
{
|
||||
bool ret;
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
string json = File.ReadAllText(fileName);
|
||||
notfacts = JsonConvert.DeserializeObject<List<string>>(json);
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = false;
|
||||
}
|
||||
IsEnabled = ret;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ namespace StarsiegeBot
|
||||
{
|
||||
private List<string> facts;
|
||||
private bool IsEnabled;
|
||||
private readonly string fileName = "snapple.json";
|
||||
|
||||
public SnappleFacts()
|
||||
{
|
||||
@@ -74,8 +75,8 @@ namespace StarsiegeBot
|
||||
// report our new setting.
|
||||
embed.AddField("New", (IsEnabled ? "Enabled" : "Disabled"));
|
||||
// since the only thing that *should* go wrong is a missing file, report it if thats the case.
|
||||
if (!File.Exists("snapple.json"))
|
||||
embed.WithFooter(":warning: snapple.json file is missing.");
|
||||
if (!File.Exists(fileName))
|
||||
embed.WithFooter($":warning: {fileName} file is missing.");
|
||||
// send our results.
|
||||
await ctx.RespondAsync(embed);
|
||||
}
|
||||
@@ -93,7 +94,7 @@ namespace StarsiegeBot
|
||||
DiscordEmbedBuilder embed = StartEmbed("Snapple Toggle");
|
||||
embed.AddField("Old", (IsEnabled ? "Enabled" : "Disabled"));
|
||||
// check for file.
|
||||
if (File.Exists("snapple.json"))
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
// compare desired input against on or off values.
|
||||
if (turnOn.Contains(isEnabled))
|
||||
@@ -118,7 +119,7 @@ namespace StarsiegeBot
|
||||
// file is missing, disable this, regardless of their desires. Report the file is missing in the footer with a :warning:
|
||||
IsEnabled = false;
|
||||
embed.AddField("New", (IsEnabled ? "Enabled" : "Disabled"));
|
||||
embed.WithFooter(":warning: snapple.json file is missing, and it can not be enabled.");
|
||||
embed.WithFooter($":warning: {fileName} file is missing, and it can not be enabled.");
|
||||
}
|
||||
await ctx.RespondAsync(embed);
|
||||
}
|
||||
@@ -136,9 +137,9 @@ namespace StarsiegeBot
|
||||
private bool Load()
|
||||
{
|
||||
bool ret;
|
||||
if (File.Exists("snapple.json"))
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
string json = File.ReadAllText("snapple.json");
|
||||
string json = File.ReadAllText(fileName);
|
||||
facts = JsonConvert.DeserializeObject<List<string>>(json);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ namespace StarsiegeBot
|
||||
{
|
||||
private Dictionary<string, Quickchat> quickchats;
|
||||
private bool IsEnabled;
|
||||
private readonly string fileName = "quickchats.json";
|
||||
|
||||
|
||||
public QuickchatHandler()
|
||||
{
|
||||
@@ -32,11 +34,11 @@ 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();
|
||||
quickchats = JsonConvert.DeserializeObject<Dictionary<string, Quickchat>>(json);
|
||||
@@ -76,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);
|
||||
@@ -264,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))
|
||||
{
|
||||
@@ -280,7 +280,7 @@ namespace StarsiegeBot
|
||||
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