diff --git a/Geekbot.net/Commands/Admin/Admin.cs b/Geekbot.net/Commands/Admin/Admin.cs index fc0c231..0925e54 100644 --- a/Geekbot.net/Commands/Admin/Admin.cs +++ b/Geekbot.net/Commands/Admin/Admin.cs @@ -10,7 +10,6 @@ using Geekbot.net.Database.Models; using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.Localization; -using StackExchange.Redis; namespace Geekbot.net.Commands.Admin { diff --git a/Geekbot.net/Commands/Admin/Say.cs b/Geekbot.net/Commands/Admin/Say.cs index f8708cd..f3db09b 100644 --- a/Geekbot.net/Commands/Admin/Say.cs +++ b/Geekbot.net/Commands/Admin/Say.cs @@ -2,7 +2,6 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; namespace Geekbot.net.Commands.Admin diff --git a/Geekbot.net/Commands/Audio/Voice.cs b/Geekbot.net/Commands/Audio/Voice.cs index 410d8e2..169f298 100644 --- a/Geekbot.net/Commands/Audio/Voice.cs +++ b/Geekbot.net/Commands/Audio/Voice.cs @@ -65,7 +65,7 @@ namespace Geekbot.net.Commands.Audio } // [Command("ytplay")] - public async Task ytplay(string url) + public async Task Ytplay(string url) { try { diff --git a/Geekbot.net/Commands/Games/Pokedex.cs b/Geekbot.net/Commands/Games/Pokedex.cs index d4cbc0e..25f4c88 100644 --- a/Geekbot.net/Commands/Games/Pokedex.cs +++ b/Geekbot.net/Commands/Games/Pokedex.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Threading.Tasks; using Discord; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; using PokeAPI; diff --git a/Geekbot.net/Commands/Games/Roll.cs b/Geekbot.net/Commands/Games/Roll.cs index 59a3c27..1d2ab4f 100644 --- a/Geekbot.net/Commands/Games/Roll.cs +++ b/Geekbot.net/Commands/Games/Roll.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.Localization; using StackExchange.Redis; diff --git a/Geekbot.net/Commands/Integrations/MagicTheGathering.cs b/Geekbot.net/Commands/Integrations/MagicTheGathering.cs index 842c9de..968c558 100644 --- a/Geekbot.net/Commands/Integrations/MagicTheGathering.cs +++ b/Geekbot.net/Commands/Integrations/MagicTheGathering.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Threading.Tasks; using Discord; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.Converters; using Geekbot.net.Lib.ErrorHandling; using MtgApiManager.Lib.Service; diff --git a/Geekbot.net/Commands/Integrations/Mal.cs b/Geekbot.net/Commands/Integrations/Mal.cs index 36c6457..b617b44 100644 --- a/Geekbot.net/Commands/Integrations/Mal.cs +++ b/Geekbot.net/Commands/Integrations/Mal.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using System.Web; using Discord; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.Clients; using Geekbot.net.Lib.ErrorHandling; diff --git a/Geekbot.net/Commands/Integrations/UbranDictionary/UrbanDictionary.cs b/Geekbot.net/Commands/Integrations/UbranDictionary/UrbanDictionary.cs index 3ad37f3..36d70b1 100644 --- a/Geekbot.net/Commands/Integrations/UbranDictionary/UrbanDictionary.cs +++ b/Geekbot.net/Commands/Integrations/UbranDictionary/UrbanDictionary.cs @@ -4,7 +4,6 @@ using System.Net.Http; using System.Threading.Tasks; using Discord; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; using Newtonsoft.Json; diff --git a/Geekbot.net/Commands/Randomness/Cat/Cat.cs b/Geekbot.net/Commands/Randomness/Cat/Cat.cs index a79eb37..f46ed25 100644 --- a/Geekbot.net/Commands/Randomness/Cat/Cat.cs +++ b/Geekbot.net/Commands/Randomness/Cat/Cat.cs @@ -3,7 +3,6 @@ using System.Net.Http; using System.Threading.Tasks; using Discord; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; using Newtonsoft.Json; diff --git a/Geekbot.net/Commands/Randomness/CheckEm.cs b/Geekbot.net/Commands/Randomness/CheckEm.cs index 325d7cc..94a895a 100644 --- a/Geekbot.net/Commands/Randomness/CheckEm.cs +++ b/Geekbot.net/Commands/Randomness/CheckEm.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.Media; diff --git a/Geekbot.net/Commands/Randomness/Chuck/ChuckNorrisJokes.cs b/Geekbot.net/Commands/Randomness/Chuck/ChuckNorrisJokes.cs index 8e8a369..b9d906e 100644 --- a/Geekbot.net/Commands/Randomness/Chuck/ChuckNorrisJokes.cs +++ b/Geekbot.net/Commands/Randomness/Chuck/ChuckNorrisJokes.cs @@ -3,7 +3,6 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; using Newtonsoft.Json; diff --git a/Geekbot.net/Commands/Randomness/Dad/DadJokes.cs b/Geekbot.net/Commands/Randomness/Dad/DadJokes.cs index a14a098..3945609 100644 --- a/Geekbot.net/Commands/Randomness/Dad/DadJokes.cs +++ b/Geekbot.net/Commands/Randomness/Dad/DadJokes.cs @@ -3,7 +3,6 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; using Newtonsoft.Json; diff --git a/Geekbot.net/Commands/Randomness/Dog/Dog.cs b/Geekbot.net/Commands/Randomness/Dog/Dog.cs index 83d7a2e..6606ef5 100644 --- a/Geekbot.net/Commands/Randomness/Dog/Dog.cs +++ b/Geekbot.net/Commands/Randomness/Dog/Dog.cs @@ -3,7 +3,6 @@ using System.Net.Http; using System.Threading.Tasks; using Discord; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; using Newtonsoft.Json; diff --git a/Geekbot.net/Commands/Randomness/EightBall.cs b/Geekbot.net/Commands/Randomness/EightBall.cs index cf59431..b6f37d3 100644 --- a/Geekbot.net/Commands/Randomness/EightBall.cs +++ b/Geekbot.net/Commands/Randomness/EightBall.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; namespace Geekbot.net.Commands.Randomness diff --git a/Geekbot.net/Commands/Randomness/Fortune.cs b/Geekbot.net/Commands/Randomness/Fortune.cs index 498085a..d4f6b5f 100644 --- a/Geekbot.net/Commands/Randomness/Fortune.cs +++ b/Geekbot.net/Commands/Randomness/Fortune.cs @@ -1,6 +1,5 @@ using System.Threading.Tasks; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.Media; namespace Geekbot.net.Commands.Randomness diff --git a/Geekbot.net/Commands/Randomness/Gdq.cs b/Geekbot.net/Commands/Randomness/Gdq.cs index 8d0472c..c723c6f 100644 --- a/Geekbot.net/Commands/Randomness/Gdq.cs +++ b/Geekbot.net/Commands/Randomness/Gdq.cs @@ -2,7 +2,6 @@ using System.Net; using System.Threading.Tasks; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; namespace Geekbot.net.Commands.Randomness diff --git a/Geekbot.net/Commands/Randomness/RandomAnimals.cs b/Geekbot.net/Commands/Randomness/RandomAnimals.cs index 608b52d..90138af 100644 --- a/Geekbot.net/Commands/Randomness/RandomAnimals.cs +++ b/Geekbot.net/Commands/Randomness/RandomAnimals.cs @@ -1,7 +1,6 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.Media; namespace Geekbot.net.Commands.Randomness diff --git a/Geekbot.net/Commands/User/GuildInfo.cs b/Geekbot.net/Commands/User/GuildInfo.cs index c475d99..6f602b1 100644 --- a/Geekbot.net/Commands/User/GuildInfo.cs +++ b/Geekbot.net/Commands/User/GuildInfo.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; using Geekbot.net.Database; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.Levels; @@ -42,7 +41,7 @@ namespace Geekbot.net.Commands.User var messages = _database.Messages .Where(e => e.GuildId == Context.Guild.Id.AsLong()) .Sum(e => e.MessageCount); - var level = _levelCalc.GetLevel((int) messages); + var level = _levelCalc.GetLevel(messages); eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)"); eb.AddInlineField("Level", level) diff --git a/Geekbot.net/Commands/User/Karma.cs b/Geekbot.net/Commands/User/Karma.cs index bf2511f..8a9189d 100644 --- a/Geekbot.net/Commands/User/Karma.cs +++ b/Geekbot.net/Commands/User/Karma.cs @@ -5,7 +5,6 @@ using Discord; using Discord.Commands; using Geekbot.net.Database; using Geekbot.net.Database.Models; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.Localization; diff --git a/Geekbot.net/Commands/Utils/AvatarGetter.cs b/Geekbot.net/Commands/Utils/AvatarGetter.cs index cf34ca3..3f74770 100644 --- a/Geekbot.net/Commands/Utils/AvatarGetter.cs +++ b/Geekbot.net/Commands/Utils/AvatarGetter.cs @@ -2,7 +2,6 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; namespace Geekbot.net.Commands.Utils diff --git a/Geekbot.net/Commands/Utils/Changelog/Changelog.cs b/Geekbot.net/Commands/Utils/Changelog/Changelog.cs index c218c66..5d47c08 100644 --- a/Geekbot.net/Commands/Utils/Changelog/Changelog.cs +++ b/Geekbot.net/Commands/Utils/Changelog/Changelog.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; using Discord.WebSocket; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; using Newtonsoft.Json; diff --git a/Geekbot.net/Commands/Utils/Choose.cs b/Geekbot.net/Commands/Utils/Choose.cs index 2b9ff19..411802a 100644 --- a/Geekbot.net/Commands/Utils/Choose.cs +++ b/Geekbot.net/Commands/Utils/Choose.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.Localization; diff --git a/Geekbot.net/Commands/Utils/Dice/Dice.cs b/Geekbot.net/Commands/Utils/Dice/Dice.cs index c8e31f5..7733476 100644 --- a/Geekbot.net/Commands/Utils/Dice/Dice.cs +++ b/Geekbot.net/Commands/Utils/Dice/Dice.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Discord.Commands; -using Geekbot.net.Lib; namespace Geekbot.net.Commands.Utils.Dice { diff --git a/Geekbot.net/Commands/Utils/Emojify.cs b/Geekbot.net/Commands/Utils/Emojify.cs index 07adadb..f0e172e 100644 --- a/Geekbot.net/Commands/Utils/Emojify.cs +++ b/Geekbot.net/Commands/Utils/Emojify.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.Converters; using Geekbot.net.Lib.ErrorHandling; diff --git a/Geekbot.net/Commands/Utils/Help.cs b/Geekbot.net/Commands/Utils/Help.cs index 4372692..ace5087 100644 --- a/Geekbot.net/Commands/Utils/Help.cs +++ b/Geekbot.net/Commands/Utils/Help.cs @@ -3,7 +3,6 @@ using System.Text; using System.Threading.Tasks; using Discord; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; namespace Geekbot.net.Commands.Utils diff --git a/Geekbot.net/Commands/Utils/Ping.cs b/Geekbot.net/Commands/Utils/Ping.cs index 653a46f..18cf9cb 100644 --- a/Geekbot.net/Commands/Utils/Ping.cs +++ b/Geekbot.net/Commands/Utils/Ping.cs @@ -1,6 +1,5 @@ using System.Threading.Tasks; using Discord.Commands; -using Geekbot.net.Lib; namespace Geekbot.net.Commands.Utils { diff --git a/Geekbot.net/Commands/Utils/Poll/Poll.cs b/Geekbot.net/Commands/Utils/Poll/Poll.cs index e94e6d4..ba4e49f 100644 --- a/Geekbot.net/Commands/Utils/Poll/Poll.cs +++ b/Geekbot.net/Commands/Utils/Poll/Poll.cs @@ -5,7 +5,6 @@ using System.Text; using System.Threading.Tasks; using Discord; using Discord.Commands; -using Geekbot.net.Lib; using Geekbot.net.Lib.Converters; using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.UserRepository; @@ -167,7 +166,10 @@ namespace Geekbot.net.Commands.Utils.Poll }; results.Add(result); } - catch {} + catch + { + // ignored + } results.Sort((x, y) => y.VoteCount.CompareTo(x.VoteCount)); return results; diff --git a/Geekbot.net/Commands/Utils/Quote/Quote.cs b/Geekbot.net/Commands/Utils/Quote/Quote.cs index dab31a0..949350b 100644 --- a/Geekbot.net/Commands/Utils/Quote/Quote.cs +++ b/Geekbot.net/Commands/Utils/Quote/Quote.cs @@ -5,11 +5,9 @@ using Discord; using Discord.Commands; using Geekbot.net.Database; using Geekbot.net.Database.Models; -using Geekbot.net.Lib; using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.Polyfills; -using StackExchange.Redis; namespace Geekbot.net.Commands.Utils.Quote { diff --git a/Geekbot.net/Database/InMemoryDatabase.cs b/Geekbot.net/Database/InMemoryDatabase.cs index 178c0e3..2b2cfd0 100644 --- a/Geekbot.net/Database/InMemoryDatabase.cs +++ b/Geekbot.net/Database/InMemoryDatabase.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Logging; namespace Geekbot.net.Database { @@ -13,6 +12,6 @@ namespace Geekbot.net.Database } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - => optionsBuilder.UseInMemoryDatabase(databaseName: _name); + => optionsBuilder.UseInMemoryDatabase(_name); } } \ No newline at end of file diff --git a/Geekbot.net/Database/Models/UserModel.cs b/Geekbot.net/Database/Models/UserModel.cs index 0083ada..f14ed61 100644 --- a/Geekbot.net/Database/Models/UserModel.cs +++ b/Geekbot.net/Database/Models/UserModel.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace Geekbot.net.Database.Models diff --git a/Geekbot.net/Database/RedisMigration.cs b/Geekbot.net/Database/RedisMigration.cs index c7dd881..005aa69 100644 --- a/Geekbot.net/Database/RedisMigration.cs +++ b/Geekbot.net/Database/RedisMigration.cs @@ -8,7 +8,6 @@ using Geekbot.net.Commands.Utils.Quote; using Geekbot.net.Database.Models; using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.Logger; -using MtgApiManager.Lib.Model; using Newtonsoft.Json; using StackExchange.Redis; diff --git a/Geekbot.net/Geekbot.net.csproj b/Geekbot.net/Geekbot.net.csproj index 83a37d9..124dd6d 100755 --- a/Geekbot.net/Geekbot.net.csproj +++ b/Geekbot.net/Geekbot.net.csproj @@ -24,7 +24,11 @@ - + + + + + diff --git a/Geekbot.net/Handlers.cs b/Geekbot.net/Handlers.cs index b901c1f..f9fbc62 100644 --- a/Geekbot.net/Handlers.cs +++ b/Geekbot.net/Handlers.cs @@ -25,7 +25,9 @@ namespace Geekbot.net private readonly IUserRepository _userRepository; private readonly IReactionListener _reactionListener; - public Handlers(DatabaseContext database, IDiscordClient client, IGeekbotLogger logger, IDatabase redis, IServiceProvider servicesProvider, CommandService commands, IUserRepository userRepository, IReactionListener reactionListener) + public Handlers(DatabaseContext database, IDiscordClient client, IGeekbotLogger logger, IDatabase redis, + IServiceProvider servicesProvider, CommandService commands, IUserRepository userRepository, + IReactionListener reactionListener) { _database = database; _client = client; diff --git a/Geekbot.net/Lib/Clients/MalClient.cs b/Geekbot.net/Lib/Clients/MalClient.cs index 95d7dbd..a014cf1 100644 --- a/Geekbot.net/Lib/Clients/MalClient.cs +++ b/Geekbot.net/Lib/Clients/MalClient.cs @@ -1,45 +1,38 @@ using System.Threading.Tasks; +using Geekbot.net.Lib.GlobalSettings; using Geekbot.net.Lib.Logger; using MyAnimeListSharp.Auth; using MyAnimeListSharp.Core; using MyAnimeListSharp.Facade.Async; -using StackExchange.Redis; namespace Geekbot.net.Lib.Clients { public class MalClient : IMalClient { - private readonly IDatabase _redis; + private readonly IGlobalSettings _globalSettings; private readonly IGeekbotLogger _logger; private ICredentialContext _credentials; private AnimeSearchMethodsAsync _animeSearch; private MangaSearchMethodsAsync _mangaSearch; - public MalClient(IDatabase redis, IGeekbotLogger logger) + public MalClient(IGlobalSettings globalSettings, IGeekbotLogger logger) { - _redis = redis; + _globalSettings = globalSettings; _logger = logger; ReloadClient(); } public bool ReloadClient() { - var malCredentials = _redis.HashGetAll("malCredentials"); - if (malCredentials.Length != 0) + var malCredentials = _globalSettings.GetKey("MalCredentials"); + if (!string.IsNullOrEmpty(malCredentials)) { - _credentials = new CredentialContext(); - foreach (var c in malCredentials) + var credSplit = malCredentials.Split('|'); + _credentials = new CredentialContext() { - switch (c.Name) - { - case "Username": - _credentials.UserName = c.Value; - break; - case "Password": - _credentials.Password = c.Value; - break; - } - } + UserName = credSplit[0], + Password = credSplit[1] + }; _animeSearch = new AnimeSearchMethodsAsync(_credentials); _mangaSearch = new MangaSearchMethodsAsync(_credentials); _logger.Debug(LogSource.Geekbot, "Logged in to MAL"); diff --git a/Geekbot.net/Lib/Logger/DiscordLogger.cs b/Geekbot.net/Lib/Logger/DiscordLogger.cs index 2adcd73..688e26b 100644 --- a/Geekbot.net/Lib/Logger/DiscordLogger.cs +++ b/Geekbot.net/Lib/Logger/DiscordLogger.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using Discord; -using Geekbot.net.Commands.Randomness.Cat; namespace Geekbot.net.Lib.Logger { diff --git a/Geekbot.net/Lib/UserRepository/UserRepository.cs b/Geekbot.net/Lib/UserRepository/UserRepository.cs index 0125ee5..263a2f3 100644 --- a/Geekbot.net/Lib/UserRepository/UserRepository.cs +++ b/Geekbot.net/Lib/UserRepository/UserRepository.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Discord.WebSocket; diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index c9b53b3..f94a785 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -53,6 +53,7 @@ namespace Geekbot.net logo.AppendLine(@"| |_| | |___| |___| . \| |_) | |_| || |"); logo.AppendLine(@" \____|_____|_____|_|\_\____/ \___/ |_|"); logo.AppendLine("========================================="); + logo.AppendLine($"Version {Constants.BotVersion()}"); Console.WriteLine(logo.ToString()); var sumologicActive = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GEEKBOT_SUMO")); var logger = new GeekbotLogger(runParameters, sumologicActive); @@ -112,7 +113,7 @@ namespace Geekbot.net _userRepository = new UserRepository(_database, logger); var fortunes = new FortunesProvider(logger); var mediaProvider = new MediaProvider(logger); - var malClient = new MalClient(_redis, logger); + var malClient = new MalClient(_globalSettings, logger); var levelCalc = new LevelCalc(); var emojiConverter = new EmojiConverter(); var mtgManaConverter = new MtgManaConverter(); @@ -174,13 +175,12 @@ namespace Geekbot.net _client.UserLeft += handlers.UserLeft; _client.ReactionAdded += handlers.ReactionAdded; _client.ReactionRemoved += handlers.ReactionRemoved; - - if (!_runParameters.DisableApi) - { - StartWebApi(); - } + + var webserver = _runParameters.DisableApi ? Task.Delay(10) : StartWebApi(); _logger.Information(LogSource.Geekbot, "Done and ready for use"); + + await webserver; } } catch (Exception e) @@ -197,12 +197,11 @@ namespace Geekbot.net return true; } - private void StartWebApi() + private Task StartWebApi() { _logger.Information(LogSource.Api, "Starting Webserver"); - var webApiUrl = new Uri($"http://{_runParameters.ApiHost}:{_runParameters.ApiPort}"); - WebApi.WebApiStartup.StartWebApi(_logger, _runParameters, _commands); - _logger.Information(LogSource.Api, $"Webserver now running on {webApiUrl}"); + WebApi.WebApiStartup.StartWebApi(_logger, _runParameters, _commands, _database); + return Task.CompletedTask; } } } \ No newline at end of file diff --git a/Geekbot.net/WebApi/Controllers/Commands/HelpController.cs b/Geekbot.net/WebApi/Controllers/Commands/CommandController.cs similarity index 83% rename from Geekbot.net/WebApi/Controllers/Commands/HelpController.cs rename to Geekbot.net/WebApi/Controllers/Commands/CommandController.cs index 9105706..04caaae 100644 --- a/Geekbot.net/WebApi/Controllers/Commands/HelpController.cs +++ b/Geekbot.net/WebApi/Controllers/Commands/CommandController.cs @@ -6,11 +6,11 @@ using Microsoft.AspNetCore.Mvc; namespace Geekbot.net.WebApi.Controllers.Commands { [EnableCors("AllowSpecificOrigin")] - public class HelpController : Controller + public class CommandController : Controller { private readonly CommandService _commands; - public HelpController(CommandService commands) + public CommandController(CommandService commands) { _commands = commands; } @@ -22,7 +22,7 @@ namespace Geekbot.net.WebApi.Controllers.Commands let cmdParamsObj = cmd.Parameters.Select(cmdParam => new CommandParamDto { Summary = cmdParam.Summary, - Default = cmdParam.DefaultValue?.ToString() ?? null, + Default = cmdParam.DefaultValue?.ToString(), Type = cmdParam.Type?.ToString() }) .ToList() @@ -31,7 +31,7 @@ namespace Geekbot.net.WebApi.Controllers.Commands { Name = cmd.Name, Summary = cmd.Summary, - IsAdminCommand = (param.Contains("admin")), + IsAdminCommand = param.Contains("admin") || param.Contains("owner"), Aliases = cmd.Aliases.ToArray(), Params = cmdParamsObj }).ToList(); diff --git a/Geekbot.net/WebApi/Controllers/Status/StatusController.cs b/Geekbot.net/WebApi/Controllers/Status/StatusController.cs index e9af6bb..c437e64 100644 --- a/Geekbot.net/WebApi/Controllers/Status/StatusController.cs +++ b/Geekbot.net/WebApi/Controllers/Status/StatusController.cs @@ -1,4 +1,5 @@ -using Geekbot.net.Lib; +using System.Globalization; +using Geekbot.net.Lib; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; @@ -13,7 +14,7 @@ namespace Geekbot.net.WebApi.Controllers.Status var responseBody = new ApiStatusDto { GeekbotVersion = Constants.BotVersion(), - ApiVersion = Constants.ApiVersion.ToString(), + ApiVersion = Constants.ApiVersion.ToString(CultureInfo.InvariantCulture), Status = "Online" }; return Ok(responseBody); diff --git a/Geekbot.net/WebApi/Logging/AspLogProvider.cs b/Geekbot.net/WebApi/Logging/AspLogProvider.cs index 9a1599a..d35872d 100644 --- a/Geekbot.net/WebApi/Logging/AspLogProvider.cs +++ b/Geekbot.net/WebApi/Logging/AspLogProvider.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Concurrent; +using System.Collections.Concurrent; using Geekbot.net.Lib.Logger; using Microsoft.Extensions.Logging; diff --git a/Geekbot.net/WebApi/Logging/AspLogger.cs b/Geekbot.net/WebApi/Logging/AspLogger.cs index 37c9de1..85dd619 100644 --- a/Geekbot.net/WebApi/Logging/AspLogger.cs +++ b/Geekbot.net/WebApi/Logging/AspLogger.cs @@ -36,6 +36,8 @@ namespace Geekbot.net.WebApi.Logging case LogLevel.Critical: _geekbotLogger.Error(LogSource.Api, $"{eventId.Id} - {_categoryName} - {state}", exception); break; + case LogLevel.None: + break; default: throw new ArgumentOutOfRangeException(nameof(logLevel)); } @@ -67,6 +69,9 @@ namespace Geekbot.net.WebApi.Logging return NLog.LogLevel.Error; case LogLevel.Critical: return NLog.LogLevel.Fatal; + case LogLevel.None: + return NLog.LogLevel.Off; + break; default: throw new ArgumentOutOfRangeException(nameof(level)); } diff --git a/Geekbot.net/WebApi/WebApiStartup.cs b/Geekbot.net/WebApi/WebApiStartup.cs index 675ba1b..e91ff9f 100644 --- a/Geekbot.net/WebApi/WebApiStartup.cs +++ b/Geekbot.net/WebApi/WebApiStartup.cs @@ -1,7 +1,7 @@ -using System; -using System.Net; +using System.Net; using System.Reflection; using Discord.Commands; +using Geekbot.net.Database; using Geekbot.net.Lib; using Geekbot.net.Lib.Logger; using Geekbot.net.WebApi.Logging; @@ -13,9 +13,10 @@ using Microsoft.Extensions.Logging; namespace Geekbot.net.WebApi { - public class WebApiStartup + public static class WebApiStartup { - public static void StartWebApi(IGeekbotLogger logger, RunParameters runParameters, CommandService commandService) + public static void StartWebApi(IGeekbotLogger logger, RunParameters runParameters, CommandService commandService, + DatabaseContext databaseContext) { WebHost.CreateDefaultBuilder() .UseKestrel(options => @@ -26,6 +27,7 @@ namespace Geekbot.net.WebApi { services.AddMvc(); services.AddSingleton(commandService); + services.AddSingleton(databaseContext); services.AddCors(options => { options.AddPolicy("AllowSpecificOrigin", diff --git a/Tests/Lib/EmojiConverter.test.cs b/Tests/Lib/EmojiConverter.test.cs index aaaaa8f..170d521 100644 --- a/Tests/Lib/EmojiConverter.test.cs +++ b/Tests/Lib/EmojiConverter.test.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Geekbot.net.Lib; using Geekbot.net.Lib.Converters; using Xunit; diff --git a/Tests/Lib/LevelCalc.test.cs b/Tests/Lib/LevelCalc.test.cs index 4b6b095..5ac5fd3 100644 --- a/Tests/Lib/LevelCalc.test.cs +++ b/Tests/Lib/LevelCalc.test.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Geekbot.net.Lib; using Geekbot.net.Lib.Levels; using Xunit;