Adding Initial API support, updating readme

This commit is contained in:
Runebaas 2017-10-02 21:57:48 +02:00
parent 6732506dae
commit 92015d8880
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
27 changed files with 78 additions and 33 deletions

View file

@ -8,7 +8,7 @@ using Geekbot.net.Lib;
using Serilog; using Serilog;
using StackExchange.Redis; using StackExchange.Redis;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
[Group("admin")] [Group("admin")]
public class AdminCmd : ModuleBase public class AdminCmd : ModuleBase
@ -85,7 +85,7 @@ namespace Geekbot.net.Modules
return; return;
} }
} }
catch (Exception e) catch (Exception)
{ {
await ReplyAsync( await ReplyAsync(
$"Sorry, only the botowner can do this"); $"Sorry, only the botowner can do this");

View file

@ -4,7 +4,7 @@ using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Cat : ModuleBase public class Cat : ModuleBase
{ {

View file

@ -7,7 +7,7 @@ using Geekbot.net.Lib;
using Geekbot.net.Lib.Media; using Geekbot.net.Lib.Media;
using Serilog; using Serilog;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class CheckEm : ModuleBase public class CheckEm : ModuleBase
{ {

View file

@ -2,7 +2,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Choose : ModuleBase public class Choose : ModuleBase
{ {

View file

@ -3,10 +3,10 @@ using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib; using Geekbot.net.Lib;
using StackExchange.Redis;
using Serilog; using Serilog;
using StackExchange.Redis;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Counters : ModuleBase public class Counters : ModuleBase
{ {

View file

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Dice : ModuleBase public class Dice : ModuleBase
{ {

View file

@ -4,7 +4,7 @@ using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Dog : ModuleBase public class Dog : ModuleBase
{ {

View file

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class EightBall : ModuleBase public class EightBall : ModuleBase
{ {

View file

@ -2,7 +2,7 @@
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib.Media; using Geekbot.net.Lib.Media;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Fortune : ModuleBase public class Fortune : ModuleBase
{ {

View file

@ -1,7 +1,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Google : ModuleBase public class Google : ModuleBase
{ {

View file

@ -6,7 +6,7 @@ using Discord.Commands;
using Geekbot.net.Lib; using Geekbot.net.Lib;
using StackExchange.Redis; using StackExchange.Redis;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class GuildInfo : ModuleBase public class GuildInfo : ModuleBase
{ {

View file

@ -3,7 +3,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Help : ModuleBase public class Help : ModuleBase
{ {

View file

@ -6,7 +6,7 @@ using Discord.Commands;
using Geekbot.net.Lib; using Geekbot.net.Lib;
using StackExchange.Redis; using StackExchange.Redis;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Info : ModuleBase public class Info : ModuleBase
{ {

View file

@ -2,7 +2,7 @@
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib.Media; using Geekbot.net.Lib.Media;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Panda : ModuleBase public class Panda : ModuleBase
{ {

View file

@ -1,8 +1,7 @@
using System.Linq; using System.Threading.Tasks;
using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Ping : ModuleBase public class Ping : ModuleBase
{ {

View file

@ -5,12 +5,11 @@ using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib; using Geekbot.net.Lib;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json; using Newtonsoft.Json;
using Serilog; using Serilog;
using StackExchange.Redis; using StackExchange.Redis;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
[Group("quote")] [Group("quote")]
public class Quote : ModuleBase public class Quote : ModuleBase

View file

@ -3,7 +3,7 @@ using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using StackExchange.Redis; using StackExchange.Redis;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Roll : ModuleBase public class Roll : ModuleBase
{ {

View file

@ -2,7 +2,7 @@
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Say : ModuleBase public class Say : ModuleBase
{ {

View file

@ -4,7 +4,7 @@ using Discord;
using Discord.Commands; using Discord.Commands;
using StackExchange.Redis; using StackExchange.Redis;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Ship : ModuleBase public class Ship : ModuleBase
{ {

View file

@ -9,7 +9,7 @@ using Geekbot.net.Lib;
using Serilog; using Serilog;
using StackExchange.Redis; using StackExchange.Redis;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class UserInfo : ModuleBase public class UserInfo : ModuleBase
{ {

View file

@ -5,7 +5,7 @@ using Google.Apis.Services;
using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3;
using StackExchange.Redis; using StackExchange.Redis;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class Youtube : ModuleBase public class Youtube : ModuleBase
{ {

View file

@ -4,7 +4,7 @@ using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib; using Geekbot.net.Lib;
namespace Geekbot.net.Modules namespace Geekbot.net.Commands
{ {
public class mal : ModuleBase public class mal : ModuleBase
{ {

View file

@ -18,6 +18,8 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" /> <PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
<PackageReference Include="MyAnimeListSharp" Version="1.3.4" /> <PackageReference Include="MyAnimeListSharp" Version="1.3.4" />
<PackageReference Include="Nancy" Version="2.0.0-clinteastwood" />
<PackageReference Include="Nancy.Hosting.Self" Version="2.0.0-clinteastwood" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="Serilog" Version="2.6.0-dev-00894" /> <PackageReference Include="Serilog" Version="2.6.0-dev-00894" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1-dev-00757" /> <PackageReference Include="Serilog.Sinks.Console" Version="3.1.1-dev-00757" />
@ -34,5 +36,6 @@
<PackageReference Include="System.Runtime.Serialization.Primitives"> <PackageReference Include="System.Runtime.Serialization.Primitives">
<Version>4.3.0</Version> <Version>4.3.0</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Utf8Json" Version="1.1.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -10,7 +10,7 @@ namespace Geekbot.net.Lib
var loggerCreation = new LoggerConfiguration() var loggerCreation = new LoggerConfiguration()
.WriteTo.LiterateConsole() .WriteTo.LiterateConsole()
.WriteTo.RollingFile("Logs/geekbot-{Date}.txt", shared: true); .WriteTo.RollingFile("Logs/geekbot-{Date}.txt", shared: true);
if (args.Length != 0 && args.Contains("--verbose")) if (args.Contains("--verbose"))
{ {
loggerCreation.MinimumLevel.Verbose(); loggerCreation.MinimumLevel.Verbose();
} }

View file

@ -11,7 +11,9 @@ using Discord.Commands;
using Discord.WebSocket; using Discord.WebSocket;
using Geekbot.net.Lib; using Geekbot.net.Lib;
using Geekbot.net.Lib.Media; using Geekbot.net.Lib.Media;
using Geekbot.net.WebApi;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Nancy.Hosting.Self;
using Serilog; using Serilog;
using StackExchange.Redis; using StackExchange.Redis;
@ -72,7 +74,7 @@ namespace Geekbot.net
Environment.Exit(102); 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.WriteLine("\nYou are about to migrate the database, this will overwrite an already migrated database?");
Console.Write("Are you sure [y:N]: "); Console.Write("Are you sure [y:N]: ");
@ -156,12 +158,17 @@ namespace Geekbot.net
client.UserUpdated += handlers.UserUpdated; client.UserUpdated += handlers.UserUpdated;
client.UserLeft += handlers.UserLeft; client.UserLeft += handlers.UserLeft;
if (firstStart || (args.Length != 0 && args.Contains("--reset"))) if (firstStart || args.Contains("--reset"))
{ {
logger.Information("[Geekbot] Finishing setup"); logger.Information("[Geekbot] Finishing setup");
await FinishSetup(); await FinishSetup();
logger.Information("[Geekbot] Setup finished"); 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"); logger.Information("[Geekbot] Done and ready for use\n");
} }

View file

@ -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; }
}
}

View file

@ -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) 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 * DotNet Core 2
* Redis * Redis
* Discord.net * Discord.net
### Running ## Running
Make sure redis is 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. 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<br> (make sure to backup before running this) |
## Contributing
Everyone is free to open an issue or create a pull request Everyone is free to open an issue or create a pull request