Apply merge and resolve conflicts from upstream

This commit is contained in:
Amrit Panesar committed 2021-04-29 05:45:41 -07:00
commit 59c9e34ea3
11 files changed
+434 -270

No files matched your search

+6 -1
View File
@@ -1 +1,6 @@
# DiscordBot # DiscordBot
## Setup
The bot tokens
-2
View File
@@ -18,8 +18,6 @@ namespace StarsiegeBot
class BotSettings : BaseCommandModule class BotSettings : BaseCommandModule
{ {
public static Dictionary<string, GuildSettings> GuildSettings; public static Dictionary<string, GuildSettings> GuildSettings;
public BotSettings() public BotSettings()
{ {
Console.WriteLine("Bot Setting Commands Loaded"); Console.WriteLine("Bot Setting Commands Loaded");
+230 -180
View File
@@ -6,43 +6,109 @@ using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities; using DSharpPlus.Entities;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Linq; using System.Linq;
using System.Collections.Generic;
namespace StarsiegeBot namespace StarsiegeBot
{ {
class Commands : BaseCommandModule class Commands : BaseCommandModule
{ {
// this class depends a lot on the random stuff. so make it class level. // Master insult list.
private readonly Random rnd = new Random(); private readonly string[] InsultMaster = {
"{0} slaps {1} around a bit with a large trout.",
// start: neo wanted this shit.... "{0} puts a jellyfish on {1}'s head.",
private readonly string[] insult = { "{0} slaps {1} around a bit with the mustache of Caanon.",
"> {0} slaps {1} around a bit with a large trout.", "{0} slaps {1} around a bit with a questionable rubber object.",
"> {0} puts a jellyfish on {1}'s head.", "{0} slaps {1} around a bit with a rubber chicken."
"> {0} slaps {1} around a bit with the mustache of Caanon.",
"> {0} slaps {1} around a bit with a questionable rubber object.",
"> {0} slaps {1} around a bit with a rubber chicken."
}; };
private uint insultIndex; private List<string> InsultCopy;
public string Insult {
get {
if (insultIndex >= insult.Length) {
insultIndex = 0;
}
return insult[insultIndex++ % insult.Length];
}
}
// end: neo's shit.
public Commands() public Commands()
{ {
// Let the console know we've loaded basic commands. // Let the console know we've loaded basic commands.
Console.WriteLine("Basic Commands Loaded"); 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 = "")
{
await ctx.TriggerTypingAsync();
// 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);
}
[Command("about")]
[Description("Gives some basic info about the bot")]
public async Task About(CommandContext ctx)
{
await ctx.TriggerTypingAsync();
// delcare an embed builder.
DiscordEmbedBuilder embed = new DiscordEmbedBuilder();
// Title the ebemd with the bot's name and discrim.
embed.WithTitle("About " + ctx.Client.CurrentUser.Username + "#" + ctx.Client.CurrentUser.Discriminator);
// add the bot's avatar as the Thumbnail.
embed.WithThumbnail(ctx.Client.CurrentUser.GetAvatarUrl(DSharpPlus.ImageFormat.Png, 32));
// Add a bit of color... the color from the member's top most role.
embed.WithColor(ctx.Member.Color);
// output various data abotu the bot.
embed.AddField("D#+ Ver", ctx.Client.VersionString, true);
embed.AddField("Guild Count", ctx.Client.Guilds.Count.ToString(), true);
embed.AddField("Ping", ctx.Client.Ping.ToString(), true);
embed.AddField("Shard Count", ctx.Client.ShardCount.ToString(), true);
embed.AddField("Shard", ctx.Client.ShardId.ToString(), true);
embed.Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)];
// list all the owners of the bot.
string owners = "";
foreach (DiscordUser owner in ctx.Client.CurrentApplication.Owners)
{
owners += owner.Username + "#" + owner.Discriminator + "\r\n";
}
embed.AddField("Owner(s)", owners, false);
// send the data to the end user.
await ctx.RespondAsync(embed);
}
[Command("coin")]
[Description("Flips a coin for ya!")]
public async Task Coinflip(CommandContext ctx)
{
// 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);
}
[Command("credits")]
[Description("Shows all those that have helped with my bot(s) over the years!")]
public async Task Credits(CommandContext ctx)
{
await ctx.TriggerTypingAsync();
// just some people that have helped me build the bot.
string credits = "```asciidoc\r\n= CREDITS (Outdated) =\r\n" +
"• UndeadShadow :: Flood Protection. Keepign teh bot from killing itself, and others.\r\n" +
"• Da_D_Master :: For giving me my start in my first couple bots, and being a friendly rival.\r\n" +
"• ThinkExist & Bored.com :: Quotes for the Quote Database\r\n" +
"• Hanibal, TaMeD, Liquid- :: For awlays proving the points of others.\r\n" +
"• Neo :: For all their hard work on all the things I've ever asked about.\r\n" +
"• Alias :: For helping me learn how to make IRC bots back in the day.\r\n" +
"• Drake, Eledore :: Supporting the development of the bot and supplying code for it.\r\n" +
"\r\n```";
await ctx.RespondAsync(credits);
}
[Command("dice"), Aliases("r", "d", "roll")] [Command("dice"), Aliases("r", "d", "roll")]
[Description("A classic dice throwing command. Limited to 1 use per 2 seconds. Format: <NumberOfDice>d<SidesOnDie> ")] [Description("A classic dice throwing command. Limited to 1 use per 2 seconds. Format: <NumberOfDice>d<SidesOnDie> ")]
[Cooldown(1, 2, CooldownBucketType.Guild)] [Cooldown(1, 2, CooldownBucketType.Guild)]
public async Task Dice(CommandContext ctx, [RemainingText,Description("XdY")] String throwing = "d") public async Task Dice(CommandContext ctx, [RemainingText, Description("XdY")] String throwing = "d")
{ {
// let the end user know the bot is doing something... // let the end user know the bot is doing something...
await ctx.TriggerTypingAsync(); await ctx.TriggerTypingAsync();
@@ -84,7 +150,7 @@ namespace StarsiegeBot
// this is the result. // this is the result.
// This line looks weird, I know, so here is what is going on. If the number of sides is negative, we adjust for that. // This line looks weird, I know, so here is what is going on. If the number of sides is negative, we adjust for that.
// since the rnd.Next is inclusive, exclusive, we have to adjust for that. // since the rnd.Next is inclusive, exclusive, we have to adjust for that.
int roll = rnd.Next(Math.Min(1, sides), Math.Max(sides + 1, 0)); int roll = Program.rnd.Next(Math.Min(1, sides), Math.Max(sides + 1, 0));
// do we have our first result? No, make it! Store the results in a string to show the end user. // do we have our first result? No, make it! Store the results in a string to show the end user.
if (dieResults.Equals(String.Empty)) if (dieResults.Equals(String.Empty))
dieResults = roll.ToString(); dieResults = roll.ToString();
@@ -95,7 +161,7 @@ namespace StarsiegeBot
dieResult += roll; dieResult += roll;
} }
// If the end user is rolling more than 10 of any kind of die, dont show the results of the rolls. Just // If the end user is rolling more than 10 of any kind of die, dont show the results of the rolls. Just
if(volume < 11) if (volume < 11)
dieResults = $"{volume}d{sides}: Total: " + dieResult + " Avg: " + Math.Round(dieResult * 1.0 / volume, 2) + " Results: " + dieResults; dieResults = $"{volume}d{sides}: Total: " + dieResult + " Avg: " + Math.Round(dieResult * 1.0 / volume, 2) + " Results: " + dieResults;
else else
dieResults = $"{volume}d{sides}: Total: " + dieResult + " Avg: " + Math.Round(dieResult * 1.0 / volume, 2); dieResults = $"{volume}d{sides}: Total: " + dieResult + " Avg: " + Math.Round(dieResult * 1.0 / volume, 2);
@@ -108,6 +174,17 @@ namespace StarsiegeBot
else else
await ctx.RespondAsync(overallResults); await ctx.RespondAsync(overallResults);
} }
[Command("guilds"),Hidden,RequireOwner]
public async Task GimmeServerNames (CommandContext ctx)
{
string output = "";
foreach (KeyValuePair<ulong,DiscordGuild> item in ctx.Client.Guilds)
{
output += item.Value.Name + "\r\n";
}
await ctx.RespondAsync(output);
}
[Command("random")] [Command("random")]
[Description("Random number generator.")] [Description("Random number generator.")]
@@ -119,53 +196,91 @@ namespace StarsiegeBot
int i = Math.Min(min, max); int i = Math.Min(min, max);
int a = Math.Max(min, max) + 1; int a = Math.Max(min, max) + 1;
// output the results // output the results
await ctx.RespondAsync($"🎲 Your random number is: {rnd.Next(i, a)}"); 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);
} }
[Command("random")] [Command("random")]
public async Task Random(CommandContext ctx) public async Task Random(CommandContext ctx)
{ {
await ctx.TriggerTypingAsync(); await ctx.TriggerTypingAsync();
// some one didn't read the HELP file on Random. Explain it to them. // some one didn't read the HELP file on Random. Explain it to them.
await ctx.RespondAsync($"Gives you a random number between <Option 1> and <Option 2> Try someething like `random 3 30`!"); DiscordEmbedBuilder embed = new DiscordEmbedBuilder
}
[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 = "")
{
await ctx.TriggerTypingAsync();
// 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.
await ctx.RespondAsync(results[rnd.Next(0, results.Length)]);
}
[Command("slap")]
public async Task Slap(CommandContext ctx, DiscordMember user = null)
{
await ctx.TriggerTypingAsync();
// we're going to find out who we're slapping. Declare their place holders now.
string user1;
string user2;
// If we have some one not slapping some one, or they're trying to slap themself, the one getting slapped is the
// author, the one doing the slapping is the bot.
if (user == null || user.Mention == ctx.Message.Author.Mention)
{ {
user1 = ctx.Client.CurrentUser.Mention; Description = $"Gives you a random number between <Option 1> and <Option 2> Try someething like `random 3 30`!",
user2 = ctx.Message.Author.Mention; Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
};
await ctx.RespondAsync(embed);
}
[Command("rps")]
[Description("Rock Paper Scissors")]
public async Task Rps(CommandContext ctx, [RemainingText, Description("Your choice of hand sign to use.")] string text = "")
{
await ctx.TriggerTypingAsync();
/* --- THIS FUNCTION IS A COPY AND PASTE OF RPSLS. AND ALL LOGIC IS IDENTICAL TO IT. PLEASE REFER TO THAT METHOD. ---
// --- THIS FUNCTION IS A COPY AND PASTE OF RPSLS. AND ALL LOGIC IS IDENTICAL TO IT. PLEASE REFER TO THAT METHOD. ---
// --- THIS FUNCTION IS A COPY AND PASTE OF RPSLS. AND ALL LOGIC IS IDENTICAL TO IT. PLEASE REFER TO THAT METHOD. --- */
string[] choices = new string[] { "rock", "paper", "scissors" };
text = text.ToLower();
string botChoice = choices[Program.rnd.Next(0, choices.Length)];
string result;
if (text.Equals(""))
{
result = "I'm handing you a";
switch (botChoice)
{
case "rock":
result += " shiny rock.";
break;
case "paper":
result += " crumpled paper.";
break;
case "scissors":
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);
} }
// We're attempting to slap user that isn't the author... Lets do it!
else else
{ {
user1 = ctx.Message.Author.Mention; if (choices.Contains(text))
user2 = user.Mention; {
if (((botChoice == "scissors") && (text == "paper")) ||
((botChoice == "paper") && (text == "rock")) ||
((botChoice == "rock") && (text == "scissors")))
{
result = $"{botChoice} beats {text}. I'm sorry about this.";
}
else if (text.Equals(botChoice))
{
result = $"We both picked {text}, looks like we drew, go again?";
}
else
{
result = $"{text} beats {botChoice}. **YOU WIN!!**";
}
}
else
{
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);
} }
// pick a random insult, and populate the names correctly.
await ctx.RespondAsync(string.Format(Insult, user1, user2));
} }
[Command("rpsls")] [Command("rpsls")]
[Description("Rock Paper Scissors Lizard Spock")] [Description("Rock Paper Scissors Lizard Spock")]
public async Task Rpsls(CommandContext ctx, [RemainingText, Description("Your choice of hand sign to use.")] string text = "") public async Task Rpsls(CommandContext ctx, [RemainingText, Description("Your choice of hand sign to use.")] string text = "")
@@ -176,7 +291,7 @@ namespace StarsiegeBot
// lets work in all lower case letters. makes life easier. // lets work in all lower case letters. makes life easier.
text = text.ToLower(); text = text.ToLower();
// make a choice for the bot. // make a choice for the bot.
string botChoice = choices[rnd.Next(0, choices.Length)]; string botChoice = choices[Program.rnd.Next(0, choices.Length)];
// create a result string. // create a result string.
string result; string result;
@@ -203,7 +318,12 @@ namespace StarsiegeBot
break; break;
} }
// tell the user we're giving them a thing. // tell the user we're giving them a thing.
await ctx.RespondAsync(result); DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Description = result,
Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
};
await ctx.RespondAsync(embed);
} }
// the end user actually wants to throw down... Lets go! // the end user actually wants to throw down... Lets go!
else else
@@ -241,127 +361,14 @@ namespace StarsiegeBot
result = "Please pick a valid option! Options: " + String.Join(", ", choices); result = "Please pick a valid option! Options: " + String.Join(", ", choices);
} }
// Actually send out all our info now. // Actually send out all our info now.
await ctx.RespondAsync(result); DiscordEmbedBuilder embed = new DiscordEmbedBuilder
}
}
[Command("rps")]
[Description("Rock Paper Scissors")]
public async Task Rps(CommandContext ctx, [RemainingText, Description("Your choice of hand sign to use.")] string text = "")
{
await ctx.TriggerTypingAsync();
/* --- THIS FUNCTION IS A COPY AND PASTE OF RPSLS. AND ALL LOGIC IS IDENTICAL TO IT. PLEASE REFER TO THAT METHOD. ---
// --- THIS FUNCTION IS A COPY AND PASTE OF RPSLS. AND ALL LOGIC IS IDENTICAL TO IT. PLEASE REFER TO THAT METHOD. ---
// --- THIS FUNCTION IS A COPY AND PASTE OF RPSLS. AND ALL LOGIC IS IDENTICAL TO IT. PLEASE REFER TO THAT METHOD. --- */
string[] choices = new string[] { "rock", "paper", "scissors" };
text = text.ToLower();
string botChoice = choices[rnd.Next(0, choices.Length)];
string result;
if (text.Equals(""))
{
result = "I'm handing you a";
switch (botChoice)
{ {
case "rock": Description = result,
result += " shiny rock."; Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]
break; };
case "paper": await ctx.RespondAsync(embed);
result += " crumpled paper.";
break;
case "scissors":
result += " set of child proof scissors.";
break;
}
await ctx.RespondAsync(result);
}
else
{
if (choices.Contains(text))
{
if (((botChoice == "scissors") && (text == "paper")) ||
((botChoice == "paper") && (text == "rock")) ||
((botChoice == "rock") && (text == "scissors")))
{
result = $"{botChoice} beats {text}. I'm sorry about this.";
}
else if (text.Equals(botChoice))
{
result = $"We both picked {text}, looks like we drew, go again?";
}
else
{
result = $"{text} beats {botChoice}. **YOU WIN!!**";
}
}
else
{
result = "Please pick a valid option! Options: " + String.Join(", ", choices);
}
await ctx.RespondAsync(result);
} }
} }
[Command("about")]
[Description("Gives some basic info about the bot")]
public async Task About(CommandContext ctx)
{
await ctx.TriggerTypingAsync();
// delcare an embed builder.
DiscordEmbedBuilder embed = new DiscordEmbedBuilder();
// Title the ebemd with the bot's name and discrim.
embed.WithTitle("About " + ctx.Client.CurrentUser.Username + "#" + ctx.Client.CurrentUser.Discriminator);
// add the bot's avatar as the Thumbnail.
embed.WithThumbnail(ctx.Client.CurrentUser.GetAvatarUrl(DSharpPlus.ImageFormat.Png, 32));
// Add a bit of color... the color from the member's top most role.
embed.WithColor(ctx.Member.Color);
// output various data abotu the bot.
embed.AddField("D#+ Ver", ctx.Client.VersionString, true);
embed.AddField("Guild Count", ctx.Client.Guilds.Count.ToString(), true);
embed.AddField("Ping", ctx.Client.Ping.ToString(), true);
embed.AddField("Shard Count", ctx.Client.ShardCount.ToString(), true);
embed.AddField("Shard", ctx.Client.ShardId.ToString(), true);
// list all the owners of the bot.
string owners = "";
foreach (DiscordUser owner in ctx.Client.CurrentApplication.Owners)
{
owners += owner.Username + "#" + owner.Discriminator+"\r\n";
}
embed.AddField("Owner(s)", owners, false);
// send the data to the end user.
await ctx.RespondAsync(embed);
}
[Command("credits")]
[Description("Shows all those that have helped with my bot(s) over the years!")]
public async Task Credits(CommandContext ctx)
{
await ctx.TriggerTypingAsync();
// just some people that have helped me build the bot.
string credits = "```asciidoc\r\n= CREDITS (Outdated) =\r\n" +
"• UndeadShadow :: Flood Protection. Keepign teh bot from killing itself, and others.\r\n" +
"• Da_D_Master :: For giving me my start in my first couple bots, and being a friendly rival.\r\n" +
"• ThinkExist & Bored.com :: Quotes for the Quote Database\r\n" +
"• Hanibal, TaMeD, Liquid- :: For always proving the points of others.\r\n" +
"• Neo :: For all their hard work on all the things I've ever asked about.\r\n" +
"• Alias :: For helping me learn how to make IRC bots back in the day.\r\n" +
"• Drake, Eledore :: Supporting the development of the bot and supplying code for it.\r\n" +
"\r\n```";
await ctx.RespondAsync(credits);
}
[Command("coin")]
[Description("Flips a coin for ya!")]
public async Task Coinflip(CommandContext ctx)
{
// We're going to randomly select heads or tails and then give it to the user.
await ctx.TriggerTypingAsync();
string[] choices = { "heads", "tails" };
await ctx.RespondAsync("The coin landed on... " + choices[rnd.Next(0, choices.Length)]);
}
[Command("say")] [Command("say")]
[Description("Make the bot say something, perhaps silly?!")] [Description("Make the bot say something, perhaps silly?!")]
public async Task MsgSay(CommandContext ctx, [RemainingText, Description("The stuff you want the bot to say.")] string msg = "") public async Task MsgSay(CommandContext ctx, [RemainingText, Description("The stuff you want the bot to say.")] string msg = "")
@@ -371,10 +378,53 @@ namespace StarsiegeBot
return; return;
await ctx.TriggerTypingAsync(); await ctx.TriggerTypingAsync();
// did the end user supply us something to say? no whine about it. // did the end user supply us something to say? no whine about it.
string result;
if (msg != "") if (msg != "")
await ctx.RespondAsync(msg); result = msg;
else else
await ctx.RespondAsync("I need something to say..."); 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);
}
[Command("slap")]
public async Task Slap(CommandContext ctx, DiscordMember user = null)
{
await ctx.TriggerTypingAsync();
// we're going to find out who we're slapping. Declare their place holders now.
string user1;
string user2;
// If we have some one not slapping some one, or they're trying to slap themself, the one getting slapped is the
// author, the one doing the slapping is the bot.
if (user == null || user.Mention == ctx.Message.Author.Mention)
{
user1 = ctx.Client.CurrentUser.Mention;
user2 = ctx.Message.Author.Mention;
}
// We're attempting to slap user that isn't the author... Lets do it!
else
{
user1 = ctx.Message.Author.Mention;
user2 = user.Mention;
}
// 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);
InsultCopy.RemoveAt(randInt);
if (InsultCopy.Count == 0)
{
InsultCopy = InsultMaster.ToList<string>();
}
} }
} }
} }
+30 -42
View File
@@ -58,16 +58,11 @@ namespace StarsiegeBot
// Check if message has valid prefix. // Check if message has valid prefix.
// json file loaded... // json file loaded...
int cmdStart = msg.GetStringPrefixLength("!"); int cmdStart = msg.GetStringPrefixLength("!");
List<string> prefixes = BotSettings.GuildSettings["default"].Prefixes;
// if Guild is null, do nothing for now. prefixes.Add(d.CurrentUser.Mention);
if (e.Guild is null) if (!(e.Guild is null))
{
}
else
{ {
string gId = e.Guild.Id.ToString(); string gId = e.Guild.Id.ToString();
List<string> prefixes = BotSettings.GuildSettings["default"].Prefixes;
// Check to see if the guild has settings. // Check to see if the guild has settings.
if (BotSettings.GuildSettings.ContainsKey(gId)) if (BotSettings.GuildSettings.ContainsKey(gId))
{ {
@@ -83,27 +78,25 @@ namespace StarsiegeBot
prefixes = BotSettings.GuildSettings[gId].Prefixes; prefixes = BotSettings.GuildSettings[gId].Prefixes;
} }
} }
// check each prefix. break on the one that is evoked.
foreach (string item in prefixes)
{
cmdStart = msg.GetStringPrefixLength(item);
if (cmdStart != -1) break;
}
// we didn't find a command prefix... Break.
if (cmdStart == -1) return Task.CompletedTask;
// Retrieve prefix.
var prefix = msg.Content.Substring(0, cmdStart);
var cmdString = msg.Content[cmdStart..];
// Retrieve full command string.
var command = cnext.FindCommand(cmdString, out var args);
if (command == null) return Task.CompletedTask;
var ctx = cnext.CreateContext(msg, prefix, command, args);
Task.Run(async () => await cnext.ExecuteCommandAsync(ctx));
} }
foreach (string item in prefixes)
{
cmdStart = msg.GetStringPrefixLength(item);
if (cmdStart != -1) break;
}
// we didn't find a command prefix... Break.
if (cmdStart == -1) return Task.CompletedTask;
// Retrieve prefix.
var prefix = msg.Content.Substring(0, cmdStart);
var cmdString = msg.Content[cmdStart..];
// Retrieve full command string.
var command = cnext.FindCommand(cmdString, out var args);
if (command == null) return Task.CompletedTask;
var ctx = cnext.CreateContext(msg, prefix, command, args);
Task.Run(async () => await cnext.ExecuteCommandAsync(ctx));
return Task.CompletedTask; return Task.CompletedTask;
} }
@@ -231,7 +224,9 @@ namespace StarsiegeBot
public Task GuildDownloadCompleted(DiscordClient d, GuildDownloadCompletedEventArgs e) public Task GuildDownloadCompleted(DiscordClient d, GuildDownloadCompletedEventArgs e)
{ {
d.Logger.LogDebug(BotEventId, "GuildDownloadCompleted."); d.Logger.LogDebug(BotEventId, "GuildDownloadCompleted.");
notify = e.Guilds[376937422010974209].Members[139548200099905536]; //if(e.Guilds[376937422010974209].Members.ContainsKey(139548200099905536))
//notify = e.Guilds[376937422010974209].Members[139548200099905536];
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task GuildEmojisUpdated(DiscordClient d, GuildEmojisUpdateEventArgs e) public Task GuildEmojisUpdated(DiscordClient d, GuildEmojisUpdateEventArgs e)
@@ -246,26 +241,19 @@ namespace StarsiegeBot
} }
public Task GuildMemberAdded(DiscordClient d, GuildMemberAddEventArgs e) public Task GuildMemberAdded(DiscordClient d, GuildMemberAddEventArgs e)
{ {
d.Logger.LogDebug(BotEventId, $"GuildMemberAdded.{e.Guild.Name}"); d.Logger.LogDebug(BotEventId, $"GuildMemberAdded.");
if (e.Member.IsBot) if (e.Member.IsBot)
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }
string gId = e.Guild.Id.ToString(); string gId = e.Guild.Id.ToString();
if (BotSettings.GuildSettings[gId].UseWelcome) if (BotSettings.GuildSettings[gId].UseWelcome &&
!(BotSettings.GuildSettings[gId].WelcomeChannel is null) &&
!(BotSettings.GuildSettings[gId].WelcomeMessage is null))
{ {
if (BotSettings.GuildSettings[gId].WelcomeChannel is null) string msg = WelcomeMessage.WelcomeMessageProcessing(BotSettings.GuildSettings[gId].WelcomeMessage, e.Member, e.Guild);
{ } BotSettings.GuildSettings[gId].WelcomeChannel.SendMessageAsync(msg);
else
{
if (BotSettings.GuildSettings[gId].WelcomeMessage is null)
{ }
else
{
BotSettings.GuildSettings[gId].WelcomeChannel.SendMessageAsync(BotSettings.GuildSettings[gId].WelcomeMessage);
}
}
} }
return Task.CompletedTask; return Task.CompletedTask;
+20 -13
View File
@@ -20,12 +20,19 @@ namespace StarsiegeBot
class Program class Program
{ {
public readonly EventId BotEventId; public readonly EventId BotEventId;
public static Triggers Events; public static Triggers Events;
public static readonly DiscordColor[] colours = { DiscordColor.Aquamarine, DiscordColor.Azure, DiscordColor.Black, DiscordColor.Blue, DiscordColor.Blurple,
DiscordColor.Brown, DiscordColor.Chartreuse, DiscordColor.CornflowerBlue, DiscordColor.Cyan, DiscordColor.DarkBlue, DiscordColor.DarkButNotBlack,
DiscordColor.DarkGray, DiscordColor.DarkGreen, DiscordColor.DarkRed, DiscordColor.Gold, DiscordColor.Goldenrod, DiscordColor.Gray, DiscordColor.Grayple,
DiscordColor.Green, DiscordColor.HotPink, DiscordColor.IndianRed, DiscordColor.LightGray, DiscordColor.Lilac, DiscordColor.Magenta, DiscordColor.MidnightBlue,
DiscordColor.None, DiscordColor.NotQuiteBlack, DiscordColor.Orange, DiscordColor.PhthaloBlue, DiscordColor.PhthaloGreen, DiscordColor.Purple, DiscordColor.Red,
DiscordColor.Rose, DiscordColor.SapGreen, DiscordColor.Sienna, DiscordColor.SpringGreen, DiscordColor.Teal, DiscordColor.Turquoise, DiscordColor.VeryDarkGray,
DiscordColor.Violet, DiscordColor.Wheat, DiscordColor.White, DiscordColor.Yellow };
public static readonly Random rnd = new Random();
public DiscordClient Client { get; set; } public DiscordClient Client { get; set; }
public CommandsNextExtension Commands { get; set; } public CommandsNextExtension Commands { get; set; }
public VoiceNextExtension Voice { get; set; } public VoiceNextExtension Voice { get; set; }
protected string BotName { get; set; } protected string BotName { get; set; }
private async Task StartTimer(CancellationToken cancellationToken) private async Task StartTimer(CancellationToken cancellationToken)
@@ -62,7 +69,7 @@ namespace StarsiegeBot
if (args.Length > 0) if (args.Length > 0)
BotName = args[0].ToLower(); BotName = args[0].ToLower();
else else
BotName = "ssp"; BotName = "sspdev";
BotEventId = new EventId(276, BotName); BotEventId = new EventId(276, BotName);
Events = new Triggers(BotEventId); Events = new Triggers(BotEventId);
@@ -114,17 +121,17 @@ namespace StarsiegeBot
this.Commands = this.Client.UseCommandsNext(ccfg); this.Commands = this.Client.UseCommandsNext(ccfg);
// up next, let's register our commands // up next, let's register our commands
this.Commands.RegisterCommands<Commands>();
this.Commands.RegisterCommands<BotSettings>(); // Main Folder. Test Items. this.Commands.RegisterCommands<BotSettings>(); // Main Folder. Test Items.
this.Commands.RegisterCommands<WelcomeMessage>(); // Main Folder. Test Items. this.Commands.RegisterCommands<Commands>();
this.Commands.RegisterCommands<GroupManagement>(); // Main Folder. Test Items.
this.Commands.RegisterCommands<GroupRoleManagement>(); // Main Folder. Test Items.
this.Commands.RegisterCommands<LevelManagement>(); // Main Folder. Test Items.
this.Commands.RegisterCommands<LevelRoleManagement>(); // Main Folder. Test Items.
this.Commands.RegisterCommands<PrefixManagement>(); this.Commands.RegisterCommands<PrefixManagement>();
// this.Commands.RegisterCommands<SnappleFacts>(); this.Commands.RegisterCommands<RoleManagement>(); // Main Folder. Test Items.
// this.Commands.RegisterCommands<RoleManagement>(); // Main Folder. Test Items. this.Commands.RegisterCommands<SnappleFacts>();
// this.Commands.RegisterCommands<LevelRoleManagement>(); // Main Folder. Test Items. this.Commands.RegisterCommands<StarsiegeCommands>();
// this.Commands.RegisterCommands<GroupRoleManagement>(); // Main Folder. Test Items. this.Commands.RegisterCommands<WelcomeMessage>(); // Main Folder. Test Items.
// this.Commands.RegisterCommands<LevelManagement>(); // Main Folder. Test Items.
// this.Commands.RegisterCommands<GroupManagement>(); // Main Folder. Test Items.
// this.Commands.RegisterCommands<StarsiegeCommands>();
// All these commands are in the STARSIEGE folder. // All these commands are in the STARSIEGE folder.
//if (BotName.Contains("ssp")) //if (BotName.Contains("ssp"))
+2 -3
View File
@@ -8,8 +8,7 @@ namespace StarsiegeBot
{ {
class SnappleFacts : BaseCommandModule class SnappleFacts : BaseCommandModule
{ {
private string[] facts; private readonly string[] facts;
private Random rnd = new Random();
[Command("snapple"), Description("Get a Snapple \"Real Fact\".")] [Command("snapple"), Description("Get a Snapple \"Real Fact\".")]
public async Task Snapplefact(CommandContext ctx, [Description("[Optional] A Snapple Fact ID")]int snapId = -1) public async Task Snapplefact(CommandContext ctx, [Description("[Optional] A Snapple Fact ID")]int snapId = -1)
@@ -17,7 +16,7 @@ namespace StarsiegeBot
if (snapId == -1) if (snapId == -1)
{ {
await ctx.TriggerTypingAsync(); await ctx.TriggerTypingAsync();
await ctx.RespondAsync(facts[rnd.Next(0, facts.Length)]); await ctx.RespondAsync(facts[Program.rnd.Next(0, facts.Length)]);
} }
else else
{ {
+4 -5
View File
@@ -25,7 +25,6 @@ namespace StarsiegeBot
[Cooldown(1, 2, CooldownBucketType.Guild)] [Cooldown(1, 2, CooldownBucketType.Guild)]
class DeathMessages : BaseCommandModule class DeathMessages : BaseCommandModule
{ {
private readonly Random rnd = new Random();
private DeathMessageLines dmLines; private DeathMessageLines dmLines;
private bool DeathMessagesEnabled; private bool DeathMessagesEnabled;
@@ -136,7 +135,7 @@ namespace StarsiegeBot
// if there is no target, we're going to "kill" the author. // if there is no target, we're going to "kill" the author.
if (target == null) if (target == null)
{ {
int choice = rnd.Next(0, dmLines.Generic.Length); int choice = Program.rnd.Next(0, dmLines.Generic.Length);
line = dmLines.Generic[choice]; line = dmLines.Generic[choice];
await ctx.RespondAsync(string.Format(line, ctx.Message.Author.Mention)); await ctx.RespondAsync(string.Format(line, ctx.Message.Author.Mention));
} }
@@ -144,18 +143,18 @@ namespace StarsiegeBot
else else
{ {
// Pick a death message type at random. // Pick a death message type at random.
int opt = rnd.Next(1, 3); int opt = Program.rnd.Next(1, 3);
// If we picked active death messages... // If we picked active death messages...
if (opt == 1) if (opt == 1)
{ {
// Pick an Active death message at random, and set our output to it. // Pick an Active death message at random, and set our output to it.
int choice = rnd.Next(0, dmLines.Active.Length); int choice = Program.rnd.Next(0, dmLines.Active.Length);
line = dmLines.Active[choice]; line = dmLines.Active[choice];
} }
else if (opt == 2) else if (opt == 2)
{ {
// We picked a Passive death message type. Pick the exact line at random. Set it to the output. // We picked a Passive death message type. Pick the exact line at random. Set it to the output.
int choice = rnd.Next(0, dmLines.Passive.Length); int choice = Program.rnd.Next(0, dmLines.Passive.Length);
line = dmLines.Passive[choice]; line = dmLines.Passive[choice];
} }
// Give the selected death message to the user. // Give the selected death message to the user.
+1 -9
View File
@@ -22,14 +22,6 @@ namespace StarsiegeBot
[Group("functions"), Aliases("func")] [Group("functions"), Aliases("func")]
class Functions : BaseCommandModule class Functions : BaseCommandModule
{ {
private readonly DiscordColor[] colours = { DiscordColor.Aquamarine, DiscordColor.Azure, DiscordColor.Black, DiscordColor.Blue, DiscordColor.Blurple,
DiscordColor.Brown, DiscordColor.Chartreuse, DiscordColor.CornflowerBlue, DiscordColor.Cyan, DiscordColor.DarkBlue, DiscordColor.DarkButNotBlack,
DiscordColor.DarkGray, DiscordColor.DarkGreen, DiscordColor.DarkRed, DiscordColor.Gold, DiscordColor.Goldenrod, DiscordColor.Gray, DiscordColor.Grayple,
DiscordColor.Green, DiscordColor.HotPink, DiscordColor.IndianRed, DiscordColor.LightGray, DiscordColor.Lilac, DiscordColor.Magenta, DiscordColor.MidnightBlue,
DiscordColor.None, DiscordColor.NotQuiteBlack, DiscordColor.Orange, DiscordColor.PhthaloBlue, DiscordColor.PhthaloGreen, DiscordColor.Purple, DiscordColor.Red,
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 Dictionary<string, SSFunction> ssFunctions; private Dictionary<string, SSFunction> ssFunctions;
private bool FunctionsEnabled; private bool FunctionsEnabled;
@@ -101,7 +93,7 @@ namespace StarsiegeBot
// set the timestamp to now... why, idk, its not really needed actually. // set the timestamp to now... why, idk, its not really needed actually.
embed.WithTimestamp(DateTime.Now); embed.WithTimestamp(DateTime.Now);
// add a random color to the left side bar of the embed. // add a random color to the left side bar of the embed.
embed.WithColor(colours[rnd.Next(0, colours.Length)]); embed.WithColor(Program.colours[Program.rnd.Next(0, Program.colours.Length)]);
// Message Description, I dont remember what it is any more, sorry! // Message Description, I dont remember what it is any more, sorry!
embed.WithDescription(outItem.description); embed.WithDescription(outItem.description);
// iterate over each field item, and add them to the embed. // iterate over each field item, and add them to the embed.
+13 -7
View File
@@ -65,9 +65,11 @@ namespace StarsiegeBot
{ {
return; return;
} }
DiscordEmbedBuilder embed = new DiscordEmbedBuilder(); DiscordEmbedBuilder embed = new DiscordEmbedBuilder
embed.Title = "Master|Game Server Overview"; {
embed.Description = "Number of Master, and Game servers. Along with number of errors."; 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("Masters", gameData.Masters.Length.ToString(),true);
embed.AddField("Games", gameData.Games.Length.ToString(),true); embed.AddField("Games", gameData.Games.Length.ToString(),true);
embed.AddField("Errors", gameData.Errors.Length.ToString(),true); embed.AddField("Errors", gameData.Errors.Length.ToString(),true);
@@ -91,8 +93,10 @@ namespace StarsiegeBot
{ {
return; return;
} }
DiscordMessageBuilder msg = new DiscordMessageBuilder(); DiscordMessageBuilder msg = new DiscordMessageBuilder
msg.Content = "Server Listing Errors:\r\n"; {
Content = "Server Listing Errors:\r\n"
};
foreach (var item in gameData.Errors) foreach (var item in gameData.Errors)
{ {
msg.Content += $"{item}\r\n"; msg.Content += $"{item}\r\n";
@@ -117,8 +121,10 @@ namespace StarsiegeBot
{ {
return; return;
} }
DiscordMessageBuilder msg = new DiscordMessageBuilder(); DiscordMessageBuilder msg = new DiscordMessageBuilder
msg.Content = "```csharp\r\n"; {
Content = "```csharp\r\n"
};
int count = 0; int count = 0;
foreach (var item in gameData.Masters) foreach (var item in gameData.Masters)
{ {
+2 -2
View File
@@ -23,7 +23,6 @@ namespace StarsiegeBot
class QuickchatHandler : BaseCommandModule class QuickchatHandler : BaseCommandModule
{ {
private Dictionary<string, Quickchat> quickchats; private Dictionary<string, Quickchat> quickchats;
private readonly Random rnd = new Random();
private bool IsQuickChatEnabled; private bool IsQuickChatEnabled;
public QuickchatHandler() public QuickchatHandler()
@@ -167,7 +166,7 @@ namespace StarsiegeBot
{ {
try try
{ {
id = rnd.Next(quickchats.Count); id = Program.rnd.Next(quickchats.Count);
chat = quickchats[id.ToString()]; chat = quickchats[id.ToString()];
output = $"[{id}] " + chat.text; output = $"[{id}] " + chat.text;
} }
@@ -195,6 +194,7 @@ namespace StarsiegeBot
} }
[Command("search"), Aliases("s")] [Command("search"), Aliases("s")]
[Cooldown(1,5,CooldownBucketType.Global)]
[Description("Searches all the [T]ext and [S]ound file names for the Search input.")] [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)
{ {
+126 -6
View File
@@ -27,33 +27,153 @@ namespace StarsiegeBot
[RequireGuild, RequirePermissions(Permissions.ManageChannels)] [RequireGuild, RequirePermissions(Permissions.ManageChannels)]
class WelcomeMessage : BotSettings class WelcomeMessage : BotSettings
{ {
[GroupCommand]
public async Task GeneralWelcome (CommandContext ctx)
{
await ctx.TriggerTypingAsync();
string gId = ctx.Guild.Id.ToString();
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Description = "Welcome Message Info",
Color = Program.colours[0]
};
if (GuildSettings[gId].WelcomeChannel is null)
embed.AddField("Channel", "*None*");
else
embed.AddField("Channel", GuildSettings[gId].WelcomeChannel.Mention, true);
embed.AddField("Enabled?", GuildSettings[gId].UseWelcome.ToString(), true);
if (GuildSettings[gId].WelcomeMessage is null || GuildSettings[gId].WelcomeMessage == "")
embed.AddField("Message", "*None*");
else
embed.AddField("Message", GuildSettings[gId].WelcomeMessage);
await ctx.RespondAsync(embed);
}
[GroupCommand]
public async Task GeneralWelcome(CommandContext ctx, bool enable, DiscordChannel channel)
{
await WelcomeChannel(ctx, channel);
await WelcomeEnabled(ctx, enable);
}
[GroupCommand]
public async Task GeneralWelcome(CommandContext ctx, DiscordChannel channel, bool enable)
{
await WelcomeChannel(ctx, channel);
await WelcomeEnabled(ctx, enable);
}
[Command("enable")] [Command("enable")]
public async Task WelcomeEnabled(CommandContext ctx, bool enable) public async Task WelcomeEnabled(CommandContext ctx, bool enable)
{ {
await ctx.TriggerTypingAsync(); await ctx.TriggerTypingAsync();
string gId = ctx.Guild.Id.ToString(); string gId = ctx.Guild.Id.ToString();
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Description = "Welcome Message Usage",
Color = Program.colours[0]
};
embed.AddField("Old", GuildSettings[gId].UseWelcome.ToString(), true);
GuildSettings[gId].UseWelcome = enable; GuildSettings[gId].UseWelcome = enable;
embed.AddField("New", GuildSettings[gId].UseWelcome.ToString(), true);
await ctx.RespondAsync($"Use welcome message? {enable}"); await ctx.RespondAsync(embed);
} }
[Command("Channel")]
public async Task WelcomeChannel(CommandContext ctx, DiscordChannel channel)
{
await ctx.TriggerTypingAsync();
string gId = ctx.Guild.Id.ToString();
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Description = "Welcome Message Channel",
Color = Program.colours[0]
};
if (GuildSettings[gId].WelcomeChannel != null)
{
embed.AddField("Old", GuildSettings[gId].WelcomeChannel.Mention, true);
}
else
{
embed.AddField("Old", "*None*");
}
GuildSettings[gId].WelcomeChannel = channel;
embed.AddField("New", GuildSettings[gId].WelcomeChannel.Mention, true);
await ctx.RespondAsync(embed);
}
[Command("Channel")] [Command("Channel")]
public async Task WelcomeChannel(CommandContext ctx, [RemainingText]string here) public async Task WelcomeChannel(CommandContext ctx, [RemainingText]string here)
{ {
await ctx.TriggerTypingAsync(); await ctx.TriggerTypingAsync();
string gId = ctx.Guild.Id.ToString(); string gId = ctx.Guild.Id.ToString();
GuildSettings[gId].WelcomeChannel = ctx.Channel; DiscordEmbedBuilder embed = new DiscordEmbedBuilder
await ctx.RespondAsync("This channel is the welcome channel now!"); {
} Description = "Welcome Message Channel",
Color = Program.colours[0]
};
if (GuildSettings[gId].WelcomeChannel != null)
{
embed.AddField("Old", GuildSettings[gId].WelcomeChannel.Mention, true);
}
else
{
embed.AddField("Old", "*None*");
}
GuildSettings[gId].WelcomeChannel = ctx.Channel;
embed.AddField("New", GuildSettings[gId].WelcomeChannel.Mention, true);
await ctx.RespondAsync(embed);
}
[Command("Message")] [Command("Message")]
[Description("Hello. Run `>welcome help` for more info.")]
public async Task MessageOfWelcome(CommandContext ctx, [RemainingText]string msg) public async Task MessageOfWelcome(CommandContext ctx, [RemainingText]string msg)
{ {
await ctx.TriggerTypingAsync(); await ctx.TriggerTypingAsync();
Console.WriteLine("1");
string gId = ctx.Guild.Id.ToString(); string gId = ctx.Guild.Id.ToString();
Console.WriteLine("2");
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Description = "Welcome Message String",
Color = Program.colours[0]
};
Console.WriteLine("3");
if (GuildSettings[gId].WelcomeMessage == "" || GuildSettings[gId].WelcomeMessage is null)
embed.AddField("Old", "*None*");
else
embed.AddField("Old", GuildSettings[gId].WelcomeMessage);
Console.WriteLine("4");
GuildSettings[gId].WelcomeMessage = msg; GuildSettings[gId].WelcomeMessage = msg;
await ctx.RespondAsync("welcome message set."); Console.WriteLine("5");
embed.AddField("New", GuildSettings[gId].WelcomeMessage);
Console.WriteLine("6");
string example = WelcomeMessageProcessing(GuildSettings[gId].WelcomeMessage, ctx.Member, ctx.Guild);
Console.WriteLine("7");
await ctx.RespondAsync($"An example:\r\n> {example}", embed);
}
[Command("Help")]
public async Task WelcomeHelp(CommandContext ctx)
{
await ctx.TriggerTypingAsync();
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Title = "Welcome Message Help",
Description = "List of placeholders and their intended replacement. Channel tags can be inserted without a placeholder.",
Color = Program.colours[0]
};
embed.AddField("[Discrim]", "Inserts the username of the member.");
embed.AddField("[UName]", "Inserts the username of the member.");
embed.AddField("[GName]", "Inserts your Guild/Server Name.");
embed.AddField("[Mention]", "Inserts your Guild/Server Name.");
await ctx.RespondAsync(embed);
}
public static string WelcomeMessageProcessing(string msg, DiscordMember member, DiscordGuild guild)
{
string output = msg
.Replace("[discrim]", member.Discriminator, StringComparison.OrdinalIgnoreCase)
.Replace("[gname]", guild.Name, StringComparison.OrdinalIgnoreCase)
.Replace("[uname]", member.Username, StringComparison.OrdinalIgnoreCase)
.Replace("[mention]", member.Mention, StringComparison.OrdinalIgnoreCase);
return output;
} }
} }
} }