From 92015d8880be8741dee0072a15ae343e353e104f Mon Sep 17 00:00:00 2001 From: Runebaas Date: Mon, 2 Oct 2017 21:57:48 +0200 Subject: [PATCH] Adding Initial API support, updating readme --- Geekbot.net/{Modules => Commands}/AdminCmd.cs | 4 +-- Geekbot.net/{Modules => Commands}/Cat.cs | 2 +- Geekbot.net/{Modules => Commands}/CheckEm.cs | 2 +- Geekbot.net/{Modules => Commands}/Choose.cs | 2 +- Geekbot.net/{Modules => Commands}/Counters.cs | 4 +-- Geekbot.net/{Modules => Commands}/Dice.cs | 2 +- Geekbot.net/{Modules => Commands}/Dog.cs | 2 +- .../{Modules => Commands}/EightBall.cs | 2 +- Geekbot.net/{Modules => Commands}/Fortune.cs | 2 +- Geekbot.net/{Modules => Commands}/Google.cs | 2 +- .../{Modules => Commands}/GuildInfo.cs | 2 +- Geekbot.net/{Modules => Commands}/Help.cs | 2 +- Geekbot.net/{Modules => Commands}/Info.cs | 2 +- Geekbot.net/{Modules => Commands}/Panda.cs | 2 +- Geekbot.net/{Modules => Commands}/Ping.cs | 5 ++-- Geekbot.net/{Modules => Commands}/Quote.cs | 3 +- Geekbot.net/{Modules => Commands}/Roll.cs | 2 +- Geekbot.net/{Modules => Commands}/Say.cs | 2 +- Geekbot.net/{Modules => Commands}/Ship.cs | 2 +- Geekbot.net/{Modules => Commands}/UserInfo.cs | 2 +- Geekbot.net/{Modules => Commands}/Youtube.cs | 2 +- Geekbot.net/{Modules => Commands}/mal.cs | 2 +- Geekbot.net/Geekbot.net.csproj | 3 ++ Geekbot.net/Lib/LoggerFactory.cs | 2 +- Geekbot.net/Program.cs | 11 ++++++-- Geekbot.net/WebApi/Status.cs | 28 +++++++++++++++++++ readme.md | 15 ++++++++-- 27 files changed, 78 insertions(+), 33 deletions(-) rename Geekbot.net/{Modules => Commands}/AdminCmd.cs (97%) rename Geekbot.net/{Modules => Commands}/Cat.cs (94%) rename Geekbot.net/{Modules => Commands}/CheckEm.cs (98%) rename Geekbot.net/{Modules => Commands}/Choose.cs (92%) rename Geekbot.net/{Modules => Commands}/Counters.cs (99%) rename Geekbot.net/{Modules => Commands}/Dice.cs (99%) rename Geekbot.net/{Modules => Commands}/Dog.cs (94%) rename Geekbot.net/{Modules => Commands}/EightBall.cs (97%) rename Geekbot.net/{Modules => Commands}/Fortune.cs (90%) rename Geekbot.net/{Modules => Commands}/Google.cs (93%) rename Geekbot.net/{Modules => Commands}/GuildInfo.cs (95%) rename Geekbot.net/{Modules => Commands}/Help.cs (98%) rename Geekbot.net/{Modules => Commands}/Info.cs (95%) rename Geekbot.net/{Modules => Commands}/Panda.cs (90%) rename Geekbot.net/{Modules => Commands}/Ping.cs (77%) rename Geekbot.net/{Modules => Commands}/Quote.cs (98%) rename Geekbot.net/{Modules => Commands}/Roll.cs (97%) rename Geekbot.net/{Modules => Commands}/Say.cs (93%) rename Geekbot.net/{Modules => Commands}/Ship.cs (95%) rename Geekbot.net/{Modules => Commands}/UserInfo.cs (99%) rename Geekbot.net/{Modules => Commands}/Youtube.cs (95%) rename Geekbot.net/{Modules => Commands}/mal.cs (96%) create mode 100644 Geekbot.net/WebApi/Status.cs diff --git a/Geekbot.net/Modules/AdminCmd.cs b/Geekbot.net/Commands/AdminCmd.cs similarity index 97% rename from Geekbot.net/Modules/AdminCmd.cs rename to Geekbot.net/Commands/AdminCmd.cs index f4a91de..0d9292e 100644 --- a/Geekbot.net/Modules/AdminCmd.cs +++ b/Geekbot.net/Commands/AdminCmd.cs @@ -8,7 +8,7 @@ using Geekbot.net.Lib; using Serilog; using StackExchange.Redis; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { [Group("admin")] public class AdminCmd : ModuleBase @@ -85,7 +85,7 @@ namespace Geekbot.net.Modules return; } } - catch (Exception e) + catch (Exception) { await ReplyAsync( $"Sorry, only the botowner can do this"); diff --git a/Geekbot.net/Modules/Cat.cs b/Geekbot.net/Commands/Cat.cs similarity index 94% rename from Geekbot.net/Modules/Cat.cs rename to Geekbot.net/Commands/Cat.cs index bf6fa81..3e7973b 100644 --- a/Geekbot.net/Modules/Cat.cs +++ b/Geekbot.net/Commands/Cat.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using Discord.Commands; using Newtonsoft.Json; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Cat : ModuleBase { diff --git a/Geekbot.net/Modules/CheckEm.cs b/Geekbot.net/Commands/CheckEm.cs similarity index 98% rename from Geekbot.net/Modules/CheckEm.cs rename to Geekbot.net/Commands/CheckEm.cs index 8af8ae0..5aaef53 100644 --- a/Geekbot.net/Modules/CheckEm.cs +++ b/Geekbot.net/Commands/CheckEm.cs @@ -7,7 +7,7 @@ using Geekbot.net.Lib; using Geekbot.net.Lib.Media; using Serilog; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class CheckEm : ModuleBase { diff --git a/Geekbot.net/Modules/Choose.cs b/Geekbot.net/Commands/Choose.cs similarity index 92% rename from Geekbot.net/Modules/Choose.cs rename to Geekbot.net/Commands/Choose.cs index 68ea4af..338851d 100644 --- a/Geekbot.net/Modules/Choose.cs +++ b/Geekbot.net/Commands/Choose.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Discord.Commands; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Choose : ModuleBase { diff --git a/Geekbot.net/Modules/Counters.cs b/Geekbot.net/Commands/Counters.cs similarity index 99% rename from Geekbot.net/Modules/Counters.cs rename to Geekbot.net/Commands/Counters.cs index ee844ca..45ffa3d 100644 --- a/Geekbot.net/Modules/Counters.cs +++ b/Geekbot.net/Commands/Counters.cs @@ -3,10 +3,10 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; using Geekbot.net.Lib; -using StackExchange.Redis; using Serilog; +using StackExchange.Redis; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Counters : ModuleBase { diff --git a/Geekbot.net/Modules/Dice.cs b/Geekbot.net/Commands/Dice.cs similarity index 99% rename from Geekbot.net/Modules/Dice.cs rename to Geekbot.net/Commands/Dice.cs index 698e825..c40757c 100644 --- a/Geekbot.net/Modules/Dice.cs +++ b/Geekbot.net/Commands/Dice.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using Discord.Commands; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Dice : ModuleBase { diff --git a/Geekbot.net/Modules/Dog.cs b/Geekbot.net/Commands/Dog.cs similarity index 94% rename from Geekbot.net/Modules/Dog.cs rename to Geekbot.net/Commands/Dog.cs index 326e4ac..481500e 100644 --- a/Geekbot.net/Modules/Dog.cs +++ b/Geekbot.net/Commands/Dog.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using Discord.Commands; using Newtonsoft.Json; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Dog : ModuleBase { diff --git a/Geekbot.net/Modules/EightBall.cs b/Geekbot.net/Commands/EightBall.cs similarity index 97% rename from Geekbot.net/Modules/EightBall.cs rename to Geekbot.net/Commands/EightBall.cs index 3f34d0b..5ca4ae6 100644 --- a/Geekbot.net/Modules/EightBall.cs +++ b/Geekbot.net/Commands/EightBall.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Discord.Commands; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class EightBall : ModuleBase { diff --git a/Geekbot.net/Modules/Fortune.cs b/Geekbot.net/Commands/Fortune.cs similarity index 90% rename from Geekbot.net/Modules/Fortune.cs rename to Geekbot.net/Commands/Fortune.cs index cc52bcf..d97b437 100644 --- a/Geekbot.net/Modules/Fortune.cs +++ b/Geekbot.net/Commands/Fortune.cs @@ -2,7 +2,7 @@ using Discord.Commands; using Geekbot.net.Lib.Media; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Fortune : ModuleBase { diff --git a/Geekbot.net/Modules/Google.cs b/Geekbot.net/Commands/Google.cs similarity index 93% rename from Geekbot.net/Modules/Google.cs rename to Geekbot.net/Commands/Google.cs index e2205aa..05c8c55 100644 --- a/Geekbot.net/Modules/Google.cs +++ b/Geekbot.net/Commands/Google.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; using Discord.Commands; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Google : ModuleBase { diff --git a/Geekbot.net/Modules/GuildInfo.cs b/Geekbot.net/Commands/GuildInfo.cs similarity index 95% rename from Geekbot.net/Modules/GuildInfo.cs rename to Geekbot.net/Commands/GuildInfo.cs index 11a3d44..ff9c4a0 100644 --- a/Geekbot.net/Modules/GuildInfo.cs +++ b/Geekbot.net/Commands/GuildInfo.cs @@ -6,7 +6,7 @@ using Discord.Commands; using Geekbot.net.Lib; using StackExchange.Redis; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class GuildInfo : ModuleBase { diff --git a/Geekbot.net/Modules/Help.cs b/Geekbot.net/Commands/Help.cs similarity index 98% rename from Geekbot.net/Modules/Help.cs rename to Geekbot.net/Commands/Help.cs index 57feb87..d8942e4 100644 --- a/Geekbot.net/Modules/Help.cs +++ b/Geekbot.net/Commands/Help.cs @@ -3,7 +3,7 @@ using System.Text; using System.Threading.Tasks; using Discord.Commands; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Help : ModuleBase { diff --git a/Geekbot.net/Modules/Info.cs b/Geekbot.net/Commands/Info.cs similarity index 95% rename from Geekbot.net/Modules/Info.cs rename to Geekbot.net/Commands/Info.cs index bf02862..85a01c5 100644 --- a/Geekbot.net/Modules/Info.cs +++ b/Geekbot.net/Commands/Info.cs @@ -6,7 +6,7 @@ using Discord.Commands; using Geekbot.net.Lib; using StackExchange.Redis; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Info : ModuleBase { diff --git a/Geekbot.net/Modules/Panda.cs b/Geekbot.net/Commands/Panda.cs similarity index 90% rename from Geekbot.net/Modules/Panda.cs rename to Geekbot.net/Commands/Panda.cs index f5675c9..6d9be69 100644 --- a/Geekbot.net/Modules/Panda.cs +++ b/Geekbot.net/Commands/Panda.cs @@ -2,7 +2,7 @@ using Discord.Commands; using Geekbot.net.Lib.Media; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Panda : ModuleBase { diff --git a/Geekbot.net/Modules/Ping.cs b/Geekbot.net/Commands/Ping.cs similarity index 77% rename from Geekbot.net/Modules/Ping.cs rename to Geekbot.net/Commands/Ping.cs index a3ba98d..698c383 100644 --- a/Geekbot.net/Modules/Ping.cs +++ b/Geekbot.net/Commands/Ping.cs @@ -1,8 +1,7 @@ -using System.Linq; -using System.Threading.Tasks; +using System.Threading.Tasks; using Discord.Commands; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Ping : ModuleBase { diff --git a/Geekbot.net/Modules/Quote.cs b/Geekbot.net/Commands/Quote.cs similarity index 98% rename from Geekbot.net/Modules/Quote.cs rename to Geekbot.net/Commands/Quote.cs index 49e10ab..053a63a 100644 --- a/Geekbot.net/Modules/Quote.cs +++ b/Geekbot.net/Commands/Quote.cs @@ -5,12 +5,11 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; using Geekbot.net.Lib; -using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using Serilog; using StackExchange.Redis; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { [Group("quote")] public class Quote : ModuleBase diff --git a/Geekbot.net/Modules/Roll.cs b/Geekbot.net/Commands/Roll.cs similarity index 97% rename from Geekbot.net/Modules/Roll.cs rename to Geekbot.net/Commands/Roll.cs index 9d84a8d..66caa40 100644 --- a/Geekbot.net/Modules/Roll.cs +++ b/Geekbot.net/Commands/Roll.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Discord.Commands; using StackExchange.Redis; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Roll : ModuleBase { diff --git a/Geekbot.net/Modules/Say.cs b/Geekbot.net/Commands/Say.cs similarity index 93% rename from Geekbot.net/Modules/Say.cs rename to Geekbot.net/Commands/Say.cs index 7d4b7af..52b4477 100644 --- a/Geekbot.net/Modules/Say.cs +++ b/Geekbot.net/Commands/Say.cs @@ -2,7 +2,7 @@ using Discord; using Discord.Commands; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Say : ModuleBase { diff --git a/Geekbot.net/Modules/Ship.cs b/Geekbot.net/Commands/Ship.cs similarity index 95% rename from Geekbot.net/Modules/Ship.cs rename to Geekbot.net/Commands/Ship.cs index ea426e4..da2bd2e 100644 --- a/Geekbot.net/Modules/Ship.cs +++ b/Geekbot.net/Commands/Ship.cs @@ -4,7 +4,7 @@ using Discord; using Discord.Commands; using StackExchange.Redis; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Ship : ModuleBase { diff --git a/Geekbot.net/Modules/UserInfo.cs b/Geekbot.net/Commands/UserInfo.cs similarity index 99% rename from Geekbot.net/Modules/UserInfo.cs rename to Geekbot.net/Commands/UserInfo.cs index cb7725d..0730117 100644 --- a/Geekbot.net/Modules/UserInfo.cs +++ b/Geekbot.net/Commands/UserInfo.cs @@ -9,7 +9,7 @@ using Geekbot.net.Lib; using Serilog; using StackExchange.Redis; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class UserInfo : ModuleBase { diff --git a/Geekbot.net/Modules/Youtube.cs b/Geekbot.net/Commands/Youtube.cs similarity index 95% rename from Geekbot.net/Modules/Youtube.cs rename to Geekbot.net/Commands/Youtube.cs index afb7027..c496cde 100644 --- a/Geekbot.net/Modules/Youtube.cs +++ b/Geekbot.net/Commands/Youtube.cs @@ -5,7 +5,7 @@ using Google.Apis.Services; using Google.Apis.YouTube.v3; using StackExchange.Redis; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class Youtube : ModuleBase { diff --git a/Geekbot.net/Modules/mal.cs b/Geekbot.net/Commands/mal.cs similarity index 96% rename from Geekbot.net/Modules/mal.cs rename to Geekbot.net/Commands/mal.cs index 662e7c8..840c7c7 100644 --- a/Geekbot.net/Modules/mal.cs +++ b/Geekbot.net/Commands/mal.cs @@ -4,7 +4,7 @@ using Discord; using Discord.Commands; using Geekbot.net.Lib; -namespace Geekbot.net.Modules +namespace Geekbot.net.Commands { public class mal : ModuleBase { diff --git a/Geekbot.net/Geekbot.net.csproj b/Geekbot.net/Geekbot.net.csproj index 5764975..056eb93 100755 --- a/Geekbot.net/Geekbot.net.csproj +++ b/Geekbot.net/Geekbot.net.csproj @@ -18,6 +18,8 @@ + + @@ -34,5 +36,6 @@ 4.3.0 + \ No newline at end of file diff --git a/Geekbot.net/Lib/LoggerFactory.cs b/Geekbot.net/Lib/LoggerFactory.cs index 055c2f2..b52ad5a 100644 --- a/Geekbot.net/Lib/LoggerFactory.cs +++ b/Geekbot.net/Lib/LoggerFactory.cs @@ -10,7 +10,7 @@ namespace Geekbot.net.Lib var loggerCreation = new LoggerConfiguration() .WriteTo.LiterateConsole() .WriteTo.RollingFile("Logs/geekbot-{Date}.txt", shared: true); - if (args.Length != 0 && args.Contains("--verbose")) + if (args.Contains("--verbose")) { loggerCreation.MinimumLevel.Verbose(); } diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index 4cbc953..be63aba 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -11,7 +11,9 @@ using Discord.Commands; using Discord.WebSocket; using Geekbot.net.Lib; using Geekbot.net.Lib.Media; +using Geekbot.net.WebApi; using Microsoft.Extensions.DependencyInjection; +using Nancy.Hosting.Self; using Serilog; using StackExchange.Redis; @@ -72,7 +74,7 @@ namespace Geekbot.net Environment.Exit(102); } - if (args.Length != 0 && args.Contains("--migrate")) + if (args.Contains("--migrate")) { Console.WriteLine("\nYou are about to migrate the database, this will overwrite an already migrated database?"); Console.Write("Are you sure [y:N]: "); @@ -156,12 +158,17 @@ namespace Geekbot.net client.UserUpdated += handlers.UserUpdated; client.UserLeft += handlers.UserLeft; - if (firstStart || (args.Length != 0 && args.Contains("--reset"))) + if (firstStart || args.Contains("--reset")) { logger.Information("[Geekbot] Finishing setup"); await FinishSetup(); logger.Information("[Geekbot] Setup finished"); } + if (!args.Contains("--disable-api")) + { + logger.Information("[API] Starting Webserver"); + new NancyHost(new Uri("http://localhost:4567")).Start(); + } logger.Information("[Geekbot] Done and ready for use\n"); } diff --git a/Geekbot.net/WebApi/Status.cs b/Geekbot.net/WebApi/Status.cs new file mode 100644 index 0000000..0597e83 --- /dev/null +++ b/Geekbot.net/WebApi/Status.cs @@ -0,0 +1,28 @@ +using Nancy; + +namespace Geekbot.net.WebApi +{ + public class Status : NancyModule + { + public Status() + { + Get("/", args => + { + var responseBody = new ApiStatusDto() + { + GeekbotVersion = "3.4", + ApiVersion = "0.1", + Status = "Online" + }; + return Response.AsJson(responseBody); + }); + } + } + + public class ApiStatusDto + { + public string GeekbotVersion { get; set; } + public string ApiVersion { get; set; } + public string Status { get; set; } + } +} \ No newline at end of file diff --git a/readme.md b/readme.md index 4257ac4..90d91fa 100644 --- a/readme.md +++ b/readme.md @@ -4,13 +4,13 @@ A General Purpose Discord Bot written in DotNet Core. You can invite Geekbot to your server with [this link](https://discordapp.com/oauth2/authorize?client_id=171249478546882561&scope=bot&permissions=1416834054) -### Technologies +## Technologies * DotNet Core 2 * Redis * Discord.net -### Running +## Running Make sure redis is running @@ -21,6 +21,15 @@ Run these commands On your first run geekbot will ask for your bot token, everything else is taken care of. -### Contributing +### Launch Parameters + +| Parameter | Description | +| --- | --- | +| `--verbose` | Show more log information | +| `--disable-api` | Disables the webapi on startup | +| `--reset` | Resets certain parts of the bot | +| `--migrate` | Migrates the database from V3.1 to the new format from V3.2
(make sure to backup before running this) | + +## Contributing Everyone is free to open an issue or create a pull request