Standardize formatting
* Updated remaining indentation to spaces (x4) * Added editorconfig * Added a newline to the end of files which didn't have one * Replaced any lines containing only spaces with blank lines
This commit is contained in:
parent
062f3ceb2f
commit
ac4b268508
|
@ -0,0 +1,9 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
[*.cs]
|
||||
indent_size = 4
|
||||
indent_style = space
|
|
@ -12,21 +12,20 @@
|
|||
<PackageReference Include="CodeHollow.FeedReader" Version="1.2.6" />
|
||||
<PackageReference Include="DSharpPlus" Version="4.4.2" />
|
||||
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.4.2" />
|
||||
<PackageReference Include="DSharpPlus.Interactivity" Version="4.4.2" />
|
||||
<PackageReference Include="DSharpPlus.Interactivity" Version="4.4.2" />
|
||||
<PackageReference Include="Magick.NET-Q16-x64" Version="13.2.0" />
|
||||
<PackageReference Include="MarkovSharp" Version="4.0.32" />
|
||||
<PackageReference Include="MarkovSharp" Version="4.0.32" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.6.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Miki.UrbanDictionary" Version="5.0.0-v5248015595" />
|
||||
<PackageReference Include="Miki.UrbanDictionary" Version="5.0.0-v5248015595" />
|
||||
<PackageReference Include="Newtonsoft.json" Version="13.0.3" />
|
||||
<PackageReference Include="RestSharp" Version="110.2.0" />
|
||||
<PackageReference Include="ScottPlot" Version="4.0.49" />
|
||||
<PackageReference Include="Serilog" Version="3.0.1" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.1" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.1" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
|
||||
<PackageReference Include="Genbox.Wikipedia" Version="4.0.0" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
32
HBot.sln
32
HBot.sln
|
@ -6,20 +6,20 @@ MinimumVisualStudioVersion = 10.0.40219.1
|
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBot", "HBot.csproj", "{BC8E712F-D5D6-4941-88BF-1C877A412F13}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BC8E712F-D5D6-4941-88BF-1C877A412F13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BC8E712F-D5D6-4941-88BF-1C877A412F13}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BC8E712F-D5D6-4941-88BF-1C877A412F13}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BC8E712F-D5D6-4941-88BF-1C877A412F13}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {88DD5A88-85B3-46C4-B2DA-B5C895D11CA5}
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BC8E712F-D5D6-4941-88BF-1C877A412F13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BC8E712F-D5D6-4941-88BF-1C877A412F13}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BC8E712F-D5D6-4941-88BF-1C877A412F13}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BC8E712F-D5D6-4941-88BF-1C877A412F13}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {88DD5A88-85B3-46C4-B2DA-B5C895D11CA5}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace HBot {
|
|||
|
||||
await VerifyIntegrityAsync();
|
||||
LoadConfigs();
|
||||
|
||||
|
||||
// Set up the Discord client
|
||||
client = new DiscordClient(new DiscordConfiguration() {
|
||||
Token = config.token,
|
||||
|
@ -248,7 +248,7 @@ namespace HBot {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This is awful awful awful awful awful AWFUL to do this on every startup
|
||||
// but I'm lazy and it's the only way I can think of right now to make the bot
|
||||
// update lyrics on startup lol
|
||||
|
@ -279,7 +279,7 @@ namespace HBot {
|
|||
public APIConfig apiKeys { get; set; }
|
||||
public MCServer[] minecraftServers { get; set; }
|
||||
}
|
||||
|
||||
|
||||
class IDConfig {
|
||||
public ulong targetGuild { get; set; } = 0; // Where muted role etc are
|
||||
public ulong logChannel { get; set; } = 0;
|
||||
|
@ -300,7 +300,7 @@ namespace HBot {
|
|||
public static List<List<string>> reminders = new List<List<string>>();
|
||||
public static DiscordGuild targetGuild;
|
||||
public static DiscordChannel logChannel = null;
|
||||
|
||||
|
||||
// Moderation
|
||||
public static List<ulong> blacklistedUsers = new List<ulong>();
|
||||
public static List<ulong> mutedUsers = new List<ulong>();
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace HBot.Commands {
|
|||
if(msg.ToLower().Contains(": 413.")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
await Global.logChannel.SendMessageAsync($"**Command Execution Failed!**\n**Command:** `{e.Command.Name}`\n**Message:** `{e.Context.Message.Content}`\n**Exception:** `{e.Exception}`");
|
||||
if(msg != "One or more pre-execution checks failed.")
|
||||
await e.Context.RespondAsync($"There was an error executing your command!\nMessage: `{msg}`");
|
||||
|
|
|
@ -12,7 +12,7 @@ using HBot.Commands.Attributes;
|
|||
|
||||
namespace HBot.Commands.Fun {
|
||||
public class BedCommand : BaseCommandModule {
|
||||
[Command("bed")]
|
||||
[Command("bed")]
|
||||
[Description("Tell someone to go to bed.")]
|
||||
[Usage("[User] [Image: parz, agp, agp2, mehdi]")]
|
||||
[Attributes.Category(Category.Fun)]
|
||||
|
@ -21,7 +21,7 @@ namespace HBot.Commands.Fun {
|
|||
if(image == "parz" || string.IsNullOrWhiteSpace(image))
|
||||
image = images[new System.Random().Next(0, images.Length)];
|
||||
|
||||
// Select the image with some YanDev code
|
||||
// Select the image with some YanDev code
|
||||
string imageFile = GetResourcePath("parz.png", Util.ResourceType.Resource);
|
||||
float genX = 365f;
|
||||
float bedY = 506f;
|
||||
|
@ -51,12 +51,12 @@ namespace HBot.Commands.Fun {
|
|||
// Load the font
|
||||
PrivateFontCollection fonts = new PrivateFontCollection();
|
||||
fonts.AddFontFile(GetResourcePath("impact.ttf", Util.ResourceType.Resource));
|
||||
|
||||
// Create the image
|
||||
|
||||
// Create the image
|
||||
Bitmap img = new Bitmap(Bitmap.FromFile(imageFile));
|
||||
Graphics bmp = Graphics.FromImage(img);
|
||||
|
||||
// Set up the fonts and drawing stuff
|
||||
Graphics bmp = Graphics.FromImage(img);
|
||||
|
||||
// Set up the fonts and drawing stuff
|
||||
Font IMPACTfont = new Font (
|
||||
fonts.Families[0].Name,
|
||||
fontSize,
|
||||
|
@ -65,23 +65,23 @@ namespace HBot.Commands.Fun {
|
|||
);
|
||||
|
||||
SolidBrush brush;
|
||||
brush = new SolidBrush(System.Drawing.Color.White);
|
||||
StringFormat snFormat = new StringFormat();
|
||||
snFormat.Alignment = StringAlignment.Center;
|
||||
snFormat.LineAlignment = StringAlignment.Center;
|
||||
|
||||
// Draw the text onto the image
|
||||
brush = new SolidBrush(System.Drawing.Color.White);
|
||||
StringFormat snFormat = new StringFormat();
|
||||
snFormat.Alignment = StringAlignment.Center;
|
||||
snFormat.LineAlignment = StringAlignment.Center;
|
||||
|
||||
// Draw the text onto the image
|
||||
bmp.DrawString("GO TO BED", IMPACTfont, brush, genX, bedY, snFormat);
|
||||
bmp.DrawString(screenname.ToUpper(), IMPACTfont, brush, genX, userY, snFormat);
|
||||
|
||||
// Save the image to a temporary file
|
||||
bmp.DrawString(screenname.ToUpper(), IMPACTfont, brush, genX, userY, snFormat);
|
||||
|
||||
// Save the image to a temporary file
|
||||
bmp.Save();
|
||||
string imagePath = TempManager.GetTempFile($"bed-{image}-" + DateTime.Now.Ticks + "-{Context.User.Id}.png", true);
|
||||
img.Save(imagePath);
|
||||
await Context.Channel.SendFileAsync(imagePath);
|
||||
TempManager.RemoveTempFile($"bed-{image}-" + DateTime.Now.Ticks + "-{Context.User.Id}.png");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static string[] images = { "NONE", "mehdi", "agp", "agp2" };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace HBot.Commands.Fun {
|
|||
[Attributes.Category(Category.Fun)]
|
||||
public async Task Exec(CommandContext Context) {
|
||||
DiscordEmbedBuilder eb = new DiscordEmbedBuilder();
|
||||
eb.WithTitle("BSD Fortune program... but Discord");
|
||||
eb.WithTitle("BSD Fortune program... but Discord");
|
||||
eb.WithColor(DiscordColor.Gold);
|
||||
if(!Environment.OSVersion.VersionString.Contains("Unix"))
|
||||
eb.WithDescription($"```{Shell.WinCmd("C:\\cygwin64\\bin\\fortune.exe -a")}```");
|
||||
|
@ -26,4 +26,4 @@ namespace HBot.Commands.Fun {
|
|||
await Context.ReplyAsync("", eb.Build());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ using HBot.Commands.Attributes;
|
|||
|
||||
namespace HBot.Commands.Fun {
|
||||
public class GZTrCommand : BaseCommandModule {
|
||||
[Command("gztr")]
|
||||
[Command("gztr")]
|
||||
[Description("One-way Gen Z translator")]
|
||||
[Usage("[Normal Human Text]")]
|
||||
[Attributes.Category(Category.Fun)]
|
||||
|
@ -18,7 +18,7 @@ namespace HBot.Commands.Fun {
|
|||
output = output.Replace(word.Key, word.Value);
|
||||
output = output.Replace("'", "").Replace("@", "").Replace(",", "");
|
||||
await Context.ReplyAsync(output);
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, string> Dicctionary = new Dictionary<string, string>() {
|
||||
{ "enough", "enf" },
|
||||
|
@ -58,5 +58,5 @@ namespace HBot.Commands.Fun {
|
|||
{ "cool", "based" },
|
||||
{ "amazing", "straight buckets bro" }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ namespace HBot.Commands.Fun {
|
|||
[Attributes.Category(Category.Fun)]
|
||||
public async Task HTTP(CommandContext Context, string code = "") {
|
||||
string url = "";
|
||||
string[] codes = { "0", "100", "101", "102", "200", "201", "202", "203", "204", "206", "207", "300", "301", "302", "303", "304", "305", "307", "308", "400", "401", "402", "403", "404", "405", "406", "407", "408", "409", "410", "411", "412", "413", "414", "415", "416", "417", "418", "420", "421", "422", "423", "424", "425", "426", "428", "429", "431", "444", "450", "451", "497", "498", "499", "500", "501", "502", "503", "504", "506", "507", "508", "509", "510", "511", "521", "523", "525", "599" };
|
||||
string[] codes = { "0", "100", "101", "102", "200", "201", "202", "203", "204", "206", "207", "300", "301", "302", "303", "304", "305", "307", "308", "400", "401", "402", "403", "404", "405", "406", "407", "408", "409", "410", "411", "412", "413", "414", "415", "416", "417", "418", "420", "421", "422", "423", "424", "425", "426", "428", "429", "431", "444", "450", "451", "497", "498", "499", "500", "501", "502", "503", "504", "506", "507", "508", "509", "510", "511", "521", "523", "525", "599" };
|
||||
if (code != "")
|
||||
if (Array.IndexOf(codes, code) != -1) url = $"https://http.cat/{code}";
|
||||
if (Array.IndexOf(codes, code) != -1) url = $"https://http.cat/{code}";
|
||||
else throw new System.Exception("Invalid HTTP status code!");
|
||||
else {
|
||||
int codeLength = codes.Length - 1;
|
||||
|
@ -34,4 +34,4 @@ namespace HBot.Commands.Fun {
|
|||
await Context.RespondAsync("", eb.Build());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace HBot.Commands.Fun {
|
|||
}
|
||||
jargon += things[r.Next(0, things.Length)] + " ";
|
||||
}
|
||||
|
||||
|
||||
// Send an embed
|
||||
DiscordEmbedBuilder eb = new DiscordEmbedBuilder();
|
||||
eb.WithColor(DiscordColor.Gold);
|
||||
|
|
|
@ -26,9 +26,9 @@ namespace HBot.Commands.fun {
|
|||
eb.WithTitle("Get insulted... loser.");
|
||||
eb.WithColor(DiscordColor.Gold);
|
||||
eb.WithDescription($"{insultText.insult}");
|
||||
|
||||
|
||||
// Send the thing
|
||||
await Context.ReplyAsync("", eb.Build());
|
||||
}
|
||||
}
|
||||
await Context.ReplyAsync("", eb.Build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,12 +22,12 @@ namespace HBot.Commands.Fun {
|
|||
dynamic output = JsonConvert.DeserializeObject(json); // Deserialize the string into a dynamic object
|
||||
|
||||
// Send the image in an embed
|
||||
DiscordEmbedBuilder eb = new DiscordEmbedBuilder();
|
||||
eb.WithTitle("Rory");
|
||||
eb.WithColor(DiscordColor.Gold);
|
||||
eb.WithFooter($"Rory ID: {output.id}");
|
||||
eb.WithImageUrl((string)output.url);
|
||||
await Context.ReplyAsync("", eb.Build());
|
||||
DiscordEmbedBuilder eb = new DiscordEmbedBuilder();
|
||||
eb.WithTitle("Rory");
|
||||
eb.WithColor(DiscordColor.Gold);
|
||||
eb.WithFooter($"Rory ID: {output.id}");
|
||||
eb.WithImageUrl((string)output.url);
|
||||
await Context.ReplyAsync("", eb.Build());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace HBot.Commands.Fun {
|
|||
await context.Message.RespondAsync("Do not dumb.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
await context.Message.DeleteAsync();
|
||||
await context.Channel.SendMessageAsync(message);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace HBot.Commands.Fun {
|
|||
|
||||
string imageName = $"{formattedNumber}";
|
||||
string encodedImageName = Uri.EscapeDataString(imageName);
|
||||
|
||||
|
||||
string url = $"https://focabot.github.io/random-seal/seals/{encodedImageName}.jpg";
|
||||
|
||||
var eb = new DiscordEmbedBuilder();
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace HBot.Commands.Main
|
|||
await Context.ReplyAsync("I can't play Tic Tac Toe with myself!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Create a new game
|
||||
TicTacToeGame game = new TicTacToeGame(Context.User, user, Context);
|
||||
|
||||
|
@ -100,7 +100,7 @@ namespace HBot.Commands.Main
|
|||
|
||||
// Game loop
|
||||
while(isRunning) {
|
||||
|
||||
|
||||
// Get player 1's move in a message
|
||||
if(inputMessage == null)
|
||||
inputMessage = await Context.Channel.SendMessageAsync($"{player1.Mention}, make your move!");
|
||||
|
@ -260,14 +260,14 @@ namespace HBot.Commands.Main
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check columns
|
||||
for(int i = 0; i < 3; i++) {
|
||||
if(grid[0,i] == grid[1,i] && grid[1,i] == grid[2,i] && grid[0,i] != "-") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check diagonals
|
||||
if(grid[0,0] == grid[1,1] && grid[1,1] == grid[2,2] && grid[0,0] != "-") {
|
||||
return true;
|
||||
|
@ -275,7 +275,7 @@ namespace HBot.Commands.Main
|
|||
if(grid[0,2] == grid[1,1] && grid[1,1] == grid[2,0] && grid[0,2] != "-") {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Check for free space
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 3; j++) {
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace HBot.Commands.Main
|
|||
return;
|
||||
}
|
||||
else if(input != null && input.ToLower() == "lb") {
|
||||
|
||||
|
||||
List<User> leaderboard = UserData.users.OrderByDescending(x => x.correctTrivia).ToList();
|
||||
foreach(User tUser in leaderboard)
|
||||
tUser.triviaScore = (int)((float)tUser.correctTrivia/(float)tUser.totalTrivia*100.0f)*tUser.correctTrivia;
|
||||
|
@ -89,12 +89,12 @@ namespace HBot.Commands.Main
|
|||
answerStrings.Add((string)output.results[0].correct_answer);
|
||||
for(int i = 0; i < output.results[0].incorrect_answers.Count; i++)
|
||||
answerStrings.Add((string)output.results[0].incorrect_answers[i]);
|
||||
|
||||
|
||||
// Shuffle answers
|
||||
int answer = 0;
|
||||
string answerText = "";
|
||||
for(int i = answerStrings.Count-1; i > 0; i--) {
|
||||
|
||||
|
||||
// Swap random answers
|
||||
int k = new Random().Next(i+1);
|
||||
string value = answerStrings[k];
|
||||
|
@ -112,7 +112,7 @@ namespace HBot.Commands.Main
|
|||
// Cleanly format the answers
|
||||
for(int i = 0; i < answerStrings.Count; i++)
|
||||
answerStrings[i] = $"[{i + 1}] " + HttpUtility.HtmlDecode(answerStrings[i]);
|
||||
|
||||
|
||||
// Create and send trivia embed
|
||||
DiscordEmbedBuilder eb = new DiscordEmbedBuilder();
|
||||
eb.WithColor(DiscordColor.Gold);
|
||||
|
@ -139,7 +139,7 @@ namespace HBot.Commands.Main
|
|||
// Parse the answer number
|
||||
int.TryParse(result.Result.Content, out int index);
|
||||
index -= 1;
|
||||
|
||||
|
||||
// Verify answer & send response embed
|
||||
DiscordEmbedBuilder eb2 = new DiscordEmbedBuilder();
|
||||
User user = UserData.GetOrCreateUser(result.Result.Author);
|
||||
|
|
|
@ -18,39 +18,39 @@ namespace HBot.Commands.Fun {
|
|||
[Usage("[query]")]
|
||||
[Attributes.Category(Category.Fun)]
|
||||
public async Task Urban(CommandContext Context, [RemainingText]string query) {
|
||||
if(string.IsNullOrWhiteSpace(query)) {
|
||||
throw new Exception("You must provide a search query!");
|
||||
}
|
||||
if(string.IsNullOrWhiteSpace(query)) {
|
||||
throw new Exception("You must provide a search query!");
|
||||
}
|
||||
|
||||
// Get the definition
|
||||
UrbanDictionaryApi api = new UrbanDictionaryApi();
|
||||
var definition = await api.SearchTermAsync(query);
|
||||
UrbanDictionaryApi api = new UrbanDictionaryApi();
|
||||
var definition = await api.SearchTermAsync(query);
|
||||
|
||||
// Error checking
|
||||
bool hasExample = true;
|
||||
if (definition.List.Count < 1 || string.IsNullOrWhiteSpace(definition.List.First().Definition.Truncate(1024))) {
|
||||
await Context.ReplyAsync("Error: There are no results for that query.");
|
||||
return;
|
||||
}
|
||||
// Error checking
|
||||
bool hasExample = true;
|
||||
if (definition.List.Count < 1 || string.IsNullOrWhiteSpace(definition.List.First().Definition.Truncate(1024))) {
|
||||
await Context.ReplyAsync("Error: There are no results for that query.");
|
||||
return;
|
||||
}
|
||||
|
||||
else if (string.IsNullOrWhiteSpace(definition.List.First().Example.Truncate(1024))) {
|
||||
hasExample = false;
|
||||
}
|
||||
else if (string.IsNullOrWhiteSpace(definition.List.First().Example.Truncate(1024))) {
|
||||
hasExample = false;
|
||||
}
|
||||
|
||||
// Create an embed
|
||||
DiscordEmbedBuilder eb = new DiscordEmbedBuilder();
|
||||
var result = definition.List[new Random().Next(0, definition.List.Count)];
|
||||
eb.WithTitle($"Urban Dictionary: {query}");
|
||||
eb.WithColor(DiscordColor.Gold);
|
||||
eb.AddField("Definition", result.Definition.Truncate(1024));
|
||||
if(hasExample) {
|
||||
eb.AddField("Examples", result.Example.Truncate(1024));
|
||||
}
|
||||
eb.WithUrl(result.Permalink);
|
||||
eb.WithThumbnail("https://reclaimthenet.org/wp-content/uploads/2020/07/urban-dictionary.png");
|
||||
eb.WithFooter($"The information above does not represent the views of {Context.Guild.Name} or {Bot.client.CurrentApplication.Owners.First().Username}, obviously :P");
|
||||
// Create an embed
|
||||
DiscordEmbedBuilder eb = new DiscordEmbedBuilder();
|
||||
var result = definition.List[new Random().Next(0, definition.List.Count)];
|
||||
eb.WithTitle($"Urban Dictionary: {query}");
|
||||
eb.WithColor(DiscordColor.Gold);
|
||||
eb.AddField("Definition", result.Definition.Truncate(1024));
|
||||
if(hasExample) {
|
||||
eb.AddField("Examples", result.Example.Truncate(1024));
|
||||
}
|
||||
eb.WithUrl(result.Permalink);
|
||||
eb.WithThumbnail("https://reclaimthenet.org/wp-content/uploads/2020/07/urban-dictionary.png");
|
||||
eb.WithFooter($"The information above does not represent the views of {Context.Guild.Name} or {Bot.client.CurrentApplication.Owners.First().Username}, obviously :P");
|
||||
|
||||
await Context.ReplyAsync("", eb.Build());
|
||||
await Context.ReplyAsync("", eb.Build());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ namespace HBot.Commands.Images {
|
|||
image.Resize(image.Width/2, image.Height/2);
|
||||
image.Posterize(2, DitherMethod.Undefined, Channels.RGB);
|
||||
image.Resize(image.Width*2, image.Height*2);
|
||||
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(args.textArg) && args.textArg.ToLower() == "-jpeg" && args.extension.ToLower() != "gif") {
|
||||
JpegCommand.DoJpegification(image, args);
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace HBot.Commands.Images {
|
|||
gif.Write(imgStream);
|
||||
}
|
||||
imgStream.Position = 0;
|
||||
|
||||
|
||||
// Send the image
|
||||
await msg.ModifyAsync("Uploading...\nThis may take a while depending on the image size");
|
||||
await Context.Channel.SendFileAsync(imgStream, "haah."+args.extension);
|
||||
|
@ -74,7 +74,7 @@ namespace HBot.Commands.Images {
|
|||
public static void DoHaah(MagickImage image) {
|
||||
MagickImage right;
|
||||
right = (MagickImage)image.Clone();
|
||||
|
||||
|
||||
int width = image.Width/2;
|
||||
if(width <= 0) {
|
||||
width = 1;
|
||||
|
@ -83,7 +83,7 @@ namespace HBot.Commands.Images {
|
|||
right.Crop(width, image.Height, Gravity.West);
|
||||
right.Rotate(180);
|
||||
right.Flip();
|
||||
|
||||
|
||||
image.Composite(right, width, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ namespace HBot.Commands.Images {
|
|||
public static void DoHooh(MagickImage image) {
|
||||
MagickImage top;
|
||||
top = (MagickImage)image.Clone();
|
||||
|
||||
|
||||
int height = image.Height/2;
|
||||
if(height <= 0) {
|
||||
height = 1;
|
||||
|
@ -83,7 +83,7 @@ namespace HBot.Commands.Images {
|
|||
|
||||
top.Crop(image.Width, height, Gravity.South);
|
||||
top.Flip();
|
||||
|
||||
|
||||
image.Composite(top);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,11 +72,11 @@ namespace HBot.Commands.Images {
|
|||
if (args.scale > 3) {
|
||||
throw new System.Exception("Scale must not be greater than 3");
|
||||
}
|
||||
|
||||
|
||||
MagickFormat originalFormat = image.Format;
|
||||
image.Format = MagickFormat.Jpeg;
|
||||
image.Quality = args.scale;
|
||||
|
||||
|
||||
// Temporarily save the image to memory
|
||||
MemoryStream stream = new MemoryStream();
|
||||
image.Write(stream);
|
||||
|
@ -91,7 +91,7 @@ namespace HBot.Commands.Images {
|
|||
if (args.scale > 3) {
|
||||
throw new System.Exception("Scale must not be greater than 3");
|
||||
}
|
||||
|
||||
|
||||
/* If we're doing gradual scaling, add the number of frames in the gif to the scale
|
||||
this is to provide room for decrementing the value, thus creating a gradual
|
||||
jpegification effect. */
|
||||
|
@ -104,7 +104,7 @@ namespace HBot.Commands.Images {
|
|||
IMagickImage<ushort> newFrame = frame.Clone();
|
||||
newFrame.Format = MagickFormat.Jpeg;
|
||||
newFrame.Quality = args.scale;
|
||||
|
||||
|
||||
// Temporarily save the image to memory
|
||||
MemoryStream stream = new MemoryStream();
|
||||
newFrame.Write(stream);
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace HBot.Commands.Images {
|
|||
var tmp = gif.OrderBy(x => new System.Random().Next()).ToArray();
|
||||
gif = new MagickImageCollection(tmp);
|
||||
}
|
||||
|
||||
|
||||
TempManager.RemoveTempFile(seed+"-scrambleDL."+args.extension);
|
||||
|
||||
// Save the image
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace HBot.Commands.Images {
|
|||
img.Resize(new MagickGeometry("256x256!"));
|
||||
mask.Resize(new MagickGeometry($"{img.Width}x{img.Height}!"));
|
||||
img.Composite(mask, Channels.Opacity);
|
||||
|
||||
|
||||
// Rotate
|
||||
gifOut.Add(img);
|
||||
for(int i = 0; i <= 340; i += 20) {
|
||||
|
@ -85,7 +85,7 @@ namespace HBot.Commands.Images {
|
|||
}
|
||||
gifOut.Deconstruct();
|
||||
gifOut.RePage();
|
||||
|
||||
|
||||
return gifOut;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ namespace HBot.Commands.Images {
|
|||
public static void DoWaaw(MagickImage image) {
|
||||
MagickImage left;
|
||||
left = (MagickImage)image.Clone();
|
||||
|
||||
|
||||
int width = image.Width/2;
|
||||
if(width <= 0) {
|
||||
width = 1;
|
||||
|
@ -81,7 +81,7 @@ namespace HBot.Commands.Images {
|
|||
left.Crop(width, image.Height, Gravity.East);
|
||||
left.Rotate(180);
|
||||
left.Flip();
|
||||
|
||||
|
||||
image.Composite(left);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,14 +73,14 @@ namespace HBot.Commands.Images {
|
|||
public static void DoWoow(MagickImage image) {
|
||||
MagickImage bottom;
|
||||
bottom = (MagickImage)image.Clone();
|
||||
|
||||
|
||||
int height = image.Height/2;
|
||||
if(height <= 0) {
|
||||
height = 1;
|
||||
}
|
||||
bottom.Crop(image.Width, height, Gravity.North);
|
||||
bottom.Flip();
|
||||
|
||||
|
||||
image.Composite(bottom, 0, height);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace HBot.Commands.Main {
|
|||
await Context.ReplyAsync("Must be in format #000000 (# is optional) and be valid HEX");
|
||||
return;
|
||||
}
|
||||
DiscordEmbedBuilder eb = new DiscordEmbedBuilder();
|
||||
DiscordEmbedBuilder eb = new DiscordEmbedBuilder();
|
||||
eb.WithThumbnail($"https://singlecolorimage.com/get/{hexString}/100x100");
|
||||
if (!hexString.StartsWith("#")) hexString = $"#{hexString}";
|
||||
eb.WithTitle($"Color Info");
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace HBot.Commands.Main {
|
|||
eb.WithFooter($"Type \"{Bot.config.prefix}help [command]\" for more info on a specific command");
|
||||
|
||||
if(command == null) {
|
||||
|
||||
|
||||
// List all commands
|
||||
eb.WithTitle($"{Bot.client.CurrentUser.Username} Commands");
|
||||
eb.AddField("**Main**", GetCommands(Category.Main), false);
|
||||
|
@ -77,7 +77,7 @@ namespace HBot.Commands.Main {
|
|||
if (command == null)
|
||||
return null;
|
||||
UsageAttribute usage = (UsageAttribute)command.CustomAttributes.FirstOrDefault(x => x.GetType() == typeof(UsageAttribute));
|
||||
|
||||
|
||||
// Create the usage string
|
||||
string desc = $"{command.Description}\n\n**Usage:** {Bot.config.prefix}{commandName}";
|
||||
if (usage != null)
|
||||
|
|
|
@ -34,29 +34,29 @@ namespace HBot.Commands.Main {
|
|||
|
||||
// Download the server info
|
||||
string json = "";
|
||||
|
||||
|
||||
using(HttpClient http = new HttpClient())
|
||||
json = await http.GetStringAsync($"https://api.mcsrvstat.us/2/{server.address}");
|
||||
|
||||
dynamic serverInfo = JsonConvert.DeserializeObject(json);
|
||||
|
||||
|
||||
// Format the info in an embed
|
||||
DiscordEmbedBuilder eb = new DiscordEmbedBuilder();
|
||||
eb.WithColor(DiscordColor.Gold);
|
||||
|
||||
// Set up the embed
|
||||
|
||||
// Set up the embed
|
||||
if((bool)serverInfo.online) {
|
||||
eb.WithThumbnail(Context.Guild.IconUrl);
|
||||
eb.WithTitle(WebUtility.HtmlDecode((string)serverInfo.motd.clean[0]));
|
||||
eb.AddField("Address", server.address, true);
|
||||
eb.AddField("Versions", server.versions, true);
|
||||
if (server.dynmap != null)
|
||||
eb.AddField("Dynmap", server.dynmap, true);
|
||||
eb.AddField("Dynmap", server.dynmap, true);
|
||||
eb.AddField("Online?", ((bool)serverInfo.online) ? "Yes" : "No", true);
|
||||
eb.AddField("Users Count", $"{(int)serverInfo.players.online}/{(int)serverInfo.players.max}", true);
|
||||
if((int)serverInfo.players.online > 0) {
|
||||
eb.AddField("Users", $"{string.Join('\n', serverInfo.players.list)}", true);
|
||||
}
|
||||
eb.AddField("Users", $"{string.Join('\n', serverInfo.players.list)}", true);
|
||||
}
|
||||
eb.AddField("Supports Cracked Accounts?", server.crackedInfo, true);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace HBot.Commands.Main {
|
|||
Bitmap bmp = new Bitmap(934, 282);
|
||||
Graphics img = Graphics.FromImage(bmp);
|
||||
img.Clear(Color.FromArgb(35, 39, 42));
|
||||
|
||||
|
||||
// Graphics
|
||||
img.DrawImage(avatar, new Point(26, 26)); // 26 in on x and y with a 230x230 avatar allows for all 3 sides to be evenly spaced.
|
||||
brush.Color = Color.FromArgb(72, 75, 78);
|
||||
|
|
|
@ -31,9 +31,9 @@ namespace HBot.Commands.Main {
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
TimeSpan timeSpan;
|
||||
TimeSpan maxDelay = TimeSpan.FromDays(24); //workaround for Task.Delay limitations
|
||||
|
||||
TimeSpan timeSpan;
|
||||
TimeSpan maxDelay = TimeSpan.FromDays(24); //workaround for Task.Delay limitations
|
||||
|
||||
if (timeStr.EndsWith("s")) {
|
||||
if (!int.TryParse(timeStr.TrimEnd('s'), out int seconds)) {
|
||||
|
@ -82,17 +82,17 @@ namespace HBot.Commands.Main {
|
|||
|
||||
await Context.RespondAsync($"Reminder set for {timeStr} from now.");
|
||||
|
||||
|
||||
|
||||
var reminderTime = DateTime.Now + timeSpan;
|
||||
var reminder = Tuple.Create(message, reminderTime);
|
||||
reminders.AddOrUpdate(Context.User.Id, new List<Tuple<string, DateTime>> { reminder }, (key, oldList) => { oldList.Add(reminder); return oldList; });
|
||||
|
||||
// workaround for Task.Delay limitations
|
||||
// workaround for Task.Delay limitations
|
||||
while (timeSpan > maxDelay) {
|
||||
await Task.Delay(maxDelay);
|
||||
timeSpan -= maxDelay;
|
||||
}
|
||||
await Task.Delay(timeSpan);
|
||||
await Task.Delay(maxDelay);
|
||||
timeSpan -= maxDelay;
|
||||
}
|
||||
await Task.Delay(timeSpan);
|
||||
|
||||
// Send the reminder
|
||||
await Context.RespondAsync($"{Context.User.Mention}: {message}");
|
||||
|
|
|
@ -57,7 +57,6 @@ namespace HBot.Commands.Main
|
|||
case "Voice":
|
||||
types[8] += 1;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,11 +163,11 @@ Placeholder
|
|||
eb.AddField("Features", $@"```
|
||||
{features}
|
||||
```");
|
||||
|
||||
|
||||
eb.AddField("URLs", $"**[Icon Image]({Guild.IconUrl})**, **[Splash Image]({Guild.SplashUrl})**");
|
||||
|
||||
eb.WithImageUrl(Guild.BannerUrl);
|
||||
|
||||
|
||||
await Context.ReplyAsync("", eb.Build());
|
||||
}
|
||||
|
||||
|
|
|
@ -16,69 +16,69 @@ namespace HBot.Commands.Main {
|
|||
public class TranslateCommand : BaseCommandModule {
|
||||
[Command("tr")]
|
||||
[Description("Translates text from one language to another")]
|
||||
[Usage("[-from=code] [-to=code] [text]")]
|
||||
[Usage("[-from=code] [-to=code] [text]")]
|
||||
[Attributes.Category(Category.Main)]
|
||||
public async Task Translate(CommandContext Context, [RemainingText]string text = null) {
|
||||
string source = "";
|
||||
string source = "";
|
||||
string target = "";
|
||||
string arg1 = "";
|
||||
string arg2 = "";
|
||||
string apiUrl = "https://translate.argosopentech.com/";
|
||||
string confidence = "";
|
||||
//bool auto = false;
|
||||
HttpClient client = new HttpClient();
|
||||
try { arg1 = text.Split()[0]; } catch { arg1 = ""; }
|
||||
try { arg2 = text.Split()[1]; } catch { arg2 = ""; }
|
||||
|
||||
string arg1 = "";
|
||||
string arg2 = "";
|
||||
string apiUrl = "https://translate.argosopentech.com/";
|
||||
string confidence = "";
|
||||
//bool auto = false;
|
||||
HttpClient client = new HttpClient();
|
||||
try { arg1 = text.Split()[0]; } catch { arg1 = ""; }
|
||||
try { arg2 = text.Split()[1]; } catch { arg2 = ""; }
|
||||
|
||||
if (arg1.Contains("-from=")) {
|
||||
source = arg1.Replace("-from=", "");
|
||||
} else if (arg1.Contains("-to=")) {
|
||||
target = arg1.Replace("-to=", "");
|
||||
}
|
||||
|
||||
|
||||
if (arg2.Contains("-from=")) {
|
||||
source = arg2.Replace("-from=", "");
|
||||
} else if (arg2.Contains("-to=")) {
|
||||
target = arg2.Replace("-to=", "");
|
||||
}
|
||||
string sourceText = text.Replace($"-from={source}", "");
|
||||
string sourceText = text.Replace($"-from={source}", "");
|
||||
sourceText = sourceText.Replace($"-to={target}", "");
|
||||
if (source == "") {
|
||||
var values2 = new Dictionary<string, string>
|
||||
{
|
||||
{ "q", sourceText },
|
||||
{ "api_key", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" }
|
||||
};
|
||||
var data2 = new FormUrlEncodedContent(values2);
|
||||
var response2 = await client.PostAsync($"{apiUrl}detect", data2);
|
||||
dynamic responseData2 = JsonConvert.DeserializeObject(await response2.Content.ReadAsStringAsync());
|
||||
source = responseData2[0].language;
|
||||
//auto = true;
|
||||
confidence = $"{responseData2[0].confidence}";
|
||||
}
|
||||
|
||||
if (target == "") target = "en";
|
||||
if (source == "") {
|
||||
var values2 = new Dictionary<string, string>
|
||||
{
|
||||
{ "q", sourceText },
|
||||
{ "api_key", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" }
|
||||
};
|
||||
var data2 = new FormUrlEncodedContent(values2);
|
||||
var response2 = await client.PostAsync($"{apiUrl}detect", data2);
|
||||
dynamic responseData2 = JsonConvert.DeserializeObject(await response2.Content.ReadAsStringAsync());
|
||||
source = responseData2[0].language;
|
||||
//auto = true;
|
||||
confidence = $"{responseData2[0].confidence}";
|
||||
}
|
||||
|
||||
if (target == "") target = "en";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var values = new Dictionary<string, string> {
|
||||
{ "q", sourceText },
|
||||
{ "source", source },
|
||||
{ "target", target },
|
||||
{ "format", "text" },
|
||||
{ "api_key", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" }
|
||||
{ "api_key", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" }
|
||||
};
|
||||
|
||||
var data = new FormUrlEncodedContent(values);
|
||||
var response = await client.PostAsync($"{apiUrl}translate", data);
|
||||
dynamic responseData = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
|
||||
string translatedText = Convert.ToString(responseData.translatedText);
|
||||
if (translatedText.Length >= 1024) {
|
||||
string baseUrl = "https://paste.hiden.pw/";
|
||||
var hasteBinClient = new HasteBinClient(baseUrl);
|
||||
HasteBinResult HBresult = hasteBinClient.Post(translatedText).Result;
|
||||
translatedText = $"{baseUrl}{HBresult.Key}";
|
||||
}
|
||||
string translatedText = Convert.ToString(responseData.translatedText);
|
||||
if (translatedText.Length >= 1024) {
|
||||
string baseUrl = "https://paste.hiden.pw/";
|
||||
var hasteBinClient = new HasteBinClient(baseUrl);
|
||||
HasteBinResult HBresult = hasteBinClient.Post(translatedText).Result;
|
||||
translatedText = $"{baseUrl}{HBresult.Key}";
|
||||
}
|
||||
DiscordEmbedBuilder eb = new DiscordEmbedBuilder();
|
||||
eb.WithTitle($"Translate");
|
||||
eb.AddField("Translation Pathway", $"{source} -> {target}", false);
|
||||
|
|
|
@ -12,15 +12,15 @@ namespace HBot.Commands.Main {
|
|||
[Description("Gets the bot's uptime")]
|
||||
[Attributes.Category(Category.Main)]
|
||||
public async Task Uptime(CommandContext Context) {
|
||||
|
||||
TimeSpan t = TimeSpan.FromMilliseconds(Convert.ToInt32(Bot.sw.ElapsedMilliseconds));
|
||||
string uptime = "";
|
||||
if (t.Days != 00) uptime += $"{Convert.ToString(t.Days)}d ";
|
||||
if (t.Hours != 00) uptime += $"{Convert.ToString(t.Hours)}h ";
|
||||
if (t.Minutes != 00) uptime += $"{Convert.ToString(t.Minutes)}m ";
|
||||
if (t.Seconds != 00) uptime += $"{Convert.ToString(t.Seconds)}s";
|
||||
|
||||
await Context.ReplyAsync($"Uptime: **{uptime}**");
|
||||
TimeSpan t = TimeSpan.FromMilliseconds(Convert.ToInt32(Bot.sw.ElapsedMilliseconds));
|
||||
string uptime = "";
|
||||
if (t.Days != 00) uptime += $"{Convert.ToString(t.Days)}d ";
|
||||
if (t.Hours != 00) uptime += $"{Convert.ToString(t.Hours)}h ";
|
||||
if (t.Minutes != 00) uptime += $"{Convert.ToString(t.Minutes)}m ";
|
||||
if (t.Seconds != 00) uptime += $"{Convert.ToString(t.Seconds)}s";
|
||||
|
||||
await Context.ReplyAsync($"Uptime: **{uptime}**");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,18 +21,18 @@ namespace HBot.Commands.Main {
|
|||
}
|
||||
|
||||
using WikipediaClient wikiclient = new WikipediaClient();
|
||||
|
||||
WikiSearchRequest req = new WikiSearchRequest(query);
|
||||
req.Limit = 1;
|
||||
|
||||
WikiSearchResponse resp = await wikiclient.SearchAsync(req);
|
||||
|
||||
foreach (SearchResult s in resp.QueryResult.SearchResults) {
|
||||
await Context.ReplyAsync($"{s.Url}".Replace(" ", "_"));
|
||||
return;
|
||||
}
|
||||
|
||||
await Context.ReplyAsync("No results.");;
|
||||
|
||||
WikiSearchRequest req = new WikiSearchRequest(query);
|
||||
req.Limit = 1;
|
||||
|
||||
WikiSearchResponse resp = await wikiclient.SearchAsync(req);
|
||||
|
||||
foreach (SearchResult s in resp.QueryResult.SearchResults) {
|
||||
await Context.ReplyAsync($"{s.Url}".Replace(" ", "_"));
|
||||
return;
|
||||
}
|
||||
|
||||
await Context.ReplyAsync("No results.");;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace HBot.Commands.Staff {
|
|||
public async Task Blacklist(CommandContext Context, DiscordMember user = null) {
|
||||
if(!PermissionMethods.HasPermission(Context.Member.PermissionsIn(Context.Channel), Permissions.KickMembers) && Context.Member.Id != Bot.client.CurrentApplication.Owners.FirstOrDefault().Id)
|
||||
return;
|
||||
|
||||
|
||||
// This is a clunky method of listing things but it works
|
||||
if(user == null) {
|
||||
string list = "";
|
||||
|
|
|
@ -26,10 +26,10 @@ namespace HBot.Commands.Owner {
|
|||
}
|
||||
// Execute the command
|
||||
CommandContext context = Bot.commands.CreateFakeContext(Context.User, channel, command, ".", realCommand, args);
|
||||
await Bot.commands.ExecuteCommandAsync(context);
|
||||
await Bot.commands.ExecuteCommandAsync(context);
|
||||
|
||||
// React
|
||||
await Context.Message.CreateReactionAsync(DiscordEmoji.FromUnicode("👍"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,10 +18,10 @@ namespace HBot.Commands.Owner {
|
|||
[RequireOwner]
|
||||
public async Task Kill(CommandContext Context) {
|
||||
await Context.ReplyAsync(replyGifs[new Random().Next(0, replyGifs.Length)]);
|
||||
Log.Information("Shutdown triggered by command");
|
||||
DailyReportSystem.CreateBackup();
|
||||
Log.Information("Shutdown triggered by command");
|
||||
DailyReportSystem.CreateBackup();
|
||||
UserData.SaveData();
|
||||
Environment.Exit(0);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
static string[] replyGifs = {
|
||||
|
@ -45,4 +45,4 @@ namespace HBot.Commands.Owner {
|
|||
"https://media.tenor.com/x8g-_OihqFkAAAAC/pass-time.gif"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace HBot.Commands.Owner {
|
|||
|
||||
// Execute the command
|
||||
CommandContext context = Bot.commands.CreateFakeContext(user, Context.Channel, command, ".", realCommand, args);
|
||||
await Bot.commands.ExecuteCommandAsync(context);
|
||||
await Bot.commands.ExecuteCommandAsync(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace HBot.Commands.Staff {
|
|||
if(count <= 0) {
|
||||
throw new Exception("Invalid number; it cannot be 0.");
|
||||
}
|
||||
|
||||
|
||||
// Delete the messages
|
||||
var messages = await Context.Channel.GetMessagesAsync(count+1);
|
||||
await Context.Channel.DeleteMessagesAsync(messages, $"Purged by {Context.User.Username}");
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace HBot.Commands.Main {
|
|||
public async Task Warn(CommandContext Context, DiscordMember user, [RemainingText] string reason = null) {
|
||||
if (reason == null)
|
||||
reason = "No reason given"; // Default reason
|
||||
|
||||
|
||||
DiscordEmbedBuilder warnEmbed = new DiscordEmbedBuilder();
|
||||
DateTime now = DateTime.Now;
|
||||
string date = $"{now.Day}/{now.Month}/{now.Year}";
|
||||
|
|
|
@ -16,102 +16,102 @@ using static HBot.Util.ResourceManager;
|
|||
using HBot.Util;
|
||||
|
||||
namespace HBot.Misc {
|
||||
public class DailyReportSystem {
|
||||
public static DailyReport report = new DailyReport() {
|
||||
dayOfReport = DateTime.Now,
|
||||
commandsRan = 0,
|
||||
messagesSent = 0,
|
||||
usersJoined = 0,
|
||||
usersLeft = 0
|
||||
};
|
||||
public class DailyReportSystem {
|
||||
public static DailyReport report = new DailyReport() {
|
||||
dayOfReport = DateTime.Now,
|
||||
commandsRan = 0,
|
||||
messagesSent = 0,
|
||||
usersJoined = 0,
|
||||
usersLeft = 0
|
||||
};
|
||||
|
||||
public static List<DailyReport> reports = new List<DailyReport>();
|
||||
public static List<DailyReport> reports = new List<DailyReport>();
|
||||
|
||||
public static void Init() {
|
||||
// Load the backup report if it exists.
|
||||
if (File.Exists(TempManager.GetTempFile("dailyreport")))
|
||||
report = JsonConvert.DeserializeObject<DailyReport>(File.ReadAllText(TempManager.GetTempFile("dailyreport")));
|
||||
public static void Init() {
|
||||
// Load the backup report if it exists.
|
||||
if (File.Exists(TempManager.GetTempFile("dailyreport")))
|
||||
report = JsonConvert.DeserializeObject<DailyReport>(File.ReadAllText(TempManager.GetTempFile("dailyreport")));
|
||||
|
||||
// Load previous reports
|
||||
if (File.Exists(GetResourcePath("dailyReports", ResourceType.JsonData)))
|
||||
reports = JsonConvert.DeserializeObject<List<DailyReport>>(File.ReadAllText(GetResourcePath("dailyReports", ResourceType.JsonData)));
|
||||
// Load previous reports
|
||||
if (File.Exists(GetResourcePath("dailyReports", ResourceType.JsonData)))
|
||||
reports = JsonConvert.DeserializeObject<List<DailyReport>>(File.ReadAllText(GetResourcePath("dailyReports", ResourceType.JsonData)));
|
||||
|
||||
// E v e n t s
|
||||
Bot.client.MessageCreated += (DiscordClient client, MessageCreateEventArgs e) => {
|
||||
|
||||
if(!e.Author.IsBot)
|
||||
report.messagesSent++;
|
||||
if (e.Message.Content.StartsWith(".")) // Inaccurate but oh well.
|
||||
report.commandsRan++;
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
Bot.client.GuildMemberAdded += (DiscordClient client, GuildMemberAddEventArgs e) => {
|
||||
// E v e n t s
|
||||
Bot.client.MessageCreated += (DiscordClient client, MessageCreateEventArgs e) => {
|
||||
|
||||
report.usersJoined++;
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
Bot.client.GuildMemberRemoved += (DiscordClient client, GuildMemberRemoveEventArgs e) => {
|
||||
if(!e.Author.IsBot)
|
||||
report.messagesSent++;
|
||||
if (e.Message.Content.StartsWith(".")) // Inaccurate but oh well.
|
||||
report.commandsRan++;
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
Bot.client.GuildMemberAdded += (DiscordClient client, GuildMemberAddEventArgs e) => {
|
||||
|
||||
report.usersLeft++;
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
report.usersJoined++;
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
Bot.client.GuildMemberRemoved += (DiscordClient client, GuildMemberRemoveEventArgs e) => {
|
||||
|
||||
// Report timer
|
||||
Timer t = new Timer(30000); // 30 seconds
|
||||
t.AutoReset = true;
|
||||
t.Elapsed += (object sender, ElapsedEventArgs e) => { if (DateTime.Now.Day != report.dayOfReport.Day) SendReport(); };
|
||||
t.Start();
|
||||
report.usersLeft++;
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
// Backup timer
|
||||
Timer t2 = new Timer(300000); // 5 minutes
|
||||
t2.AutoReset = true;
|
||||
t2.Elapsed += (object sender, ElapsedEventArgs e) => { CreateBackup(); };
|
||||
t2.Start();
|
||||
// Report timer
|
||||
Timer t = new Timer(30000); // 30 seconds
|
||||
t.AutoReset = true;
|
||||
t.Elapsed += (object sender, ElapsedEventArgs e) => { if (DateTime.Now.Day != report.dayOfReport.Day) SendReport(); };
|
||||
t.Start();
|
||||
|
||||
Log.Write(Serilog.Events.LogEventLevel.Information, "Daily report service started");
|
||||
}
|
||||
// Backup timer
|
||||
Timer t2 = new Timer(300000); // 5 minutes
|
||||
t2.AutoReset = true;
|
||||
t2.Elapsed += (object sender, ElapsedEventArgs e) => { CreateBackup(); };
|
||||
t2.Start();
|
||||
|
||||
private async static void SendReport() {
|
||||
// Write the reports
|
||||
reports.Add(report);
|
||||
File.WriteAllText(GetResourcePath("dailyReports", ResourceType.JsonData),
|
||||
JsonConvert.SerializeObject(reports, Formatting.Indented));
|
||||
Log.Write(Serilog.Events.LogEventLevel.Information, "Daily report service started");
|
||||
}
|
||||
|
||||
// Create and send the report embed
|
||||
DiscordEmbedBuilder eb = new DiscordEmbedBuilder();
|
||||
eb.WithTitle($"Daily Report For {report.dayOfReport.ToString("dddd, dd, MMMM, yyyy")}");
|
||||
eb.WithTimestamp(report.dayOfReport);
|
||||
eb.WithColor(DiscordColor.Gold);
|
||||
eb.AddField("Messages Sent", report.messagesSent.ToString(), true);
|
||||
eb.AddField("Commands Ran", report.commandsRan.ToString(), true);
|
||||
eb.AddField("Users Joined", report.usersJoined.ToString(), true);
|
||||
eb.AddField("Users Left", report.usersLeft.ToString(), true);
|
||||
await Global.logChannel.SendMessageAsync("", eb.Build());
|
||||
private async static void SendReport() {
|
||||
// Write the reports
|
||||
reports.Add(report);
|
||||
File.WriteAllText(GetResourcePath("dailyReports", ResourceType.JsonData),
|
||||
JsonConvert.SerializeObject(reports, Formatting.Indented));
|
||||
|
||||
// Reset the report
|
||||
report = new DailyReport() {
|
||||
dayOfReport = DateTime.Now,
|
||||
commandsRan = 0,
|
||||
messagesSent = 0,
|
||||
usersJoined = 0,
|
||||
usersLeft = 0
|
||||
};
|
||||
// Create and send the report embed
|
||||
DiscordEmbedBuilder eb = new DiscordEmbedBuilder();
|
||||
eb.WithTitle($"Daily Report For {report.dayOfReport.ToString("dddd, dd, MMMM, yyyy")}");
|
||||
eb.WithTimestamp(report.dayOfReport);
|
||||
eb.WithColor(DiscordColor.Gold);
|
||||
eb.AddField("Messages Sent", report.messagesSent.ToString(), true);
|
||||
eb.AddField("Commands Ran", report.commandsRan.ToString(), true);
|
||||
eb.AddField("Users Joined", report.usersJoined.ToString(), true);
|
||||
eb.AddField("Users Left", report.usersLeft.ToString(), true);
|
||||
await Global.logChannel.SendMessageAsync("", eb.Build());
|
||||
|
||||
// Remove the backup so it doesn't pass onto the next day
|
||||
TempManager.RemoveTempFile("dailyreport");
|
||||
}
|
||||
// Reset the report
|
||||
report = new DailyReport() {
|
||||
dayOfReport = DateTime.Now,
|
||||
commandsRan = 0,
|
||||
messagesSent = 0,
|
||||
usersJoined = 0,
|
||||
usersLeft = 0
|
||||
};
|
||||
|
||||
// This is done in its own method rather than the lambda function so it can be called from other parts of the program
|
||||
public static void CreateBackup() {
|
||||
File.WriteAllText(TempManager.GetTempFile("dailyreport"), JsonConvert.SerializeObject(report, Formatting.Indented));
|
||||
}
|
||||
}
|
||||
// Remove the backup so it doesn't pass onto the next day
|
||||
TempManager.RemoveTempFile("dailyreport");
|
||||
}
|
||||
|
||||
public class DailyReport {
|
||||
public DateTime dayOfReport { get; set; }
|
||||
public int messagesSent { get; set; }
|
||||
public int commandsRan { get; set; }
|
||||
public int usersJoined { get; set; }
|
||||
public int usersLeft { get; set; }
|
||||
}
|
||||
}
|
||||
// This is done in its own method rather than the lambda function so it can be called from other parts of the program
|
||||
public static void CreateBackup() {
|
||||
File.WriteAllText(TempManager.GetTempFile("dailyreport"), JsonConvert.SerializeObject(report, Formatting.Indented));
|
||||
}
|
||||
}
|
||||
|
||||
public class DailyReport {
|
||||
public DateTime dayOfReport { get; set; }
|
||||
public int messagesSent { get; set; }
|
||||
public int commandsRan { get; set; }
|
||||
public int usersJoined { get; set; }
|
||||
public int usersLeft { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace HBot.Misc {
|
|||
Log.Error(ex, "Exception occurred in MESSAGE_UPDATED event handler: {Message}", ex.Message);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Delete logging
|
||||
Bot.client.MessageDeleted += async (DiscordClient client, MessageDeleteEventArgs e) => {
|
||||
try {
|
||||
|
@ -51,7 +51,7 @@ namespace HBot.Misc {
|
|||
|
||||
if (e.Channel?.GuildId != targetGuildId)
|
||||
return;
|
||||
|
||||
|
||||
DiscordEmbedBuilder builder = new DiscordEmbedBuilder();
|
||||
builder.WithColor(DiscordColor.Gold);
|
||||
builder.WithDescription($"**{e.Message.Author.Username}**'s message in {e.Channel.Mention} was deleted");
|
||||
|
@ -67,7 +67,7 @@ namespace HBot.Misc {
|
|||
Log.Error(ex, "Exception occurred in MESSAGE_DELETED event handler: {Message}", ex.Message);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Guild member added
|
||||
Bot.client.GuildMemberAdded += async (DiscordClient client, GuildMemberAddEventArgs e) => {
|
||||
try {
|
||||
|
@ -91,7 +91,7 @@ namespace HBot.Misc {
|
|||
Log.Error(ex, "Exception occurred in GUILD_MEMBER_ADDED event handler: {Message}", ex.Message);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Guild member removed
|
||||
Bot.client.GuildMemberRemoved += async (DiscordClient client, GuildMemberRemoveEventArgs e) => {
|
||||
try {
|
||||
|
@ -115,7 +115,7 @@ namespace HBot.Misc {
|
|||
Log.Error(ex, "Exception occurred in GUILD_MEMBER_REMOVED event handler: {Message}", ex.Message);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Invite created
|
||||
Bot.client.InviteCreated += async (DiscordClient client, InviteCreateEventArgs e) => {
|
||||
try {
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace HBot.Misc {
|
|||
public string dynmap;
|
||||
public string versions;
|
||||
public string crackedInfo;
|
||||
|
||||
|
||||
public MCServer(ulong guildID, string address, string dynmap, string versions) {
|
||||
this.guildID = guildID;
|
||||
this.address = address;
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace HBot.Misc {
|
|||
|
||||
DiscordChannel additions = await Bot.client.GetChannelAsync(Bot.config.ids.rssChannel);
|
||||
DiscordGuild guild = additions.Guild;
|
||||
|
||||
|
||||
DiscordRole blogPostsRole = guild.Roles.Values.FirstOrDefault(role => role.Name == "Blog Posts");
|
||||
|
||||
if (blogPostsRole == null) {
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace HBot.Misc {
|
|||
if(users.FirstOrDefault(x => x.id == user.Id) != null) {
|
||||
return users.FirstOrDefault(x => x.id == user.Id);
|
||||
}
|
||||
|
||||
|
||||
// Possible trouble point; adding to a list but returning original value
|
||||
// Remove these comments if no issues arise
|
||||
User newUser = new User() { id = user.Id, username = user.Username };
|
||||
|
|
|
@ -5,38 +5,38 @@ using System.Net.Http;
|
|||
using Newtonsoft.Json;
|
||||
|
||||
public class HasteBinClient : IDisposable {
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly UriBuilder _uriBuilder;
|
||||
|
||||
public HasteBinClient(string baseUrl) {
|
||||
_httpClient = new HttpClient();
|
||||
_uriBuilder = new UriBuilder(baseUrl);
|
||||
}
|
||||
|
||||
public async Task<HasteBinResult> Post(string content) {
|
||||
_uriBuilder.Path = "/documents";
|
||||
string postUrl = _uriBuilder.Uri.ToString();
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly UriBuilder _uriBuilder;
|
||||
|
||||
var requestContent = new StringContent(content);
|
||||
var response = await _httpClient.PostAsync(postUrl, requestContent);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
string json = await response.Content.ReadAsStringAsync();
|
||||
var hasteBinResult = JsonConvert.DeserializeObject<HasteBinResult>(json);
|
||||
hasteBinResult.FullUrl = $"{_uriBuilder.Uri}/{hasteBinResult.Key}";
|
||||
hasteBinResult.IsSuccess = true;
|
||||
hasteBinResult.StatusCode = (int)response.StatusCode;
|
||||
return hasteBinResult;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
_httpClient.Dispose();
|
||||
}
|
||||
public HasteBinClient(string baseUrl) {
|
||||
_httpClient = new HttpClient();
|
||||
_uriBuilder = new UriBuilder(baseUrl);
|
||||
}
|
||||
|
||||
public async Task<HasteBinResult> Post(string content) {
|
||||
_uriBuilder.Path = "/documents";
|
||||
string postUrl = _uriBuilder.Uri.ToString();
|
||||
|
||||
var requestContent = new StringContent(content);
|
||||
var response = await _httpClient.PostAsync(postUrl, requestContent);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
string json = await response.Content.ReadAsStringAsync();
|
||||
var hasteBinResult = JsonConvert.DeserializeObject<HasteBinResult>(json);
|
||||
hasteBinResult.FullUrl = $"{_uriBuilder.Uri}/{hasteBinResult.Key}";
|
||||
hasteBinResult.IsSuccess = true;
|
||||
hasteBinResult.StatusCode = (int)response.StatusCode;
|
||||
return hasteBinResult;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
_httpClient.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public class HasteBinResult {
|
||||
public string Key { get; set; }
|
||||
public string FullUrl { get; set; }
|
||||
public bool IsSuccess { get; set; }
|
||||
public int StatusCode { get; set; }
|
||||
public string Key { get; set; }
|
||||
public string FullUrl { get; set; }
|
||||
public bool IsSuccess { get; set; }
|
||||
public int StatusCode { get; set; }
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ namespace HBot.Util {
|
|||
for (int x = 0; x < bmp.Width; x++) {
|
||||
for (int y = 0; y < bmp.Height; y++) {
|
||||
Color clr = bmp.GetPixel(x, y);
|
||||
|
||||
|
||||
r += clr.R;
|
||||
g += clr.G;
|
||||
b += clr.B;
|
||||
|
@ -100,7 +100,7 @@ namespace HBot.Util {
|
|||
if((r+g+b)/3 < 128) {
|
||||
r = g = b = 128;
|
||||
}
|
||||
|
||||
|
||||
return Color.FromArgb(r, g, b);
|
||||
}
|
||||
public static string GetGitExec() {
|
||||
|
|
|
@ -18,15 +18,15 @@ namespace HBot.Util {
|
|||
string result = process.StandardOutput.ReadToEnd();
|
||||
process.WaitForExit();
|
||||
if (result.Length < 1024)
|
||||
return result;
|
||||
else {
|
||||
string baseUrl = "https://paste.hiden.pw/";
|
||||
var hasteBinClient = new HasteBinClient(baseUrl);
|
||||
HasteBinResult HBresult = hasteBinClient.Post(result).Result;
|
||||
return $"{baseUrl}{HBresult.Key}";
|
||||
}
|
||||
return result;
|
||||
else {
|
||||
string baseUrl = "https://paste.hiden.pw/";
|
||||
var hasteBinClient = new HasteBinClient(baseUrl);
|
||||
HasteBinResult HBresult = hasteBinClient.Post(result).Result;
|
||||
return $"{baseUrl}{HBresult.Key}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static string WinCmd(this string cmd) {
|
||||
var escapedArgs = cmd.Replace("\"", "\\\"");
|
||||
|
||||
|
@ -42,14 +42,14 @@ namespace HBot.Util {
|
|||
process.Start();
|
||||
string result = process.StandardOutput.ReadToEnd();
|
||||
process.WaitForExit();
|
||||
if (result.Length < 1024)
|
||||
return result;
|
||||
else {
|
||||
string baseUrl = "https://paste.hiden.pw/";
|
||||
var hasteBinClient = new HasteBinClient(baseUrl);
|
||||
HasteBinResult HBresult = hasteBinClient.Post(result).Result;
|
||||
return $"{baseUrl}{HBresult.Key}";
|
||||
}
|
||||
}
|
||||
if (result.Length < 1024)
|
||||
return result;
|
||||
else {
|
||||
string baseUrl = "https://paste.hiden.pw/";
|
||||
var hasteBinClient = new HasteBinClient(baseUrl);
|
||||
HasteBinResult HBresult = hasteBinClient.Post(result).Result;
|
||||
return $"{baseUrl}{HBresult.Key}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue