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
|
||||
{
|
||||
var userRepo = _userRepository.Get(user.Id);
|
||||
if (userRepo != null && userRepo.UsedNames != null)
|
||||
if (userRepo?.UsedNames != null)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($":bust_in_silhouette: {user.Username} has been known as:");
|
||||
|
@ -50,7 +50,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
catch (Exception e)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
eb.Title = card.Name;
|
||||
eb.Description = card.Type;
|
||||
var eb = new EmbedBuilder
|
||||
{
|
||||
Title = card.Name,
|
||||
Description = card.Type
|
||||
};
|
||||
|
||||
if (card.Colors != null) eb.WithColor(GetColor(card.Colors));
|
||||
|
||||
|
@ -74,21 +76,15 @@ namespace Geekbot.net.Commands.Integrations
|
|||
private Color GetColor(IEnumerable<string> colors)
|
||||
{
|
||||
var color = colors.FirstOrDefault();
|
||||
switch (color)
|
||||
return color switch
|
||||
{
|
||||
case "Black":
|
||||
return new Color(203, 194, 191);
|
||||
case "White":
|
||||
return new Color(255, 251, 213);
|
||||
case "Blue":
|
||||
return new Color(170, 224, 250);
|
||||
case "Red":
|
||||
return new Color(250, 170, 143);
|
||||
case "Green":
|
||||
return new Color(155, 211, 174);
|
||||
default:
|
||||
return new Color(204, 194, 212);
|
||||
}
|
||||
"Black" => new Color(203, 194, 191),
|
||||
"White" => new Color(255, 251, 213),
|
||||
"Blue" => new Color(170, 224, 250),
|
||||
"Red" => new Color(250, 170, 143),
|
||||
"Green" => new Color(155, 211, 174),
|
||||
_ => new Color(204, 194, 212)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,43 +25,43 @@ namespace Geekbot.net.Commands.Integrations.UbranDictionary
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
using var client = new HttpClient
|
||||
{
|
||||
client.BaseAddress = new Uri("https://api.urbandictionary.com");
|
||||
var response = await client.GetAsync($"/v0/define?term={word}");
|
||||
response.EnsureSuccessStatusCode();
|
||||
BaseAddress = new Uri("https://api.urbandictionary.com")
|
||||
};
|
||||
var response = await client.GetAsync($"/v0/define?term={word}");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var definitions = JsonConvert.DeserializeObject<UrbanResponseDto>(stringResponse);
|
||||
if (definitions.List.Count == 0)
|
||||
{
|
||||
await ReplyAsync("That word hasn't been defined...");
|
||||
return;
|
||||
}
|
||||
|
||||
var definition = definitions.List.First(e => !string.IsNullOrWhiteSpace(e.Example));
|
||||
|
||||
var description = definition.Definition;
|
||||
if (description.Length > 1801)
|
||||
{
|
||||
description = description.Substring(0, 1800) + " [...]";
|
||||
}
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithAuthor(new EmbedAuthorBuilder
|
||||
{
|
||||
Name = definition.Word,
|
||||
Url = definition.Permalink
|
||||
});
|
||||
eb.WithColor(new Color(239, 255, 0));
|
||||
if (!string.IsNullOrEmpty(definition.Definition)) eb.Description = description;
|
||||
if (!string.IsNullOrEmpty(definition.Example)) eb.AddField("Example", definition.Example ?? "(no example given...)");
|
||||
if (!string.IsNullOrEmpty(definition.ThumbsUp)) eb.AddInlineField("Upvotes", definition.ThumbsUp);
|
||||
if (!string.IsNullOrEmpty(definition.ThumbsDown)) eb.AddInlineField("Downvotes", definition.ThumbsDown);
|
||||
if (definitions.Tags?.Length > 0) eb.AddField("Tags", string.Join(", ", definitions.Tags));
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var definitions = JsonConvert.DeserializeObject<UrbanResponseDto>(stringResponse);
|
||||
if (definitions.List.Count == 0)
|
||||
{
|
||||
await ReplyAsync("That word hasn't been defined...");
|
||||
return;
|
||||
}
|
||||
|
||||
var definition = definitions.List.First(e => !string.IsNullOrWhiteSpace(e.Example));
|
||||
|
||||
var description = definition.Definition;
|
||||
if (description.Length > 1801)
|
||||
{
|
||||
description = description.Substring(0, 1800) + " [...]";
|
||||
}
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithAuthor(new EmbedAuthorBuilder
|
||||
{
|
||||
Name = definition.Word,
|
||||
Url = definition.Permalink
|
||||
});
|
||||
eb.WithColor(new Color(239, 255, 0));
|
||||
if (!string.IsNullOrEmpty(definition.Definition)) eb.Description = description;
|
||||
if (!string.IsNullOrEmpty(definition.Example)) eb.AddField("Example", definition.Example ?? "(no example given...)");
|
||||
if (!string.IsNullOrEmpty(definition.ThumbsUp)) eb.AddInlineField("Upvotes", definition.ThumbsUp);
|
||||
if (!string.IsNullOrEmpty(definition.ThumbsDown)) eb.AddInlineField("Downvotes", definition.ThumbsDown);
|
||||
if (definitions.Tags?.Length > 0) eb.AddField("Tags", string.Join(", ", definitions.Tags));
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -23,24 +23,27 @@ namespace Geekbot.net.Commands.Randomness.Cat
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
using var client = new HttpClient
|
||||
{
|
||||
client.BaseAddress = new Uri("https://aws.random.cat");
|
||||
var response = await client.GetAsync("/meow");
|
||||
response.EnsureSuccessStatusCode();
|
||||
BaseAddress = new Uri("https://aws.random.cat")
|
||||
};
|
||||
var response = await client.GetAsync("/meow");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var catFile = JsonConvert.DeserializeObject<CatResponseDto>(stringResponse);
|
||||
var eb = new EmbedBuilder();
|
||||
eb.ImageUrl = catFile.File;
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var catFile = JsonConvert.DeserializeObject<CatResponseDto>(stringResponse);
|
||||
var eb = new EmbedBuilder
|
||||
{
|
||||
await ReplyAsync("Seems like the dog cought the cat (error occured)");
|
||||
}
|
||||
ImageUrl = catFile.File
|
||||
};
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch
|
||||
{
|
||||
await ReplyAsync("Seems like the dog cought the cat (error occured)");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace Geekbot.net.Commands.Randomness
|
|||
while (num > 0)
|
||||
{
|
||||
listOfInts.Add(num % 10);
|
||||
num = num / 10;
|
||||
num /= 10;
|
||||
}
|
||||
|
||||
listOfInts.Reverse();
|
||||
|
|
|
@ -23,23 +23,21 @@ namespace Geekbot.net.Commands.Randomness.Chuck
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
|
||||
var response = await client.GetAsync("https://api.chucknorris.io/jokes/random");
|
||||
response.EnsureSuccessStatusCode();
|
||||
using var client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
|
||||
var response = await client.GetAsync("https://api.chucknorris.io/jokes/random");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var data = JsonConvert.DeserializeObject<ChuckNorrisJokeResponseDto>(stringResponse);
|
||||
await ReplyAsync(data.Value);
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
await ReplyAsync("Api down...");
|
||||
}
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var data = JsonConvert.DeserializeObject<ChuckNorrisJokeResponseDto>(stringResponse);
|
||||
await ReplyAsync(data.Value);
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
await ReplyAsync("Api down...");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -23,23 +23,21 @@ namespace Geekbot.net.Commands.Randomness.Dad
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
|
||||
var response = await client.GetAsync("https://icanhazdadjoke.com/");
|
||||
response.EnsureSuccessStatusCode();
|
||||
using var client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
|
||||
var response = await client.GetAsync("https://icanhazdadjoke.com/");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var data = JsonConvert.DeserializeObject<DadJokeResponseDto>(stringResponse);
|
||||
await ReplyAsync(data.Joke);
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
await ReplyAsync("Api down...");
|
||||
}
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var data = JsonConvert.DeserializeObject<DadJokeResponseDto>(stringResponse);
|
||||
await ReplyAsync(data.Joke);
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
await ReplyAsync("Api down...");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -23,24 +23,26 @@ namespace Geekbot.net.Commands.Randomness.Dog
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
try
|
||||
{
|
||||
try
|
||||
using var client = new HttpClient
|
||||
{
|
||||
client.BaseAddress = new Uri("http://random.dog");
|
||||
var response = await client.GetAsync("/woof.json");
|
||||
response.EnsureSuccessStatusCode();
|
||||
BaseAddress = new Uri("http://random.dog")
|
||||
};
|
||||
var response = await client.GetAsync("/woof.json");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var dogFile = JsonConvert.DeserializeObject<DogResponseDto>(stringResponse);
|
||||
var eb = new EmbedBuilder();
|
||||
eb.ImageUrl = dogFile.Url;
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var dogFile = JsonConvert.DeserializeObject<DogResponseDto>(stringResponse);
|
||||
var eb = new EmbedBuilder
|
||||
{
|
||||
await ReplyAsync($"Seems like the dog got lost (error occured)\r\n{e.Message}");
|
||||
}
|
||||
ImageUrl = dogFile.Url
|
||||
};
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
await ReplyAsync($"Seems like the dog got lost (error occured)\r\n{e.Message}");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -21,13 +21,11 @@ namespace Geekbot.net.Commands.Randomness
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var client = new WebClient())
|
||||
{
|
||||
var url = new Uri("http://taskinoz.com/gdq/api/");
|
||||
var response = client.DownloadString(url);
|
||||
using var client = new WebClient();
|
||||
var url = new Uri("http://taskinoz.com/gdq/api/");
|
||||
var response = client.DownloadString(url);
|
||||
|
||||
await ReplyAsync(response);
|
||||
}
|
||||
await ReplyAsync(response);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -23,23 +23,21 @@ namespace Geekbot.net.Commands.Randomness.Kanye
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
|
||||
var response = await client.GetAsync("https://api.kanye.rest/");
|
||||
response.EnsureSuccessStatusCode();
|
||||
using var client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
|
||||
var response = await client.GetAsync("https://api.kanye.rest/");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var data = JsonConvert.DeserializeObject<KanyeResponseDto>(stringResponse);
|
||||
await ReplyAsync(data.Quote);
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
await ReplyAsync("Api down...");
|
||||
}
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var data = JsonConvert.DeserializeObject<KanyeResponseDto>(stringResponse);
|
||||
await ReplyAsync(data.Quote);
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
await ReplyAsync("Api down...");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -56,8 +56,8 @@ namespace Geekbot.net.Commands.Randomness
|
|||
}
|
||||
|
||||
var reply = ":heartpulse: **Matchmaking** :heartpulse:\r\n";
|
||||
reply = reply + $":two_hearts: {user1.Mention} :heart: {user2.Mention} :two_hearts:\r\n";
|
||||
reply = reply + $"0% [{BlockCounter(shippingRate)}] 100% - {DeterminateSuccess(shippingRate)}";
|
||||
reply += $":two_hearts: {user1.Mention} :heart: {user2.Mention} :two_hearts:\r\n";
|
||||
reply += $"0% [{BlockCounter(shippingRate)}] 100% - {DeterminateSuccess(shippingRate)}";
|
||||
await ReplyAsync(reply);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -87,13 +87,13 @@ namespace Geekbot.net.Commands.Randomness
|
|||
for (var i = 1; i <= 10; i++)
|
||||
if (i <= amount)
|
||||
{
|
||||
blocks = blocks + ":white_medium_small_square:";
|
||||
blocks += ":white_medium_small_square:";
|
||||
if (i == amount)
|
||||
blocks = blocks + $" {rate}% ";
|
||||
blocks += $" {rate}% ";
|
||||
}
|
||||
else
|
||||
{
|
||||
blocks = blocks + ":black_medium_small_square:";
|
||||
blocks += ":black_medium_small_square:";
|
||||
}
|
||||
|
||||
return blocks;
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace Geekbot.net.Commands.User
|
|||
else
|
||||
{
|
||||
var target = await GetUser(user.Id);
|
||||
target.Karma = target.Karma + 1;
|
||||
target.Karma += 1;
|
||||
SetUser(target);
|
||||
|
||||
actor.TimeOut = DateTimeOffset.Now;
|
||||
|
@ -93,7 +93,7 @@ namespace Geekbot.net.Commands.User
|
|||
else
|
||||
{
|
||||
var target = await GetUser(user.Id);
|
||||
target.Karma = target.Karma - 1;
|
||||
target.Karma -= 1;
|
||||
SetUser(target);
|
||||
|
||||
actor.TimeOut = DateTimeOffset.Now;
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace Geekbot.net.Commands.User.Ranking
|
|||
return;
|
||||
}
|
||||
|
||||
int guildMessages = 0;
|
||||
var guildMessages = 0;
|
||||
if (type == HighscoreTypes.messages)
|
||||
{
|
||||
guildMessages = _database.Messages
|
||||
|
@ -99,7 +99,7 @@ namespace Geekbot.net.Commands.User.Ranking
|
|||
: $"**{user.Key.Id}**");
|
||||
|
||||
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");
|
||||
|
||||
highscorePlace++;
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace Geekbot.net.Commands.User
|
|||
|
||||
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
|
||||
?.FirstOrDefault(e => e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.UserId.Equals(userInfo.Id.AsLong()))
|
||||
|
|
|
@ -29,34 +29,34 @@ namespace Geekbot.net.Commands.Utils.Changelog
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
using var client = new HttpClient
|
||||
{
|
||||
client.BaseAddress = new Uri("https://api.github.com");
|
||||
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent",
|
||||
"http://developer.github.com/v3/#user-agent-required");
|
||||
var response = await client.GetAsync("/repos/pizzaandcoffee/geekbot.net/commits");
|
||||
response.EnsureSuccessStatusCode();
|
||||
BaseAddress = new Uri("https://api.github.com")
|
||||
};
|
||||
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent",
|
||||
"http://developer.github.com/v3/#user-agent-required");
|
||||
var response = await client.GetAsync("/repos/pizzaandcoffee/geekbot.net/commits");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var commits = JsonConvert.DeserializeObject<List<CommitDto>>(stringResponse);
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithColor(new Color(143, 165, 102));
|
||||
eb.WithAuthor(new EmbedAuthorBuilder
|
||||
{
|
||||
IconUrl = _client.CurrentUser.GetAvatarUrl(),
|
||||
Name = "Latest Updates",
|
||||
Url = "https://geekbot.pizzaandcoffee.rocks/updates"
|
||||
});
|
||||
var sb = new StringBuilder();
|
||||
foreach (var commit in commits.Take(10))
|
||||
sb.AppendLine($"- {commit.Commit.Message} ({commit.Commit.Author.Date:yyyy-MM-dd})");
|
||||
eb.Description = sb.ToString();
|
||||
eb.WithFooter(new EmbedFooterBuilder
|
||||
{
|
||||
Text = $"List generated from github commits on {DateTime.Now:yyyy-MM-dd}"
|
||||
});
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var commits = JsonConvert.DeserializeObject<List<CommitDto>>(stringResponse);
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithColor(new Color(143, 165, 102));
|
||||
eb.WithAuthor(new EmbedAuthorBuilder
|
||||
{
|
||||
IconUrl = _client.CurrentUser.GetAvatarUrl(),
|
||||
Name = "Latest Updates",
|
||||
Url = "https://geekbot.pizzaandcoffee.rocks/updates"
|
||||
});
|
||||
var sb = new StringBuilder();
|
||||
foreach (var commit in commits.Take(10))
|
||||
sb.AppendLine($"- {commit.Commit.Message} ({commit.Commit.Author.Date:yyyy-MM-dd})");
|
||||
eb.Description = sb.ToString();
|
||||
eb.WithFooter(new EmbedFooterBuilder
|
||||
{
|
||||
Text = $"List generated from github commits on {DateTime.Now:yyyy-MM-dd}"
|
||||
});
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
|||
return;
|
||||
}
|
||||
|
||||
var random = _randomNumberGenerator.Next(0, s.Count());
|
||||
var random = _randomNumberGenerator.Next(0, s.Count);
|
||||
var quote = s[random];
|
||||
|
||||
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()))
|
||||
.OrderByDescending(e => e.InternalId).FirstOrDefault();
|
||||
int internalId = 1;
|
||||
var internalId = 1;
|
||||
if (last != null) internalId = last.InternalId + 1;
|
||||
return new QuoteModel()
|
||||
{
|
||||
|
|
|
@ -54,23 +54,16 @@ namespace Geekbot.net.Database.LoggingAdapter
|
|||
|
||||
private static LogLevel ToGeekbotLogLevel(NpgsqlLogLevel level)
|
||||
{
|
||||
switch (level)
|
||||
return level switch
|
||||
{
|
||||
case NpgsqlLogLevel.Trace:
|
||||
return LogLevel.Trace;
|
||||
case NpgsqlLogLevel.Debug:
|
||||
return LogLevel.Debug;
|
||||
case NpgsqlLogLevel.Info:
|
||||
return LogLevel.Info;
|
||||
case NpgsqlLogLevel.Warn:
|
||||
return LogLevel.Warn;
|
||||
case NpgsqlLogLevel.Error:
|
||||
return LogLevel.Error;
|
||||
case NpgsqlLogLevel.Fatal:
|
||||
return LogLevel.Fatal;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(level));
|
||||
}
|
||||
NpgsqlLogLevel.Trace => LogLevel.Trace,
|
||||
NpgsqlLogLevel.Debug => LogLevel.Debug,
|
||||
NpgsqlLogLevel.Info => LogLevel.Info,
|
||||
NpgsqlLogLevel.Warn => LogLevel.Warn,
|
||||
NpgsqlLogLevel.Error => LogLevel.Error,
|
||||
NpgsqlLogLevel.Fatal => LogLevel.Fatal,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(level))
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@ namespace Geekbot.net.Lib.Clients
|
|||
ReloadClient();
|
||||
}
|
||||
|
||||
public bool ReloadClient()
|
||||
private bool ReloadClient()
|
||||
{
|
||||
var malCredentials = _globalSettings.GetKey("MalCredentials");
|
||||
if (!string.IsNullOrEmpty(malCredentials))
|
||||
|
|
|
@ -4,7 +4,7 @@ using Discord.Commands;
|
|||
|
||||
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 override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace Geekbot.net.Lib.Converters
|
|||
{
|
||||
public class MtgManaConverter : IMtgManaConverter
|
||||
{
|
||||
private Dictionary<string, string> _manaDict;
|
||||
private readonly Dictionary<string, string> _manaDict;
|
||||
|
||||
public MtgManaConverter()
|
||||
{
|
||||
|
|
|
@ -20,26 +20,15 @@ namespace Geekbot.net.Lib.Highscores
|
|||
|
||||
public Dictionary<HighscoreUserDto, int> GetHighscoresWithUserData(HighscoreTypes type, ulong guildId, int amount)
|
||||
{
|
||||
Dictionary<ulong, int> list;
|
||||
switch (type)
|
||||
var list = type switch
|
||||
{
|
||||
case HighscoreTypes.messages:
|
||||
list = GetMessageList(guildId, amount);
|
||||
break;
|
||||
case HighscoreTypes.karma:
|
||||
list = GetKarmaList(guildId, amount);
|
||||
break;
|
||||
case HighscoreTypes.rolls:
|
||||
list = GetRollsList(guildId, amount);
|
||||
break;
|
||||
case HighscoreTypes.cookies:
|
||||
list = GetCookiesList(guildId, amount);
|
||||
break;
|
||||
default:
|
||||
list = new Dictionary<ulong, int>();
|
||||
break;
|
||||
}
|
||||
|
||||
HighscoreTypes.messages => GetMessageList(guildId, amount),
|
||||
HighscoreTypes.karma => GetKarmaList(guildId, amount),
|
||||
HighscoreTypes.rolls => GetRollsList(guildId, amount),
|
||||
HighscoreTypes.cookies => GetCookiesList(guildId, amount),
|
||||
_ => new Dictionary<ulong, int>()
|
||||
};
|
||||
|
||||
if (!list.Any())
|
||||
{
|
||||
throw new HighscoreListEmptyException($"No {type} found for guild {guildId}");
|
||||
|
@ -103,8 +92,8 @@ namespace Geekbot.net.Lib.Highscores
|
|||
.Take(amount)
|
||||
.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
|
||||
.Where(k => k.GuildId.Equals(guildId.AsLong()))
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Geekbot.net.Lib.Levels
|
||||
{
|
||||
public class LevelCalc : ILevelCalc
|
||||
{
|
||||
private int[] _levels;
|
||||
private readonly int[] _levels;
|
||||
|
||||
public LevelCalc()
|
||||
{
|
||||
|
@ -21,13 +22,7 @@ namespace Geekbot.net.Lib.Levels
|
|||
|
||||
public int GetLevel(int? messages)
|
||||
{
|
||||
var returnVal = 1;
|
||||
foreach (var level in _levels)
|
||||
{
|
||||
if (level > messages) break;
|
||||
returnVal++;
|
||||
}
|
||||
return returnVal;
|
||||
return 1 + _levels.TakeWhile(level => !(level > messages)).Count();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ namespace Geekbot.net.Lib.Logger
|
|||
}
|
||||
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
|
||||
{
|
||||
Message = new MessageDto.MessageContent
|
||||
|
|
|
@ -63,8 +63,11 @@ namespace Geekbot.net.Lib.ReactionListener
|
|||
_listener[messageId].Add(emoji, role.Id);
|
||||
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);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
|
|
@ -32,14 +32,16 @@ namespace Geekbot.net.WebApi.Controllers.Callback
|
|||
var accessToken = _globalSettings.GetKey("OAuthToken");
|
||||
var callbackUrl = _globalSettings.GetKey("OAuthCallbackUrl");
|
||||
|
||||
var form = new Dictionary<string, string>();
|
||||
form.Add("client_id", appInfo.Id.ToString());
|
||||
form.Add("client_secret", accessToken);
|
||||
form.Add("grant_type", "authorization_code");
|
||||
form.Add("code", code);
|
||||
form.Add("scope", "identify email guilds");
|
||||
form.Add("redirect_uri", callbackUrl);
|
||||
|
||||
var form = new Dictionary<string, string>
|
||||
{
|
||||
{"client_id", appInfo.Id.ToString()},
|
||||
{"client_secret", accessToken},
|
||||
{"grant_type", "authorization_code"},
|
||||
{"code", code},
|
||||
{"scope", "identify email guilds"},
|
||||
{"redirect_uri", callbackUrl}
|
||||
};
|
||||
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
|
||||
var result = await client.PostAsync("/api/oauth2/token", new FormUrlEncodedContent(form));
|
||||
result.EnsureSuccessStatusCode();
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Geekbot.net.WebApi.Controllers.Highscores
|
|||
[Required]
|
||||
public ulong GuildId { get; set; }
|
||||
|
||||
public HighscoreTypes Type { get; set; } = HighscoreTypes.messages;
|
||||
public HighscoreTypes Type { get; } = HighscoreTypes.messages;
|
||||
|
||||
[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)
|
||||
{
|
||||
switch (level)
|
||||
return level switch
|
||||
{
|
||||
case LogLevel.Trace:
|
||||
return NLog.LogLevel.Trace;
|
||||
case LogLevel.Debug:
|
||||
return NLog.LogLevel.Debug;
|
||||
case LogLevel.Information:
|
||||
return NLog.LogLevel.Info;
|
||||
case LogLevel.Warning:
|
||||
return NLog.LogLevel.Warn;
|
||||
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));
|
||||
}
|
||||
LogLevel.Trace => NLog.LogLevel.Trace,
|
||||
LogLevel.Debug => NLog.LogLevel.Debug,
|
||||
LogLevel.Information => NLog.LogLevel.Info,
|
||||
LogLevel.Warning => NLog.LogLevel.Warn,
|
||||
LogLevel.Error => NLog.LogLevel.Error,
|
||||
LogLevel.Critical => NLog.LogLevel.Fatal,
|
||||
LogLevel.None => NLog.LogLevel.Off,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(level))
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue