Resharper cleanup and fixes and remove useless asp overhead

This commit is contained in:
runebaas 2018-05-15 01:18:26 +02:00
parent e0d6a97dca
commit acb2b25e09
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
44 changed files with 54 additions and 81 deletions

View file

@ -10,7 +10,6 @@ using Geekbot.net.Database.Models;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.Extensions;
using Geekbot.net.Lib.Localization; using Geekbot.net.Lib.Localization;
using StackExchange.Redis;
namespace Geekbot.net.Commands.Admin namespace Geekbot.net.Commands.Admin
{ {

View file

@ -2,7 +2,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
namespace Geekbot.net.Commands.Admin namespace Geekbot.net.Commands.Admin

View file

@ -65,7 +65,7 @@ namespace Geekbot.net.Commands.Audio
} }
// [Command("ytplay")] // [Command("ytplay")]
public async Task ytplay(string url) public async Task Ytplay(string url)
{ {
try try
{ {

View file

@ -3,7 +3,6 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using PokeAPI; using PokeAPI;

View file

@ -1,7 +1,6 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Localization; using Geekbot.net.Lib.Localization;
using StackExchange.Redis; using StackExchange.Redis;

View file

@ -4,7 +4,6 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Converters; using Geekbot.net.Lib.Converters;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using MtgApiManager.Lib.Service; using MtgApiManager.Lib.Service;

View file

@ -3,7 +3,6 @@ using System.Threading.Tasks;
using System.Web; using System.Web;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Clients; using Geekbot.net.Lib.Clients;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;

View file

@ -4,7 +4,6 @@ using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using Newtonsoft.Json; using Newtonsoft.Json;

View file

@ -3,7 +3,6 @@ using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using Newtonsoft.Json; using Newtonsoft.Json;

View file

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Media; using Geekbot.net.Lib.Media;

View file

@ -3,7 +3,6 @@ using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using Newtonsoft.Json; using Newtonsoft.Json;

View file

@ -3,7 +3,6 @@ using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using Newtonsoft.Json; using Newtonsoft.Json;

View file

@ -3,7 +3,6 @@ using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using Newtonsoft.Json; using Newtonsoft.Json;

View file

@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
namespace Geekbot.net.Commands.Randomness namespace Geekbot.net.Commands.Randomness

View file

@ -1,6 +1,5 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Media; using Geekbot.net.Lib.Media;
namespace Geekbot.net.Commands.Randomness namespace Geekbot.net.Commands.Randomness

View file

@ -2,7 +2,6 @@
using System.Net; using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
namespace Geekbot.net.Commands.Randomness namespace Geekbot.net.Commands.Randomness

View file

@ -1,7 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Media; using Geekbot.net.Lib.Media;
namespace Geekbot.net.Commands.Randomness namespace Geekbot.net.Commands.Randomness

View file

@ -4,7 +4,6 @@ using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Database; using Geekbot.net.Database;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.Extensions;
using Geekbot.net.Lib.Levels; using Geekbot.net.Lib.Levels;
@ -42,7 +41,7 @@ namespace Geekbot.net.Commands.User
var messages = _database.Messages var messages = _database.Messages
.Where(e => e.GuildId == Context.Guild.Id.AsLong()) .Where(e => e.GuildId == Context.Guild.Id.AsLong())
.Sum(e => e.MessageCount); .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.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)");
eb.AddInlineField("Level", level) eb.AddInlineField("Level", level)

View file

@ -5,7 +5,6 @@ using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Database; using Geekbot.net.Database;
using Geekbot.net.Database.Models; using Geekbot.net.Database.Models;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.Extensions;
using Geekbot.net.Lib.Localization; using Geekbot.net.Lib.Localization;

View file

@ -2,7 +2,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
namespace Geekbot.net.Commands.Utils namespace Geekbot.net.Commands.Utils

View file

@ -7,7 +7,6 @@ using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Discord.WebSocket; using Discord.WebSocket;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using Newtonsoft.Json; using Newtonsoft.Json;

View file

@ -1,7 +1,6 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Localization; using Geekbot.net.Lib.Localization;

View file

@ -4,7 +4,6 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
namespace Geekbot.net.Commands.Utils.Dice namespace Geekbot.net.Commands.Utils.Dice
{ {

View file

@ -1,7 +1,6 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Converters; using Geekbot.net.Lib.Converters;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;

View file

@ -3,7 +3,6 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
namespace Geekbot.net.Commands.Utils namespace Geekbot.net.Commands.Utils

View file

@ -1,6 +1,5 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
namespace Geekbot.net.Commands.Utils namespace Geekbot.net.Commands.Utils
{ {

View file

@ -5,7 +5,6 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Converters; using Geekbot.net.Lib.Converters;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.UserRepository; using Geekbot.net.Lib.UserRepository;
@ -167,7 +166,10 @@ namespace Geekbot.net.Commands.Utils.Poll
}; };
results.Add(result); results.Add(result);
} }
catch {} catch
{
// ignored
}
results.Sort((x, y) => y.VoteCount.CompareTo(x.VoteCount)); results.Sort((x, y) => y.VoteCount.CompareTo(x.VoteCount));
return results; return results;

View file

@ -5,11 +5,9 @@ using Discord;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Database; using Geekbot.net.Database;
using Geekbot.net.Database.Models; using Geekbot.net.Database.Models;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling; using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.Extensions;
using Geekbot.net.Lib.Polyfills; using Geekbot.net.Lib.Polyfills;
using StackExchange.Redis;
namespace Geekbot.net.Commands.Utils.Quote namespace Geekbot.net.Commands.Utils.Quote
{ {

View file

@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace Geekbot.net.Database namespace Geekbot.net.Database
{ {
@ -13,6 +12,6 @@ namespace Geekbot.net.Database
} }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseInMemoryDatabase(databaseName: _name); => optionsBuilder.UseInMemoryDatabase(_name);
} }
} }

View file

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Geekbot.net.Database.Models namespace Geekbot.net.Database.Models

View file

@ -8,7 +8,6 @@ using Geekbot.net.Commands.Utils.Quote;
using Geekbot.net.Database.Models; using Geekbot.net.Database.Models;
using Geekbot.net.Lib.Extensions; using Geekbot.net.Lib.Extensions;
using Geekbot.net.Lib.Logger; using Geekbot.net.Lib.Logger;
using MtgApiManager.Lib.Model;
using Newtonsoft.Json; using Newtonsoft.Json;
using StackExchange.Redis; using StackExchange.Redis;

View file

@ -24,7 +24,11 @@
</PackageReference> </PackageReference>
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.33.1.1217" /> <PackageReference Include="Google.Apis.YouTube.v3" Version="1.33.1.1217" />
<PackageReference Include="HtmlAgilityPack" Version="1.8.1" /> <PackageReference Include="HtmlAgilityPack" Version="1.8.1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" /> <PackageReference Include="Microsoft.AspNetCore" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.Redis" Version="0.3.3" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Cors" Version="2.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.0.2" />

View file

@ -25,7 +25,9 @@ namespace Geekbot.net
private readonly IUserRepository _userRepository; private readonly IUserRepository _userRepository;
private readonly IReactionListener _reactionListener; 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; _database = database;
_client = client; _client = client;

View file

@ -1,45 +1,38 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Geekbot.net.Lib.GlobalSettings;
using Geekbot.net.Lib.Logger; using Geekbot.net.Lib.Logger;
using MyAnimeListSharp.Auth; using MyAnimeListSharp.Auth;
using MyAnimeListSharp.Core; using MyAnimeListSharp.Core;
using MyAnimeListSharp.Facade.Async; using MyAnimeListSharp.Facade.Async;
using StackExchange.Redis;
namespace Geekbot.net.Lib.Clients namespace Geekbot.net.Lib.Clients
{ {
public class MalClient : IMalClient public class MalClient : IMalClient
{ {
private readonly IDatabase _redis; private readonly IGlobalSettings _globalSettings;
private readonly IGeekbotLogger _logger; private readonly IGeekbotLogger _logger;
private ICredentialContext _credentials; private ICredentialContext _credentials;
private AnimeSearchMethodsAsync _animeSearch; private AnimeSearchMethodsAsync _animeSearch;
private MangaSearchMethodsAsync _mangaSearch; private MangaSearchMethodsAsync _mangaSearch;
public MalClient(IDatabase redis, IGeekbotLogger logger) public MalClient(IGlobalSettings globalSettings, IGeekbotLogger logger)
{ {
_redis = redis; _globalSettings = globalSettings;
_logger = logger; _logger = logger;
ReloadClient(); ReloadClient();
} }
public bool ReloadClient() public bool ReloadClient()
{ {
var malCredentials = _redis.HashGetAll("malCredentials"); var malCredentials = _globalSettings.GetKey("MalCredentials");
if (malCredentials.Length != 0) if (!string.IsNullOrEmpty(malCredentials))
{ {
_credentials = new CredentialContext(); var credSplit = malCredentials.Split('|');
foreach (var c in malCredentials) _credentials = new CredentialContext()
{ {
switch (c.Name) UserName = credSplit[0],
{ Password = credSplit[1]
case "Username": };
_credentials.UserName = c.Value;
break;
case "Password":
_credentials.Password = c.Value;
break;
}
}
_animeSearch = new AnimeSearchMethodsAsync(_credentials); _animeSearch = new AnimeSearchMethodsAsync(_credentials);
_mangaSearch = new MangaSearchMethodsAsync(_credentials); _mangaSearch = new MangaSearchMethodsAsync(_credentials);
_logger.Debug(LogSource.Geekbot, "Logged in to MAL"); _logger.Debug(LogSource.Geekbot, "Logged in to MAL");

View file

@ -1,7 +1,6 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Geekbot.net.Commands.Randomness.Cat;
namespace Geekbot.net.Lib.Logger namespace Geekbot.net.Lib.Logger
{ {

View file

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.WebSocket; using Discord.WebSocket;

View file

@ -53,6 +53,7 @@ namespace Geekbot.net
logo.AppendLine(@"| |_| | |___| |___| . \| |_) | |_| || |"); logo.AppendLine(@"| |_| | |___| |___| . \| |_) | |_| || |");
logo.AppendLine(@" \____|_____|_____|_|\_\____/ \___/ |_|"); logo.AppendLine(@" \____|_____|_____|_|\_\____/ \___/ |_|");
logo.AppendLine("========================================="); logo.AppendLine("=========================================");
logo.AppendLine($"Version {Constants.BotVersion()}");
Console.WriteLine(logo.ToString()); Console.WriteLine(logo.ToString());
var sumologicActive = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GEEKBOT_SUMO")); var sumologicActive = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GEEKBOT_SUMO"));
var logger = new GeekbotLogger(runParameters, sumologicActive); var logger = new GeekbotLogger(runParameters, sumologicActive);
@ -112,7 +113,7 @@ namespace Geekbot.net
_userRepository = new UserRepository(_database, logger); _userRepository = new UserRepository(_database, logger);
var fortunes = new FortunesProvider(logger); var fortunes = new FortunesProvider(logger);
var mediaProvider = new MediaProvider(logger); var mediaProvider = new MediaProvider(logger);
var malClient = new MalClient(_redis, logger); var malClient = new MalClient(_globalSettings, logger);
var levelCalc = new LevelCalc(); var levelCalc = new LevelCalc();
var emojiConverter = new EmojiConverter(); var emojiConverter = new EmojiConverter();
var mtgManaConverter = new MtgManaConverter(); var mtgManaConverter = new MtgManaConverter();
@ -174,13 +175,12 @@ namespace Geekbot.net
_client.UserLeft += handlers.UserLeft; _client.UserLeft += handlers.UserLeft;
_client.ReactionAdded += handlers.ReactionAdded; _client.ReactionAdded += handlers.ReactionAdded;
_client.ReactionRemoved += handlers.ReactionRemoved; _client.ReactionRemoved += handlers.ReactionRemoved;
if (!_runParameters.DisableApi) var webserver = _runParameters.DisableApi ? Task.Delay(10) : StartWebApi();
{
StartWebApi();
}
_logger.Information(LogSource.Geekbot, "Done and ready for use"); _logger.Information(LogSource.Geekbot, "Done and ready for use");
await webserver;
} }
} }
catch (Exception e) catch (Exception e)
@ -197,12 +197,11 @@ namespace Geekbot.net
return true; return true;
} }
private void StartWebApi() private Task StartWebApi()
{ {
_logger.Information(LogSource.Api, "Starting Webserver"); _logger.Information(LogSource.Api, "Starting Webserver");
var webApiUrl = new Uri($"http://{_runParameters.ApiHost}:{_runParameters.ApiPort}"); WebApi.WebApiStartup.StartWebApi(_logger, _runParameters, _commands, _database);
WebApi.WebApiStartup.StartWebApi(_logger, _runParameters, _commands); return Task.CompletedTask;
_logger.Information(LogSource.Api, $"Webserver now running on {webApiUrl}");
} }
} }
} }

View file

@ -6,11 +6,11 @@ using Microsoft.AspNetCore.Mvc;
namespace Geekbot.net.WebApi.Controllers.Commands namespace Geekbot.net.WebApi.Controllers.Commands
{ {
[EnableCors("AllowSpecificOrigin")] [EnableCors("AllowSpecificOrigin")]
public class HelpController : Controller public class CommandController : Controller
{ {
private readonly CommandService _commands; private readonly CommandService _commands;
public HelpController(CommandService commands) public CommandController(CommandService commands)
{ {
_commands = commands; _commands = commands;
} }
@ -22,7 +22,7 @@ namespace Geekbot.net.WebApi.Controllers.Commands
let cmdParamsObj = cmd.Parameters.Select(cmdParam => new CommandParamDto let cmdParamsObj = cmd.Parameters.Select(cmdParam => new CommandParamDto
{ {
Summary = cmdParam.Summary, Summary = cmdParam.Summary,
Default = cmdParam.DefaultValue?.ToString() ?? null, Default = cmdParam.DefaultValue?.ToString(),
Type = cmdParam.Type?.ToString() Type = cmdParam.Type?.ToString()
}) })
.ToList() .ToList()
@ -31,7 +31,7 @@ namespace Geekbot.net.WebApi.Controllers.Commands
{ {
Name = cmd.Name, Name = cmd.Name,
Summary = cmd.Summary, Summary = cmd.Summary,
IsAdminCommand = (param.Contains("admin")), IsAdminCommand = param.Contains("admin") || param.Contains("owner"),
Aliases = cmd.Aliases.ToArray(), Aliases = cmd.Aliases.ToArray(),
Params = cmdParamsObj Params = cmdParamsObj
}).ToList(); }).ToList();

View file

@ -1,4 +1,5 @@
using Geekbot.net.Lib; using System.Globalization;
using Geekbot.net.Lib;
using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -13,7 +14,7 @@ namespace Geekbot.net.WebApi.Controllers.Status
var responseBody = new ApiStatusDto var responseBody = new ApiStatusDto
{ {
GeekbotVersion = Constants.BotVersion(), GeekbotVersion = Constants.BotVersion(),
ApiVersion = Constants.ApiVersion.ToString(), ApiVersion = Constants.ApiVersion.ToString(CultureInfo.InvariantCulture),
Status = "Online" Status = "Online"
}; };
return Ok(responseBody); return Ok(responseBody);

View file

@ -1,5 +1,4 @@
using System; using System.Collections.Concurrent;
using System.Collections.Concurrent;
using Geekbot.net.Lib.Logger; using Geekbot.net.Lib.Logger;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View file

@ -36,6 +36,8 @@ namespace Geekbot.net.WebApi.Logging
case LogLevel.Critical: case LogLevel.Critical:
_geekbotLogger.Error(LogSource.Api, $"{eventId.Id} - {_categoryName} - {state}", exception); _geekbotLogger.Error(LogSource.Api, $"{eventId.Id} - {_categoryName} - {state}", exception);
break; break;
case LogLevel.None:
break;
default: default:
throw new ArgumentOutOfRangeException(nameof(logLevel)); throw new ArgumentOutOfRangeException(nameof(logLevel));
} }
@ -67,6 +69,9 @@ namespace Geekbot.net.WebApi.Logging
return NLog.LogLevel.Error; return NLog.LogLevel.Error;
case LogLevel.Critical: case LogLevel.Critical:
return NLog.LogLevel.Fatal; return NLog.LogLevel.Fatal;
case LogLevel.None:
return NLog.LogLevel.Off;
break;
default: default:
throw new ArgumentOutOfRangeException(nameof(level)); throw new ArgumentOutOfRangeException(nameof(level));
} }

View file

@ -1,7 +1,7 @@
using System; using System.Net;
using System.Net;
using System.Reflection; using System.Reflection;
using Discord.Commands; using Discord.Commands;
using Geekbot.net.Database;
using Geekbot.net.Lib; using Geekbot.net.Lib;
using Geekbot.net.Lib.Logger; using Geekbot.net.Lib.Logger;
using Geekbot.net.WebApi.Logging; using Geekbot.net.WebApi.Logging;
@ -13,9 +13,10 @@ using Microsoft.Extensions.Logging;
namespace Geekbot.net.WebApi 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() WebHost.CreateDefaultBuilder()
.UseKestrel(options => .UseKestrel(options =>
@ -26,6 +27,7 @@ namespace Geekbot.net.WebApi
{ {
services.AddMvc(); services.AddMvc();
services.AddSingleton<CommandService>(commandService); services.AddSingleton<CommandService>(commandService);
services.AddSingleton<DatabaseContext>(databaseContext);
services.AddCors(options => services.AddCors(options =>
{ {
options.AddPolicy("AllowSpecificOrigin", options.AddPolicy("AllowSpecificOrigin",

View file

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Converters; using Geekbot.net.Lib.Converters;
using Xunit; using Xunit;

View file

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Levels; using Geekbot.net.Lib.Levels;
using Xunit; using Xunit;