From 1295ed6206d2c8e2dbc509e80a59a1c6dc102831 Mon Sep 17 00:00:00 2001 From: Runebaas Date: Fri, 15 Sep 2017 12:58:49 +0200 Subject: [PATCH 1/3] Add Checkem Command --- Geekbot.net/Lib/CheckEmImageProvider.cs | 40 ++++++ .../Lib/{Fortunes.cs => FortunesProvider.cs} | 9 +- Geekbot.net/Modules/CheckEm.cs | 38 ++++++ Geekbot.net/Modules/Fortune.cs | 4 +- Geekbot.net/Program.cs | 6 +- Geekbot.net/Storage/checkEmPics | 122 ++++++++++++++++++ Geekbot.net/{ => Storage}/fortunes | 0 7 files changed, 211 insertions(+), 8 deletions(-) create mode 100644 Geekbot.net/Lib/CheckEmImageProvider.cs rename Geekbot.net/Lib/{Fortunes.cs => FortunesProvider.cs} (77%) create mode 100644 Geekbot.net/Modules/CheckEm.cs create mode 100644 Geekbot.net/Storage/checkEmPics rename Geekbot.net/{ => Storage}/fortunes (100%) diff --git a/Geekbot.net/Lib/CheckEmImageProvider.cs b/Geekbot.net/Lib/CheckEmImageProvider.cs new file mode 100644 index 0000000..823d349 --- /dev/null +++ b/Geekbot.net/Lib/CheckEmImageProvider.cs @@ -0,0 +1,40 @@ +using System; +using System.IO; + +namespace Geekbot.net.Lib +{ + public class CheckEmImageProvider : ICheckEmImageProvider + { + private string[] checkEmImageArray; + private int totalCheckEmImages; + private Random rnd; + + public CheckEmImageProvider() + { + var path = Path.GetFullPath("./Storage/checkEmPics"); + if (File.Exists(path)) + { + var rawCheckEmPics = File.ReadAllText(path); + checkEmImageArray = rawCheckEmPics.Split("\n"); + totalCheckEmImages = checkEmImageArray.Length; + rnd = new Random(); + Console.WriteLine($"- Loaded {totalCheckEmImages} CheckEm Images"); + } + else + { + Console.WriteLine("checkEmPics File not found"); + Console.WriteLine($"Path should be {path}"); + } + } + + public string GetRandomCheckEmPic() + { + return checkEmImageArray[rnd.Next(0, totalCheckEmImages)]; + } + } + + public interface ICheckEmImageProvider + { + string GetRandomCheckEmPic(); + } +} \ No newline at end of file diff --git a/Geekbot.net/Lib/Fortunes.cs b/Geekbot.net/Lib/FortunesProvider.cs similarity index 77% rename from Geekbot.net/Lib/Fortunes.cs rename to Geekbot.net/Lib/FortunesProvider.cs index 15cc710..b11c368 100644 --- a/Geekbot.net/Lib/Fortunes.cs +++ b/Geekbot.net/Lib/FortunesProvider.cs @@ -6,21 +6,22 @@ using System.Text.RegularExpressions; namespace Geekbot.net.Lib { - class Fortunes : IFortunes + class FortunesProvider : IFortunesProvider { private string[] fortuneArray; private int totalFortunes; private Random rnd; - public Fortunes() + public FortunesProvider() { - var path = Path.GetFullPath("./fortunes"); + var path = Path.GetFullPath("./Storage/fortunes"); if (File.Exists(path)) { var rawFortunes= File.ReadAllText(path); fortuneArray = rawFortunes.Split("%"); totalFortunes = fortuneArray.Length; rnd = new Random(); + Console.WriteLine($"- Loaded {totalFortunes} Fortunes"); } else { @@ -40,7 +41,7 @@ namespace Geekbot.net.Lib } } - public interface IFortunes + public interface IFortunesProvider { string GetRandomFortune(); string GetFortune(int id); diff --git a/Geekbot.net/Modules/CheckEm.cs b/Geekbot.net/Modules/CheckEm.cs new file mode 100644 index 0000000..6c5d45f --- /dev/null +++ b/Geekbot.net/Modules/CheckEm.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Discord.Commands; +using Geekbot.net.Lib; + +namespace Geekbot.net.Modules +{ + public class CheckEm : ModuleBase + { + private readonly Random rnd; + private readonly ICheckEmImageProvider checkEmImages; + public CheckEm(Random RandomClient, ICheckEmImageProvider checkEmImages) + { + this.rnd = RandomClient; + this.checkEmImages = checkEmImages; + } + [Command("checkem", RunMode = RunMode.Async), Summary("Check for dubs")] + public async Task MuhDubs() + { + try + { + var sb = new StringBuilder(); + + sb.AppendLine($"Check em {Context.User.Mention}"); + sb.AppendLine($"**{rnd.Next(100000, 99999999)}**"); + sb.AppendLine(checkEmImages.GetRandomCheckEmPic()); + + await ReplyAsync(sb.ToString()); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + } +} \ No newline at end of file diff --git a/Geekbot.net/Modules/Fortune.cs b/Geekbot.net/Modules/Fortune.cs index c898750..b4e4b07 100644 --- a/Geekbot.net/Modules/Fortune.cs +++ b/Geekbot.net/Modules/Fortune.cs @@ -7,8 +7,8 @@ namespace Geekbot.net.Modules { public class Fortune : ModuleBase { - private readonly IFortunes fortunes; - public Fortune(IFortunes fortunes) + private readonly IFortunesProvider fortunes; + public Fortune(IFortunesProvider fortunes) { this.fortunes = fortunes; } diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index 63cebad..51699e1 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -68,9 +68,11 @@ namespace Geekbot.net } services = new ServiceCollection(); - var fortunes = new Fortunes(); + var fortunes = new FortunesProvider(); + var checkEmImages = new CheckEmImageProvider(); var RandomClient = new Random(); - services.AddSingleton(fortunes); + services.AddSingleton(fortunes); + services.AddSingleton(checkEmImages); services.AddSingleton(RandomClient); services.AddSingleton(redis); diff --git a/Geekbot.net/Storage/checkEmPics b/Geekbot.net/Storage/checkEmPics new file mode 100644 index 0000000..03be23e --- /dev/null +++ b/Geekbot.net/Storage/checkEmPics @@ -0,0 +1,122 @@ +http://s19.postimg.org/pcq2kwzoj/4cb.png +http://s19.postimg.org/cvetk0f4z/5_Dim_Dy6p.jpg +http://s19.postimg.org/5hzfl1v37/1310151998600.jpg +http://s19.postimg.org/53y3lgazn/1324181141954.jpg +http://s19.postimg.org/724rjg3hf/1392512742365.png +http://s19.postimg.org/3rgejkdk3/1393501296733.png +http://s19.postimg.org/a6ffg8k9v/1401667341503.jpg +http://s19.postimg.org/qiph5yylf/1419231572452.jpg +http://s19.postimg.org/fqwi4m8ir/1427600681401.png +http://s19.postimg.org/4c00zzw6b/1447813628974.png +http://s19.postimg.org/uuio8puw3/b5_3q_ycaaavxtf.jpg +http://s19.postimg.org/bghu913fn/check_em_by_boyboy99100_d57xp3y.png +http://s19.postimg.org/s1pgooujn/l_Hkppjs.jpg +http://s19.postimg.org/m08itft0j/checkem.jpg +https://old.postimg.org/image/6vx33rb1b/ +https://old.postimg.org/image/wxiaz1mov/ +https://old.postimg.org/image/azqfizx27/ +https://old.postimg.org/image/6iy2kbiu7/ +https://old.postimg.org/image/k8slt45y7/ +https://old.postimg.org/image/t7ruxmplr/ +https://old.postimg.org/image/ssbzqvean/ +https://old.postimg.org/image/kbchfy9lr/ +https://old.postimg.org/image/dl0lk9btr/ +https://old.postimg.org/image/e5k80oufz/ +https://old.postimg.org/image/er005baqn/ +https://old.postimg.org/image/bfk2uzcin/ +https://old.postimg.org/image/556fp0jkv/ +https://old.postimg.org/image/i0efbryu7/ +https://old.postimg.org/image/943n7u87z/ +https://old.postimg.org/image/xn5op5cm7/ +https://old.postimg.org/image/3l5p4d0kf/ +https://old.postimg.org/image/5boq5ui3j/ +https://old.postimg.org/image/ru082bqcf/ +https://old.postimg.org/image/ytea1oqan/ +https://old.postimg.org/image/vu7dekgtb/ +https://old.postimg.org/image/hl7qwi2an/ +https://old.postimg.org/image/5aescfg9r/ +https://old.postimg.org/image/9gzmrrfvj/ +https://old.postimg.org/image/50bv6tr1b/ +https://old.postimg.org/image/afkl7silb/ +https://old.postimg.org/image/nrdsgzllr/ +https://old.postimg.org/image/s32e5zsin/ +https://old.postimg.org/image/5sej60v8f/ +https://old.postimg.org/image/lgfqctau7/ +https://old.postimg.org/image/tn7q4e0wv/ +https://old.postimg.org/image/8612arz1b/ +https://old.postimg.org/image/w5tf52mn3/ +https://old.postimg.org/image/zdxwi48wv/ +https://old.postimg.org/image/lphwghd0f/ +https://old.postimg.org/image/uzu0k0nq7/ +https://old.postimg.org/image/3vqzsxjbz/ +https://old.postimg.org/image/5d7uqqyov/ +https://old.postimg.org/image/dntnyku8v/ +https://old.postimg.org/image/dsxf891jz/ +https://old.postimg.org/image/3nyrioizj/ +https://old.postimg.org/image/6zx2bzaqn/ +https://old.postimg.org/image/wu6v1raqn/ +https://old.postimg.org/image/hb9f4n2fz/ +https://old.postimg.org/image/p7yhqm3a7/ +https://old.postimg.org/image/oelvxzx9b/ +https://old.postimg.org/image/vcq03xvdr/ +https://old.postimg.org/image/b08t1yqlb/ +https://old.postimg.org/image/6yrpwayan/ +https://old.postimg.org/image/btleukwm7/ +https://old.postimg.org/image/62ztuldzz/ +https://old.postimg.org/image/w3iq9pxr3/ +https://old.postimg.org/image/byp6493xb/ +https://old.postimg.org/image/xp2lf9xcv/ +https://old.postimg.org/image/j9p9u49pb/ +https://old.postimg.org/image/hvxmytafz/ +https://old.postimg.org/image/5eqzbnfa7/ +https://old.postimg.org/image/do2uq290f/ +https://old.postimg.org/image/54o261q1r/ +https://old.postimg.org/image/94qm4jr4v/ +https://old.postimg.org/image/lee88y0pr/ +https://old.postimg.org/image/bncb58cv3/ +https://old.postimg.org/image/5246j7me7/ +https://old.postimg.org/image/4uby8ym1r/ +https://old.postimg.org/image/qn996tj4v/ +https://old.postimg.org/image/c1dn4twyn/ +https://old.postimg.org/image/6rd9ra23j/ +https://lehcark14.files.wordpress.com/2008/08/botan16.jpg +http://i.imgur.com/p9vALew.jpg +http://i.imgur.com/4a9l2Rm.png +http://i.imgur.com/RNtixMQ.jpg +https://pbs.twimg.com/media/Cro9aIGUEAAkXCP.jpg +http://s16.postimg.org/empvloimd/Check_em_Guts.png +https://s18.postimg.io/qgbhe7u09/1424491645996.gif +http://s19.postimg.org/hhemlt7xf/3eb.jpg +http://s19.postimg.org/cwsg6vo83/8aa.png +http://s19.postimg.org/rh9j1pj6r/28mohl4.png +http://s19.postimg.org/zba4n3qzn/86d.jpg +http://s19.postimg.org/cb3hart5v/2016_09_16_08_58_45.png +http://s19.postimg.org/m9ofx92lf/bb1.jpg +http://s19.postimg.org/maydqo4f7/e8b.jpg +http://s19.postimg.org/yqzoy5n4z/fbe.png +http://s19.postimg.org/xd822unvn/giphy.gif +http://s19.postimg.org/c4udlf9er/l_TU3eup.jpg +https://66.media.tumblr.com/cc893a0ee40d73d083da3df4bdaf45cc/tumblr_mx8psiFduG1t1g1k8o1_500.gif +http://i.imgur.com/swbXHSy.gif +http://img1.reactor.cc/pics/post/full/Anime-Touhou-Project-Yakumo-Yukari-%D0%A0%D0%B5%D0%BA%D1%83%D1%80%D1%81%D0%B8%D1%8F-1303807.jpeg +http://i.imgur.com/ftGLHE0.png +http://i.imgur.com/JELDhKQ.png +http://imgur.com/yBJound +http://i.imgur.com/f7gAVPJ.png +http://i.imgur.com/HxWyo2Z.jpg +http://i.imgur.com/8Eb9CxQ.png +http://i.imgur.com/kOECcjz.png +http://i.imgur.com/MJLu7oJ.jpg +http://i.imgur.com/itG3rPM.jpg +http://i.imgur.com/G83Go9t.jpg +http://i.imgur.com/jI2dBnU.jpg +http://i.imgur.com/FtALzg0.jpg +http://i.imgur.com/GwZpJEv.gif +http://i.imgur.com/TYGRD3B.gif +http://i.imgur.com/P6TxLS3.png +http://i.imgur.com/phTVTdn.jpg +http://i.imgur.com/thhR6UE.jpg +http://i.imgur.com/KbROufx.jpg +http://i.imgur.com/sQqWbcm.jpg +http://i.imgur.com/YYpis53.png +http://i.imgur.com/kwaRd54.gif \ No newline at end of file diff --git a/Geekbot.net/fortunes b/Geekbot.net/Storage/fortunes similarity index 100% rename from Geekbot.net/fortunes rename to Geekbot.net/Storage/fortunes From c82d6ec6668d22480869d0988c1527807c1daff2 Mon Sep 17 00:00:00 2001 From: Runebaas Date: Fri, 15 Sep 2017 21:10:22 +0200 Subject: [PATCH 2/3] Add Dub, Trips and Quads check to !checkem (please fix if you see this) --- Geekbot.net/Modules/CheckEm.cs | 60 ++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/Geekbot.net/Modules/CheckEm.cs b/Geekbot.net/Modules/CheckEm.cs index 6c5d45f..150b97d 100644 --- a/Geekbot.net/Modules/CheckEm.cs +++ b/Geekbot.net/Modules/CheckEm.cs @@ -19,20 +19,54 @@ namespace Geekbot.net.Modules [Command("checkem", RunMode = RunMode.Async), Summary("Check for dubs")] public async Task MuhDubs() { - try - { - var sb = new StringBuilder(); - - sb.AppendLine($"Check em {Context.User.Mention}"); - sb.AppendLine($"**{rnd.Next(100000, 99999999)}**"); - sb.AppendLine(checkEmImages.GetRandomCheckEmPic()); - - await ReplyAsync(sb.ToString()); - } - catch (Exception e) - { - Console.WriteLine(e.Message); + try + { + int number = rnd.Next(10000000, 99999999); + var dubtriqua = ""; + + var ns = GetIntArray(number); + Console.WriteLine(ns.Length); + if (ns[7] == ns[6]) + { + dubtriqua = "DUBS"; + if (ns[6] == ns[5]) + { + dubtriqua = "TRIPS"; + if (ns[5] == ns[4]) + { + dubtriqua = "QUADS"; + } + } + } + + var sb = new StringBuilder(); + sb.AppendLine($"Check em {Context.User.Mention}"); + sb.AppendLine($"**{number}**"); + if (!string.IsNullOrEmpty(dubtriqua)) + { + sb.AppendLine($":tada: {dubtriqua} :tada:"); + } + sb.AppendLine(checkEmImages.GetRandomCheckEmPic()); + + await ReplyAsync(sb.ToString()); + } + catch (Exception e) + { + Console.WriteLine(e.Message); } + + } + + private int[] GetIntArray(int num) + { + List listOfInts = new List(); + while (num > 0) + { + listOfInts.Add(num % 10); + num = num / 10; + } + listOfInts.Reverse(); + return listOfInts.ToArray(); } } } \ No newline at end of file From 8911123b787b64975377d8fb23996754b10237d7 Mon Sep 17 00:00:00 2001 From: Runebaas Date: Fri, 15 Sep 2017 22:56:03 +0200 Subject: [PATCH 3/3] Updated Help Command and code update --- Geekbot.net/Lib/CheckEmImageProvider.cs | 6 +- Geekbot.net/Lib/FortunesProvider.cs | 15 ++-- Geekbot.net/Lib/LevelCalc.cs | 14 ++-- Geekbot.net/Lib/StatsRecorder.cs | 4 +- Geekbot.net/Modules/AdminCmd.cs | 14 ++-- Geekbot.net/Modules/Cat.cs | 11 ++- Geekbot.net/Modules/CheckEm.cs | 94 ++++++++++++------------- Geekbot.net/Modules/Choose.cs | 6 +- Geekbot.net/Modules/Counters.cs | 37 +++++----- Geekbot.net/Modules/Dice.cs | 16 ++--- Geekbot.net/Modules/Dog.cs | 7 +- Geekbot.net/Modules/EightBall.cs | 13 ++-- Geekbot.net/Modules/Fortune.cs | 11 +-- Geekbot.net/Modules/GuildInfo.cs | 22 +++--- Geekbot.net/Modules/Help.cs | 47 +++++++++---- Geekbot.net/Modules/Info.cs | 4 +- Geekbot.net/Modules/Ping.cs | 4 +- Geekbot.net/Modules/Roll.cs | 10 +-- Geekbot.net/Modules/Say.cs | 8 ++- Geekbot.net/Modules/Ship.cs | 40 ++++------- Geekbot.net/Modules/UserInfo.cs | 50 +++++++------ Geekbot.net/Modules/Youtube.cs | 13 ++-- Geekbot.net/Program.cs | 40 +++++------ 23 files changed, 248 insertions(+), 238 deletions(-) diff --git a/Geekbot.net/Lib/CheckEmImageProvider.cs b/Geekbot.net/Lib/CheckEmImageProvider.cs index 823d349..5ead4a2 100644 --- a/Geekbot.net/Lib/CheckEmImageProvider.cs +++ b/Geekbot.net/Lib/CheckEmImageProvider.cs @@ -5,9 +5,9 @@ namespace Geekbot.net.Lib { public class CheckEmImageProvider : ICheckEmImageProvider { - private string[] checkEmImageArray; - private int totalCheckEmImages; - private Random rnd; + private readonly string[] checkEmImageArray; + private readonly Random rnd; + private readonly int totalCheckEmImages; public CheckEmImageProvider() { diff --git a/Geekbot.net/Lib/FortunesProvider.cs b/Geekbot.net/Lib/FortunesProvider.cs index b11c368..614d018 100644 --- a/Geekbot.net/Lib/FortunesProvider.cs +++ b/Geekbot.net/Lib/FortunesProvider.cs @@ -1,23 +1,20 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Text; -using System.Text.RegularExpressions; namespace Geekbot.net.Lib { - class FortunesProvider : IFortunesProvider + internal class FortunesProvider : IFortunesProvider { - private string[] fortuneArray; - private int totalFortunes; - private Random rnd; + private readonly string[] fortuneArray; + private readonly Random rnd; + private readonly int totalFortunes; public FortunesProvider() { var path = Path.GetFullPath("./Storage/fortunes"); if (File.Exists(path)) { - var rawFortunes= File.ReadAllText(path); + var rawFortunes = File.ReadAllText(path); fortuneArray = rawFortunes.Split("%"); totalFortunes = fortuneArray.Length; rnd = new Random(); @@ -46,4 +43,4 @@ namespace Geekbot.net.Lib string GetRandomFortune(); string GetFortune(int id); } -} +} \ No newline at end of file diff --git a/Geekbot.net/Lib/LevelCalc.cs b/Geekbot.net/Lib/LevelCalc.cs index 1298319..5d47dc9 100644 --- a/Geekbot.net/Lib/LevelCalc.cs +++ b/Geekbot.net/Lib/LevelCalc.cs @@ -1,20 +1,16 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Geekbot.net.Lib { - class LevelCalc + internal class LevelCalc { private static int GetExperienceAtLevel(int level) { double total = 0; - for (int i = 1; i < level; i++) - { + for (var i = 1; i < level; i++) total += Math.Floor(i + 300 * Math.Pow(2, i / 7.0)); - } - return (int)Math.Floor(total / 16); + return (int) Math.Floor(total / 16); } public static int GetLevelAtExperience(int experience) @@ -22,12 +18,10 @@ namespace Geekbot.net.Lib int index; for (index = 0; index < 120; index++) - { if (GetExperienceAtLevel(index + 1) > experience) break; - } return index; } } -} +} \ No newline at end of file diff --git a/Geekbot.net/Lib/StatsRecorder.cs b/Geekbot.net/Lib/StatsRecorder.cs index 85572fb..c88ec2d 100644 --- a/Geekbot.net/Lib/StatsRecorder.cs +++ b/Geekbot.net/Lib/StatsRecorder.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; using Discord.WebSocket; using StackExchange.Redis; @@ -7,7 +6,6 @@ namespace Geekbot.net.Lib { public class StatsRecorder { - private readonly SocketMessage message; private readonly IDatabase redis; diff --git a/Geekbot.net/Modules/AdminCmd.cs b/Geekbot.net/Modules/AdminCmd.cs index 9385409..72beb36 100644 --- a/Geekbot.net/Modules/AdminCmd.cs +++ b/Geekbot.net/Modules/AdminCmd.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using Discord; using Discord.Commands; using StackExchange.Redis; @@ -8,23 +9,26 @@ namespace Geekbot.net.Modules public class AdminCmd : ModuleBase { private readonly IDatabase redis; + public AdminCmd(IDatabase redis) { this.redis = redis; } - [RequireUserPermission(Discord.GuildPermission.Administrator)] - [Command("welcome", RunMode = RunMode.Async), Summary("Set a Welcome Message (use '$user' to mention the new joined user).")] - public async Task SetWelcomeMessage([Remainder, Summary("The message")] string welcomeMessage) + [RequireUserPermission(GuildPermission.Administrator)] + [Command("welcome", RunMode = RunMode.Async)] + [Summary("Set a Welcome Message (use '$user' to mention the new joined user).")] + public async Task SetWelcomeMessage([Remainder] [Summary("message")] string welcomeMessage) { var key = Context.Guild.Id + "-welcomeMsg"; redis.StringSet(key, welcomeMessage); var formatedMessage = welcomeMessage.Replace("$user", Context.User.Mention); await ReplyAsync("Welcome message has been changed\r\nHere is an example of how it would look:\r\n" + - formatedMessage); + formatedMessage); } - [Command("youtubekey", RunMode = RunMode.Async), Summary("Set the youtube api key")] + [Command("youtubekey", RunMode = RunMode.Async)] + [Summary("Set the youtube api key")] public async Task SetYoutubeKey([Summary("API Key")] string key) { var botOwner = redis.StringGet("botOwner"); diff --git a/Geekbot.net/Modules/Cat.cs b/Geekbot.net/Modules/Cat.cs index 2f9e63e..fe134ad 100644 --- a/Geekbot.net/Modules/Cat.cs +++ b/Geekbot.net/Modules/Cat.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; using Discord.Commands; using RestSharp; @@ -7,17 +6,15 @@ namespace Geekbot.net.Modules { public class Cat : ModuleBase { - [Command("cat", RunMode = RunMode.Async), Summary("Return a random image of a cat.")] + [Command("cat", RunMode = RunMode.Async)] + [Summary("Return a random image of a cat.")] public async Task Say() { var catClient = new RestClient("http://random.cat"); var request = new RestRequest("meow.php", Method.GET); - catClient.ExecuteAsync(request, async response => { - await ReplyAsync(response.Data.file); - }); + catClient.ExecuteAsync(request, async response => { await ReplyAsync(response.Data.file); }); } - } public class CatResponse diff --git a/Geekbot.net/Modules/CheckEm.cs b/Geekbot.net/Modules/CheckEm.cs index 150b97d..0d72241 100644 --- a/Geekbot.net/Modules/CheckEm.cs +++ b/Geekbot.net/Modules/CheckEm.cs @@ -9,64 +9,62 @@ namespace Geekbot.net.Modules { public class CheckEm : ModuleBase { - private readonly Random rnd; private readonly ICheckEmImageProvider checkEmImages; + private readonly Random rnd; + public CheckEm(Random RandomClient, ICheckEmImageProvider checkEmImages) { - this.rnd = RandomClient; + rnd = RandomClient; this.checkEmImages = checkEmImages; } - [Command("checkem", RunMode = RunMode.Async), Summary("Check for dubs")] + + [Command("checkem", RunMode = RunMode.Async)] + [Summary("Check for dubs")] public async Task MuhDubs() { - try - { - int number = rnd.Next(10000000, 99999999); - var dubtriqua = ""; - - var ns = GetIntArray(number); - Console.WriteLine(ns.Length); - if (ns[7] == ns[6]) - { - dubtriqua = "DUBS"; - if (ns[6] == ns[5]) - { - dubtriqua = "TRIPS"; - if (ns[5] == ns[4]) - { - dubtriqua = "QUADS"; - } - } - } - - var sb = new StringBuilder(); - sb.AppendLine($"Check em {Context.User.Mention}"); - sb.AppendLine($"**{number}**"); - if (!string.IsNullOrEmpty(dubtriqua)) - { - sb.AppendLine($":tada: {dubtriqua} :tada:"); - } - sb.AppendLine(checkEmImages.GetRandomCheckEmPic()); - - await ReplyAsync(sb.ToString()); - } - catch (Exception e) - { - Console.WriteLine(e.Message); + try + { + var number = rnd.Next(10000000, 99999999); + var dubtriqua = ""; + + var ns = GetIntArray(number); + Console.WriteLine(ns.Length); + if (ns[7] == ns[6]) + { + dubtriqua = "DUBS"; + if (ns[6] == ns[5]) + { + dubtriqua = "TRIPS"; + if (ns[5] == ns[4]) + dubtriqua = "QUADS"; + } + } + + var sb = new StringBuilder(); + sb.AppendLine($"Check em {Context.User.Mention}"); + sb.AppendLine($"**{number}**"); + if (!string.IsNullOrEmpty(dubtriqua)) + sb.AppendLine($":tada: {dubtriqua} :tada:"); + sb.AppendLine(checkEmImages.GetRandomCheckEmPic()); + + await ReplyAsync(sb.ToString()); + } + catch (Exception e) + { + Console.WriteLine(e.Message); } - } - private int[] GetIntArray(int num) - { - List listOfInts = new List(); - while (num > 0) - { - listOfInts.Add(num % 10); - num = num / 10; - } - listOfInts.Reverse(); - return listOfInts.ToArray(); + private int[] GetIntArray(int num) + { + var listOfInts = new List(); + while (num > 0) + { + listOfInts.Add(num % 10); + num = num / 10; + } + listOfInts.Reverse(); + return listOfInts.ToArray(); } } } \ No newline at end of file diff --git a/Geekbot.net/Modules/Choose.cs b/Geekbot.net/Modules/Choose.cs index 3242ed5..68ea4af 100644 --- a/Geekbot.net/Modules/Choose.cs +++ b/Geekbot.net/Modules/Choose.cs @@ -7,13 +7,15 @@ namespace Geekbot.net.Modules public class Choose : ModuleBase { private readonly Random rnd; + public Choose(Random RandomClient) { rnd = RandomClient; } - [Command("choose", RunMode = RunMode.Async), Summary("Let the bot make a choice for you.")] - public async Task Command([Remainder, Summary("The choices, sepperated by a ;")] string choices) + [Command("choose", RunMode = RunMode.Async)] + [Summary("Seperate options with a semicolon.")] + public async Task Command([Remainder] [Summary("option1;option2")] string choices) { var choicesArray = choices.Split(';'); var choice = rnd.Next(choicesArray.Length); diff --git a/Geekbot.net/Modules/Counters.cs b/Geekbot.net/Modules/Counters.cs index 9668ea3..66ecd9a 100644 --- a/Geekbot.net/Modules/Counters.cs +++ b/Geekbot.net/Modules/Counters.cs @@ -9,13 +9,15 @@ namespace Geekbot.net.Modules public class Counters : ModuleBase { private readonly IDatabase redis; + public Counters(IDatabase redis) { this.redis = redis; } - [Command("good", RunMode = RunMode.Async), Summary("Increase Someones Karma")] - public async Task Good([Summary("The someone")] IUser user) + [Command("good", RunMode = RunMode.Async)] + [Summary("Increase Someones Karma")] + public async Task Good([Summary("@someone")] IUser user) { var lastKarma = GetLastKarma(); if (user.Id == Context.User.Id) @@ -24,12 +26,13 @@ namespace Geekbot.net.Modules } else if (lastKarma > GetUnixTimestamp()) { - await ReplyAsync($"Sorry {Context.User.Username}, but you have to wait {GetTimeLeft(lastKarma)} before you can give karma again..."); + await ReplyAsync( + $"Sorry {Context.User.Username}, but you have to wait {GetTimeLeft(lastKarma)} before you can give karma again..."); } else { var key = Context.Guild.Id + "-" + user.Id + "-karma"; - var badJokes = (int)redis.StringGet(key); + var badJokes = (int) redis.StringGet(key); var newBadJokes = badJokes + 1; redis.StringSet(key, newBadJokes.ToString()); var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout"; @@ -44,13 +47,14 @@ namespace Geekbot.net.Modules eb.Title = "Karma Increased"; eb.AddInlineField("By", Context.User.Username); eb.AddInlineField("amount", "+1"); - eb.AddInlineField("Current Karma",newBadJokes); + eb.AddInlineField("Current Karma", newBadJokes); await ReplyAsync("", false, eb.Build()); } } - [Command("bad", RunMode = RunMode.Async), Summary("Decrease Someones Karma")] - public async Task Bad([Summary("The someone")] IUser user) + [Command("bad", RunMode = RunMode.Async)] + [Summary("Decrease Someones Karma")] + public async Task Bad([Summary("@someone")] IUser user) { var lastKarma = GetLastKarma(); if (user.Id == Context.User.Id) @@ -59,17 +63,18 @@ namespace Geekbot.net.Modules } else if (lastKarma > GetUnixTimestamp()) { - await ReplyAsync($"Sorry {Context.User.Username}, but you have to wait {GetTimeLeft(lastKarma)} before you can take karma again..."); + await ReplyAsync( + $"Sorry {Context.User.Username}, but you have to wait {GetTimeLeft(lastKarma)} before you can take karma again..."); } else { var key = Context.Guild.Id + "-" + user.Id + "-karma"; - var badJokes = (int)redis.StringGet(key); + var badJokes = (int) redis.StringGet(key); var newBadJokes = badJokes - 1; redis.StringSet(key, newBadJokes.ToString()); var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout"; redis.StringSet(lastKey, GetNewLastKarma()); - + var eb = new EmbedBuilder(); eb.WithAuthor(new EmbedAuthorBuilder() .WithIconUrl(user.GetAvatarUrl()) @@ -79,7 +84,7 @@ namespace Geekbot.net.Modules eb.Title = "Karma Decreased"; eb.AddInlineField("By", Context.User.Username); eb.AddInlineField("amount", "-1"); - eb.AddInlineField("Current Karma",newBadJokes); + eb.AddInlineField("Current Karma", newBadJokes); await ReplyAsync("", false, eb.Build()); } } @@ -89,27 +94,25 @@ namespace Geekbot.net.Modules var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout"; var redisReturn = redis.StringGet(lastKey); if (!int.TryParse(redisReturn.ToString(), out var i)) - { i = GetUnixTimestamp(); - } return i; } private int GetNewLastKarma() { var timeout = TimeSpan.FromMinutes(3); - return (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).Add(timeout)).TotalSeconds; + return (int) DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).Add(timeout).TotalSeconds; } private int GetUnixTimestamp() { - return (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; + return (int) DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; } private string GetTimeLeft(int time) { - DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0,DateTimeKind.Utc); - dtDateTime = dtDateTime.AddSeconds( time ).ToLocalTime(); + var dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); + dtDateTime = dtDateTime.AddSeconds(time).ToLocalTime(); var dt = dtDateTime.Subtract(DateTime.Now); return $"{dt.Minutes} Minutes and {dt.Seconds} Seconds"; } diff --git a/Geekbot.net/Modules/Dice.cs b/Geekbot.net/Modules/Dice.cs index b559446..b44c7e8 100644 --- a/Geekbot.net/Modules/Dice.cs +++ b/Geekbot.net/Modules/Dice.cs @@ -1,25 +1,25 @@ using System; -using System.Text; using System.Threading.Tasks; using Discord; using Discord.Commands; -using StackExchange.Redis; namespace Geekbot.net.Modules { public class Dice : ModuleBase { private readonly Random rnd; + public Dice(Random RandomClient) { rnd = RandomClient; } - [Command("dice", RunMode = RunMode.Async), Summary("Roll a dice.")] - public async Task RollCommand([Remainder, Summary("1d20, 1d6, 2d3, etc...")] string diceType = "1d6") + [Command("dice", RunMode = RunMode.Async)] + [Summary("Roll a dice.")] + public async Task RollCommand([Remainder] [Summary("diceType")] string diceType = "1d6") { - var dice = diceType.Split("d"); - + var dice = diceType.Split("d"); + if (dice.Length != 2 || !int.TryParse(dice[0], out int times) || !int.TryParse(dice[1], out int max)) @@ -45,9 +45,7 @@ namespace Geekbot.net.Modules eb.WithColor(new Color(133, 189, 219)); eb.Title = $":game_die: Dice Roll - Type {diceType} :game_die:"; for (var i = 0; i < times; i++) - { - eb.AddInlineField($"Dice {i+1}", rnd.Next(1, max)); - } + eb.AddInlineField($"Dice {i + 1}", rnd.Next(1, max)); await ReplyAsync("", false, eb.Build()); } } diff --git a/Geekbot.net/Modules/Dog.cs b/Geekbot.net/Modules/Dog.cs index 356cd09..80fd250 100644 --- a/Geekbot.net/Modules/Dog.cs +++ b/Geekbot.net/Modules/Dog.cs @@ -7,16 +7,15 @@ namespace Geekbot.net.Modules { public class Dog : ModuleBase { - [Command("dog", RunMode = RunMode.Async), Summary("Return a random image of a dog.")] + [Command("dog", RunMode = RunMode.Async)] + [Summary("Return a random image of a dog.")] public async Task Say() { var dogClient = new RestClient("http://random.dog"); var request = new RestRequest("woof.json", Method.GET); Console.WriteLine(dogClient.BaseUrl); - dogClient.ExecuteAsync(request, async response => { - await ReplyAsync(response.Data.url); - }); + dogClient.ExecuteAsync(request, async response => { await ReplyAsync(response.Data.url); }); } } diff --git a/Geekbot.net/Modules/EightBall.cs b/Geekbot.net/Modules/EightBall.cs index efce699..3f34d0b 100644 --- a/Geekbot.net/Modules/EightBall.cs +++ b/Geekbot.net/Modules/EightBall.cs @@ -8,14 +8,18 @@ namespace Geekbot.net.Modules public class EightBall : ModuleBase { private readonly Random rnd; + public EightBall(Random RandomClient) { rnd = RandomClient; } - [Command("8ball", RunMode = RunMode.Async), Summary("Ask 8Ball a Question.")] - public async Task Ball([Remainder, Summary("The Question")] string echo) + + [Command("8ball", RunMode = RunMode.Async)] + [Summary("Ask 8Ball a Question.")] + public async Task Ball([Remainder] [Summary("Question")] string echo) { - var replies = new List { + var replies = new List + { "It is certain", "It is decidedly so", "Without a doubt", @@ -35,7 +39,8 @@ namespace Geekbot.net.Modules "My reply is no", "My sources say no", "Outlook not so good", - "Very doubtful"}; + "Very doubtful" + }; var answer = rnd.Next(replies.Count); await ReplyAsync(replies[answer]); diff --git a/Geekbot.net/Modules/Fortune.cs b/Geekbot.net/Modules/Fortune.cs index b4e4b07..2040034 100644 --- a/Geekbot.net/Modules/Fortune.cs +++ b/Geekbot.net/Modules/Fortune.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; using Discord.Commands; using Geekbot.net.Lib; @@ -8,15 +7,17 @@ namespace Geekbot.net.Modules public class Fortune : ModuleBase { private readonly IFortunesProvider fortunes; + public Fortune(IFortunesProvider fortunes) { this.fortunes = fortunes; } - - [Command("fortune", RunMode = RunMode.Async), Summary("Get a random fortune")] + + [Command("fortune", RunMode = RunMode.Async)] + [Summary("Get a random fortune")] public async Task GetAFortune() { await ReplyAsync(fortunes.GetRandomFortune()); } } -} +} \ No newline at end of file diff --git a/Geekbot.net/Modules/GuildInfo.cs b/Geekbot.net/Modules/GuildInfo.cs index 6c357e5..20f4447 100644 --- a/Geekbot.net/Modules/GuildInfo.cs +++ b/Geekbot.net/Modules/GuildInfo.cs @@ -1,9 +1,9 @@ using System; -using System.Threading.Tasks; -using Discord.Commands; -using Discord; -using Geekbot.net.Lib; using System.Linq; +using System.Threading.Tasks; +using Discord; +using Discord.Commands; +using Geekbot.net.Lib; using StackExchange.Redis; namespace Geekbot.net.Modules @@ -11,25 +11,27 @@ namespace Geekbot.net.Modules public class GuildInfo : ModuleBase { private readonly IDatabase redis; + public GuildInfo(IDatabase redis) { this.redis = redis; } - [Command("serverstats", RunMode = RunMode.Async), Summary("Show some info about the bot.")] + [Command("serverstats", RunMode = RunMode.Async)] + [Summary("Show some info about the bot.")] public async Task getInfo() { var eb = new EmbedBuilder(); eb.WithAuthor(new EmbedAuthorBuilder() - .WithIconUrl(Context.Guild.IconUrl) - .WithName(Context.Guild.Name)); + .WithIconUrl(Context.Guild.IconUrl) + .WithName(Context.Guild.Name)); eb.WithColor(new Color(110, 204, 147)); - + var created = Context.Guild.CreatedAt; var age = Math.Floor((DateTime.Now - created).TotalDays); var messages = redis.StringGet($"{Context.Guild.Id}-messages"); - var level = LevelCalc.GetLevelAtExperience((int)messages); + var level = LevelCalc.GetLevelAtExperience((int) messages); eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)"); eb.AddInlineField("Level", level) @@ -40,7 +42,7 @@ namespace Geekbot.net.Modules public static string FirstCharToUpper(string input) { - if (String.IsNullOrEmpty(input)) + if (string.IsNullOrEmpty(input)) throw new ArgumentException("ARGH!"); return input.First().ToString().ToUpper() + input.Substring(1); } diff --git a/Geekbot.net/Modules/Help.cs b/Geekbot.net/Modules/Help.cs index 7064cba..9dd80a5 100644 --- a/Geekbot.net/Modules/Help.cs +++ b/Geekbot.net/Modules/Help.cs @@ -1,27 +1,48 @@ -using System.Threading.Tasks; +using System.Linq; +using System.Text; +using System.Threading.Tasks; using Discord.Commands; -using System.Reflection; namespace Geekbot.net.Modules { public class Help : ModuleBase { - [Command("help", RunMode = RunMode.Async), Summary("List all Commands")] + private readonly CommandService commands; + + public Help(CommandService commands) + { + this.commands = commands; + } + + [Command("help", RunMode = RunMode.Async)] + [Summary("List all Commands")] public async Task GetHelp() { - var commands = new CommandService(); - await commands.AddModulesAsync(Assembly.GetEntryAssembly()); - var cmdList = commands.Commands; - var reply = "**Geekbot Command list**\r\n"; - foreach (var cmd in cmdList) + var sb = new StringBuilder(); + sb.AppendLine("```"); + sb.AppendLine("**Geekbot Command list**"); + sb.AppendLine(""); + sb.AppendLine(tp("Name", 15) + tp("Parameters", 19) + "Description"); + foreach (var cmd in commands.Commands) { - var param = string.Join(", !",cmd.Aliases); + var param = string.Join(", !", cmd.Aliases); if (!param.Contains("admin")) - { - reply = reply + $"**{cmd.Name}** (!{param}) - {cmd.Summary}\r\n"; - } + if (cmd.Parameters.Any()) + sb.AppendLine(tp(param, 15) + + tp(string.Join(",", cmd.Parameters.Select(e => e.Summary)), 19) + + cmd.Summary); + else + sb.AppendLine(tp(param, 34) + cmd.Summary); } - await ReplyAsync(reply); + sb.AppendLine("```"); + var dm = await Context.User.GetOrCreateDMChannelAsync(); + await dm.SendMessageAsync(sb.ToString()); + } + + // Table Padding, short function name because of many usages + private string tp(string text, int shouldHave) + { + return text.PadRight(shouldHave); } } } \ No newline at end of file diff --git a/Geekbot.net/Modules/Info.cs b/Geekbot.net/Modules/Info.cs index 73e04fc..62d4a01 100644 --- a/Geekbot.net/Modules/Info.cs +++ b/Geekbot.net/Modules/Info.cs @@ -8,12 +8,14 @@ namespace Geekbot.net.Modules public class Info : ModuleBase { private readonly IDatabase redis; + public Info(IDatabase redis) { this.redis = redis; } - [Command("info", RunMode = RunMode.Async), Summary("Get Information about the bot")] + [Command("info", RunMode = RunMode.Async)] + [Summary("Get Information about the bot")] public async Task BotInfo() { var eb = new EmbedBuilder(); diff --git a/Geekbot.net/Modules/Ping.cs b/Geekbot.net/Modules/Ping.cs index 0803413..2ccca12 100644 --- a/Geekbot.net/Modules/Ping.cs +++ b/Geekbot.net/Modules/Ping.cs @@ -1,12 +1,12 @@ using System.Threading.Tasks; -using Discord; using Discord.Commands; namespace Geekbot.net.Modules { public class Ping : ModuleBase { - [Command("👀", RunMode = RunMode.Async), Summary("Look at the bot.")] + [Command("👀", RunMode = RunMode.Async)] + [Summary("Look at the bot.")] public async Task Eyes() { await ReplyAsync("S... Stop looking at me... baka!"); diff --git a/Geekbot.net/Modules/Roll.cs b/Geekbot.net/Modules/Roll.cs index 1c8755d..c46b887 100644 --- a/Geekbot.net/Modules/Roll.cs +++ b/Geekbot.net/Modules/Roll.cs @@ -9,14 +9,16 @@ namespace Geekbot.net.Modules { private readonly IDatabase redis; private readonly Random rnd; + public Roll(IDatabase redis, Random RandomClient) { this.redis = redis; - this.rnd = RandomClient; + rnd = RandomClient; } - [Command("roll", RunMode = RunMode.Async), Summary("Roll a number between 1 and 100.")] - public async Task RollCommand([Remainder, Summary("stuff...")] string stuff = "nothing") + [Command("roll", RunMode = RunMode.Async)] + [Summary("Roll a number between 1 and 100.")] + public async Task RollCommand([Remainder] [Summary("stuff...")] string stuff = "nothing") { var number = rnd.Next(1, 100); var guess = 1000; @@ -28,7 +30,7 @@ namespace Geekbot.net.Modules { await ReplyAsync($"Congratulations {Context.User.Username}, your guess was correct!"); var key = $"{Context.Guild.Id}-{Context.User.Id}-correctRolls"; - var messages = (int)redis.StringGet(key); + var messages = (int) redis.StringGet(key); redis.StringSet(key, (messages + 1).ToString()); } } diff --git a/Geekbot.net/Modules/Say.cs b/Geekbot.net/Modules/Say.cs index 35f0294..7d4b7af 100644 --- a/Geekbot.net/Modules/Say.cs +++ b/Geekbot.net/Modules/Say.cs @@ -1,13 +1,15 @@ using System.Threading.Tasks; +using Discord; using Discord.Commands; namespace Geekbot.net.Modules { public class Say : ModuleBase { - [RequireUserPermission(Discord.GuildPermission.Administrator)] - [Command("say", RunMode = RunMode.Async), Summary("Say Something.")] - public async Task Echo([Remainder, Summary("What?")] string echo) + [RequireUserPermission(GuildPermission.Administrator)] + [Command("say", RunMode = RunMode.Async)] + [Summary("Say Something.")] + public async Task Echo([Remainder] [Summary("What?")] string echo) { await Context.Message.DeleteAsync(); await ReplyAsync(echo); diff --git a/Geekbot.net/Modules/Ship.cs b/Geekbot.net/Modules/Ship.cs index 2049580..ed4365f 100644 --- a/Geekbot.net/Modules/Ship.cs +++ b/Geekbot.net/Modules/Ship.cs @@ -8,28 +8,25 @@ namespace Geekbot.net.Modules { public class Ship : ModuleBase { - private readonly IDatabase redis; private readonly Random rnd; + public Ship(IDatabase redis, Random RandomClient) { this.redis = redis; - this.rnd = RandomClient; + rnd = RandomClient; } - [Command("Ship", RunMode = RunMode.Async), Summary("Ask the Shipping meter")] - public async Task Command([Summary("User 1")] IUser user1, [Summary("User 2")] IUser user2) + [Command("Ship", RunMode = RunMode.Async)] + [Summary("Ask the Shipping meter")] + public async Task Command([Summary("@User1")] IUser user1, [Summary("@User2")] IUser user2) { // Create a String var dbstring = ""; if (user1.Id > user2.Id) - { dbstring = $"{user1.Id}-{user2.Id}"; - } else - { dbstring = $"{user2.Id}-{user1.Id}"; - } dbstring = $"{Context.Guild.Id}-{dbstring}"; Console.WriteLine(dbstring); @@ -54,21 +51,15 @@ namespace Geekbot.net.Modules private string DeterminateSuccess(int rate) { if (rate < 20) - { return "Not gonna happen"; - } if (rate >= 20 && rate < 40) - { + if (rate >= 20 && rate < 40) return "Not such a good idea"; - } if (rate >= 40 && rate < 60) - { + if (rate >= 40 && rate < 60) return "There might be a chance"; - } if (rate >= 60 && rate < 80) - { + if (rate >= 60 && rate < 80) return "Almost a match, but could work"; - } if (rate >= 80) - { + if (rate >= 80) return "It's a match"; - } return "a"; } @@ -77,20 +68,17 @@ namespace Geekbot.net.Modules var amount = Math.Floor(decimal.Floor(rate / 10)); Console.WriteLine(amount); var blocks = ""; - for(int i = 1; i <= 10; i++) - { - if(i <= amount) + for (var i = 1; i <= 10; i++) + if (i <= amount) { blocks = blocks + ":white_medium_small_square:"; - if(i == amount) - { + if (i == amount) blocks = blocks + $" {rate}% "; - } - } else + } + else { blocks = blocks + ":black_medium_small_square:"; } - } return blocks; } } diff --git a/Geekbot.net/Modules/UserInfo.cs b/Geekbot.net/Modules/UserInfo.cs index dd57ad6..1af885d 100644 --- a/Geekbot.net/Modules/UserInfo.cs +++ b/Geekbot.net/Modules/UserInfo.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Linq; using Discord; using Discord.Commands; using Geekbot.net.Lib; @@ -13,27 +13,28 @@ namespace Geekbot.net.Modules public class UserInfo : ModuleBase { private readonly IDatabase redis; + public UserInfo(IDatabase redis) { this.redis = redis; } - [Alias("stats")] - [Command("user", RunMode = RunMode.Async), Summary("Get information about this user")] - public async Task User([Summary("The (optional) user to get info for")] IUser user = null) + [Command("user", RunMode = RunMode.Async)] + [Summary("Get information about this user")] + public async Task User([Summary("@someone")] IUser user = null) { var userInfo = user ?? Context.Message.Author; var age = Math.Floor((DateTime.Now - userInfo.CreatedAt).TotalDays); var key = Context.Guild.Id + "-" + userInfo.Id; - var messages = (int)redis.StringGet(key + "-messages"); + var messages = (int) redis.StringGet(key + "-messages"); var level = LevelCalc.GetLevelAtExperience(messages); var guildKey = Context.Guild.Id.ToString(); - var guildMessages = (int)redis.StringGet(guildKey + "-messages"); + var guildMessages = (int) redis.StringGet(guildKey + "-messages"); - var percent = Math.Round((double)(100 * messages) / guildMessages, 2); + var percent = Math.Round((double) (100 * messages) / guildMessages, 2); var eb = new EmbedBuilder(); eb.WithAuthor(new EmbedAuthorBuilder() @@ -42,57 +43,54 @@ namespace Geekbot.net.Modules eb.WithColor(new Color(221, 255, 119)); - eb.AddField("Discordian Since", $"{userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)"); + eb.AddField("Discordian Since", + $"{userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)"); eb.AddInlineField("Level", level) .AddInlineField("Messages Sent", messages) .AddInlineField("Server Total", $"{percent}%"); var karma = redis.StringGet(key + "-karma"); if (!karma.IsNullOrEmpty) - { eb.AddInlineField("Karma", karma); - } var correctRolls = redis.StringGet($"{Context.Guild.Id}-{userInfo.Id}-correctRolls"); if (!correctRolls.IsNullOrEmpty) - { eb.AddInlineField("Guessed Rolls", correctRolls); - } await ReplyAsync("", false, eb.Build()); } - [Alias("highscore")] - [Command("rank", RunMode = RunMode.Async), Summary("get user top 10")] - public async Task Rank() + [Command("rank", RunMode = RunMode.Async)] + [Summary("get user top 10")] + public async Task Rank() { await ReplyAsync("this will take a moment..."); var guildKey = Context.Guild.Id.ToString(); - var guildMessages = (int)redis.StringGet(guildKey + "-messages"); + var guildMessages = (int) redis.StringGet(guildKey + "-messages"); var allGuildUsers = await Context.Guild.GetUsersAsync(); var unsortedDict = new Dictionary(); - foreach(var user in allGuildUsers) + foreach (var user in allGuildUsers) { var key = Context.Guild.Id + "-" + user.Id; - var messages = (int)redis.StringGet(key + "-messages"); - if(messages > 0) { + var messages = (int) redis.StringGet(key + "-messages"); + if (messages > 0) unsortedDict.Add($"{user.Username}#{user.Discriminator}", messages); - } } var sortedDict = unsortedDict.OrderByDescending(x => x.Value); var reply = new StringBuilder(); reply.AppendLine($"Total Messages on {Context.Guild.Name}: {guildMessages}"); var count = 1; - foreach(KeyValuePair entry in sortedDict) - { - if(count < 11){ - var percent = Math.Round((double)(100 * entry.Value) / guildMessages, 2); + foreach (var entry in sortedDict) + if (count < 11) + { + var percent = Math.Round((double) (100 * entry.Value) / guildMessages, 2); reply.AppendLine($"#{count} - **{entry.Key}** - {percent}% of total - {entry.Value} messages"); count++; - } else { + } + else + { break; } - } await ReplyAsync(reply.ToString()); } } diff --git a/Geekbot.net/Modules/Youtube.cs b/Geekbot.net/Modules/Youtube.cs index 3127ff4..afb7027 100644 --- a/Geekbot.net/Modules/Youtube.cs +++ b/Geekbot.net/Modules/Youtube.cs @@ -10,13 +10,15 @@ namespace Geekbot.net.Modules public class Youtube : ModuleBase { private readonly IDatabase redis; + public Youtube(IDatabase redis) { this.redis = redis; } - [Command("yt", RunMode = RunMode.Async), Summary("Search for something on youtube.")] - public async Task Yt([Remainder, Summary("A Song Title")] string searchQuery) + [Command("yt", RunMode = RunMode.Async)] + [Summary("Search for something on youtube.")] + public async Task Yt([Remainder] [Summary("Title")] string searchQuery) { var key = redis.StringGet("youtubeKey"); if (key.IsNullOrEmpty) @@ -27,10 +29,10 @@ namespace Geekbot.net.Modules try { - var youtubeService = new YouTubeService(new BaseClientService.Initializer() + var youtubeService = new YouTubeService(new BaseClientService.Initializer { ApiKey = key.ToString(), - ApplicationName = this.GetType().ToString() + ApplicationName = GetType().ToString() }); var searchListRequest = youtubeService.Search.List("snippet"); @@ -49,7 +51,8 @@ namespace Geekbot.net.Modules await ReplyAsync("Something went wrong... informing my senpai..."); var botOwner = Context.Guild.GetUserAsync(ulong.Parse(redis.StringGet("botOwner"))).Result; var dm = await botOwner.GetOrCreateDMChannelAsync(); - await dm.SendMessageAsync($"Something went wrong while getting a video from youtube:\r\n```\r\n{e.Message}\r\n```"); + await dm.SendMessageAsync( + $"Something went wrong while getting a video from youtube:\r\n```\r\n{e.Message}\r\n```"); } } } diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index 51699e1..319db04 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -1,30 +1,25 @@ using System; using System.Reflection; using System.Threading.Tasks; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Discord; using Discord.Commands; using Discord.WebSocket; using Geekbot.net.Lib; -using Geekbot.net.Modules; -using RestSharp; +using Microsoft.Extensions.DependencyInjection; using StackExchange.Redis; namespace Geekbot.net { - class Program + internal class Program { - private CommandService commands; private DiscordSocketClient client; + private CommandService commands; private IDatabase redis; - private RedisValue token; private IServiceCollection services; private IServiceProvider servicesProvider; + private RedisValue token; - private static void Main(string[] args) + private static void Main() { Console.WriteLine(@" ____ _____ _____ _ ______ ___ _____"); Console.WriteLine(@" / ___| ____| ____| |/ / __ ) / _ \\_ _|"); @@ -71,10 +66,10 @@ namespace Geekbot.net var fortunes = new FortunesProvider(); var checkEmImages = new CheckEmImageProvider(); var RandomClient = new Random(); + services.AddSingleton(redis); + services.AddSingleton(RandomClient); services.AddSingleton(fortunes); services.AddSingleton(checkEmImages); - services.AddSingleton(RandomClient); - services.AddSingleton(redis); Console.WriteLine("* Connecting to Discord"); @@ -101,6 +96,7 @@ namespace Geekbot.net client.MessageReceived += HandleMessageReceived; client.UserJoined += HandleUserJoined; await commands.AddModulesAsync(Assembly.GetEntryAssembly()); + services.AddSingleton(commands); servicesProvider = services.BuildServiceProvider(); Console.WriteLine("* Done and ready for use\n"); @@ -116,9 +112,7 @@ namespace Geekbot.net public async Task isConnected() { while (!client.ConnectionState.Equals(ConnectionState.Connected)) - { await Task.Delay(25); - } return true; } @@ -127,7 +121,7 @@ namespace Geekbot.net var message = messageParam as SocketUserMessage; if (message == null) return; if (message.Author.IsBot) return; - int argPos = 0; + var argPos = 0; var lowCaseMsg = message.ToString().ToLower(); if (lowCaseMsg.StartsWith("ping")) { @@ -139,7 +133,8 @@ namespace Geekbot.net await message.Channel.SendMessageAsync("hui!!!"); return; } - if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))) return; + if (!(message.HasCharPrefix('!', ref argPos) || + message.HasMentionPrefix(client.CurrentUser, ref argPos))) return; var context = new CommandContext(client, message); Task.Run(async () => await commands.ExecuteAsync(context, argPos, servicesProvider)); } @@ -148,14 +143,15 @@ namespace Geekbot.net { var message = messsageParam; if (message == null) return; - - var channel = (SocketGuildChannel)message.Channel; - - Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " + message.Content); - + var statsRecorder = new StatsRecorder(message, redis); Task.Run(async () => await statsRecorder.UpdateUserRecordAsync()); Task.Run(async () => await statsRecorder.UpdateGuildRecordAsync()); + + if (message.Author.Id == client.CurrentUser.Id) return; + var channel = (SocketGuildChannel) message.Channel; + Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " + + message.Content); } public async Task HandleUserJoined(SocketGuildUser user) @@ -171,4 +167,4 @@ namespace Geekbot.net } } } -} +} \ No newline at end of file