From e97ebf86efeb282796134a2966304e93961e28b5 Mon Sep 17 00:00:00 2001 From: Runebaas Date: Thu, 14 Sep 2017 20:24:04 +0200 Subject: [PATCH 1/3] Upgrading Dependencies and start restructure --- Geekbot.net/Geekbot.net.csproj | 74 ++++++++++-------- .../Lib/IClients/FourChanBoardClient.cs | 38 --------- Geekbot.net/Program.cs | 20 +++-- Geekbot.net/derp.ico | Bin 0 -> 370070 bytes derp.ico | Bin 0 -> 370070 bytes 5 files changed, 54 insertions(+), 78 deletions(-) delete mode 100644 Geekbot.net/Lib/IClients/FourChanBoardClient.cs create mode 100644 Geekbot.net/derp.ico create mode 100644 derp.ico diff --git a/Geekbot.net/Geekbot.net.csproj b/Geekbot.net/Geekbot.net.csproj index f943a96..5e543ab 100755 --- a/Geekbot.net/Geekbot.net.csproj +++ b/Geekbot.net/Geekbot.net.csproj @@ -1,33 +1,43 @@ - - - Exe - netcoreapp1.1 - - - - - 1.0.0-rc - - - 1.25.0.760 - - - 1.5.0.1 - - - 105.2.4-rc4-24214-01 - - - 1.2.1 - - - 4.3.1 - - - 4.3.0 - - - 4.3.0 - - + + + Exe + netcoreapp2.0 + derp.ico + 1.1.0 + Pizza and Coffee Studios + Pizza and Coffee Studios + A Discord bot + https://github.com/pizzaandcoffee/Geekbot.net + + + + 1.0.2 + + + 1.29.1.976 + + + 1.5.0.1 + + + + + + + 105.2.3 + + + 1.2.6 + + + 4.3.2 + + + + 4.3.0 + + + 4.3.0 + + \ No newline at end of file diff --git a/Geekbot.net/Lib/IClients/FourChanBoardClient.cs b/Geekbot.net/Lib/IClients/FourChanBoardClient.cs deleted file mode 100644 index 49fdc8d..0000000 --- a/Geekbot.net/Lib/IClients/FourChanBoardClient.cs +++ /dev/null @@ -1,38 +0,0 @@ -using RestSharp; -using System; -using System.Collections.Generic; -using static Geekbot.net.Lib.Dtos.FourChanDto; - -namespace Geekbot.net.Lib.IClients -{ - - class FourChanBoardClient - { - private BoardList boards; - private static FourChanBoardClient instace; - - private FourChanBoardClient() - { - Console.WriteLine("Fetching Boards"); - var boardClient = new RestClient("https://a.4cdn.org"); - var boardRequest = new RestRequest("boards.json", Method.GET); - var boardResult = boardClient.Execute(boardRequest); - this.boards = boardResult.Data; - } - - public static FourChanBoardClient Boards() - { - if (instace == null) - { - instace = new FourChanBoardClient(); - } - - return instace; - } - - public List getBoards() - { - return this.boards.Boards; - } - } -} diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index cf0487c..c5e31f1 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -2,6 +2,10 @@ using System.Reflection; using System.Runtime.InteropServices.ComTypes; 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; @@ -16,9 +20,9 @@ namespace Geekbot.net { private CommandService commands; private DiscordSocketClient client; - private DependencyMap map; private IRedisClient redis; private RedisValue token; + private ServiceCollection services; private static void Main(string[] args) { @@ -30,7 +34,7 @@ namespace Geekbot.net Console.WriteLine("========================================="); Console.WriteLine("Starting..."); - Task.WaitAll(new Program().MainAsync()); + new Program().MainAsync().GetAwaiter().GetResult(); } public async Task MainAsync() @@ -52,11 +56,11 @@ namespace Geekbot.net redis.Client.StringSet("botOwner", ownerId); } - map = new DependencyMap(); - map.Add(new CatClient()); - map.Add(new DogClient()); - map.Add(redis); - map.Add(new RandomClient()); + services = new ServiceCollection(); + services.AddSingleton(new CatClient()); + services.AddSingleton(new DogClient()); + services.AddSingleton(new RandomClient()); + services.AddSingleton(redis); Console.WriteLine("Connecting to Discord..."); @@ -127,7 +131,7 @@ namespace Geekbot.net // } 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, map)); + Task.Run(async () => await commands.ExecuteAsync(context, argPos, services)); } public async Task HandleMessageReceived(SocketMessage messsageParam) diff --git a/Geekbot.net/derp.ico b/Geekbot.net/derp.ico new file mode 100644 index 0000000000000000000000000000000000000000..bf7cde6107c7f01be02d4d4809fdf15e4db7b4c6 GIT binary patch literal 370070 zcmeI536K<3n#Zg9zPqdGrlGs*LL3eS6;K?}0r3Ej1_4177(q}F@c{3WOFbk4CGV937Uq^hMb>#8h z_x=9gd-*c+mB-`t)Ogz3JnApxSykonoTp!f`rrRteg13p*`bH-e}ACIb491eGi_S` z`_a=qp1>53XTyg5@9Vst6R+2=^H(NZT}_nax-y2^y_%=&w4swDjBR`FdhSz4D(h%w)qqa^&%X7M&w zCv0EotCPBkT~hze9vSh~oheOk-!P@yShsRWU1UEEGY*#Edz&Tv#qGwn!S`>H@MpJ0 z_7nd6b}>Hta+`#e1%IbW|T52NuH;+@% zTqi@nyHFaA?v?r@yTy0u3DS7#!Nz(G#~&ntH?EVOhnFU7XKrsUdtbOp0&i`UhN;1f z>zdn?_fnJ}ayOl4LdvEoGxN*_Be$s!V*l`Wx#U^uVK2)ymD0L$x-_45pj39$XT9$V zU!$}vIb53OjuLOfKu%V&%X%MrU7cHXyA^u(DycnaNY>j{e`A=@9);eyQYwcwWW8N{ z`69=E|5~X#q*FXq6F%J4aRrDcQ&Q;N$}kpjdlF5T$iv;@SV-ZcSEk2lJfW_|4pYK zk+6N;kt2=mTF#l8@SRy!-@2K`I$D3`XXdhX#k7paO?Uj~{^KKAwrrWCJN}k`+a(V? z@PJr7eq~pS)E_fS8fT1))MNJ7Kb6B@QvTg_b>uU%Zsv08zy3&Od~mmPKXQ?=PUyXB zq)GJ!>!%zbRo!h_*WdJmnSadv4|W-R>(Z?9Uqw^3X!BHhW6EeAKm6G((*4WT()Gg? zS=sQPUtrWf>G3PP#<7g!>GnXq55Bohg0Eg6b%zg2dVHe}1Q68iO(5_oQ@RF7!2yw6niH_LCFL+@E@TlvlL3q3wb`BV2_V*S5PI<8gMeV2^2 zWF6~|H<&bHT0sAYe!D?}uU}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V# z?)twp!liDXO7;0)$DjYJ>jq}~-}}%h(r{`I`p@_Mnl9Qu`Y-YJ|FtzS`fr>SME@?* zXQsZF)$h@N{`Ftk)}XHceK)7;5WzPtiqU`5X<_t_{%vCb{TD$0trqkjHP51P{*V4` zW8Z4qSq|Ihtp7JT|Iar5l@|0LdjDG5f7<)J<-FYWAN%{ijQ^z`1Gc39->#3+zZ(BP zZA9K!$TpwFub0#K|0g%`{7(twHS}NF{r}K!Hw@^1JNl2$J-kod?quT|^zS77_o?>3 zOve9c|4X7DhyER=|8lwi=i?jc|2w(=zh`ZvU&{SI>HA<6&2~PnX{y- zqp>7(YnR`BD-J0wA1gn%E*Mo-KDH}XuG&v2>R+*0)!9&1Y@+`XZwE`@oW3Y|2mKc$ z&!B(wUle_3%4_H!{byo??+e06vGRle>2uXs+eHPi3)L~AOg$r~=j=`Y-Eq=x9AT z?R8Q0Py3(8egW;j)3jKO@)lM9ZaM#_{ippe(d#JapZNHGs#ucUZx>jMhRjM!j{FunC(m00S@p126ys zFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE z00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p z126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ys zFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE z00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p z126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ys zFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE z00S@p126ysFaQIEV8Fv49>4>501w~+Jb(xA03N^tcmNOJ0X%>Q@Bkjb19$)r-~l{< U2k-zMzyo*y58wej;A{{4KR^n?YybcN literal 0 HcmV?d00001 diff --git a/derp.ico b/derp.ico new file mode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|FtzS`fr>SME@?* zXQsZF)$h@N{`Ftk)}XHceK)7;5WzPtiqU`5X<_t_{%vCb{TD$0trqkjHP51P{*V4` zW8Z4qSq|Ihtp7JT|Iar5l@|0LdjDG5f7<)J<-FYWAN%{ijQ^z`1Gc39->#3+zZ(BP zZA9K!$TpwFub0#K|0g%`{7(twHS}NF{r}K!Hw@^1JNl2$J-kod?quT|^zS77_o?>3 zOve9c|4X7DhyER=|8lwi=i?jc|2w(=zh`ZvU&{SI>HA<6&2~PnX{y- zqp>7(YnR`BD-J0wA1gn%E*Mo-KDH}XuG&v2>R+*0)!9&1Y@+`XZwE`@oW3Y|2mKc$ z&!B(wUle_3%4_H!{byo??+e06vGRle>2uXs+eHPi3)L~AOg$r~=j=`Y-Eq=x9AT z?R8Q0Py3(8egW;j)3jKO@)lM9ZaM#_{ippe(d#JapZNHGs#ucUZx>jMhRjM!j{FunC(m00S@p126ys zFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE z00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p z126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ys zFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE z00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p z126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ys zFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE00S@p126ysFaQHE z00S@p126ysFaQIEV8Fv49>4>501w~+Jb(xA03N^tcmNOJ0X%>Q@Bkjb19$)r-~l{< U2k-zMzyo*y58wej;A{{4KR^n?YybcN literal 0 HcmV?d00001 From 7d0b0c4634a14aab26c04f3c70532139d9e6588b Mon Sep 17 00:00:00 2001 From: Runebaas Date: Thu, 14 Sep 2017 22:11:19 +0200 Subject: [PATCH 2/3] Upgraded to dotnet core 2 and small arch restructure --- Geekbot.net/Lib/Dtos/FourChanDto.cs | 20 --- Geekbot.net/Lib/IClients/CatClient.cs | 19 --- Geekbot.net/Lib/IClients/DogClient.cs | 19 --- Geekbot.net/Lib/IClients/RandomClient.cs | 29 ---- Geekbot.net/Lib/IClients/RedisClient.cs | 30 ---- Geekbot.net/Lib/StatsRecorder.cs | 67 ++++---- Geekbot.net/Modules/AdminCmd.cs | 80 +++++----- Geekbot.net/Modules/Cat.cs | 50 +++--- Geekbot.net/Modules/Choose.cs | 45 +++--- Geekbot.net/Modules/Counters.cs | 22 +-- Geekbot.net/Modules/Dog.cs | 50 +++--- Geekbot.net/Modules/EightBall.cs | 9 +- Geekbot.net/Modules/FourChan.cs | 43 ----- Geekbot.net/Modules/GuildInfo.cs | 94 +++++------ Geekbot.net/Modules/Info.cs | 66 ++++---- Geekbot.net/Modules/Roll.cs | 23 +-- Geekbot.net/Modules/Ship.cs | 192 +++++++++++------------ Geekbot.net/Modules/UserInfo.cs | 20 +-- Geekbot.net/Modules/Youtube.cs | 110 ++++++------- Geekbot.net/Program.cs | 41 ++--- 20 files changed, 438 insertions(+), 591 deletions(-) delete mode 100644 Geekbot.net/Lib/Dtos/FourChanDto.cs delete mode 100644 Geekbot.net/Lib/IClients/CatClient.cs delete mode 100644 Geekbot.net/Lib/IClients/DogClient.cs delete mode 100644 Geekbot.net/Lib/IClients/RandomClient.cs delete mode 100644 Geekbot.net/Lib/IClients/RedisClient.cs delete mode 100644 Geekbot.net/Modules/FourChan.cs diff --git a/Geekbot.net/Lib/Dtos/FourChanDto.cs b/Geekbot.net/Lib/Dtos/FourChanDto.cs deleted file mode 100644 index 9d71d8c..0000000 --- a/Geekbot.net/Lib/Dtos/FourChanDto.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; - -namespace Geekbot.net.Lib.Dtos -{ - class FourChanDto - { - public class BoardList - { - public List Boards { get; set; } - } - - public class Board - { - public string board { get; set; } - public string title { get; set; } - public string ws_board { get; set; } - public string meta_description { get; set; } - } - } -} diff --git a/Geekbot.net/Lib/IClients/CatClient.cs b/Geekbot.net/Lib/IClients/CatClient.cs deleted file mode 100644 index 7a7e8c6..0000000 --- a/Geekbot.net/Lib/IClients/CatClient.cs +++ /dev/null @@ -1,19 +0,0 @@ -using RestSharp; - -namespace Geekbot.net.Lib.IClients -{ - public interface ICatClient - { - IRestClient Client { get; set; } - } - - public class CatClient : ICatClient - { - public CatClient() - { - Client = new RestClient("http://random.cat"); - } - - public IRestClient Client { get; set; } - } -} \ No newline at end of file diff --git a/Geekbot.net/Lib/IClients/DogClient.cs b/Geekbot.net/Lib/IClients/DogClient.cs deleted file mode 100644 index 20feed1..0000000 --- a/Geekbot.net/Lib/IClients/DogClient.cs +++ /dev/null @@ -1,19 +0,0 @@ -using RestSharp; - -namespace Geekbot.net.Lib.IClients -{ - public interface IDogClient - { - IRestClient Client { get; set; } - } - - public class DogClient : IDogClient - { - public DogClient() - { - Client = new RestClient("http://random.dog"); - } - - public IRestClient Client { get; set; } - } -} \ No newline at end of file diff --git a/Geekbot.net/Lib/IClients/RandomClient.cs b/Geekbot.net/Lib/IClients/RandomClient.cs deleted file mode 100644 index b6a3a50..0000000 --- a/Geekbot.net/Lib/IClients/RandomClient.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; - -namespace Geekbot.net.Lib.IClients -{ - - public interface IRandomClient - { - Random Client { get; set; } - } - - public sealed class RandomClient : IRandomClient - { - public RandomClient() - { - try - { - Client = new Random(); - } - catch (Exception) - { - Console.WriteLine("Start Redis pls..."); - Environment.Exit(1); - } - } - - public Random Client { get; set; } - } - -} \ No newline at end of file diff --git a/Geekbot.net/Lib/IClients/RedisClient.cs b/Geekbot.net/Lib/IClients/RedisClient.cs deleted file mode 100644 index 7fc890f..0000000 --- a/Geekbot.net/Lib/IClients/RedisClient.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using StackExchange.Redis; - -namespace Geekbot.net.Lib.IClients -{ - public interface IRedisClient - { - IDatabase Client { get; set; } - } - - public sealed class RedisClient : IRedisClient - { - public RedisClient() - { - try - { - var redis = ConnectionMultiplexer.Connect("127.0.0.1:6379"); - Client = redis.GetDatabase(6); - } - catch (Exception) - { - Console.WriteLine("Start Redis pls..."); - Environment.Exit(1); - } - } - - public IDatabase Client { get; set; } - } -} - diff --git a/Geekbot.net/Lib/StatsRecorder.cs b/Geekbot.net/Lib/StatsRecorder.cs index 8a17ff1..85572fb 100644 --- a/Geekbot.net/Lib/StatsRecorder.cs +++ b/Geekbot.net/Lib/StatsRecorder.cs @@ -1,35 +1,34 @@ -using System; -using System.Threading.Tasks; -using Discord.WebSocket; -using Geekbot.net.Lib.IClients; -using StackExchange.Redis; - -namespace Geekbot.net.Lib -{ - public class StatsRecorder - { - - private readonly SocketMessage message; - private readonly IDatabase redis; - - public StatsRecorder(SocketMessage message, IRedisClient redisClient) - { - this.message = message; - redis = redisClient.Client; - } - - public async Task UpdateUserRecordAsync() - { - var guildId = ((SocketGuildChannel) message.Channel).Guild.Id; - var key = guildId + "-" + message.Author.Id + "-messages"; - await redis.StringIncrementAsync(key); - } - - public async Task UpdateGuildRecordAsync() - { - var guildId = ((SocketGuildChannel) message.Channel).Guild.Id; - var key = guildId + "-messages"; - await redis.StringIncrementAsync(key); - } - } +using System; +using System.Threading.Tasks; +using Discord.WebSocket; +using StackExchange.Redis; + +namespace Geekbot.net.Lib +{ + public class StatsRecorder + { + + private readonly SocketMessage message; + private readonly IDatabase redis; + + public StatsRecorder(SocketMessage message, IDatabase redis) + { + this.message = message; + this.redis = redis; + } + + public async Task UpdateUserRecordAsync() + { + var guildId = ((SocketGuildChannel) message.Channel).Guild.Id; + var key = guildId + "-" + message.Author.Id + "-messages"; + await redis.StringIncrementAsync(key); + } + + public async Task UpdateGuildRecordAsync() + { + var guildId = ((SocketGuildChannel) message.Channel).Guild.Id; + var key = guildId + "-messages"; + await redis.StringIncrementAsync(key); + } + } } \ No newline at end of file diff --git a/Geekbot.net/Modules/AdminCmd.cs b/Geekbot.net/Modules/AdminCmd.cs index b6732af..9385409 100644 --- a/Geekbot.net/Modules/AdminCmd.cs +++ b/Geekbot.net/Modules/AdminCmd.cs @@ -1,41 +1,41 @@ -using System.Threading.Tasks; -using Discord.Commands; -using Geekbot.net.Lib.IClients; - -namespace Geekbot.net.Modules -{ - [Group("admin")] - public class AdminCmd : ModuleBase - { - private readonly IRedisClient redis; - public AdminCmd(IRedisClient redisClient) - { - redis = redisClient; - } - - [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) - { - var key = Context.Guild.Id + "-welcomeMsg"; - redis.Client.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); - } - - [Command("youtubekey", RunMode = RunMode.Async), Summary("Set the youtube api key")] - public async Task SetYoutubeKey([Summary("API Key")] string key) - { - var botOwner = redis.Client.StringGet("botOwner"); - if (!Context.User.Id.ToString().Equals(botOwner.ToString())) - { - await ReplyAsync($"Sorry, only the botowner can do this ({botOwner}"); - return; - } - - redis.Client.StringSet("youtubeKey", key); - await ReplyAsync("Apikey has been set"); - } - } +using System.Threading.Tasks; +using Discord.Commands; +using StackExchange.Redis; + +namespace Geekbot.net.Modules +{ + [Group("admin")] + 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) + { + 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); + } + + [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"); + if (!Context.User.Id.ToString().Equals(botOwner.ToString())) + { + await ReplyAsync($"Sorry, only the botowner can do this ({botOwner}"); + return; + } + + redis.StringSet("youtubeKey", key); + await ReplyAsync("Apikey has been set"); + } + } } \ No newline at end of file diff --git a/Geekbot.net/Modules/Cat.cs b/Geekbot.net/Modules/Cat.cs index 0250e0a..2f9e63e 100644 --- a/Geekbot.net/Modules/Cat.cs +++ b/Geekbot.net/Modules/Cat.cs @@ -1,25 +1,27 @@ -using System.Threading.Tasks; -using Discord.Commands; -using Geekbot.net.Lib.IClients; -using RestSharp; - -namespace Geekbot.net.Modules -{ - public class Cat : ModuleBase - { - private readonly ICatClient catClient; - public Cat(ICatClient catClient) - { - this.catClient = catClient; - } - - [Command("cat", RunMode = RunMode.Async), Summary("Return a random image of a cat.")] - public async Task Say() - { - var request = new RestRequest("meow.php", Method.GET); - - dynamic response = catClient.Client.Execute(request); - await ReplyAsync(response.Data["file"]); - } - } +using System; +using System.Threading.Tasks; +using Discord.Commands; +using RestSharp; + +namespace Geekbot.net.Modules +{ + public class Cat : ModuleBase + { + [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); + }); + } + + } + + public class CatResponse + { + public string file { get; set; } + } } \ No newline at end of file diff --git a/Geekbot.net/Modules/Choose.cs b/Geekbot.net/Modules/Choose.cs index 28a8be2..3242ed5 100644 --- a/Geekbot.net/Modules/Choose.cs +++ b/Geekbot.net/Modules/Choose.cs @@ -1,24 +1,23 @@ -using System; -using System.Threading.Tasks; -using Discord.Commands; -using Geekbot.net.Lib.IClients; - -namespace Geekbot.net.Modules -{ - public class Choose : ModuleBase - { - private readonly IRandomClient rnd; - public Choose(IRandomClient 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) - { - var choicesArray = choices.Split(';'); - var choice = rnd.Client.Next(choicesArray.Length); - await ReplyAsync($"I choose **{choicesArray[choice]}**"); - } - } +using System; +using System.Threading.Tasks; +using Discord.Commands; + +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) + { + var choicesArray = choices.Split(';'); + var choice = rnd.Next(choicesArray.Length); + await ReplyAsync($"I choose **{choicesArray[choice]}**"); + } + } } \ No newline at end of file diff --git a/Geekbot.net/Modules/Counters.cs b/Geekbot.net/Modules/Counters.cs index 04f3707..9668ea3 100644 --- a/Geekbot.net/Modules/Counters.cs +++ b/Geekbot.net/Modules/Counters.cs @@ -2,16 +2,16 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; -using Geekbot.net.Lib.IClients; +using StackExchange.Redis; namespace Geekbot.net.Modules { public class Counters : ModuleBase { - private readonly IRedisClient redis; - public Counters(IRedisClient redisClient) + private readonly IDatabase redis; + public Counters(IDatabase redis) { - redis = redisClient; + this.redis = redis; } [Command("good", RunMode = RunMode.Async), Summary("Increase Someones Karma")] @@ -29,11 +29,11 @@ namespace Geekbot.net.Modules else { var key = Context.Guild.Id + "-" + user.Id + "-karma"; - var badJokes = (int)redis.Client.StringGet(key); + var badJokes = (int)redis.StringGet(key); var newBadJokes = badJokes + 1; - redis.Client.StringSet(key, newBadJokes.ToString()); + redis.StringSet(key, newBadJokes.ToString()); var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout"; - redis.Client.StringSet(lastKey, GetNewLastKarma()); + redis.StringSet(lastKey, GetNewLastKarma()); var eb = new EmbedBuilder(); eb.WithAuthor(new EmbedAuthorBuilder() @@ -64,11 +64,11 @@ namespace Geekbot.net.Modules else { var key = Context.Guild.Id + "-" + user.Id + "-karma"; - var badJokes = (int)redis.Client.StringGet(key); + var badJokes = (int)redis.StringGet(key); var newBadJokes = badJokes - 1; - redis.Client.StringSet(key, newBadJokes.ToString()); + redis.StringSet(key, newBadJokes.ToString()); var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout"; - redis.Client.StringSet(lastKey, GetNewLastKarma()); + redis.StringSet(lastKey, GetNewLastKarma()); var eb = new EmbedBuilder(); eb.WithAuthor(new EmbedAuthorBuilder() @@ -87,7 +87,7 @@ namespace Geekbot.net.Modules private int GetLastKarma() { var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout"; - var redisReturn = redis.Client.StringGet(lastKey); + var redisReturn = redis.StringGet(lastKey); if (!int.TryParse(redisReturn.ToString(), out var i)) { i = GetUnixTimestamp(); diff --git a/Geekbot.net/Modules/Dog.cs b/Geekbot.net/Modules/Dog.cs index 6e98d90..356cd09 100644 --- a/Geekbot.net/Modules/Dog.cs +++ b/Geekbot.net/Modules/Dog.cs @@ -1,25 +1,27 @@ -using System.Threading.Tasks; -using Discord.Commands; -using Geekbot.net.Lib.IClients; -using RestSharp; - -namespace Geekbot.net.Modules -{ - public class Dog : ModuleBase - { - private readonly IDogClient dogClient; - public Dog(IDogClient dogClient) - { - this.dogClient = dogClient; - } - - [Command("dog", RunMode = RunMode.Async), Summary("Return a random image of a dog.")] - public async Task Say() - { - var request = new RestRequest("woof.json", Method.GET); - - dynamic response = dogClient.Client.Execute(request); - await ReplyAsync(response.Data["url"]); - } - } +using System; +using System.Threading.Tasks; +using Discord.Commands; +using RestSharp; + +namespace Geekbot.net.Modules +{ + public class Dog : ModuleBase + { + [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); + }); + } + } + + public class DogResponse + { + public string url { get; set; } + } } \ No newline at end of file diff --git a/Geekbot.net/Modules/EightBall.cs b/Geekbot.net/Modules/EightBall.cs index 2d93c1b..efce699 100644 --- a/Geekbot.net/Modules/EightBall.cs +++ b/Geekbot.net/Modules/EightBall.cs @@ -2,16 +2,15 @@ using System.Collections.Generic; using System.Threading.Tasks; using Discord.Commands; -using Geekbot.net.Lib.IClients; namespace Geekbot.net.Modules { public class EightBall : ModuleBase { - private readonly IRandomClient rnd; - public EightBall(IRandomClient randomClient) + private readonly Random rnd; + public EightBall(Random RandomClient) { - rnd = randomClient; + rnd = RandomClient; } [Command("8ball", RunMode = RunMode.Async), Summary("Ask 8Ball a Question.")] public async Task Ball([Remainder, Summary("The Question")] string echo) @@ -38,7 +37,7 @@ namespace Geekbot.net.Modules "Outlook not so good", "Very doubtful"}; - var answer = rnd.Client.Next(replies.Count); + var answer = rnd.Next(replies.Count); await ReplyAsync(replies[answer]); } } diff --git a/Geekbot.net/Modules/FourChan.cs b/Geekbot.net/Modules/FourChan.cs deleted file mode 100644 index 3cdf036..0000000 --- a/Geekbot.net/Modules/FourChan.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Discord.Commands; -using static Geekbot.net.Lib.Dtos.FourChanDto; -using Geekbot.net.Lib.IClients; - -namespace Geekbot.net.Modules -{ - public class FourChan : ModuleBase - { - [Command("4chan", RunMode = RunMode.Async), Summary("Get Something from 4chan")] - public async Task Chan([Summary("The someone")] string boardParam) - { - try - { - var boards = FourChanBoardClient.Boards(); - var board = new Board(); - foreach (var b in boards.getBoards()) - { - if (b.board.Equals(boardParam)) - { - board = b; - break; - } - } - if (board.board == boardParam) - { - await ReplyAsync($"{board.title} - {board.meta_description}"); - } else - { - await ReplyAsync("Sorry, that board does not exist..."); - } - } - catch (Exception e) - { - await ReplyAsync(e.Message); - } - } - } -} - -// var boards = new List["a", "b", "c", "d", "e", "f", "g", "gif", "h", "hr", "k", "m", "o", "p", "r", "s", "t", "u", "v", "vg", "vr", "w", "wg", "i", "ic", "r9k", "s4s", "cm", "hm", "lgbt", "y", "3", "aco", "adv", "an", "asp", "biz", "cgl", "ck", "co", "diy", "fa", "fit", "gd", "hc", "his", "int", "jp", "lit", "mlp", "mu", "n", "news", "out", "po", "pol", "qst", "sci", "soc" / sp / tg / toy / trv / tv / vp / wsg / wsr /]; diff --git a/Geekbot.net/Modules/GuildInfo.cs b/Geekbot.net/Modules/GuildInfo.cs index 9a03373..6c357e5 100644 --- a/Geekbot.net/Modules/GuildInfo.cs +++ b/Geekbot.net/Modules/GuildInfo.cs @@ -1,48 +1,48 @@ -using System; -using System.Threading.Tasks; -using Discord.Commands; -using Discord; -using Geekbot.net.Lib; -using System.Linq; -using Geekbot.net.Lib.IClients; - -namespace Geekbot.net.Modules -{ - public class GuildInfo : ModuleBase - { - private readonly IRedisClient redis; - public GuildInfo(IRedisClient redisClient) - { - redis = redisClient; - } - - [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)); - eb.WithColor(new Color(110, 204, 147)); - - var created = Context.Guild.CreatedAt; - var age = Math.Floor((DateTime.Now - created).TotalDays); - - var messages = redis.Client.StringGet($"{Context.Guild.Id}-messages"); - var level = LevelCalc.GetLevelAtExperience((int)messages); - - eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)"); - eb.AddInlineField("Level", level) - .AddInlineField("Messages", messages); - - await ReplyAsync("", false, eb.Build()); - } - - public static string FirstCharToUpper(string input) - { - if (String.IsNullOrEmpty(input)) - throw new ArgumentException("ARGH!"); - return input.First().ToString().ToUpper() + input.Substring(1); - } - } +using System; +using System.Threading.Tasks; +using Discord.Commands; +using Discord; +using Geekbot.net.Lib; +using System.Linq; +using StackExchange.Redis; + +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.")] + public async Task getInfo() + { + var eb = new EmbedBuilder(); + eb.WithAuthor(new EmbedAuthorBuilder() + .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); + + eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)"); + eb.AddInlineField("Level", level) + .AddInlineField("Messages", messages); + + await ReplyAsync("", false, eb.Build()); + } + + public static string FirstCharToUpper(string input) + { + if (String.IsNullOrEmpty(input)) + throw new ArgumentException("ARGH!"); + return input.First().ToString().ToUpper() + input.Substring(1); + } + } } \ No newline at end of file diff --git a/Geekbot.net/Modules/Info.cs b/Geekbot.net/Modules/Info.cs index a31fec9..73e04fc 100644 --- a/Geekbot.net/Modules/Info.cs +++ b/Geekbot.net/Modules/Info.cs @@ -1,34 +1,34 @@ -using System.Threading.Tasks; -using Discord; -using Discord.Commands; -using Geekbot.net.Lib.IClients; - -namespace Geekbot.net.Modules -{ - public class Info : ModuleBase - { - private readonly IRedisClient redis; - public Info(IRedisClient redisClient) - { - redis = redisClient; - } - - [Command("info", RunMode = RunMode.Async), Summary("Get Information about the bot")] - public async Task BotInfo() - { - var eb = new EmbedBuilder(); - - eb.WithTitle("Geekbot V3"); - - var botOwner = Context.Guild.GetUserAsync(ulong.Parse(redis.Client.StringGet("botOwner"))).Result; - - eb.AddInlineField("Status", Context.Client.ConnectionState.ToString()) - .AddInlineField("Bot Name", Context.Client.CurrentUser.Username) - .AddInlineField("Bot Owner", $"{botOwner.Username}#{botOwner.Discriminator}"); - - eb.AddInlineField("Servers", Context.Client.GetGuildsAsync().Result.Count); - - await ReplyAsync("", false, eb.Build()); - } - } +using System.Threading.Tasks; +using Discord; +using Discord.Commands; +using StackExchange.Redis; + +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")] + public async Task BotInfo() + { + var eb = new EmbedBuilder(); + + eb.WithTitle("Geekbot V3.1"); + + var botOwner = Context.Guild.GetUserAsync(ulong.Parse(redis.StringGet("botOwner"))).Result; + + eb.AddInlineField("Status", Context.Client.ConnectionState.ToString()) + .AddInlineField("Bot Name", Context.Client.CurrentUser.Username) + .AddInlineField("Bot Owner", $"{botOwner.Username}#{botOwner.Discriminator}"); + + eb.AddInlineField("Servers", Context.Client.GetGuildsAsync().Result.Count); + + await ReplyAsync("", false, eb.Build()); + } + } } \ No newline at end of file diff --git a/Geekbot.net/Modules/Roll.cs b/Geekbot.net/Modules/Roll.cs index 6331d22..b953859 100644 --- a/Geekbot.net/Modules/Roll.cs +++ b/Geekbot.net/Modules/Roll.cs @@ -1,24 +1,25 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using Discord.Commands; using Geekbot.net.Lib; -using Geekbot.net.Lib.IClients; +using StackExchange.Redis; namespace Geekbot.net.Modules { public class Roll : ModuleBase { - private readonly IRedisClient redis; - private readonly IRandomClient rnd; - public Roll(IRedisClient redisClient, IRandomClient randomClient) + private readonly IDatabase redis; + private readonly Random rnd; + public Roll(IDatabase redis, Random RandomClient) { - redis = redisClient; - rnd = randomClient; + this.redis = redis; + this.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") { - var number = rnd.Client.Next(1, 100); + var number = rnd.Next(1, 100); var guess = 1000; int.TryParse(stuff, out guess); if (guess <= 100 && guess > 0) @@ -28,8 +29,8 @@ 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.Client.StringGet(key); - redis.Client.StringSet(key, (messages + 1).ToString()); + var messages = (int)redis.StringGet(key); + redis.StringSet(key, (messages + 1).ToString()); } } else @@ -41,7 +42,7 @@ namespace Geekbot.net.Modules [Command("dice", RunMode = RunMode.Async), Summary("Roll a dice")] public async Task DiceCommand([Summary("The highest number on the dice")] int max = 6) { - var number = rnd.Client.Next(1, max); + var number = rnd.Next(1, max); await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number); } } diff --git a/Geekbot.net/Modules/Ship.cs b/Geekbot.net/Modules/Ship.cs index f22ed1b..2049580 100644 --- a/Geekbot.net/Modules/Ship.cs +++ b/Geekbot.net/Modules/Ship.cs @@ -1,97 +1,97 @@ -using System; -using System.Threading.Tasks; -using Discord; -using Discord.Commands; -using Geekbot.net.Lib.IClients; - -namespace Geekbot.net.Modules -{ - public class Ship : ModuleBase - { - - private readonly IRedisClient redis; - private readonly IRandomClient rnd; - public Ship(IRedisClient redisClient, IRandomClient randomClient) - { - redis = redisClient; - 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) - { - // 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); - - var dbval = redis.Client.StringGet(dbstring); - var shippingRate = 0; - if (dbval.IsNullOrEmpty) - { - shippingRate = rnd.Client.Next(1, 100); - redis.Client.StringSet(dbstring, shippingRate); - } - else - { - shippingRate = int.Parse(dbval.ToString()); - } - - var reply = ":heartpulse: **Matchmaking** :heartpulse:\r\n"; - reply = reply + $":two_hearts: {user1.Mention} :heart: {user2.Mention} :two_hearts:\r\n"; - reply = reply + $"0% [{BlockCounter(shippingRate)}] 100% - {DeterminateSuccess(shippingRate)}"; - await ReplyAsync(reply); - } - - private string DeterminateSuccess(int rate) - { - if (rate < 20) - { - return "Not gonna happen"; - } if (rate >= 20 && rate < 40) - { - return "Not such a good idea"; - } if (rate >= 40 && rate < 60) - { - return "There might be a chance"; - } if (rate >= 60 && rate < 80) - { - return "Almost a match, but could work"; - } if (rate >= 80) - { - return "It's a match"; - } - return "a"; - } - - private string BlockCounter(int rate) - { - var amount = Math.Floor(decimal.Floor(rate / 10)); - Console.WriteLine(amount); - var blocks = ""; - for(int i = 1; i <= 10; i++) - { - if(i <= amount) - { - blocks = blocks + ":white_medium_small_square:"; - if(i == amount) - { - blocks = blocks + $" {rate}% "; - } - } else - { - blocks = blocks + ":black_medium_small_square:"; - } - } - return blocks; - } - } +using System; +using System.Threading.Tasks; +using Discord; +using Discord.Commands; +using StackExchange.Redis; + +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; + } + + [Command("Ship", RunMode = RunMode.Async), Summary("Ask the Shipping meter")] + public async Task Command([Summary("User 1")] IUser user1, [Summary("User 2")] 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); + + var dbval = redis.StringGet(dbstring); + var shippingRate = 0; + if (dbval.IsNullOrEmpty) + { + shippingRate = rnd.Next(1, 100); + redis.StringSet(dbstring, shippingRate); + } + else + { + shippingRate = int.Parse(dbval.ToString()); + } + + var reply = ":heartpulse: **Matchmaking** :heartpulse:\r\n"; + reply = reply + $":two_hearts: {user1.Mention} :heart: {user2.Mention} :two_hearts:\r\n"; + reply = reply + $"0% [{BlockCounter(shippingRate)}] 100% - {DeterminateSuccess(shippingRate)}"; + await ReplyAsync(reply); + } + + private string DeterminateSuccess(int rate) + { + if (rate < 20) + { + return "Not gonna happen"; + } if (rate >= 20 && rate < 40) + { + return "Not such a good idea"; + } if (rate >= 40 && rate < 60) + { + return "There might be a chance"; + } if (rate >= 60 && rate < 80) + { + return "Almost a match, but could work"; + } if (rate >= 80) + { + return "It's a match"; + } + return "a"; + } + + private string BlockCounter(int rate) + { + var amount = Math.Floor(decimal.Floor(rate / 10)); + Console.WriteLine(amount); + var blocks = ""; + for(int i = 1; i <= 10; i++) + { + if(i <= amount) + { + blocks = blocks + ":white_medium_small_square:"; + if(i == amount) + { + blocks = blocks + $" {rate}% "; + } + } else + { + blocks = blocks + ":black_medium_small_square:"; + } + } + return blocks; + } + } } \ No newline at end of file diff --git a/Geekbot.net/Modules/UserInfo.cs b/Geekbot.net/Modules/UserInfo.cs index 2dbb827..dd57ad6 100644 --- a/Geekbot.net/Modules/UserInfo.cs +++ b/Geekbot.net/Modules/UserInfo.cs @@ -6,16 +6,16 @@ using System.Linq; using Discord; using Discord.Commands; using Geekbot.net.Lib; -using Geekbot.net.Lib.IClients; +using StackExchange.Redis; namespace Geekbot.net.Modules { public class UserInfo : ModuleBase { - private readonly IRedisClient redis; - public UserInfo(IRedisClient redisClient) + private readonly IDatabase redis; + public UserInfo(IDatabase redis) { - redis = redisClient; + this.redis = redis; } [Alias("stats")] @@ -27,11 +27,11 @@ namespace Geekbot.net.Modules var age = Math.Floor((DateTime.Now - userInfo.CreatedAt).TotalDays); var key = Context.Guild.Id + "-" + userInfo.Id; - var messages = (int)redis.Client.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.Client.StringGet(guildKey + "-messages"); + var guildMessages = (int)redis.StringGet(guildKey + "-messages"); var percent = Math.Round((double)(100 * messages) / guildMessages, 2); @@ -47,13 +47,13 @@ namespace Geekbot.net.Modules .AddInlineField("Messages Sent", messages) .AddInlineField("Server Total", $"{percent}%"); - var karma = redis.Client.StringGet(key + "-karma"); + var karma = redis.StringGet(key + "-karma"); if (!karma.IsNullOrEmpty) { eb.AddInlineField("Karma", karma); } - var correctRolls = redis.Client.StringGet($"{Context.Guild.Id}-{userInfo.Id}-correctRolls"); + var correctRolls = redis.StringGet($"{Context.Guild.Id}-{userInfo.Id}-correctRolls"); if (!correctRolls.IsNullOrEmpty) { eb.AddInlineField("Guessed Rolls", correctRolls); @@ -68,13 +68,13 @@ namespace Geekbot.net.Modules { await ReplyAsync("this will take a moment..."); var guildKey = Context.Guild.Id.ToString(); - var guildMessages = (int)redis.Client.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) { var key = Context.Guild.Id + "-" + user.Id; - var messages = (int)redis.Client.StringGet(key + "-messages"); + var messages = (int)redis.StringGet(key + "-messages"); if(messages > 0) { unsortedDict.Add($"{user.Username}#{user.Discriminator}", messages); } diff --git a/Geekbot.net/Modules/Youtube.cs b/Geekbot.net/Modules/Youtube.cs index 723ea9a..3127ff4 100644 --- a/Geekbot.net/Modules/Youtube.cs +++ b/Geekbot.net/Modules/Youtube.cs @@ -1,56 +1,56 @@ -using System; -using System.Threading.Tasks; -using Discord.Commands; -using Geekbot.net.Lib.IClients; -using Google.Apis.Services; -using Google.Apis.YouTube.v3; - -namespace Geekbot.net.Modules -{ - public class Youtube : ModuleBase - { - private readonly IRedisClient redis; - public Youtube(IRedisClient redisClient) - { - redis = redisClient; - } - - [Command("yt", RunMode = RunMode.Async), Summary("Search for something on youtube.")] - public async Task Yt([Remainder, Summary("A Song Title")] string searchQuery) - { - var key = redis.Client.StringGet("youtubeKey"); - if (key.IsNullOrEmpty) - { - await ReplyAsync("No youtube key set, please tell my senpai to set one"); - return; - } - - try - { - var youtubeService = new YouTubeService(new BaseClientService.Initializer() - { - ApiKey = key.ToString(), - ApplicationName = this.GetType().ToString() - }); - - var searchListRequest = youtubeService.Search.List("snippet"); - searchListRequest.Q = searchQuery; - searchListRequest.MaxResults = 2; - - var searchListResponse = await searchListRequest.ExecuteAsync(); - - var result = searchListResponse.Items[0]; - - await ReplyAsync( - $"\"{result.Snippet.Title}\" from \"{result.Snippet.ChannelTitle}\" https://youtu.be/{result.Id.VideoId}"); - } - catch (Exception e) - { - await ReplyAsync("Something went wrong... informing my senpai..."); - var botOwner = Context.Guild.GetUserAsync(ulong.Parse(redis.Client.StringGet("botOwner"))).Result; - var dm = await botOwner.CreateDMChannelAsync(); - await dm.SendMessageAsync($"Something went wrong while getting a video from youtube:\r\n```\r\n{e.Message}\r\n```"); - } - } - } +using System; +using System.Threading.Tasks; +using Discord.Commands; +using Google.Apis.Services; +using Google.Apis.YouTube.v3; +using StackExchange.Redis; + +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) + { + var key = redis.StringGet("youtubeKey"); + if (key.IsNullOrEmpty) + { + await ReplyAsync("No youtube key set, please tell my senpai to set one"); + return; + } + + try + { + var youtubeService = new YouTubeService(new BaseClientService.Initializer() + { + ApiKey = key.ToString(), + ApplicationName = this.GetType().ToString() + }); + + var searchListRequest = youtubeService.Search.List("snippet"); + searchListRequest.Q = searchQuery; + searchListRequest.MaxResults = 2; + + var searchListResponse = await searchListRequest.ExecuteAsync(); + + var result = searchListResponse.Items[0]; + + await ReplyAsync( + $"\"{result.Snippet.Title}\" from \"{result.Snippet.ChannelTitle}\" https://youtu.be/{result.Id.VideoId}"); + } + catch (Exception e) + { + 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```"); + } + } + } } \ No newline at end of file diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index c5e31f1..a62f0ee 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -1,6 +1,5 @@ using System; using System.Reflection; -using System.Runtime.InteropServices.ComTypes; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -10,8 +9,8 @@ using Discord; using Discord.Commands; using Discord.WebSocket; using Geekbot.net.Lib; -using Geekbot.net.Lib.IClients; using Geekbot.net.Modules; +using RestSharp; using StackExchange.Redis; namespace Geekbot.net @@ -20,9 +19,10 @@ namespace Geekbot.net { private CommandService commands; private DiscordSocketClient client; - private IRedisClient redis; + private IDatabase redis; private RedisValue token; - private ServiceCollection services; + private IServiceCollection services; + private IServiceProvider servicesProvider; private static void Main(string[] args) { @@ -41,25 +41,34 @@ namespace Geekbot.net { client = new DiscordSocketClient(); commands = new CommandService(); - redis = new RedisClient(); - token = redis.Client.StringGet("discordToken"); + try + { + var redisMultiplexer = ConnectionMultiplexer.Connect("127.0.0.1:6379"); + redis = redisMultiplexer.GetDatabase(6); + } + catch (Exception) + { + Console.WriteLine("Start Redis pls..."); + Environment.Exit(1); + } + + token = redis.StringGet("discordToken"); if (token.IsNullOrEmpty) { Console.Write("Your bot Token: "); var newToken = Console.ReadLine(); - redis.Client.StringSet("discordToken", newToken); + redis.StringSet("discordToken", newToken); token = newToken; Console.Write("Bot Owner User ID: "); var ownerId = Console.ReadLine(); - redis.Client.StringSet("botOwner", ownerId); + redis.StringSet("botOwner", ownerId); } services = new ServiceCollection(); - services.AddSingleton(new CatClient()); - services.AddSingleton(new DogClient()); - services.AddSingleton(new RandomClient()); + var RandomClient = new Random(); + services.AddSingleton(RandomClient); services.AddSingleton(redis); Console.WriteLine("Connecting to Discord..."); @@ -87,6 +96,7 @@ namespace Geekbot.net client.MessageReceived += HandleMessageReceived; client.UserJoined += HandleUserJoined; await commands.AddModulesAsync(Assembly.GetEntryAssembly()); + servicesProvider = services.BuildServiceProvider(); Console.WriteLine("Done and ready for use...\n"); } @@ -124,14 +134,9 @@ namespace Geekbot.net await message.Channel.SendMessageAsync("hui!!!"); return; } - // if (message.ToString().ToLower().Contains("teamspeak") || message.ToString().ToLower().Contains("skype")) - // { - // await message.Channel.SendMessageAsync("How dare you to use such a filthy word in here http://bit.ly/2poL2IZ"); - // 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, services)); + Task.Run(async () => await commands.ExecuteAsync(context, argPos, servicesProvider)); } public async Task HandleMessageReceived(SocketMessage messsageParam) @@ -152,7 +157,7 @@ namespace Geekbot.net { if (!user.IsBot) { - var message = redis.Client.StringGet(user.Guild.Id + "-welcomeMsg"); + var message = redis.StringGet(user.Guild.Id + "-welcomeMsg"); if (!message.IsNullOrEmpty) { message = message.ToString().Replace("$user", user.Mention); From a004ab4290061600231e14d48152bb202518357e Mon Sep 17 00:00:00 2001 From: Runebaas Date: Thu, 14 Sep 2017 22:20:28 +0200 Subject: [PATCH 3/3] Small Async fix --- Geekbot.net/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index a62f0ee..7b000a3 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -149,8 +149,8 @@ namespace Geekbot.net Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " + message.Content); var statsRecorder = new StatsRecorder(message, redis); - Task.Run(() => statsRecorder.UpdateUserRecordAsync()); - Task.Run(() => statsRecorder.UpdateGuildRecordAsync()); + Task.Run(async () => await statsRecorder.UpdateUserRecordAsync()); + Task.Run(async () => await statsRecorder.UpdateGuildRecordAsync()); } public async Task HandleUserJoined(SocketGuildUser user)