Removed extra spaces. Removed double \r\n across all code files.
This commit is contained in:
1 parent
91d6d1531b
commit
5bb1b43e81
19 files changed
+68
-389
No files matched your search
@@ -10,19 +10,16 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StarsiegeBot
|
||||
{
|
||||
|
||||
[Group("deathmessage"), Aliases("dm")]
|
||||
[Description("Gives a random death message. Or interacts with the death messages.")]
|
||||
[Cooldown(1, 2, CooldownBucketType.Guild)]
|
||||
class DeathMessages : BaseCommandModule
|
||||
{
|
||||
private DeathMessageLines _dmLines;
|
||||
private bool _deathMessagesEnabled;
|
||||
private bool _isEnabled;
|
||||
private static readonly string s_fileName = "Json/deathmessages.json";
|
||||
|
||||
public DeathMessages()
|
||||
{
|
||||
Console.WriteLine("Death Message Commands Loaded.");
|
||||
@@ -38,21 +35,19 @@ namespace StarsiegeBot
|
||||
// Decode the JSON and set it to dmLines.
|
||||
_dmLines = JsonConvert.DeserializeObject<DeathMessageLines>(json);
|
||||
// Enable all the commands.
|
||||
_deathMessagesEnabled = true;
|
||||
_isEnabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Echo out that we're missing a file. Disable the commands due to that.
|
||||
Console.WriteLine($" --- --- --- --- {s_fileName} is missing");
|
||||
_deathMessagesEnabled = false;
|
||||
_isEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
[Command("load")]
|
||||
[RequireOwner]
|
||||
public async Task LoadDeathMessages(CommandContext ctx)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
if (File.Exists(s_fileName))
|
||||
{
|
||||
// set some JSON text to blank.
|
||||
@@ -63,68 +58,56 @@ namespace StarsiegeBot
|
||||
// Decode the JSON and set it to dmLines.
|
||||
_dmLines = JsonConvert.DeserializeObject<DeathMessageLines>(json);
|
||||
// Enable all the commands.
|
||||
_deathMessagesEnabled = true;
|
||||
_isEnabled = 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;
|
||||
_isEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
[Command("toggle"), Aliases("t")]
|
||||
[RequireOwner]
|
||||
public async Task ToggleDM(CommandContext ctx, [RemainingText] string isEnabled = null)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
|
||||
isEnabled = isEnabled.ToLower();
|
||||
|
||||
string output;
|
||||
|
||||
string[] turnOn = { "on", "true", "1" };
|
||||
string[] turnOff = { "off", "false", "0" };
|
||||
|
||||
if (File.Exists(s_fileName))
|
||||
{
|
||||
if (turnOn.Contains(isEnabled))
|
||||
{
|
||||
_deathMessagesEnabled = true;
|
||||
_isEnabled = true;
|
||||
}
|
||||
else if (turnOff.Contains(isEnabled))
|
||||
{
|
||||
_deathMessagesEnabled = false;
|
||||
_isEnabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
output = $"DeathMessages Enabled: {_deathMessagesEnabled}";
|
||||
output = $"DeathMessages Enabled: {_isEnabled}";
|
||||
}
|
||||
else
|
||||
{
|
||||
_deathMessagesEnabled = false;
|
||||
_isEnabled = false;
|
||||
output = $"{s_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)
|
||||
{
|
||||
// We're typing! (In all honesty, this is just used to avoid the 'async task not using await' messages I get.
|
||||
await ctx.TriggerTypingAsync();
|
||||
|
||||
// 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.
|
||||
if (!_deathMessagesEnabled)
|
||||
if (!_isEnabled)
|
||||
{
|
||||
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.
|
||||
@@ -156,24 +139,21 @@ namespace StarsiegeBot
|
||||
await ctx.RespondAsync(string.Format(line, ctx.Message.Author.Mention, target.Mention));
|
||||
}
|
||||
}
|
||||
|
||||
[Command("inventory"), Aliases("count")]
|
||||
[Description("Gets the total of each type of death message")]
|
||||
public async Task DeathMessageCount(CommandContext ctx)
|
||||
{
|
||||
// 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.
|
||||
if (!_deathMessagesEnabled)
|
||||
if (!_isEnabled)
|
||||
{
|
||||
await ctx.RespondAsync("Death Messages Commands have been disabled. Please contact the bot owners.");
|
||||
return;
|
||||
}
|
||||
// We're typing here!
|
||||
await ctx.TriggerTypingAsync();
|
||||
// List all the types of Death Message types, and how many we have of each one.
|
||||
await ctx.RespondAsync($"\r\nActive: {_dmLines.Active.Length}\r\nPassive: {_dmLines.Passive.Length}\r\nGeneric: {_dmLines.Generic.Length}");
|
||||
}
|
||||
|
||||
[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)]
|
||||
@@ -181,15 +161,13 @@ namespace StarsiegeBot
|
||||
{
|
||||
// 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.
|
||||
if (!_deathMessagesEnabled)
|
||||
if (!_isEnabled)
|
||||
{
|
||||
await ctx.RespondAsync("Death Messages Commands have been disabled. Please contact the bot owners.");
|
||||
return;
|
||||
}
|
||||
// Let Discord know we're typing.
|
||||
await ctx.TriggerTypingAsync();
|
||||
// Message the owner know some one wants to add a new death message, along with a code block to that message.
|
||||
|
||||
// if the Queue is null, make it exist.
|
||||
if (_dmLines.Queue is null)
|
||||
_dmLines.Queue = new List<string>();
|
||||
@@ -200,34 +178,28 @@ namespace StarsiegeBot
|
||||
// Tell the person that the message has been added to a 'queue'.
|
||||
await ctx.RespondAsync("Your request has been added to the pending queue of requests.");
|
||||
}
|
||||
|
||||
[Command("script")]
|
||||
[Description("Gets a script file for all the death messages on the bot.")]
|
||||
public async Task DeathMessagesScript(CommandContext ctx)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
// 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.
|
||||
if (!_deathMessagesEnabled)
|
||||
if (!_isEnabled)
|
||||
{
|
||||
await ctx.RespondAsync("Death Messages Commands have been disabled. Please contact the bot owners.");
|
||||
return;
|
||||
}
|
||||
|
||||
// If this file exists... We could do one of two things. Delete it and remake it, or serve it up.
|
||||
if (File.Exists("deathmessages.cs"))
|
||||
{
|
||||
File.Delete("deathmessages.cs");
|
||||
}
|
||||
|
||||
// We're going to remake it. Open it.
|
||||
// We're going to remake it. Open it.
|
||||
using StreamWriter file = new StreamWriter("deathmessages.cs");
|
||||
|
||||
// Write out the total lines for each. Requirement for Starsiege.
|
||||
await file.WriteLineAsync($"$deathMessage::genericCount = {_dmLines.Generic.Length};");
|
||||
await file.WriteLineAsync($"$deathMessage::activeCount = {_dmLines.Active.Length};");
|
||||
await file.WriteLineAsync($"$deathMessage::passiveCount = {_dmLines.Passive.Length};\r\n");
|
||||
|
||||
// Set count to 0. Iterate over each type of Death Message, and put it into the file.
|
||||
int count = 0;
|
||||
foreach (string death in _dmLines.Generic)
|
||||
@@ -249,10 +221,8 @@ namespace StarsiegeBot
|
||||
await file.WriteLineAsync(string.Format($"$deathMessage::passive{count} = \"{death}\";", "%s", "%s"));
|
||||
count++;
|
||||
}
|
||||
|
||||
// We're done writing to it... So close the file.
|
||||
file.Close();
|
||||
|
||||
// We're going to Message Build the response.
|
||||
DiscordMessageBuilder msg = new DiscordMessageBuilder();
|
||||
// Open the file to upload.
|
||||
@@ -266,7 +236,6 @@ namespace StarsiegeBot
|
||||
// We're done with the file, so close access to it.
|
||||
sound.Close();
|
||||
}
|
||||
|
||||
private async Task StoreDeathMessages()
|
||||
{
|
||||
string output = JsonConvert.SerializeObject(_dmLines);
|
||||
|
||||
Reference in new issue
Block a user