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
{
public static Dictionary<string, GuildSettings> GuildSettings;
public BotSettings()
{
Console.WriteLine("Bot Setting Commands Loaded");
+230 -180
View File
@@ -6,43 +6,109 @@ using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
namespace StarsiegeBot
{
class Commands : BaseCommandModule
{
// this class depends a lot on the random stuff. so make it class level.
private readonly Random rnd = new Random();
// start: neo wanted this shit....
private readonly string[] insult = {
"> {0} slaps {1} around a bit with a large trout.",
"> {0} puts a jellyfish on {1}'s head.",
"> {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."
// Master insult list.
private readonly string[] InsultMaster = {
"{0} slaps {1} around a bit with a large trout.",
"{0} puts a jellyfish on {1}'s head.",
"{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;
public string Insult {
get {
if (insultIndex >= insult.Length) {
insultIndex = 0;
}
return insult[insultIndex++ % insult.Length];
}
}
// end: neo's shit.
private List<string> InsultCopy;
public Commands()
{
// Let the console know we've loaded basic commands.
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")]
[Description("A classic dice throwing command. Limited to 1 use per 2 seconds. Format: <NumberOfDice>d<SidesOnDie> ")]
[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...
await ctx.TriggerTypingAsync();
@@ -84,7 +150,7 @@ namespace StarsiegeBot
// 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.
// 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.
if (dieResults.Equals(String.Empty))
dieResults = roll.ToString();
@@ -95,7 +161,7 @@ namespace StarsiegeBot
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(volume < 11)
if (volume < 11)
dieResults = $"{volume}d{sides}: Total: " + dieResult + " Avg: " + Math.Round(dieResult * 1.0 / volume, 2) + " Results: " + dieResults;
else
dieResults = $"{volume}d{sides}: Total: " + dieResult + " Avg: " + Math.Round(dieResult * 1.0 / volume, 2);
@@ -108,6 +174,17 @@ namespace StarsiegeBot
else
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")]
[Description("Random number generator.")]
@@ -119,53 +196,91 @@ namespace StarsiegeBot
int i = Math.Min(min, max);
int a = Math.Max(min, max) + 1;
// 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")]
public async Task Random(CommandContext ctx)
{
await ctx.TriggerTypingAsync();
// 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`!");
}
[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)
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
user1 = ctx.Client.CurrentUser.Mention;
user2 = ctx.Message.Author.Mention;
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);
}
[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
{
user1 = ctx.Message.Author.Mention;
user2 = user.Mention;
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);
}
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")]
[Description("Rock Paper Scissors Lizard Spock")]
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.
text = text.ToLower();
// 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.
string result;
@@ -203,7 +318,12 @@ namespace StarsiegeBot
break;
}
// 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!
else
@@ -241,127 +361,14 @@ namespace StarsiegeBot
result = "Please pick a valid option! Options: " + String.Join(", ", choices);
}
// Actually send out all our info now.
await ctx.RespondAsync(result);
}
}
[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)
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
case "rock":
result += " shiny rock.";
break;
case "paper":
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);
Description = result,
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);
// 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")]
[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 = "")
@@ -371,10 +378,53 @@ namespace StarsiegeBot
return;
await ctx.TriggerTypingAsync();
// did the end user supply us something to say? no whine about it.
string result;
if (msg != "")
await ctx.RespondAsync(msg);
result = msg;
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.
// json file loaded...
int cmdStart = msg.GetStringPrefixLength("!");
// if Guild is null, do nothing for now.
if (e.Guild is null)
{
}
else
List<string> prefixes = BotSettings.GuildSettings["default"].Prefixes;
prefixes.Add(d.CurrentUser.Mention);
if (!(e.Guild is null))
{
string gId = e.Guild.Id.ToString();
List<string> prefixes = BotSettings.GuildSettings["default"].Prefixes;
// Check to see if the guild has settings.
if (BotSettings.GuildSettings.ContainsKey(gId))
{
@@ -83,27 +78,25 @@ namespace StarsiegeBot
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;
}
@@ -231,7 +224,9 @@ namespace StarsiegeBot
public Task GuildDownloadCompleted(DiscordClient d, GuildDownloadCompletedEventArgs e)
{
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;
}
public Task GuildEmojisUpdated(DiscordClient d, GuildEmojisUpdateEventArgs e)
@@ -246,26 +241,19 @@ namespace StarsiegeBot
}
public Task GuildMemberAdded(DiscordClient d, GuildMemberAddEventArgs e)
{
d.Logger.LogDebug(BotEventId, $"GuildMemberAdded.{e.Guild.Name}");
d.Logger.LogDebug(BotEventId, $"GuildMemberAdded.");
if (e.Member.IsBot)
{
return Task.CompletedTask;
}
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)
{ }
else
{
if (BotSettings.GuildSettings[gId].WelcomeMessage is null)
{ }
else
{
BotSettings.GuildSettings[gId].WelcomeChannel.SendMessageAsync(BotSettings.GuildSettings[gId].WelcomeMessage);
}
}
string msg = WelcomeMessage.WelcomeMessageProcessing(BotSettings.GuildSettings[gId].WelcomeMessage, e.Member, e.Guild);
BotSettings.GuildSettings[gId].WelcomeChannel.SendMessageAsync(msg);
}
return Task.CompletedTask;
+20 -13
View File
@@ -20,12 +20,19 @@ namespace StarsiegeBot
class Program
{
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 CommandsNextExtension Commands { get; set; }
public VoiceNextExtension Voice { get; set; }
protected string BotName { get; set; }
private async Task StartTimer(CancellationToken cancellationToken)
@@ -62,7 +69,7 @@ namespace StarsiegeBot
if (args.Length > 0)
BotName = args[0].ToLower();
else
BotName = "ssp";
BotName = "sspdev";
BotEventId = new EventId(276, BotName);
Events = new Triggers(BotEventId);
@@ -114,17 +121,17 @@ namespace StarsiegeBot
this.Commands = this.Client.UseCommandsNext(ccfg);
// up next, let's register our commands
this.Commands.RegisterCommands<Commands>();
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<SnappleFacts>();
// this.Commands.RegisterCommands<RoleManagement>(); // Main Folder. Test Items.
// this.Commands.RegisterCommands<LevelRoleManagement>(); // Main Folder. Test Items.
// this.Commands.RegisterCommands<GroupRoleManagement>(); // Main Folder. Test Items.
// this.Commands.RegisterCommands<LevelManagement>(); // Main Folder. Test Items.
// this.Commands.RegisterCommands<GroupManagement>(); // Main Folder. Test Items.
// this.Commands.RegisterCommands<StarsiegeCommands>();
this.Commands.RegisterCommands<RoleManagement>(); // Main Folder. Test Items.
this.Commands.RegisterCommands<SnappleFacts>();
this.Commands.RegisterCommands<StarsiegeCommands>();
this.Commands.RegisterCommands<WelcomeMessage>(); // Main Folder. Test Items.
// All these commands are in the STARSIEGE folder.
//if (BotName.Contains("ssp"))
+2 -3
View File
@@ -8,8 +8,7 @@ namespace StarsiegeBot
{
class SnappleFacts : BaseCommandModule
{
private string[] facts;
private Random rnd = new Random();
private readonly string[] facts;
[Command("snapple"), Description("Get a Snapple \"Real Fact\".")]
public async Task Snapplefact(CommandContext ctx, [Description("[Optional] A Snapple Fact ID")]int snapId = -1)
@@ -17,7 +16,7 @@ namespace StarsiegeBot
if (snapId == -1)
{
await ctx.TriggerTypingAsync();
await ctx.RespondAsync(facts[rnd.Next(0, facts.Length)]);
await ctx.RespondAsync(facts[Program.rnd.Next(0, facts.Length)]);
}
else
{
+4 -5
View File
@@ -25,7 +25,6 @@ namespace StarsiegeBot
[Cooldown(1, 2, CooldownBucketType.Guild)]
class DeathMessages : BaseCommandModule
{
private readonly Random rnd = new Random();
private DeathMessageLines dmLines;
private bool DeathMessagesEnabled;
@@ -136,7 +135,7 @@ namespace StarsiegeBot
// if there is no target, we're going to "kill" the author.
if (target == null)
{
int choice = rnd.Next(0, dmLines.Generic.Length);
int choice = Program.rnd.Next(0, dmLines.Generic.Length);
line = dmLines.Generic[choice];
await ctx.RespondAsync(string.Format(line, ctx.Message.Author.Mention));
}
@@ -144,18 +143,18 @@ namespace StarsiegeBot
else
{
// 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 (opt == 1)
{
// 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];
}
else if (opt == 2)
{
// 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];
}
// Give the selected death message to the user.
+1 -9
View File
@@ -22,14 +22,6 @@ namespace StarsiegeBot
[Group("functions"), Aliases("func")]
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 bool FunctionsEnabled;
@@ -101,7 +93,7 @@ namespace StarsiegeBot
// set the timestamp to now... why, idk, its not really needed actually.
embed.WithTimestamp(DateTime.Now);
// 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!
embed.WithDescription(outItem.description);
// iterate over each field item, and add them to the embed.
+13 -7
View File
@@ -65,9 +65,11 @@ namespace StarsiegeBot
{
return;
}
DiscordEmbedBuilder embed = new DiscordEmbedBuilder();
embed.Title = "Master|Game Server Overview";
embed.Description = "Number of Master, and Game servers. Along with number of errors.";
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
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);
@@ -91,8 +93,10 @@ namespace StarsiegeBot
{
return;
}
DiscordMessageBuilder msg = new DiscordMessageBuilder();
msg.Content = "Server Listing Errors:\r\n";
DiscordMessageBuilder msg = new DiscordMessageBuilder
{
Content = "Server Listing Errors:\r\n"
};
foreach (var item in gameData.Errors)
{
msg.Content += $"{item}\r\n";
@@ -117,8 +121,10 @@ namespace StarsiegeBot
{
return;
}
DiscordMessageBuilder msg = new DiscordMessageBuilder();
msg.Content = "```csharp\r\n";
DiscordMessageBuilder msg = new DiscordMessageBuilder
{
Content = "```csharp\r\n"
};
int count = 0;
foreach (var item in gameData.Masters)
{
+2 -2
View File
@@ -23,7 +23,6 @@ namespace StarsiegeBot
class QuickchatHandler : BaseCommandModule
{
private Dictionary<string, Quickchat> quickchats;
private readonly Random rnd = new Random();
private bool IsQuickChatEnabled;
public QuickchatHandler()
@@ -167,7 +166,7 @@ namespace StarsiegeBot
{
try
{
id = rnd.Next(quickchats.Count);
id = Program.rnd.Next(quickchats.Count);
chat = quickchats[id.ToString()];
output = $"[{id}] " + chat.text;
}
@@ -195,6 +194,7 @@ namespace StarsiegeBot
}
[Command("search"), Aliases("s")]
[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)
{
+126 -6
View File
@@ -27,33 +27,153 @@ namespace StarsiegeBot
[RequireGuild, RequirePermissions(Permissions.ManageChannels)]
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")]
public async Task WelcomeEnabled(CommandContext ctx, bool enable)
{
await ctx.TriggerTypingAsync();
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;
await ctx.RespondAsync($"Use welcome message? {enable}");
embed.AddField("New", GuildSettings[gId].UseWelcome.ToString(), true);
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")]
public async Task WelcomeChannel(CommandContext ctx, [RemainingText]string here)
{
await ctx.TriggerTypingAsync();
string gId = ctx.Guild.Id.ToString();
GuildSettings[gId].WelcomeChannel = ctx.Channel;
await ctx.RespondAsync("This channel is the welcome channel now!");
}
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 = ctx.Channel;
embed.AddField("New", GuildSettings[gId].WelcomeChannel.Mention, true);
await ctx.RespondAsync(embed);
}
[Command("Message")]
[Description("Hello. Run `>welcome help` for more info.")]
public async Task MessageOfWelcome(CommandContext ctx, [RemainingText]string msg)
{
await ctx.TriggerTypingAsync();
Console.WriteLine("1");
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;
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;
}
}
}