Use the new Csharp 8 features (pattern matching and using assignments) and cleanup some insignificant resparper complaints
This commit is contained in:
parent
21f813d342
commit
3568b61f38
27 changed files with 217 additions and 250 deletions
|
@ -35,7 +35,7 @@ namespace Geekbot.net.Commands.Admin
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var userRepo = _userRepository.Get(user.Id);
|
var userRepo = _userRepository.Get(user.Id);
|
||||||
if (userRepo != null && userRepo.UsedNames != null)
|
if (userRepo?.UsedNames != null)
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.AppendLine($":bust_in_silhouette: {user.Username} has been known as:");
|
sb.AppendLine($":bust_in_silhouette: {user.Username} has been known as:");
|
||||||
|
@ -50,7 +50,7 @@ namespace Geekbot.net.Commands.Admin
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
await _errorHandler.HandleCommandException(e, Context,
|
await _errorHandler.HandleCommandException(e, Context,
|
||||||
$"I don't have enough permissions do that");
|
"I don't have enough permissions do that");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,9 +41,11 @@ namespace Geekbot.net.Commands.Integrations
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var eb = new EmbedBuilder();
|
var eb = new EmbedBuilder
|
||||||
eb.Title = card.Name;
|
{
|
||||||
eb.Description = card.Type;
|
Title = card.Name,
|
||||||
|
Description = card.Type
|
||||||
|
};
|
||||||
|
|
||||||
if (card.Colors != null) eb.WithColor(GetColor(card.Colors));
|
if (card.Colors != null) eb.WithColor(GetColor(card.Colors));
|
||||||
|
|
||||||
|
@ -74,21 +76,15 @@ namespace Geekbot.net.Commands.Integrations
|
||||||
private Color GetColor(IEnumerable<string> colors)
|
private Color GetColor(IEnumerable<string> colors)
|
||||||
{
|
{
|
||||||
var color = colors.FirstOrDefault();
|
var color = colors.FirstOrDefault();
|
||||||
switch (color)
|
return color switch
|
||||||
{
|
{
|
||||||
case "Black":
|
"Black" => new Color(203, 194, 191),
|
||||||
return new Color(203, 194, 191);
|
"White" => new Color(255, 251, 213),
|
||||||
case "White":
|
"Blue" => new Color(170, 224, 250),
|
||||||
return new Color(255, 251, 213);
|
"Red" => new Color(250, 170, 143),
|
||||||
case "Blue":
|
"Green" => new Color(155, 211, 174),
|
||||||
return new Color(170, 224, 250);
|
_ => new Color(204, 194, 212)
|
||||||
case "Red":
|
};
|
||||||
return new Color(250, 170, 143);
|
|
||||||
case "Green":
|
|
||||||
return new Color(155, 211, 174);
|
|
||||||
default:
|
|
||||||
return new Color(204, 194, 212);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,9 +25,10 @@ namespace Geekbot.net.Commands.Integrations.UbranDictionary
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var client = new HttpClient())
|
using var client = new HttpClient
|
||||||
{
|
{
|
||||||
client.BaseAddress = new Uri("https://api.urbandictionary.com");
|
BaseAddress = new Uri("https://api.urbandictionary.com")
|
||||||
|
};
|
||||||
var response = await client.GetAsync($"/v0/define?term={word}");
|
var response = await client.GetAsync($"/v0/define?term={word}");
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
@ -62,7 +63,6 @@ namespace Geekbot.net.Commands.Integrations.UbranDictionary
|
||||||
|
|
||||||
await ReplyAsync("", false, eb.Build());
|
await ReplyAsync("", false, eb.Build());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
await _errorHandler.HandleCommandException(e, Context);
|
await _errorHandler.HandleCommandException(e, Context);
|
||||||
|
|
|
@ -23,18 +23,22 @@ namespace Geekbot.net.Commands.Randomness.Cat
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var client = new HttpClient())
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
client.BaseAddress = new Uri("https://aws.random.cat");
|
using var client = new HttpClient
|
||||||
|
{
|
||||||
|
BaseAddress = new Uri("https://aws.random.cat")
|
||||||
|
};
|
||||||
var response = await client.GetAsync("/meow");
|
var response = await client.GetAsync("/meow");
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||||
var catFile = JsonConvert.DeserializeObject<CatResponseDto>(stringResponse);
|
var catFile = JsonConvert.DeserializeObject<CatResponseDto>(stringResponse);
|
||||||
var eb = new EmbedBuilder();
|
var eb = new EmbedBuilder
|
||||||
eb.ImageUrl = catFile.File;
|
{
|
||||||
|
ImageUrl = catFile.File
|
||||||
|
};
|
||||||
await ReplyAsync("", false, eb.Build());
|
await ReplyAsync("", false, eb.Build());
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
@ -42,7 +46,6 @@ namespace Geekbot.net.Commands.Randomness.Cat
|
||||||
await ReplyAsync("Seems like the dog cought the cat (error occured)");
|
await ReplyAsync("Seems like the dog cought the cat (error occured)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
await _errorHandler.HandleCommandException(e, Context);
|
await _errorHandler.HandleCommandException(e, Context);
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace Geekbot.net.Commands.Randomness
|
||||||
while (num > 0)
|
while (num > 0)
|
||||||
{
|
{
|
||||||
listOfInts.Add(num % 10);
|
listOfInts.Add(num % 10);
|
||||||
num = num / 10;
|
num /= 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
listOfInts.Reverse();
|
listOfInts.Reverse();
|
||||||
|
|
|
@ -22,11 +22,10 @@ namespace Geekbot.net.Commands.Randomness.Chuck
|
||||||
public async Task Say()
|
public async Task Say()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
|
||||||
using (var client = new HttpClient())
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
using var client = new HttpClient();
|
||||||
client.DefaultRequestHeaders.Accept.Clear();
|
client.DefaultRequestHeaders.Accept.Clear();
|
||||||
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
|
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
|
||||||
var response = await client.GetAsync("https://api.chucknorris.io/jokes/random");
|
var response = await client.GetAsync("https://api.chucknorris.io/jokes/random");
|
||||||
|
@ -41,7 +40,6 @@ namespace Geekbot.net.Commands.Randomness.Chuck
|
||||||
await ReplyAsync("Api down...");
|
await ReplyAsync("Api down...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
await _errorHandler.HandleCommandException(e, Context);
|
await _errorHandler.HandleCommandException(e, Context);
|
||||||
|
|
|
@ -22,11 +22,10 @@ namespace Geekbot.net.Commands.Randomness.Dad
|
||||||
public async Task Say()
|
public async Task Say()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
|
||||||
using (var client = new HttpClient())
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
using var client = new HttpClient();
|
||||||
client.DefaultRequestHeaders.Accept.Clear();
|
client.DefaultRequestHeaders.Accept.Clear();
|
||||||
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
|
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
|
||||||
var response = await client.GetAsync("https://icanhazdadjoke.com/");
|
var response = await client.GetAsync("https://icanhazdadjoke.com/");
|
||||||
|
@ -41,7 +40,6 @@ namespace Geekbot.net.Commands.Randomness.Dad
|
||||||
await ReplyAsync("Api down...");
|
await ReplyAsync("Api down...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
await _errorHandler.HandleCommandException(e, Context);
|
await _errorHandler.HandleCommandException(e, Context);
|
||||||
|
|
|
@ -22,19 +22,22 @@ namespace Geekbot.net.Commands.Randomness.Dog
|
||||||
public async Task Say()
|
public async Task Say()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
|
||||||
using (var client = new HttpClient())
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
client.BaseAddress = new Uri("http://random.dog");
|
using var client = new HttpClient
|
||||||
|
{
|
||||||
|
BaseAddress = new Uri("http://random.dog")
|
||||||
|
};
|
||||||
var response = await client.GetAsync("/woof.json");
|
var response = await client.GetAsync("/woof.json");
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||||
var dogFile = JsonConvert.DeserializeObject<DogResponseDto>(stringResponse);
|
var dogFile = JsonConvert.DeserializeObject<DogResponseDto>(stringResponse);
|
||||||
var eb = new EmbedBuilder();
|
var eb = new EmbedBuilder
|
||||||
eb.ImageUrl = dogFile.Url;
|
{
|
||||||
|
ImageUrl = dogFile.Url
|
||||||
|
};
|
||||||
await ReplyAsync("", false, eb.Build());
|
await ReplyAsync("", false, eb.Build());
|
||||||
}
|
}
|
||||||
catch (HttpRequestException e)
|
catch (HttpRequestException e)
|
||||||
|
@ -42,7 +45,6 @@ namespace Geekbot.net.Commands.Randomness.Dog
|
||||||
await ReplyAsync($"Seems like the dog got lost (error occured)\r\n{e.Message}");
|
await ReplyAsync($"Seems like the dog got lost (error occured)\r\n{e.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
await _errorHandler.HandleCommandException(e, Context);
|
await _errorHandler.HandleCommandException(e, Context);
|
||||||
|
|
|
@ -21,14 +21,12 @@ namespace Geekbot.net.Commands.Randomness
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var client = new WebClient())
|
using var client = new WebClient();
|
||||||
{
|
|
||||||
var url = new Uri("http://taskinoz.com/gdq/api/");
|
var url = new Uri("http://taskinoz.com/gdq/api/");
|
||||||
var response = client.DownloadString(url);
|
var response = client.DownloadString(url);
|
||||||
|
|
||||||
await ReplyAsync(response);
|
await ReplyAsync(response);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
await _errorHandler.HandleCommandException(e, Context);
|
await _errorHandler.HandleCommandException(e, Context);
|
||||||
|
|
|
@ -22,11 +22,10 @@ namespace Geekbot.net.Commands.Randomness.Kanye
|
||||||
public async Task Say()
|
public async Task Say()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
|
||||||
using (var client = new HttpClient())
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
using var client = new HttpClient();
|
||||||
client.DefaultRequestHeaders.Accept.Clear();
|
client.DefaultRequestHeaders.Accept.Clear();
|
||||||
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
|
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
|
||||||
var response = await client.GetAsync("https://api.kanye.rest/");
|
var response = await client.GetAsync("https://api.kanye.rest/");
|
||||||
|
@ -41,7 +40,6 @@ namespace Geekbot.net.Commands.Randomness.Kanye
|
||||||
await ReplyAsync("Api down...");
|
await ReplyAsync("Api down...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
await _errorHandler.HandleCommandException(e, Context);
|
await _errorHandler.HandleCommandException(e, Context);
|
||||||
|
|
|
@ -56,8 +56,8 @@ namespace Geekbot.net.Commands.Randomness
|
||||||
}
|
}
|
||||||
|
|
||||||
var reply = ":heartpulse: **Matchmaking** :heartpulse:\r\n";
|
var reply = ":heartpulse: **Matchmaking** :heartpulse:\r\n";
|
||||||
reply = reply + $":two_hearts: {user1.Mention} :heart: {user2.Mention} :two_hearts:\r\n";
|
reply += $":two_hearts: {user1.Mention} :heart: {user2.Mention} :two_hearts:\r\n";
|
||||||
reply = reply + $"0% [{BlockCounter(shippingRate)}] 100% - {DeterminateSuccess(shippingRate)}";
|
reply += $"0% [{BlockCounter(shippingRate)}] 100% - {DeterminateSuccess(shippingRate)}";
|
||||||
await ReplyAsync(reply);
|
await ReplyAsync(reply);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -87,13 +87,13 @@ namespace Geekbot.net.Commands.Randomness
|
||||||
for (var i = 1; i <= 10; i++)
|
for (var i = 1; i <= 10; i++)
|
||||||
if (i <= amount)
|
if (i <= amount)
|
||||||
{
|
{
|
||||||
blocks = blocks + ":white_medium_small_square:";
|
blocks += ":white_medium_small_square:";
|
||||||
if (i == amount)
|
if (i == amount)
|
||||||
blocks = blocks + $" {rate}% ";
|
blocks += $" {rate}% ";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
blocks = blocks + ":black_medium_small_square:";
|
blocks += ":black_medium_small_square:";
|
||||||
}
|
}
|
||||||
|
|
||||||
return blocks;
|
return blocks;
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace Geekbot.net.Commands.User
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var target = await GetUser(user.Id);
|
var target = await GetUser(user.Id);
|
||||||
target.Karma = target.Karma + 1;
|
target.Karma += 1;
|
||||||
SetUser(target);
|
SetUser(target);
|
||||||
|
|
||||||
actor.TimeOut = DateTimeOffset.Now;
|
actor.TimeOut = DateTimeOffset.Now;
|
||||||
|
@ -93,7 +93,7 @@ namespace Geekbot.net.Commands.User
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var target = await GetUser(user.Id);
|
var target = await GetUser(user.Id);
|
||||||
target.Karma = target.Karma - 1;
|
target.Karma -= 1;
|
||||||
SetUser(target);
|
SetUser(target);
|
||||||
|
|
||||||
actor.TimeOut = DateTimeOffset.Now;
|
actor.TimeOut = DateTimeOffset.Now;
|
||||||
|
|
|
@ -74,7 +74,7 @@ namespace Geekbot.net.Commands.User.Ranking
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int guildMessages = 0;
|
var guildMessages = 0;
|
||||||
if (type == HighscoreTypes.messages)
|
if (type == HighscoreTypes.messages)
|
||||||
{
|
{
|
||||||
guildMessages = _database.Messages
|
guildMessages = _database.Messages
|
||||||
|
@ -99,7 +99,7 @@ namespace Geekbot.net.Commands.User.Ranking
|
||||||
: $"**{user.Key.Id}**");
|
: $"**{user.Key.Id}**");
|
||||||
|
|
||||||
replyBuilder.Append(type == HighscoreTypes.messages
|
replyBuilder.Append(type == HighscoreTypes.messages
|
||||||
? $" - {user.Value} {type} - {Math.Round((double) (100 * user.Value) / guildMessages, digits: 2)}%\n"
|
? $" - {user.Value} {type} - {Math.Round((double) (100 * user.Value) / guildMessages, 2)}%\n"
|
||||||
: $" - {user.Value} {type}\n");
|
: $" - {user.Value} {type}\n");
|
||||||
|
|
||||||
highscorePlace++;
|
highscorePlace++;
|
||||||
|
|
|
@ -51,7 +51,7 @@ namespace Geekbot.net.Commands.User
|
||||||
|
|
||||||
var level = _levelCalc.GetLevel(messages);
|
var level = _levelCalc.GetLevel(messages);
|
||||||
|
|
||||||
var percent = Math.Round((double) (100 * messages) / guildMessages, digits: 2);
|
var percent = Math.Round((double) (100 * messages) / guildMessages, 2);
|
||||||
|
|
||||||
var cookies = _database.Cookies
|
var cookies = _database.Cookies
|
||||||
?.FirstOrDefault(e => e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.UserId.Equals(userInfo.Id.AsLong()))
|
?.FirstOrDefault(e => e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.UserId.Equals(userInfo.Id.AsLong()))
|
||||||
|
|
|
@ -29,9 +29,10 @@ namespace Geekbot.net.Commands.Utils.Changelog
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var client = new HttpClient())
|
using var client = new HttpClient
|
||||||
{
|
{
|
||||||
client.BaseAddress = new Uri("https://api.github.com");
|
BaseAddress = new Uri("https://api.github.com")
|
||||||
|
};
|
||||||
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent",
|
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent",
|
||||||
"http://developer.github.com/v3/#user-agent-required");
|
"http://developer.github.com/v3/#user-agent-required");
|
||||||
var response = await client.GetAsync("/repos/pizzaandcoffee/geekbot.net/commits");
|
var response = await client.GetAsync("/repos/pizzaandcoffee/geekbot.net/commits");
|
||||||
|
@ -57,7 +58,6 @@ namespace Geekbot.net.Commands.Utils.Changelog
|
||||||
});
|
});
|
||||||
await ReplyAsync("", false, eb.Build());
|
await ReplyAsync("", false, eb.Build());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
await _errorHandler.HandleCommandException(e, Context);
|
await _errorHandler.HandleCommandException(e, Context);
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var random = _randomNumberGenerator.Next(0, s.Count());
|
var random = _randomNumberGenerator.Next(0, s.Count);
|
||||||
var quote = s[random];
|
var quote = s[random];
|
||||||
|
|
||||||
var embed = QuoteBuilder(quote);
|
var embed = QuoteBuilder(quote);
|
||||||
|
@ -238,7 +238,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
||||||
|
|
||||||
var last = _database.Quotes.Where(e => e.GuildId.Equals(Context.Guild.Id.AsLong()))
|
var last = _database.Quotes.Where(e => e.GuildId.Equals(Context.Guild.Id.AsLong()))
|
||||||
.OrderByDescending(e => e.InternalId).FirstOrDefault();
|
.OrderByDescending(e => e.InternalId).FirstOrDefault();
|
||||||
int internalId = 1;
|
var internalId = 1;
|
||||||
if (last != null) internalId = last.InternalId + 1;
|
if (last != null) internalId = last.InternalId + 1;
|
||||||
return new QuoteModel()
|
return new QuoteModel()
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,23 +54,16 @@ namespace Geekbot.net.Database.LoggingAdapter
|
||||||
|
|
||||||
private static LogLevel ToGeekbotLogLevel(NpgsqlLogLevel level)
|
private static LogLevel ToGeekbotLogLevel(NpgsqlLogLevel level)
|
||||||
{
|
{
|
||||||
switch (level)
|
return level switch
|
||||||
{
|
{
|
||||||
case NpgsqlLogLevel.Trace:
|
NpgsqlLogLevel.Trace => LogLevel.Trace,
|
||||||
return LogLevel.Trace;
|
NpgsqlLogLevel.Debug => LogLevel.Debug,
|
||||||
case NpgsqlLogLevel.Debug:
|
NpgsqlLogLevel.Info => LogLevel.Info,
|
||||||
return LogLevel.Debug;
|
NpgsqlLogLevel.Warn => LogLevel.Warn,
|
||||||
case NpgsqlLogLevel.Info:
|
NpgsqlLogLevel.Error => LogLevel.Error,
|
||||||
return LogLevel.Info;
|
NpgsqlLogLevel.Fatal => LogLevel.Fatal,
|
||||||
case NpgsqlLogLevel.Warn:
|
_ => throw new ArgumentOutOfRangeException(nameof(level))
|
||||||
return LogLevel.Warn;
|
};
|
||||||
case NpgsqlLogLevel.Error:
|
|
||||||
return LogLevel.Error;
|
|
||||||
case NpgsqlLogLevel.Fatal:
|
|
||||||
return LogLevel.Fatal;
|
|
||||||
default:
|
|
||||||
throw new ArgumentOutOfRangeException(nameof(level));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -22,7 +22,7 @@ namespace Geekbot.net.Lib.Clients
|
||||||
ReloadClient();
|
ReloadClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ReloadClient()
|
private bool ReloadClient()
|
||||||
{
|
{
|
||||||
var malCredentials = _globalSettings.GetKey("MalCredentials");
|
var malCredentials = _globalSettings.GetKey("MalCredentials");
|
||||||
if (!string.IsNullOrEmpty(malCredentials))
|
if (!string.IsNullOrEmpty(malCredentials))
|
||||||
|
|
|
@ -4,7 +4,7 @@ using Discord.Commands;
|
||||||
|
|
||||||
namespace Geekbot.net.Lib.CommandPreconditions
|
namespace Geekbot.net.Lib.CommandPreconditions
|
||||||
{
|
{
|
||||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
|
||||||
public class DisableInDirectMessageAttribute : PreconditionAttribute
|
public class DisableInDirectMessageAttribute : PreconditionAttribute
|
||||||
{
|
{
|
||||||
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
|
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace Geekbot.net.Lib.Converters
|
||||||
{
|
{
|
||||||
public class MtgManaConverter : IMtgManaConverter
|
public class MtgManaConverter : IMtgManaConverter
|
||||||
{
|
{
|
||||||
private Dictionary<string, string> _manaDict;
|
private readonly Dictionary<string, string> _manaDict;
|
||||||
|
|
||||||
public MtgManaConverter()
|
public MtgManaConverter()
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,25 +20,14 @@ namespace Geekbot.net.Lib.Highscores
|
||||||
|
|
||||||
public Dictionary<HighscoreUserDto, int> GetHighscoresWithUserData(HighscoreTypes type, ulong guildId, int amount)
|
public Dictionary<HighscoreUserDto, int> GetHighscoresWithUserData(HighscoreTypes type, ulong guildId, int amount)
|
||||||
{
|
{
|
||||||
Dictionary<ulong, int> list;
|
var list = type switch
|
||||||
switch (type)
|
|
||||||
{
|
{
|
||||||
case HighscoreTypes.messages:
|
HighscoreTypes.messages => GetMessageList(guildId, amount),
|
||||||
list = GetMessageList(guildId, amount);
|
HighscoreTypes.karma => GetKarmaList(guildId, amount),
|
||||||
break;
|
HighscoreTypes.rolls => GetRollsList(guildId, amount),
|
||||||
case HighscoreTypes.karma:
|
HighscoreTypes.cookies => GetCookiesList(guildId, amount),
|
||||||
list = GetKarmaList(guildId, amount);
|
_ => new Dictionary<ulong, int>()
|
||||||
break;
|
};
|
||||||
case HighscoreTypes.rolls:
|
|
||||||
list = GetRollsList(guildId, amount);
|
|
||||||
break;
|
|
||||||
case HighscoreTypes.cookies:
|
|
||||||
list = GetCookiesList(guildId, amount);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
list = new Dictionary<ulong, int>();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!list.Any())
|
if (!list.Any())
|
||||||
{
|
{
|
||||||
|
@ -104,7 +93,7 @@ namespace Geekbot.net.Lib.Highscores
|
||||||
.ToDictionary(key => key.UserId.AsUlong(), key => key.Rolls);
|
.ToDictionary(key => key.UserId.AsUlong(), key => key.Rolls);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<ulong, int> GetCookiesList(ulong guildId, int amount)
|
private Dictionary<ulong, int> GetCookiesList(ulong guildId, int amount)
|
||||||
{
|
{
|
||||||
return _database.Cookies
|
return _database.Cookies
|
||||||
.Where(k => k.GuildId.Equals(guildId.AsLong()))
|
.Where(k => k.GuildId.Equals(guildId.AsLong()))
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Geekbot.net.Lib.Levels
|
namespace Geekbot.net.Lib.Levels
|
||||||
{
|
{
|
||||||
public class LevelCalc : ILevelCalc
|
public class LevelCalc : ILevelCalc
|
||||||
{
|
{
|
||||||
private int[] _levels;
|
private readonly int[] _levels;
|
||||||
|
|
||||||
public LevelCalc()
|
public LevelCalc()
|
||||||
{
|
{
|
||||||
|
@ -21,13 +22,7 @@ namespace Geekbot.net.Lib.Levels
|
||||||
|
|
||||||
public int GetLevel(int? messages)
|
public int GetLevel(int? messages)
|
||||||
{
|
{
|
||||||
var returnVal = 1;
|
return 1 + _levels.TakeWhile(level => !(level > messages)).Count();
|
||||||
foreach (var level in _levels)
|
|
||||||
{
|
|
||||||
if (level > messages) break;
|
|
||||||
returnVal++;
|
|
||||||
}
|
|
||||||
return returnVal;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -37,7 +37,7 @@ namespace Geekbot.net.Lib.Logger
|
||||||
}
|
}
|
||||||
public static MessageDto ConvertSocketMessage(SocketMessage message, bool isPrivate = false)
|
public static MessageDto ConvertSocketMessage(SocketMessage message, bool isPrivate = false)
|
||||||
{
|
{
|
||||||
SocketGuildChannel channel = isPrivate ? null : (SocketGuildChannel) message.Channel;
|
var channel = isPrivate ? null : (SocketGuildChannel) message.Channel;
|
||||||
return new MessageDto
|
return new MessageDto
|
||||||
{
|
{
|
||||||
Message = new MessageDto.MessageContent
|
Message = new MessageDto.MessageContent
|
||||||
|
|
|
@ -63,8 +63,11 @@ namespace Geekbot.net.Lib.ReactionListener
|
||||||
_listener[messageId].Add(emoji, role.Id);
|
_listener[messageId].Add(emoji, role.Id);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
var dict = new Dictionary<IEmote, ulong>();
|
|
||||||
dict.Add(emoji, role.Id);
|
var dict = new Dictionary<IEmote, ulong>
|
||||||
|
{
|
||||||
|
{emoji, role.Id}
|
||||||
|
};
|
||||||
_listener.Add(messageId, dict);
|
_listener.Add(messageId, dict);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,15 @@ namespace Geekbot.net.WebApi.Controllers.Callback
|
||||||
var accessToken = _globalSettings.GetKey("OAuthToken");
|
var accessToken = _globalSettings.GetKey("OAuthToken");
|
||||||
var callbackUrl = _globalSettings.GetKey("OAuthCallbackUrl");
|
var callbackUrl = _globalSettings.GetKey("OAuthCallbackUrl");
|
||||||
|
|
||||||
var form = new Dictionary<string, string>();
|
var form = new Dictionary<string, string>
|
||||||
form.Add("client_id", appInfo.Id.ToString());
|
{
|
||||||
form.Add("client_secret", accessToken);
|
{"client_id", appInfo.Id.ToString()},
|
||||||
form.Add("grant_type", "authorization_code");
|
{"client_secret", accessToken},
|
||||||
form.Add("code", code);
|
{"grant_type", "authorization_code"},
|
||||||
form.Add("scope", "identify email guilds");
|
{"code", code},
|
||||||
form.Add("redirect_uri", callbackUrl);
|
{"scope", "identify email guilds"},
|
||||||
|
{"redirect_uri", callbackUrl}
|
||||||
|
};
|
||||||
|
|
||||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
|
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
|
||||||
var result = await client.PostAsync("/api/oauth2/token", new FormUrlEncodedContent(form));
|
var result = await client.PostAsync("/api/oauth2/token", new FormUrlEncodedContent(form));
|
||||||
|
|
|
@ -8,9 +8,9 @@ namespace Geekbot.net.WebApi.Controllers.Highscores
|
||||||
[Required]
|
[Required]
|
||||||
public ulong GuildId { get; set; }
|
public ulong GuildId { get; set; }
|
||||||
|
|
||||||
public HighscoreTypes Type { get; set; } = HighscoreTypes.messages;
|
public HighscoreTypes Type { get; } = HighscoreTypes.messages;
|
||||||
|
|
||||||
[Range(1, 150)]
|
[Range(1, 150)]
|
||||||
public int Amount { get; set; } = 50;
|
public int Amount { get; } = 50;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -55,25 +55,17 @@ namespace Geekbot.net.WebApi.Logging
|
||||||
|
|
||||||
private static NLog.LogLevel ToGeekbotLogLevel(LogLevel level)
|
private static NLog.LogLevel ToGeekbotLogLevel(LogLevel level)
|
||||||
{
|
{
|
||||||
switch (level)
|
return level switch
|
||||||
{
|
{
|
||||||
case LogLevel.Trace:
|
LogLevel.Trace => NLog.LogLevel.Trace,
|
||||||
return NLog.LogLevel.Trace;
|
LogLevel.Debug => NLog.LogLevel.Debug,
|
||||||
case LogLevel.Debug:
|
LogLevel.Information => NLog.LogLevel.Info,
|
||||||
return NLog.LogLevel.Debug;
|
LogLevel.Warning => NLog.LogLevel.Warn,
|
||||||
case LogLevel.Information:
|
LogLevel.Error => NLog.LogLevel.Error,
|
||||||
return NLog.LogLevel.Info;
|
LogLevel.Critical => NLog.LogLevel.Fatal,
|
||||||
case LogLevel.Warning:
|
LogLevel.None => NLog.LogLevel.Off,
|
||||||
return NLog.LogLevel.Warn;
|
_ => throw new ArgumentOutOfRangeException(nameof(level))
|
||||||
case LogLevel.Error:
|
};
|
||||||
return NLog.LogLevel.Error;
|
|
||||||
case LogLevel.Critical:
|
|
||||||
return NLog.LogLevel.Fatal;
|
|
||||||
case LogLevel.None:
|
|
||||||
return NLog.LogLevel.Off;
|
|
||||||
default:
|
|
||||||
throw new ArgumentOutOfRangeException(nameof(level));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue