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

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

No files matched your search

+35 -12
View File
@@ -1,14 +1,14 @@
using System;
using System.IO;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using DSharpPlus;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace StarsiegeBot
{
@@ -18,6 +18,8 @@ namespace StarsiegeBot
class BotSettings : BaseCommandModule
{
public static Dictionary<string, GuildSettings> GuildSettings;
private readonly string fileName = "guildSettings.json";
private CancellationToken cancelToken;
public BotSettings()
{
Console.WriteLine("Bot Setting Commands Loaded");
@@ -28,7 +30,7 @@ namespace StarsiegeBot
return;
}
// Check for guild settings file. If it doesnt exist, create it.
if (!File.Exists("guildSettings.json"))
if (!File.Exists(fileName))
{
// Since we need to creat it, we're going to set some default stuff.
Console.Write("Guild Settings Config File Not Found. Creating One...");
@@ -55,7 +57,7 @@ namespace StarsiegeBot
// Now that we have the initial stuff in memory, write it to file.
string output = JsonConvert.SerializeObject(GuildSettings);
File.WriteAllTextAsync("guildSettings.json", output);
File.WriteAllTextAsync(fileName, output);
// in form the console reader that we're done making the initial config.
Console.WriteLine(" Done!");
}
@@ -63,11 +65,12 @@ namespace StarsiegeBot
{
// load the config file to memory.
var json = "";
using (var fs = File.OpenRead("guildSettings.json"))
using (var fs = File.OpenRead(fileName))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
json = sr.ReadToEnd();
GuildSettings = JsonConvert.DeserializeObject<Dictionary<string, GuildSettings>>(json);
}
_ = StartTimer(cancelToken);
}
[GroupCommand]
[Description("Work in progress. Does nothing yet.")]
@@ -75,6 +78,26 @@ namespace StarsiegeBot
{
await ctx.TriggerTypingAsync();
}
private async Task StartTimer(CancellationToken cancellationToken)
{
await Task.Run(async () =>
{
while (true)
{
string output = JsonConvert.SerializeObject(BotSettings.GuildSettings);
await File.WriteAllTextAsync("guildsettings.json", output);
await Task.Delay(TimeSpan.FromSeconds(120), cancellationToken);
if (cancellationToken.IsCancellationRequested)
{
Console.WriteLine("Token Cancelled.");
break;
}
}
});
}
}
public class GuildSettings
@@ -86,8 +109,8 @@ namespace StarsiegeBot
public bool AllowRolesPurchase { get; set; }
public bool UseAutoRoles { get; set; }
public List<String> Prefixes { get; set; }
public Dictionary<string,Dictionary<string,int>> SelfRoles { get; set; }
public Dictionary<int,List<DiscordRole>> LevelRoles { get; set; }
public Dictionary<string, Dictionary<string, int>> SelfRoles { get; set; }
public Dictionary<int, List<DiscordRole>> LevelRoles { get; set; }
public List<DiscordRole> HiddenRolesList { get; set; }
public DiscordChannel WelcomeChannel { get; set; }
public bool UseWelcome { get; set; }
+21
View File
@@ -0,0 +1,21 @@
Public const fields.
Non-public const fields.
Public static properties.
Public static fields.
Non-public static properties.
Non-public static fields.
Public properties.
Public fields.
Private properties.
Private fields.
Static constructor.
Public constructors.
Non-public constructors.
Public methods (with the exception of methods overriden from System.Object).
Non-public methods.
Methods overriden from System.Object.
Public static methods.
Non-public static methods.
Operator overloads.
Public events.
Non-public events.
+6 -13
View File
@@ -1,20 +1,13 @@
#pragma warning disable IDE0060 // Remove unused parameter
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Enums;
using DSharpPlus.Interactivity.Extensions;
using DSharpPlus.VoiceNext;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace StarsiegeBot
{
@@ -225,7 +218,7 @@ namespace StarsiegeBot
{
d.Logger.LogDebug(BotEventId, "GuildDownloadCompleted.");
//if(e.Guilds[376937422010974209].Members.ContainsKey(139548200099905536))
//notify = e.Guilds[376937422010974209].Members[139548200099905536];
//notify = e.Guilds[376937422010974209].Members[139548200099905536];
return Task.CompletedTask;
}
@@ -255,7 +248,7 @@ namespace StarsiegeBot
string msg = WelcomeMessage.WelcomeMessageProcessing(BotSettings.GuildSettings[gId].WelcomeMessage, e.Member, e.Guild);
BotSettings.GuildSettings[gId].WelcomeChannel.SendMessageAsync(msg);
}
return Task.CompletedTask;
}
public Task GuildMemberRemoved(DiscordClient d, GuildMemberRemoveEventArgs e)
+35
View File
@@ -0,0 +1,35 @@
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.Interactivity.Extensions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace StarsiegeBot
{
[Group("ex")]
[Hidden]
[Description("Experimental commands. May break the bot.")]
class ExperiemntalCommands : BaseCommandModule
{
[Command("exit"), RequireOwner]
public async Task ExitProgram (CommandContext ctx)
{
await ctx.RespondAsync("Attempting a shutdown...");
System.Environment.Exit(0);
}
[Command("Report")]
public async Task Report (CommandContext ctx)
{
await ctx.RespondAsync("Report not generated");
}
}
}
@@ -1,16 +1,16 @@
#pragma warning disable IDE0060 // Remove unused parameter
using System;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using System.Text.RegularExpressions;
using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace StarsiegeBot
{
class Commands : BaseCommandModule
class GameCommands : BaseCommandModule
{
// Master insult list.
private readonly string[] InsultMaster = {
@@ -22,12 +22,13 @@ namespace StarsiegeBot
};
private List<string> InsultCopy;
public Commands()
public GameCommands()
{
// 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 = "")
@@ -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!")]
@@ -174,11 +165,11 @@ namespace StarsiegeBot
else
await ctx.RespondAsync(overallResults);
}
[Command("guilds"),Hidden,RequireOwner]
public async Task GimmeServerNames (CommandContext ctx)
[Command("guilds"), Hidden, RequireOwner]
public async Task GimmeServerNames(CommandContext ctx)
{
string output = "";
foreach (KeyValuePair<ulong,DiscordGuild> item in ctx.Client.Guilds)
foreach (KeyValuePair<ulong, DiscordGuild> item in ctx.Client.Guilds)
{
output += item.Value.Name + "\r\n";
}
@@ -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")]
@@ -382,13 +343,8 @@ namespace StarsiegeBot
if (msg != "")
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);
result = "I need something to say...";
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;
}
}
}
File renamed without changes.
File renamed without changes.
+1
View File
@@ -0,0 +1 @@
{"default":{"UseGlobalPrefix":true,"UseSelfRoles":false,"UseLevelRoles":false,"UseLevels":false,"AllowRolesPurchase":false,"UseAutoRoles":false,"Prefixes":["::"],"SelfRoles":{},"LevelRoles":{},"HiddenRolesList":null,"WelcomeChannel":null,"UseWelcome":false,"WelcomeMessage":null},"297873205316681728":{"UseGlobalPrefix":true,"UseSelfRoles":false,"UseLevelRoles":false,"UseLevels":false,"AllowRolesPurchase":false,"UseAutoRoles":false,"Prefixes":[">","::","~"],"SelfRoles":{},"LevelRoles":{},"HiddenRolesList":null,"WelcomeChannel":null,"UseWelcome":false,"WelcomeMessage":null},"376937422010974209":{"UseGlobalPrefix":true,"UseSelfRoles":false,"UseLevelRoles":false,"UseLevels":false,"AllowRolesPurchase":false,"UseAutoRoles":false,"Prefixes":[">"],"SelfRoles":{},"LevelRoles":{},"HiddenRolesList":null,"WelcomeChannel":null,"UseWelcome":false,"WelcomeMessage":null},"768366579468468244":{"UseGlobalPrefix":true,"UseSelfRoles":false,"UseLevelRoles":false,"UseLevels":false,"AllowRolesPurchase":false,"UseAutoRoles":false,"Prefixes":[">"],"SelfRoles":{},"LevelRoles":{},"HiddenRolesList":null,"WelcomeChannel":null,"UseWelcome":false,"WelcomeMessage":null},"831348953097961534":{"UseGlobalPrefix":true,"UseSelfRoles":false,"UseLevelRoles":false,"UseLevels":false,"AllowRolesPurchase":false,"UseAutoRoles":false,"Prefixes":[">","::","~","!","%","^","&","*","(",")","-","_","=","+","[","]","{","}",";",":","<",">",",",".","?"],"SelfRoles":{},"LevelRoles":{},"HiddenRolesList":null,"WelcomeChannel":{"permission_overwrites":[],"guild_id":831348953097961534,"parent_id":831348953097961535,"name":"general","type":0,"position":0,"topic":"","last_message_id":836202598540509245,"bitrate":0,"user_limit":0,"rate_limit_per_user":0,"nsfw":false,"id":831348953097961537},"UseWelcome":true,"WelcomeMessage":"Welcome to channel <#831348953097961537>!"}}
+103
View File
@@ -0,0 +1,103 @@
[
"The first bird to ever use an Xbox controller was a Kea called Parau.",
"The gold in Tutankhamun’s tomb had been stolen from the tombs of other pharaohs.",
"England’s biggest horticultural export is the fig.",
"The same molecule that makes chicken taste like chicken can also be found in ground up oyster shells.",
"Prince Phillip is widely credited with the invention of the party popper.",
"Thyme is technically a tree.",
"By definition a snake’s body is a limb.",
"The roller coaster was invented during the Hundred Years’ War as a way of launching supplies across rivers.",
"The toenail of your little toe is called the ‘spungle’.",
"Courgette is actually the feminine noun of cucumber.",
"The first video ever uploaded to Youtube had to be taken down in 2016 for violating their Terms of Service.",
"There is a nerveless area of skin half the size of a playing card on the top of your foot. Your brain compensates for it.",
"The biggest arms manufacturer in the world is Hasbro.",
"By weight, bay leaves contain more caffeine than coffee beans. They are used to make a stimulating tea in Morocco.",
"Vikings never fired flaming arrows at boats carrying the dead. They would sink them by running them over with a larger boat.",
"There is a ‘Buzzy Bee’ still at the top of Mt Everest, left there by Edmund Hillary.",
"Originally the Fonz was going to wear a leather vest but the popularity of the Village People made them switch to a jacket.",
"Johnny Cash once got into a fist fight with Colonel Sanders over a sports game.",
"There are more submarines in lakes right now than there are in the oceans.",
"Gold nuggets were named after chicken nuggets – not the other way around.",
"Buzz Aldrin left a pen on the moon after the first visit. Eugene Cernan, the last moon walker, found it. It still worked.",
"There is a pattern on the inside of your upper eyelid that is as unique as your fingerprint.",
"At least two unconnected cultures have used sparrow skulls as a form of currency.",
"The President of Senegal was one of the scientists who developed the Large Hadron Collider.",
"The kneecap is the roundest part of your body.",
"The Nobel Prize for Physics has been awarded to a scientist who proved that a tree falling in the woods really does make a sound.",
"JRR Tolkien refused to let his books be read out loud to people until after his death, preferring to keep his words ‘on the page’.",
"Paris Hilton and Nicole Richie’s ‘The Simple Life’ is one of the most syndicated TV shows in the world.",
"All fossils found in Canada belong to the Queen.",
"The first sunglasses were actually animal skin scraped so thin that it became transparent.",
"Sun Tzu’s ‘The Art of War’ is a sequel. The first book is lost forever.",
"One of the gems on the Crown Jewels is a marble glued there by Edward the Confessor’s son.",
"Researchers in the Antarctic will use apply whitening toothpaste to their drills when boring into the ice shelf.",
"Due to the inclusion of certain metal isotopes in its construction, the standard trombone is actually radioactive.",
"‘Bat Out of Hell’ was written by Meatloaf after an argument with Ozzy Osborne.",
"The word ‘Loanshark’ was originally, ‘Loans, hark’.",
"Jellified red wine was used as a lubricant by the ancient Greeks.",
"One of the rings of Saturn is almost pure silver dust.",
"Every member of Iron Maiden was a Quaker.",
"The national anthem of Lithuania is palindromic. It plays backwards exactly the same way that it plays forwards.",
"In Brazil they call Brazil nuts ‘Argentines’.",
"The first pair of scissors was left-handed.",
"The @ symbol was invented by Charles de Gaulle.",
"Every member of The Baha Men is dead.",
"A furlong was defined as the distance a mule can run in two minutes.",
"The Eiffel Tower has bumps along its ‘legs’ that spell the French national motto in braille.",
"The phrase, ‘If pain persists, see your doctor’ has been copyrighted by Bayer.",
"Venetian blinds were invented in Venice.",
"Cat Stevens first name is Catherine.",
"The first copy of the Oxford English dictionary is missing the word ‘dictionary’.",
"New Zealanders use more toilet paper per capita than any other country.",
"Otters have been known to coat stones with fish scales to lure in birds.",
"The largest sushi roll ever made would be impossible to transport through the Channel Tunnel.",
"Morris dancing was invented by a guy called Morris.",
"95% of people are pronouncing the name of the band ‘Live’ incorrectly.",
"X-rays cannot pass through Velcro.",
"The Boy Scouts were counted as part of the American military until 1986.",
"Once a year all of Wikipedia is printed off and placed in a vault in Norway.",
"While Thomas Crapper didn’t invent the toilet, he was killed by one.",
"A copy of Detective Comics #38 exists with an error that has Batman constantly refer to his sidekick as ‘Bobin’.",
"The producers of the movie ‘Air Bud’ are currently suing Apple for copyright infringement.",
"Genghis Khan brought dressage to Europe.",
"Resene has a 100 year contract to provide paint for the Hoover Dam.",
"Where’s Wally books are used in the entry exam for MI6.",
"Bubbles have a seam.",
"In Lesotho it is considered rude not to offer someone a bite of your food before you start eating.",
"Dave Bautista has been the leader of an improv troupe for the past twenty years.",
"The National Library of Singapore uses woven human hair for bookmarks to preserve the condition of the pages.",
"Percy Bysshe Shelley’s ‘Prometheus Unbound’ contains the first use of the word ‘Whoops’.",
"An adolescent owl is called a ‘novice’.",
"On average, three people are injured every time an audience gives a standing ovation.",
"Napoleon was ashamed of his nipples and refused to let anyone see them. Even during medical treatments.",
"There are no synonyms for thesaurus.",
"‘The Fellowship of the Ring’ is the most stolen book in the world.",
"Peppermint can’t be smelt by guinea pigs.",
"The Lego headquarters has had to be rebuilt three times due to shoddy construction.",
"MRI scans of cat brains have revealed that they see humans as a prey species.",
"The lowest tone that can be hit by a specific tuba is called the ‘crass’.",
"The ‘Peter Piper Procession’ is a yearly contest wherein participants compete to say the ‘Peter Piper’ tongue twister the fastest.",
"Examination of recently discovered texts indicates that the Hittites first invented the slinky.",
"Today more messages are sent using carrier pigeons than are sent via fax.",
"The banjoist from the ‘Duelling Banjos; scene of Deliverance was offered a record deal. It reached number 15 on the Billboard charts.",
"According to the International Federation of Poker, socks don’t count as an item of clothing in strip poker.",
"The Geneva Convention’s prohibition of improper use of distinctive emblems during warfare also applies to the Jolly Roger.",
"Every screw used in the construction of Vatican City has a cross on the head. They must never be upside down.",
"The shoes of King Edward IV were weighted with lead to make his walk seem more imposing.",
"During the breeding season, female cockroaches smell like pineapple.",
"The music of the band ‘Rush’ has been featured in more video games than any other band or musician.",
"Emeril Lagasse refused to ever use a spatula.",
"Kevin Bacon founded an organisation that re-homes rescued factory farm pigs.",
"Voltaire’s father was a cobbler.",
"In American Football, touchdowns were originally called ‘tapstops’.",
"The names of all missing persons in Honduras are kept in a register called ‘The Imponderables’.",
"There exists a Sherlock Holmes story containing a kiss between Holmes and Watson but all copies are held by the Doyle estate.",
"The founders of Johnson & Johnson were not related.",
"A solid gold fidget spinner has been made, but it broke its first users index finger due to its weight.",
"The longest game of mah-jong ever lasted for three years. It finished when the house it was being played in burned down.",
"In Argentina, ‘Where in the World is Carmen San Diego’ is called, ‘In Pursuit of the Red Rebellious Bird’.",
"Historical records indicate that the dairy cow’s moo used to be significantly louder than it currently is.",
"Penguins have wavy feathers that produce a similar effect when moving through water as golf ball dimples do in the air.",
"The banana tree is the tallest growing grass in the world."
]
File renamed without changes.
File renamed without changes.
File diff suppressed because it is too large. Load diff
+4 -17
View File
@@ -1,25 +1,12 @@
#pragma warning disable IDE0060 // Remove unused parameter
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.VoiceNext;
using System.Text.RegularExpressions;
using System.Linq;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext.Exceptions;
using DSharpPlus.EventArgs;
using DSharpPlus.VoiceNext.Codec;
using Microsoft.Extensions.Logging;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using System.Threading;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace StarsiegeBot
{
+5 -19
View File
@@ -1,25 +1,11 @@
#pragma warning disable IDE0060 // Remove unused parameter
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.VoiceNext;
using System;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext.Exceptions;
using DSharpPlus.EventArgs;
using DSharpPlus.VoiceNext.Codec;
using Microsoft.Extensions.Logging;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using System.Threading;
using System.Threading.Tasks;
namespace StarsiegeBot
{
@@ -41,7 +27,7 @@ namespace StarsiegeBot
[Command("add")]
[Description("Work in progress. Does nothing yet.")]
public async Task AddSelfRole(CommandContext ctx, [Description("The role to add.")]DiscordRole role, [Description("The price of the role for buyable roles. 0 for no cost. Free free to leave blank if not using Buyable roles.")]int price = 0, [Description("What group to put the role in. If not using groups, you can leave blank.")]string group = null)
public async Task AddSelfRole(CommandContext ctx, [Description("The role to add.")] DiscordRole role, [Description("The price of the role for buyable roles. 0 for no cost. Free free to leave blank if not using Buyable roles.")] int price = 0, [Description("What group to put the role in. If not using groups, you can leave blank.")] string group = null)
{
await ctx.TriggerTypingAsync();
if (price == -1)
@@ -52,7 +38,7 @@ namespace StarsiegeBot
[Command("delete")]
[Description("Work in progress. Does nothing yet.")]
public async Task DeleteSelfRole(CommandContext ctx, [Description("The role to delete.")] DiscordRole role, [Description("The group to remove the role from. If left blank, will remove from all groups.")]string group = null)
public async Task DeleteSelfRole(CommandContext ctx, [Description("The role to delete.")] DiscordRole role, [Description("The group to remove the role from. If left blank, will remove from all groups.")] string group = null)
{
await ctx.TriggerTypingAsync();
}
+4 -19
View File
@@ -1,25 +1,10 @@
#pragma warning disable IDE0060 // Remove unused parameter
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.VoiceNext;
using System;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext.Exceptions;
using DSharpPlus.EventArgs;
using DSharpPlus.VoiceNext.Codec;
using Microsoft.Extensions.Logging;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using System.Threading;
using System.Threading.Tasks;
namespace StarsiegeBot
{
@@ -57,7 +42,7 @@ namespace StarsiegeBot
[Command("edit")]
[Description("Work in progress. Does nothing yet.")]
public async Task EditLevel (CommandContext ctx, int oldLeve, int newLevel)
public async Task EditLevel(CommandContext ctx, int oldLeve, int newLevel)
{
await ctx.TriggerTypingAsync();
}
+3 -17
View File
@@ -1,25 +1,11 @@
#pragma warning disable IDE0060 // Remove unused parameter
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.VoiceNext;
using System;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext.Exceptions;
using DSharpPlus.EventArgs;
using DSharpPlus.VoiceNext.Codec;
using Microsoft.Extensions.Logging;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using System.Threading;
using System.Threading.Tasks;
namespace StarsiegeBot
{
+5 -19
View File
@@ -1,30 +1,16 @@
#pragma warning disable IDE0060 // Remove unused parameter
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.VoiceNext;
using System;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext.Exceptions;
using DSharpPlus.EventArgs;
using DSharpPlus.VoiceNext.Codec;
using Microsoft.Extensions.Logging;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using System.Threading;
using System.Threading.Tasks;
namespace StarsiegeBot
{
{
[Group("role")]
[RequireGuild,RequirePermissions(Permissions.ManageRoles)]
[RequireGuild, RequirePermissions(Permissions.ManageRoles)]
class RoleManagement : BotSettings
{
public RoleManagement()
+47 -36
View File
@@ -1,24 +1,11 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.VoiceNext;
using System.Text.RegularExpressions;
using System;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext.Exceptions;
using DSharpPlus.EventArgs;
using DSharpPlus.VoiceNext.Codec;
using Microsoft.Extensions.Logging;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using System.Threading;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace StarsiegeBot
{
@@ -120,35 +107,59 @@ namespace StarsiegeBot
await ctx.RespondAsync($"Global Prefix usage has been turned **{(isEnabled ? "on" : "off")}**");
}
[Command("global")]
public async Task UseGlobalPrefixes(CommandContext ctx, [Description("0 is off, 1 is on.")] int isEnabled)
{
// since we're just allowing the user to use different ways to turn this function on and off... Redirect the work load there.
if (isEnabled >= 1)
{
await UseGlobalPrefixes(ctx, true);
}
else
{
await UseGlobalPrefixes(ctx, false);
}
}
[Command("global")]
public async Task UseGlobalPrefixes(CommandContext ctx, [Description("ON or OFF")] string isEnabled)
public async Task UseGlobalPrefixes(CommandContext ctx, [Description("ON or OFF"), RemainingText] string isEnabled = null)
{
await ctx.TriggerTypingAsync();
isEnabled = isEnabled.ToLower();
string gId = ctx.Guild.Id.ToString();
int prefixCount = GuildSettings[gId].Prefixes.Count;
string[] turnOn = { "on", "true", "1" };
string[] turnOff = { "off", "false", "0" };
DiscordEmbedBuilder embed = StartEmbed("Global Prefix Usage");
embed.AddField("Old", Program.YesNo(GuildSettings[gId].UseGlobalPrefix));
// since we're just trying to make the end user's life easier by different means of turning this on/off. redirect work load that way.
if (isEnabled.ToLower() == "on")
if (turnOn.Contains(isEnabled))
{
await UseGlobalPrefixes(ctx, true);
GuildSettings[gId].UseGlobalPrefix = true;
embed.AddField("New", Program.YesNo(GuildSettings[gId].UseGlobalPrefix));
}
else if (isEnabled.ToLower() == "off")
else if (turnOff.Contains(isEnabled))
{
await UseGlobalPrefixes(ctx, false);
if (prefixCount > 0)
{
GuildSettings[gId].UseGlobalPrefix = false;
embed.AddField("New", Program.YesNo(GuildSettings[gId].UseGlobalPrefix));
}
else
{
embed = EmbedError("Could not turn off Global Prefix Usage. (Are you missing a server prefix?)");
}
}
else
{
// they wanna be smart, and we don't wanna, tell them that.
await ctx.RespondAsync("Please specify ON or OFF");
}
await ctx.RespondAsync(embed);
}
private DiscordEmbedBuilder StartEmbed(string desc)
{
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Description = desc,
Color = Program.colours[1]
};
return embed;
}
private DiscordEmbedBuilder EmbedError(string desc)
{
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Description = desc,
Color = Program.colours[^1]
};
return embed;
}
}
}
+18 -35
View File
@@ -1,19 +1,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Enums;
using DSharpPlus.Interactivity.Extensions;
using DSharpPlus.VoiceNext;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace StarsiegeBot
{
@@ -25,33 +22,15 @@ namespace StarsiegeBot
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.None, DiscordColor.NotQuiteBlack, DiscordColor.Orange, DiscordColor.PhthaloBlue, DiscordColor.PhthaloGreen, DiscordColor.Purple,
DiscordColor.Rose, DiscordColor.SapGreen, DiscordColor.Sienna, DiscordColor.SpringGreen, DiscordColor.Teal, DiscordColor.Turquoise, DiscordColor.VeryDarkGray,
DiscordColor.Violet, DiscordColor.Wheat, DiscordColor.White, DiscordColor.Yellow };
DiscordColor.Violet, DiscordColor.Wheat, DiscordColor.White, DiscordColor.Yellow, DiscordColor.Red };
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)
{
await Task.Run(async () =>
{
while (true)
{
string output = JsonConvert.SerializeObject(BotSettings.GuildSettings);
await File.WriteAllTextAsync("guildSettings.json", output);
await Task.Delay(TimeSpan.FromSeconds(120), cancellationToken);
if (cancellationToken.IsCancellationRequested)
{
Console.WriteLine("Token Cancelled.");
break;
}
}
});
}
public string BotName { get; protected set; }
public static void Main(string[] args)
{
@@ -99,7 +78,7 @@ namespace StarsiegeBot
this.Client.UseInteractivity(new InteractivityConfiguration()
{
PollBehaviour = PollBehaviour.KeepEmojis,
Timeout = TimeSpan.FromSeconds(15)
Timeout = TimeSpan.FromSeconds(15)
});
// up next, let's set up our commands
@@ -122,15 +101,16 @@ namespace StarsiegeBot
// up next, let's register our commands
this.Commands.RegisterCommands<BotSettings>(); // Main Folder. Test Items.
this.Commands.RegisterCommands<Commands>();
this.Commands.RegisterCommands<ExperiemntalCommands>(); // Experimental commands file.
this.Commands.RegisterCommands<GameCommands>();
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<NotFacts>(); // Raven Folder.
this.Commands.RegisterCommands<PrefixManagement>();
this.Commands.RegisterCommands<RoleManagement>(); // Main Folder. Test Items.
this.Commands.RegisterCommands<SnappleFacts>();
this.Commands.RegisterCommands<StarsiegeCommands>();
this.Commands.RegisterCommands<SnappleFacts>(); // Raven folder.
this.Commands.RegisterCommands<WelcomeMessage>(); // Main Folder. Test Items.
// All these commands are in the STARSIEGE folder.
@@ -141,7 +121,6 @@ namespace StarsiegeBot
this.Commands.RegisterCommands<DeathMessages>();
this.Commands.RegisterCommands<GameInfo>();
//}
Task thisTimerf = StartTimer(new CancellationToken());
// let's enable voice
this.Voice = this.Client.UseVoiceNext();
@@ -202,7 +181,6 @@ namespace StarsiegeBot
this.Commands.CommandExecuted += Events.CommandExecuted;
this.Commands.CommandErrored += Events.CommandErrored;
// finally, let's connect and log in
await this.Client.ConnectAsync();
@@ -219,5 +197,10 @@ namespace StarsiegeBot
[JsonProperty("prefix")]
public string CommandPrefix { get; private set; }
}
public static string YesNo(bool test)
{
return (test ? "Enabled" : "Disabled");
}
}
}
+146
View File
@@ -0,0 +1,146 @@
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 List<string> notfacts;
private bool IsEnabled;
private readonly string fileName = "Json/notfacts.json";
public NotFacts()
{
Console.WriteLine("NotFacts Command Loaded");
IsEnabled = Load();
}
[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();
string output;
notFactID--;
try
{
output = notfacts[notFactID];
}
catch (Exception)
{
output = notfacts[Program.rnd.Next(0, notfacts.Count)];
}
await ctx.RespondAsync(StartEmbed(output));
}
[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(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;
}
}
}
File diff suppressed because it is too large. Load diff
@@ -1,39 +1,27 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.VoiceNext;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext.Exceptions;
using DSharpPlus.EventArgs;
using DSharpPlus.VoiceNext.Codec;
using Microsoft.Extensions.Logging;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace StarsiegeBot
namespace StarsiegeBot.Raven
{
[Group("ex")]
[Hidden]
[Description("Experimental commands. May break the bot.")]
class StarsiegeCommands : BaseCommandModule
class TriviaHandler : BaseCommandModule
{
private readonly List<Questions> QuizQuestions;
private readonly Random rnd = new Random();
public StarsiegeCommands()
public TriviaHandler()
{
// Load all the Quick Chat texts and sound wav file info.
var json = "";
using (var fs = File.OpenRead("questions.json"))
using (var fs = File.OpenRead("Json/questions.json"))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
json = sr.ReadToEnd();
Dictionary<string, Questions> tempQC = JsonConvert.DeserializeObject<Dictionary<string, Questions>>(json);
@@ -48,7 +36,7 @@ namespace StarsiegeBot
await ctx.TriggerTypingAsync();
DiscordEmbedBuilder embed = new DiscordEmbedBuilder();
int[] ids = { rnd.Next(QuizQuestions.Count), rnd.Next(QuizQuestions.Count), rnd.Next(QuizQuestions.Count), rnd.Next(QuizQuestions.Count)};
int[] ids = { rnd.Next(QuizQuestions.Count), rnd.Next(QuizQuestions.Count), rnd.Next(QuizQuestions.Count), rnd.Next(QuizQuestions.Count) };
int selection = rnd.Next(ids.Length);
int mainId = ids[selection];
string[] options = { "a", "b", "c", "d" };
@@ -71,7 +59,7 @@ namespace StarsiegeBot
var itemEmote = DiscordEmoji.FromName(ctx.Client, $":regional_indicator_{item}:");
await message.CreateReactionAsync(itemEmote);
}
var result = message.WaitForReactionAsync(ctx.Message.Author,TimeSpan.FromSeconds(5d));
var result = message.WaitForReactionAsync(ctx.Message.Author, TimeSpan.FromSeconds(5d));
if (!result.Result.TimedOut)
{
if (result.Result.Result.Emoji == correctAnswer) await ctx.RespondAsync("**CORRECT!!**");
@@ -95,7 +83,7 @@ namespace StarsiegeBot
{
foreach (var person in reaction.Users)
{
if ( ! correctEmote.Equals(reaction.Emoji))
if (!correctEmote.Equals(reaction.Emoji))
{
losers.Add(person, true);
}
+20 -25
View File
@@ -1,21 +1,15 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.VoiceNext;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext.Exceptions;
using DSharpPlus.EventArgs;
using DSharpPlus.VoiceNext.Codec;
using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace StarsiegeBot
{
@@ -27,17 +21,18 @@ namespace StarsiegeBot
{
private DeathMessageLines dmLines;
private bool DeathMessagesEnabled;
private static readonly string fileName = "Json/deathmessages.json";
public DeathMessages()
{
Console.WriteLine("Death Message Commands Loaded.");
// If the DeathMessages file exists, load it. And enable the commands.
// Otherwise disable all the commands.
if (File.Exists("DeathMessages.json"))
if (File.Exists(fileName))
{
// set some JSON text to blank.
var json = "";
using (var fs = File.OpenRead("DeathMessages.json"))
using (var fs = File.OpenRead(fileName))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
json = sr.ReadToEnd();
// Decode the JSON and set it to dmLines.
@@ -48,7 +43,7 @@ namespace StarsiegeBot
else
{
// Echo out that we're missing a file. Disable the commands due to that.
Console.WriteLine(" --- --- --- --- DeathMessages.json is missing");
Console.WriteLine($" --- --- --- --- {fileName} is missing");
DeathMessagesEnabled = false;
}
}
@@ -58,11 +53,11 @@ namespace StarsiegeBot
public async Task LoadDeathMessages(CommandContext ctx)
{
await ctx.TriggerTypingAsync();
if (File.Exists("DeathMessages.json"))
if (File.Exists(fileName))
{
// set some JSON text to blank.
var json = "";
using (var fs = File.OpenRead("DeathMessages.json"))
using (var fs = File.OpenRead(fileName))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
json = sr.ReadToEnd();
// Decode the JSON and set it to dmLines.
@@ -92,7 +87,7 @@ namespace StarsiegeBot
string[] turnOn = { "on", "true", "1" };
string[] turnOff = { "off", "false", "0" };
if (File.Exists("DeathMessages.json"))
if (File.Exists(fileName))
{
if (turnOn.Contains(isEnabled))
{
@@ -111,13 +106,13 @@ namespace StarsiegeBot
else
{
DeathMessagesEnabled = false;
output = "DeathMessages.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);
}
[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)
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();
@@ -129,7 +124,7 @@ namespace StarsiegeBot
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.
@@ -182,7 +177,7 @@ namespace StarsiegeBot
[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)]
public async Task DeathMessageNew(CommandContext ctx, [RemainingText,Description("The Death Message you want added. See help section.")] string msg)
public async Task DeathMessageNew(CommandContext ctx, [RemainingText, Description("The Death Message you want added. See help section.")] string msg)
{
// 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.
@@ -265,7 +260,7 @@ namespace StarsiegeBot
// Tell DSharp that we want to upload this file.
msg.WithFile("deathmessages.cs", sound);
// Add some content so its not a blank file.
msg.Content ="Here is your request for a death message script.";
msg.Content = "Here is your request for a death message script.";
// send that message.
await ctx.RespondAsync(msg);
// We're done with the file, so close access to it.
@@ -275,7 +270,7 @@ namespace StarsiegeBot
private async Task StoreDeathMessages()
{
string output = JsonConvert.SerializeObject(dmLines);
await File.WriteAllTextAsync("DeathMessages.json", output);
await File.WriteAllTextAsync(fileName, output);
return;
}
}
+14 -20
View File
@@ -1,21 +1,15 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.VoiceNext;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext.Exceptions;
using DSharpPlus.EventArgs;
using DSharpPlus.VoiceNext.Codec;
using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace StarsiegeBot
{
@@ -24,17 +18,17 @@ namespace StarsiegeBot
{
private Dictionary<string, SSFunction> ssFunctions;
private bool FunctionsEnabled;
private static readonly string fileName = "Json/functions.json";
public Functions()
{
Console.WriteLine("Starsiege Function Commands Loaded");
// Check for file, if not there, disable commands.
if (File.Exists("functions.json"))
if (File.Exists(fileName))
{
// Load the Functions JSON file. Has all information regarding Starsiege in-game Functions.
var json = "";
using (var fs = File.OpenRead("functions.json"))
using (var fs = File.OpenRead(fileName))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
json = sr.ReadToEnd();
ssFunctions = JsonConvert.DeserializeObject<Dictionary<string, SSFunction>>(json);
@@ -141,7 +135,7 @@ namespace StarsiegeBot
string[] turnOn = { "on", "true", "1" };
string[] turnOff = { "off", "false", "0" };
if (File.Exists("functions.json"))
if (File.Exists(fileName))
{
if (turnOn.Contains(isEnabled))
{
@@ -160,7 +154,7 @@ namespace StarsiegeBot
else
{
FunctionsEnabled = false;
output = "Functions.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);
}
@@ -170,11 +164,11 @@ namespace StarsiegeBot
await ctx.TriggerTypingAsync();
// Check for file, if not there, disable commands.
if (File.Exists("functions.json"))
if (File.Exists(fileName))
{
// Load the Functions JSON file. Has all information regarding Starsiege in-game Functions.
var json = "";
using (var fs = File.OpenRead("functions.json"))
using (var fs = File.OpenRead(fileName))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
json = sr.ReadToEnd();
ssFunctions = JsonConvert.DeserializeObject<Dictionary<string, SSFunction>>(json);
+12 -22
View File
@@ -1,22 +1,12 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.VoiceNext;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext.Exceptions;
using DSharpPlus.EventArgs;
using DSharpPlus.VoiceNext.Codec;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace StarsiegeBot
{
@@ -50,7 +40,7 @@ namespace StarsiegeBot
}
}
[GroupCommand]
public async Task Overview (CommandContext ctx)
public async Task Overview(CommandContext ctx)
{
await ctx.TriggerTypingAsync();
Update();
@@ -70,9 +60,9 @@ namespace StarsiegeBot
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);
embed.AddField("Masters", gameData.Masters.Length.ToString(), true);
embed.AddField("Games", gameData.Games.Length.ToString(), true);
embed.AddField("Errors", gameData.Errors.Length.ToString(), true);
await ctx.RespondAsync(embed);
}
@@ -106,7 +96,7 @@ namespace StarsiegeBot
[Command("Masters"), Aliases("m")]
[Description("Gives all the master servers as a script to be improted into `master.cs`.")]
public async Task MasterServers (CommandContext ctx)
public async Task MasterServers(CommandContext ctx)
{
await ctx.TriggerTypingAsync();
Update();
@@ -137,7 +127,7 @@ namespace StarsiegeBot
[Command("games"), Aliases("g")]
[Description("Currently: Lists games that have been started (Player dropped in). End Result: Lists all games that have a player in the server (either dropped in or not)")]
public async Task GameServers(CommandContext ctx, [Description("Number of players you want to check for. Game servers will need at least this meaning or more to be listed.")]int playerCount = 1)
public async Task GameServers(CommandContext ctx, [Description("Number of players you want to check for. Game servers will need at least this meaning or more to be listed.")] int playerCount = 1)
{
await ctx.TriggerTypingAsync();
Update();
@@ -145,7 +135,7 @@ namespace StarsiegeBot
// setup an exit point check.
bool exit = false;
// if its null, we're going to exit.
if(gameData is null || gameData.Games is null)
if (gameData is null || gameData.Games is null)
{
exit = true;
}
+23 -29
View File
@@ -1,21 +1,15 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.VoiceNext;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext.Exceptions;
using DSharpPlus.EventArgs;
using DSharpPlus.VoiceNext.Codec;
using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace StarsiegeBot
{
@@ -24,6 +18,8 @@ namespace StarsiegeBot
{
private Dictionary<string, Quickchat> quickchats;
private bool IsEnabled;
private readonly string fileName = "Json/quickchats.json";
public QuickchatHandler()
{
@@ -38,13 +34,13 @@ namespace StarsiegeBot
private bool LoadQuickChatsImpl()
{
// Check to see if the file exists...
if (File.Exists("quickchats.json"))
if (File.Exists(fileName))
{
// Load the JSON file.
var json = "";
using (var fs = File.OpenRead("quickchats.json"))
using (var fs = File.OpenRead(fileName))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
json = sr.ReadToEnd();
json = sr.ReadToEnd();
quickchats = JsonConvert.DeserializeObject<Dictionary<string, Quickchat>>(json);
// enable the commands.
return true;
@@ -82,15 +78,13 @@ namespace StarsiegeBot
[Description("Gives the `say()` for use in the Quickchat.cs file.")]
public async Task GetQuickChatScript(CommandContext ctx, [Description("ID of Quick chat to get script for.")] int index)
{
// trigger some typing on discord's side.
await ctx.TriggerTypingAsync();
// If we're disabled, let them know. And exit out.
if (!IsEnabled)
{
await ctx.RespondAsync("Quick Chat Commands have been disabled. Please contact the bot owners.");
return;
}
// trigger some typing on discord's side.
await ctx.TriggerTypingAsync();
// We're good to go... If we have an index, pull it up.
index = Math.Abs(index);
@@ -194,7 +188,7 @@ namespace StarsiegeBot
{
// Open the file.
FileStream sound = new FileStream($"./qc/{chat.soundFile}", FileMode.Open, FileAccess.Read);
// feed it to the Message Builder.
msg.WithFile(chat.soundFile, sound);
}
@@ -205,9 +199,9 @@ namespace StarsiegeBot
}
[Command("search"), Aliases("s")]
[Cooldown(1,5,CooldownBucketType.Global)]
[Cooldown(1, 5, CooldownBucketType.Global)]
[Description("Searches all the [T]ext and [S]ound file names for the Search input.")]
public async Task SearchQuickChats(CommandContext ctx, [RemainingText,Description("What to search for.")] string toSearch)
public async Task SearchQuickChats(CommandContext ctx, [RemainingText, Description("What to search for.")] string toSearch)
{
await ctx.TriggerTypingAsync();
string output;
@@ -223,7 +217,7 @@ namespace StarsiegeBot
StringBuilder sb = new StringBuilder();
DiscordMessageBuilder msg = new DiscordMessageBuilder();
int count = 0;
// We're going to search each QC for the stuff in toSearch.
foreach (KeyValuePair<string, Quickchat> qc in quickchats)
{
@@ -261,8 +255,8 @@ namespace StarsiegeBot
[Command("toggle"), Aliases("t")]
[RequireOwner]
[Description("[Owner only] Enables or disables, or checks status of QuickChats.")]
public async Task ToggleQC (CommandContext ctx, [RemainingText] string isEnabled = null)
[Description("[Owner only] Enables or disables, or checks status of QuickChats.\r\nTo turn the feature on, use `TRUE`, `ON`, or `1`\r\nTo turn off, use `FALSE`, `OFF`, or `0`")]
public async Task ToggleQC(CommandContext ctx, [RemainingText] string isEnabled = null)
{
await ctx.TriggerTypingAsync();
isEnabled = isEnabled.ToLower();
@@ -270,7 +264,7 @@ namespace StarsiegeBot
string[] turnOn = { "on", "true", "1" };
string[] turnOff = { "off", "false", "0" };
if (File.Exists("quickchats.json"))
if (File.Exists(fileName))
{
if (turnOn.Contains(isEnabled))
{
@@ -281,12 +275,12 @@ namespace StarsiegeBot
IsEnabled = false;
}
output = $"Quickchats {(IsEnabled ? "Enabled":"Disabled")}";
output = $"Quickchats {(IsEnabled ? "Enabled" : "Disabled")}";
}
else
{
IsEnabled = false;
output = "QuickChats.json file is missing, and it can not be enabled.";
output = $"{fileName} file is missing, and it can not be enabled.";
}
await ctx.RespondAsync(output);
}
+27
View File
@@ -18,4 +18,31 @@
<Folder Include="Unicorn\" />
</ItemGroup>
<ItemGroup>
<None Update="Code Organization.txt">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="Json\deathmessages.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Json\functions.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Json\guildsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Json\notfacts.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Json\questions.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Json\quickchats.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Json\snapple.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
+23 -58
View File
@@ -1,25 +1,11 @@
#pragma warning disable IDE0060 // Remove unused parameter
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.VoiceNext;
using System;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext.Exceptions;
using DSharpPlus.EventArgs;
using DSharpPlus.VoiceNext.Codec;
using Microsoft.Extensions.Logging;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using System.Threading;
using System.Threading.Tasks;
namespace StarsiegeBot
{
@@ -28,16 +14,12 @@ namespace StarsiegeBot
class WelcomeMessage : BotSettings
{
[GroupCommand]
public async Task GeneralWelcome (CommandContext ctx)
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]
};
DiscordEmbedBuilder embed = StartEmbed("Welcome Message Info");
if (GuildSettings[gId].WelcomeChannel is null)
embed.AddField("Channel", "*None*");
else
@@ -67,11 +49,7 @@ namespace StarsiegeBot
await ctx.TriggerTypingAsync();
string gId = ctx.Guild.Id.ToString();
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Description = "Welcome Message Usage",
Color = Program.colours[0]
};
DiscordEmbedBuilder embed = StartEmbed("Welcome Message Status");
embed.AddField("Old", GuildSettings[gId].UseWelcome.ToString(), true);
GuildSettings[gId].UseWelcome = enable;
embed.AddField("New", GuildSettings[gId].UseWelcome.ToString(), true);
@@ -82,11 +60,7 @@ namespace StarsiegeBot
{
await ctx.TriggerTypingAsync();
string gId = ctx.Guild.Id.ToString();
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Description = "Welcome Message Channel",
Color = Program.colours[0]
};
DiscordEmbedBuilder embed = StartEmbed("Welcome Message Channel");
if (GuildSettings[gId].WelcomeChannel != null)
{
embed.AddField("Old", GuildSettings[gId].WelcomeChannel.Mention, true);
@@ -101,15 +75,11 @@ namespace StarsiegeBot
await ctx.RespondAsync(embed);
}
[Command("Channel")]
public async Task WelcomeChannel(CommandContext ctx, [RemainingText]string here)
public async Task WelcomeChannel(CommandContext ctx, [RemainingText] string here)
{
await ctx.TriggerTypingAsync();
string gId = ctx.Guild.Id.ToString();
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Description = "Welcome Message Channel",
Color = Program.colours[0]
};
DiscordEmbedBuilder embed = StartEmbed("Welcome Message Channel");
if (GuildSettings[gId].WelcomeChannel != null)
{
embed.AddField("Old", GuildSettings[gId].WelcomeChannel.Mention, true);
@@ -125,41 +95,26 @@ namespace StarsiegeBot
}
[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();
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");
DiscordEmbedBuilder embed = StartEmbed("Welcome Message String");
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;
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]
};
DiscordEmbedBuilder embed = StartEmbed("List of placeholders and their intended replacement. Channel tags can be inserted without a placeholder.");
embed.Title = "Welcome Message Help";
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.");
@@ -175,5 +130,15 @@ namespace StarsiegeBot
.Replace("[mention]", member.Mention, StringComparison.OrdinalIgnoreCase);
return output;
}
private DiscordEmbedBuilder StartEmbed(string desc)
{
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Description = desc,
Color = Program.colours[0]
};
return embed;
}
}
}