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
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue