- Updated editorconfig rules to hopefully look a bit nicer.

- Removed configureawait(false) from everywhere as it doesnt' do anything in a console app and just makes the code look ugly
- Started using .WhenAll extension instead of Task.WhenAll to make it look nicer when chaining methods
This commit is contained in:
Kwoth
2021-12-28 21:14:26 +01:00
parent d093f7eed7
commit 723447c7d4
171 changed files with 1523 additions and 1594 deletions

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using System.Collections.Immutable;
using NadekoBot.Modules.Games.Common.Acrophobia;
using NadekoBot.Modules.Games.Services;
@@ -33,7 +33,7 @@ public partial class Games
game.OnVotingStarted += Game_OnVotingStarted;
game.OnUserVoted += Game_OnUserVoted;
_client.MessageReceived += _client_MessageReceived;
await game.Run().ConfigureAwait(false);
await game.Run();
}
finally
{
@@ -44,7 +44,7 @@ public partial class Games
}
else
{
await ReplyErrorLocalizedAsync(strs.acro_running).ConfigureAwait(false);
await ReplyErrorLocalizedAsync(strs.acro_running);
}
Task _client_MessageReceived(SocketMessage msg)
@@ -56,10 +56,9 @@ public partial class Games
{
try
{
var success = await game.UserInput(msg.Author.Id, msg.Author.ToString(), msg.Content)
.ConfigureAwait(false);
var success = await game.UserInput(msg.Author.Id, msg.Author.ToString(), msg.Content);
if (success)
await msg.DeleteAsync().ConfigureAwait(false);
await msg.DeleteAsync();
}
catch { }
});
@@ -87,15 +86,14 @@ public partial class Games
{
if (submissions.Length == 0)
{
await SendErrorAsync(GetText(strs.acrophobia), GetText(strs.acro_ended_no_sub)).ConfigureAwait(false);
await SendErrorAsync(GetText(strs.acrophobia), GetText(strs.acro_ended_no_sub));
return;
}
if (submissions.Length == 1)
{
await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
.WithDescription(GetText(strs.acro_winner_only(Format.Bold(submissions.First().Key.UserName))))
.WithFooter(submissions.First().Key.Input))
.ConfigureAwait(false);
.WithFooter(submissions.First().Key.Input));
return;
}
@@ -110,14 +108,14 @@ public partial class Games
--")))
.WithFooter(GetText(strs.acro_vote));
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
await ctx.Channel.EmbedAsync(embed);
}
private async Task Game_OnEnded(AcrophobiaGame game, ImmutableArray<KeyValuePair<AcrophobiaUser, int>> votes)
{
if (!votes.Any() || votes.All(x => x.Value == 0))
{
await SendErrorAsync(GetText(strs.acrophobia), GetText(strs.acro_no_votes_cast)).ConfigureAwait(false);
await SendErrorAsync(GetText(strs.acrophobia), GetText(strs.acro_no_votes_cast));
return;
}
var table = votes.OrderByDescending(v => v.Value);
@@ -128,7 +126,7 @@ public partial class Games
Format.Bold(winner.Value.ToString()))))
.WithFooter(winner.Key.Input);
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
await ctx.Channel.EmbedAsync(embed);
}
}
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using NadekoBot.Db;
using NadekoBot.Modules.Games.Services;
@@ -29,7 +29,7 @@ public partial class Games
uow.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, false);
await uow.SaveChangesAsync();
}
await ReplyConfirmLocalizedAsync(strs.cleverbot_disabled).ConfigureAwait(false);
await ReplyConfirmLocalizedAsync(strs.cleverbot_disabled);
return;
}
@@ -41,7 +41,7 @@ public partial class Games
await uow.SaveChangesAsync();
}
await ReplyConfirmLocalizedAsync(strs.cleverbot_enabled).ConfigureAwait(false);
await ReplyConfirmLocalizedAsync(strs.cleverbot_enabled);
}
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using System.Collections.Immutable;
using CommandLine;
@@ -63,36 +63,36 @@ public sealed class AcrophobiaGame : IDisposable
public async Task Run()
{
await OnStarted(this).ConfigureAwait(false);
await Task.Delay(Opts.SubmissionTime * 1000).ConfigureAwait(false);
await locker.WaitAsync().ConfigureAwait(false);
await OnStarted(this);
await Task.Delay(Opts.SubmissionTime * 1000);
await locker.WaitAsync();
try
{
if (submissions.Count == 0)
{
CurrentPhase = Phase.Ended;
await OnVotingStarted(this, ImmutableArray.Create<KeyValuePair<AcrophobiaUser, int>>()).ConfigureAwait(false);
await OnVotingStarted(this, ImmutableArray.Create<KeyValuePair<AcrophobiaUser, int>>());
return;
}
if (submissions.Count == 1)
{
CurrentPhase = Phase.Ended;
await OnVotingStarted(this, submissions.ToArray().ToImmutableArray()).ConfigureAwait(false);
await OnVotingStarted(this, submissions.ToArray().ToImmutableArray());
return;
}
CurrentPhase = Phase.Voting;
await OnVotingStarted(this, submissions.ToArray().ToImmutableArray()).ConfigureAwait(false);
await OnVotingStarted(this, submissions.ToArray().ToImmutableArray());
}
finally { locker.Release(); }
await Task.Delay(Opts.VoteTime * 1000).ConfigureAwait(false);
await locker.WaitAsync().ConfigureAwait(false);
await Task.Delay(Opts.VoteTime * 1000);
await locker.WaitAsync();
try
{
CurrentPhase = Phase.Ended;
await OnEnded(this, submissions.ToArray().ToImmutableArray()).ConfigureAwait(false);
await OnEnded(this, submissions.ToArray().ToImmutableArray());
}
finally { locker.Release(); }
}
@@ -115,7 +115,7 @@ public sealed class AcrophobiaGame : IDisposable
{
var user = new AcrophobiaUser(userId, userName, input.ToLowerInvariant().ToTitleCase());
await locker.WaitAsync().ConfigureAwait(false);
await locker.WaitAsync();
try
{
switch (CurrentPhase)

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using Newtonsoft.Json;
namespace NadekoBot.Modules.Games.Common.ChatterBot;
@@ -26,7 +26,7 @@ public class ChatterBotSession : IChatterBotSession
public async Task<string> Think(string message)
{
using var http = _httpFactory.CreateClient();
var res = await http.GetStringAsync(string.Format(ApiEndpoint, message)).ConfigureAwait(false);
var res = await http.GetStringAsync(string.Format(ApiEndpoint, message));
var cbr = JsonConvert.DeserializeObject<ChatterBotResponse>(res);
return cbr.BotSay.Replace("<br/>", "\n", StringComparison.InvariantCulture);
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using Newtonsoft.Json;
namespace NadekoBot.Modules.Games.Common.ChatterBot;
@@ -23,7 +23,7 @@ public class OfficialCleverbotSession : IChatterBotSession
public async Task<string> Think(string input)
{
using var http = _httpFactory.CreateClient();
var dataString = await http.GetStringAsync(string.Format(QueryString, input, _cs ?? "")).ConfigureAwait(false);
var dataString = await http.GetStringAsync(string.Format(QueryString, input, _cs ?? ""));
try
{
var data = JsonConvert.DeserializeObject<CleverbotResponse>(dataString);
@@ -67,8 +67,8 @@ public class CleverbotIOSession : IChatterBotSession
new KeyValuePair<string, string>("user", _user),
new KeyValuePair<string, string>("key", _key),
});
using var data = await _http.PostAsync(_createEndpoint, msg).ConfigureAwait(false);
var str = await data.Content.ReadAsStringAsync().ConfigureAwait(false);
using var data = await _http.PostAsync(_createEndpoint, msg);
var str = await data.Content.ReadAsStringAsync();
var obj = JsonConvert.DeserializeObject<CleverbotIOCreateResponse>(str);
if (obj.Status != "success")
throw new OperationCanceledException(obj.Status);
@@ -86,8 +86,8 @@ public class CleverbotIOSession : IChatterBotSession
new KeyValuePair<string, string>("nick", await _nick),
new KeyValuePair<string, string>("text", input),
});
using var data = await _http.PostAsync(_askEndpoint, msg).ConfigureAwait(false);
var str = await data.Content.ReadAsStringAsync().ConfigureAwait(false);
using var data = await _http.PostAsync(_askEndpoint, msg);
var str = await data.Content.ReadAsStringAsync();
var obj = JsonConvert.DeserializeObject<CleverbotIOAskResponse>(str);
if (obj.Status != "success")
throw new OperationCanceledException(obj.Status);

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using Image = SixLabors.ImageSharp.Image;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
@@ -51,9 +51,9 @@ public class GirlRating
//{
// http.AddFakeHeaders();
// using (var reponse = await http.PutAsync("https://transfer.sh/img.png", byteContent).ConfigureAwait(false))
// using (var reponse = await http.PutAsync("https://transfer.sh/img.png", byteContent))
// {
// url = await reponse.Content.ReadAsStringAsync().ConfigureAwait(false);
// url = await reponse.Content.ReadAsStringAsync();
// }
//}
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using System.Collections.Immutable;
namespace NadekoBot.Modules.Games.Common.Nunchi;
@@ -39,7 +39,7 @@ public sealed class NunchiGame : IDisposable
public async Task<bool> Join(ulong userId, string userName)
{
await _locker.WaitAsync().ConfigureAwait(false);
await _locker.WaitAsync();
try
{
if (CurrentPhase != Phase.Joining)
@@ -53,8 +53,8 @@ public sealed class NunchiGame : IDisposable
public async Task<bool> Initialize()
{
CurrentPhase = Phase.Joining;
await Task.Delay(30000).ConfigureAwait(false);
await _locker.WaitAsync().ConfigureAwait(false);
await Task.Delay(30000);
await _locker.WaitAsync();
try
{
if (_participants.Count < 3)
@@ -65,7 +65,7 @@ public sealed class NunchiGame : IDisposable
_killTimer = new(async state =>
{
await _locker.WaitAsync().ConfigureAwait(false);
await _locker.WaitAsync();
try
{
if (CurrentPhase != Phase.Playing)
@@ -88,7 +88,7 @@ public sealed class NunchiGame : IDisposable
public async Task Input(ulong userId, string userName, int input)
{
await _locker.WaitAsync().ConfigureAwait(false);
await _locker.WaitAsync();
try
{
if (CurrentPhase != Phase.Playing)
@@ -159,7 +159,7 @@ public sealed class NunchiGame : IDisposable
CurrentPhase = Phase.WaitingForNextRound;
var throwawayDelay = Task.Run(async () =>
{
await Task.Delay(_nextRoundTimeout).ConfigureAwait(false);
await Task.Delay(_nextRoundTimeout);
CurrentPhase = Phase.Playing;
var ___ = OnRoundStarted?.Invoke(this, CurrentNumber);
});

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Modules.Games.Common;
@@ -21,7 +21,7 @@ public class PollRunner
public async Task<bool> TryVote(IUserMessage msg)
{
PollVote voteObj;
await _locker.WaitAsync().ConfigureAwait(false);
await _locker.WaitAsync();
try
{
// has to be a user message

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using System.Text;
using CommandLine;
@@ -130,12 +130,12 @@ public class TicTacToe
{
if (_phase is Phase.Started or Phase.Ended)
{
await _channel.SendErrorAsync(_eb, user.Mention + GetText(strs.ttt_already_running)).ConfigureAwait(false);
await _channel.SendErrorAsync(_eb, user.Mention + GetText(strs.ttt_already_running));
return;
}
else if (_users[0] == user)
{
await _channel.SendErrorAsync(_eb, user.Mention + GetText(strs.ttt_against_yourself)).ConfigureAwait(false);
await _channel.SendErrorAsync(_eb, user.Mention + GetText(strs.ttt_against_yourself));
return;
}
@@ -145,7 +145,7 @@ public class TicTacToe
_timeoutTimer = new(async _ =>
{
await _moveLock.WaitAsync().ConfigureAwait(false);
await _moveLock.WaitAsync();
try
{
if (_phase == Phase.Ended)
@@ -158,9 +158,9 @@ public class TicTacToe
var del = _previousMessage?.DeleteAsync();
try
{
await _channel.EmbedAsync(GetEmbed(GetText(strs.ttt_time_expired))).ConfigureAwait(false);
await _channel.EmbedAsync(GetEmbed(GetText(strs.ttt_time_expired)));
if (del != null)
await del.ConfigureAwait(false);
await del;
}
catch { }
}
@@ -177,7 +177,7 @@ public class TicTacToe
_client.MessageReceived += Client_MessageReceived;
_previousMessage = await _channel.EmbedAsync(GetEmbed(GetText(strs.game_started))).ConfigureAwait(false);
_previousMessage = await _channel.EmbedAsync(GetEmbed(GetText(strs.game_started)));
}
private bool IsDraw()
@@ -197,7 +197,7 @@ public class TicTacToe
{
var _ = Task.Run(async () =>
{
await _moveLock.WaitAsync().ConfigureAwait(false);
await _moveLock.WaitAsync();
try
{
var curUser = _users[_curUserIndex];
@@ -265,9 +265,9 @@ public class TicTacToe
{
var del1 = msg.DeleteAsync();
var del2 = _previousMessage?.DeleteAsync();
try { _previousMessage = await _channel.EmbedAsync(GetEmbed(reason)).ConfigureAwait(false); } catch { }
try { await del1.ConfigureAwait(false); } catch { }
try { if (del2 != null) await del2.ConfigureAwait(false); } catch { }
try { _previousMessage = await _channel.EmbedAsync(GetEmbed(reason)); } catch { }
try { await del1; } catch { }
try { if (del2 != null) await del2; } catch { }
});
_curUserIndex ^= 1;

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using System.Text;
namespace NadekoBot.Modules.Games.Common.Trivia;
@@ -65,7 +65,7 @@ public class TriviaGame
CurrentQuestion = _questionPool.GetRandomQuestion(OldQuestions, _options.IsPokemon);
if (string.IsNullOrWhiteSpace(CurrentQuestion?.Answer) || string.IsNullOrWhiteSpace(CurrentQuestion.Question))
{
await Channel.SendErrorAsync(_eb, GetText(strs.trivia_game), GetText(strs.failed_loading_question)).ConfigureAwait(false);
await Channel.SendErrorAsync(_eb, GetText(strs.trivia_game), GetText(strs.failed_loading_question));
return;
}
OldQuestions.Add(CurrentQuestion); //add it to exclusion list so it doesn't show up again
@@ -85,7 +85,7 @@ public class TriviaGame
if (Uri.IsWellFormedUriString(CurrentQuestion.ImageUrl, UriKind.Absolute))
questionEmbed.WithImageUrl(CurrentQuestion.ImageUrl);
questionMessage = await Channel.EmbedAsync(questionEmbed).ConfigureAwait(false);
questionMessage = await Channel.EmbedAsync(questionEmbed);
}
catch (HttpException ex) when (ex.HttpCode is System.Net.HttpStatusCode.NotFound or System.Net.HttpStatusCode.Forbidden or System.Net.HttpStatusCode.BadRequest)
{
@@ -94,7 +94,7 @@ public class TriviaGame
catch (Exception ex)
{
Log.Warning(ex, "Error sending trivia embed");
await Task.Delay(2000).ConfigureAwait(false);
await Task.Delay(2000);
continue;
}
@@ -108,12 +108,11 @@ public class TriviaGame
try
{
//hint
await Task.Delay(_options.QuestionTimer * 1000 / 2, _triviaCancelSource.Token).ConfigureAwait(false);
await Task.Delay(_options.QuestionTimer * 1000 / 2, _triviaCancelSource.Token);
if (!_options.NoHint)
try
{
await questionMessage.ModifyAsync(m => m.Embed = questionEmbed.WithFooter(CurrentQuestion.GetHint()).Build())
.ConfigureAwait(false);
await questionMessage.ModifyAsync(m => m.Embed = questionEmbed.WithFooter(CurrentQuestion.GetHint()).Build());
}
catch (HttpException ex) when (ex.HttpCode is System.Net.HttpStatusCode.NotFound or System.Net.HttpStatusCode.Forbidden)
{
@@ -122,7 +121,7 @@ public class TriviaGame
catch (Exception ex) { Log.Warning(ex, "Error editing triva message"); }
//timeout
await Task.Delay(_options.QuestionTimer * 1000 / 2, _triviaCancelSource.Token).ConfigureAwait(false);
await Task.Delay(_options.QuestionTimer * 1000 / 2, _triviaCancelSource.Token);
}
catch (TaskCanceledException) { _timeoutCount = 0; } //means someone guessed the answer
@@ -142,17 +141,17 @@ public class TriviaGame
if (Uri.IsWellFormedUriString(CurrentQuestion.AnswerImageUrl, UriKind.Absolute))
embed.WithImageUrl(CurrentQuestion.AnswerImageUrl);
await Channel.EmbedAsync(embed).ConfigureAwait(false);
await Channel.EmbedAsync(embed);
if (_options.Timeout != 0 && ++_timeoutCount >= _options.Timeout)
await StopGame().ConfigureAwait(false);
await StopGame();
}
catch (Exception ex)
{
Log.Warning(ex, "Error sending trivia time's up message");
}
}
await Task.Delay(5000).ConfigureAwait(false);
await Task.Delay(5000);
}
}
@@ -163,7 +162,7 @@ public class TriviaGame
await Channel.EmbedAsync(_eb.Create().WithOkColor()
.WithAuthor("Trivia Game Ended")
.WithTitle("Final Results")
.WithDescription(GetLeaderboard())).ConfigureAwait(false);
.WithDescription(GetLeaderboard()));
}
public async Task StopGame()
@@ -203,7 +202,7 @@ public class TriviaGame
var guildUser = (IGuildUser)umsg.Author;
var guess = false;
await _guessLock.WaitAsync().ConfigureAwait(false);
await _guessLock.WaitAsync();
try
{
if (GameActive && CurrentQuestion.IsAnswerCorrect(umsg.Content) && !_triviaCancelSource.IsCancellationRequested)
@@ -229,7 +228,7 @@ public class TriviaGame
Format.Bold(CurrentQuestion.Answer))));
if (Uri.IsWellFormedUriString(CurrentQuestion.AnswerImageUrl, UriKind.Absolute))
embedS.WithImageUrl(CurrentQuestion.AnswerImageUrl);
await Channel.EmbedAsync(embedS).ConfigureAwait(false);
await Channel.EmbedAsync(embedS);
}
catch
{
@@ -237,7 +236,7 @@ public class TriviaGame
}
var reward = _config.Trivia.CurrencyReward;
if (reward > 0)
await _cs.AddAsync(guildUser, "Won trivia", reward, true).ConfigureAwait(false);
await _cs.AddAsync(guildUser, "Won trivia", reward, true);
return;
}
var embed = _eb.Create().WithOkColor()
@@ -245,7 +244,7 @@ public class TriviaGame
.WithDescription(GetText(strs.trivia_guess(guildUser.Mention, Format.Bold(CurrentQuestion.Answer))));
if (Uri.IsWellFormedUriString(CurrentQuestion.AnswerImageUrl, UriKind.Absolute))
embed.WithImageUrl(CurrentQuestion.AnswerImageUrl);
await Channel.EmbedAsync(embed).ConfigureAwait(false);
await Channel.EmbedAsync(embed);
}
catch (Exception ex) { Log.Warning(ex.ToString()); }
});

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using System.Diagnostics;
using NadekoBot.Modules.Games.Services;
using CommandLine;
@@ -83,24 +83,24 @@ public class TypingGame
var msg = await Channel.SendMessageAsync($"Starting new typing contest in **{time}**...", options: new()
{
RetryMode = RetryMode.AlwaysRetry
}).ConfigureAwait(false);
});
do
{
await Task.Delay(2000).ConfigureAwait(false);
await Task.Delay(2000);
time -= 2;
try { await msg.ModifyAsync(m => m.Content = $"Starting new typing contest in **{time}**..").ConfigureAwait(false); } catch { }
try { await msg.ModifyAsync(m => m.Content = $"Starting new typing contest in **{time}**.."); } catch { }
} while (time > 2);
await msg.ModifyAsync(m => {
m.Content = CurrentSentence.Replace(" ", " \x200B", StringComparison.InvariantCulture);
}).ConfigureAwait(false);
});
sw.Start();
HandleAnswers();
while (i > 0)
{
await Task.Delay(1000).ConfigureAwait(false);
await Task.Delay(1000);
i--;
if (!IsActive)
return;
@@ -110,7 +110,7 @@ public class TypingGame
catch { }
finally
{
await Stop().ConfigureAwait(false);
await Stop();
}
}
@@ -158,8 +158,7 @@ public class TypingGame
{
await this.Channel.SendConfirmAsync(_eb,
$":exclamation: A lot of people finished, here is the text for those still typing:" +
$"\n\n**{Format.Sanitize(CurrentSentence.Replace(" ", " \x200B", StringComparison.InvariantCulture)).SanitizeMentions(true)}**")
.ConfigureAwait(false);
$"\n\n**{Format.Sanitize(CurrentSentence.Replace(" ", " \x200B", StringComparison.InvariantCulture)).SanitizeMentions(true)}**");
}
}
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using NadekoBot.Modules.Games.Common;
using NadekoBot.Modules.Games.Services;
@@ -29,7 +29,7 @@ public partial class Games : NadekoModule<GamesService>
if (listArr.Length < 2)
return;
var rng = new NadekoRandom();
await SendConfirmAsync("🤔", listArr[rng.Next(0, listArr.Length)]).ConfigureAwait(false);
await SendConfirmAsync("🤔", listArr[rng.Next(0, listArr.Length)]);
}
[NadekoCommand, Aliases]
@@ -54,7 +54,7 @@ public partial class Games : NadekoModule<GamesService>
if (originalStream is null)
{
await ReplyErrorLocalizedAsync(strs.something_went_wrong).ConfigureAwait(false);
await ReplyErrorLocalizedAsync(strs.something_went_wrong);
return;
}
@@ -73,7 +73,7 @@ public partial class Games : NadekoModule<GamesService>
.AddField("Hot", gr.Hot.ToString("F2"), true)
.AddField("Crazy", gr.Crazy.ToString("F2"), true)
.AddField("Advice", gr.Advice, false)
.Build()).ConfigureAwait(false);
.Build());
}
private double NextDouble(double x, double y)
@@ -144,5 +144,5 @@ public partial class Games : NadekoModule<GamesService>
Many computer users run a modified version of the {guhnoo} system every day, without realizing it. Through a peculiar turn of events, the version of {guhnoo} which is widely used today is often called {loonix}, and many of its users are not aware that it is basically the {guhnoo} system, developed by the {guhnoo} Project.
There really is a {loonix}, and these people are using it, but it is just a part of the system they use. {loonix} is the kernel: the program in the system that allocates the machine's resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. {loonix} is normally used in combination with the {guhnoo} operating system: the whole system is basically {guhnoo} with {loonix} added, or {guhnoo}/{loonix}. All the so-called {loonix} distributions are really distributions of {guhnoo}/{loonix}."
).ConfigureAwait(false);
);
}

View File

@@ -69,7 +69,7 @@ public partial class Games
{
if (await _service.StopHangman(ctx.Channel.Id))
{
await ReplyConfirmLocalizedAsync(strs.hangman_stopped).ConfigureAwait(false);
await ReplyConfirmLocalizedAsync(strs.hangman_stopped);
}
}
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using NadekoBot.Modules.Games.Common.Nunchi;
using NadekoBot.Modules.Games.Services;
@@ -25,10 +25,10 @@ public partial class Games
if ((nunchi = _service.NunchiGames.GetOrAdd(ctx.Guild.Id, newNunchi)) != newNunchi)
{
// join it
if (!await nunchi.Join(ctx.User.Id, ctx.User.ToString()).ConfigureAwait(false))
if (!await nunchi.Join(ctx.User.Id, ctx.User.ToString()))
{
// if you failed joining, that means game is running or just ended
// await ReplyErrorLocalized("nunchi_already_started").ConfigureAwait(false);
// await ReplyErrorLocalized("nunchi_already_started");
return;
}
@@ -46,12 +46,12 @@ public partial class Games
nunchi.OnRoundStarted += Nunchi_OnRoundStarted;
_client.MessageReceived += _client_MessageReceived;
var success = await nunchi.Initialize().ConfigureAwait(false);
var success = await nunchi.Initialize();
if (!success)
{
if (_service.NunchiGames.TryRemove(ctx.Guild.Id, out var game))
game.Dispose();
await ConfirmLocalizedAsync(strs.nunchi_failed_to_start).ConfigureAwait(false);
await ConfirmLocalizedAsync(strs.nunchi_failed_to_start);
}
Task _client_MessageReceived(SocketMessage arg)
@@ -65,7 +65,7 @@ public partial class Games
return;
try
{
await nunchi.Input(arg.Author.Id, arg.Author.ToString(), number).ConfigureAwait(false);
await nunchi.Input(arg.Author.Id, arg.Author.ToString(), number);
}
catch
{

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using NadekoBot.Modules.Games.Services;
using NadekoBot.Services.Database.Models;
using System.Text;
@@ -27,7 +27,7 @@ public partial class Games
ctx.Channel.Id, arg);
if(poll is null)
{
await ReplyErrorLocalizedAsync(strs.poll_invalid_input).ConfigureAwait(false);
await ReplyErrorLocalizedAsync(strs.poll_invalid_input);
return;
}
if (_service.StartPoll(poll))
@@ -39,12 +39,11 @@ public partial class Games
.WithDescription(
Format.Bold(poll.Question) + "\n\n" +
string.Join("\n", poll.Answers
.Select(x => $"`{x.Index + 1}.` {Format.Bold(x.Text)}"))))
.ConfigureAwait(false);
.Select(x => $"`{x.Index + 1}.` {Format.Bold(x.Text)}"))));
}
else
{
await ReplyErrorLocalizedAsync(strs.poll_already_running).ConfigureAwait(false);
await ReplyErrorLocalizedAsync(strs.poll_already_running);
}
}
@@ -56,7 +55,7 @@ public partial class Games
if (!_service.ActivePolls.TryGetValue(ctx.Guild.Id, out var pr))
return;
await ctx.Channel.EmbedAsync(GetStats(pr.Poll, GetText(strs.current_poll_results))).ConfigureAwait(false);
await ctx.Channel.EmbedAsync(GetStats(pr.Poll, GetText(strs.current_poll_results)));
}
[NadekoCommand, Aliases]
@@ -71,8 +70,7 @@ public partial class Games
return;
var embed = GetStats(p, GetText(strs.poll_closed));
await ctx.Channel.EmbedAsync(embed)
.ConfigureAwait(false);
await ctx.Channel.EmbedAsync(embed);
}
public IEmbedBuilder GetStats(Poll poll, string title)

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Modules.Permissions.Common;
using NadekoBot.Modules.Permissions.Services;
@@ -81,16 +81,16 @@ public class ChatterBotService : IEarlyBehavior
public async Task<bool> TryAsk(IChatterBotSession cleverbot, ITextChannel channel, string message)
{
await channel.TriggerTypingAsync().ConfigureAwait(false);
await channel.TriggerTypingAsync();
var response = await cleverbot.Think(message).ConfigureAwait(false);
var response = await cleverbot.Think(message);
try
{
await channel.SendConfirmAsync(_eb, response.SanitizeMentions(true)).ConfigureAwait(false);
await channel.SendConfirmAsync(_eb, response.SanitizeMentions(true));
}
catch
{
await channel.SendConfirmAsync(_eb, response.SanitizeMentions(true)).ConfigureAwait(false); // try twice :\
await channel.SendConfirmAsync(_eb, response.SanitizeMentions(true)); // try twice :\
}
return true;
}
@@ -116,13 +116,13 @@ public class ChatterBotService : IEarlyBehavior
var returnMsg = _strings.GetText(strs.perm_prevent(index + 1,
Format.Bold(pc.Permissions[index].GetCommand(_cmd.GetPrefix(sg), sg))));
try { await usrMsg.Channel.SendErrorAsync(_eb, returnMsg).ConfigureAwait(false); } catch { }
try { await usrMsg.Channel.SendErrorAsync(_eb, returnMsg); } catch { }
Log.Information(returnMsg);
}
return true;
}
var cleverbotExecuted = await TryAsk(cbs, (ITextChannel)usrMsg.Channel, message).ConfigureAwait(false);
var cleverbotExecuted = await TryAsk(cbs, (ITextChannel)usrMsg.Channel, message);
if (cleverbotExecuted)
{
Log.Information($@"CleverBot Executed

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using NadekoBot.Common.Configs;
using NadekoBot.Modules.Games.Common;
@@ -25,7 +25,7 @@ public sealed class GamesConfigService : ConfigServiceBase<GamesConfig>
private void Migrate()
{
if (_data.Version < 1)
if (data.Version < 1)
{
ModifyConfig(c =>
{

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Modules.Games.Common;
using NadekoBot.Common.Collections;
@@ -90,10 +90,9 @@ public class PollService : IEarlyBehavior
private async Task Pr_OnVoted(IUserMessage msg, IGuildUser usr)
{
var toDelete = await msg.Channel.SendConfirmAsync(_eb,
_strs.GetText(strs.poll_voted(Format.Bold(usr.ToString())), usr.GuildId))
.ConfigureAwait(false);
_strs.GetText(strs.poll_voted(Format.Bold(usr.ToString())), usr.GuildId));
toDelete.DeleteAfter(5);
try { await msg.DeleteAsync().ConfigureAwait(false); } catch { }
try { await msg.DeleteAsync(); } catch { }
}
public async Task<bool> RunBehavior(IGuild guild, IUserMessage msg)
@@ -106,7 +105,7 @@ public class PollService : IEarlyBehavior
try
{
var voted = await poll.TryVote(msg).ConfigureAwait(false);
var voted = await poll.TryVote(msg);
if (voted)
{

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using NadekoBot.Modules.Games.Common;
using NadekoBot.Modules.Games.Services;
@@ -34,7 +34,7 @@ public partial class Games
}
else
{
await game.Start().ConfigureAwait(false);
await game.Start();
}
}
@@ -44,11 +44,11 @@ public partial class Games
{
if (_service.RunningContests.TryRemove(ctx.Guild.Id, out var game))
{
await game.Stop().ConfigureAwait(false);
await game.Stop();
return;
}
await SendErrorAsync("No contest to stop on this channel.").ConfigureAwait(false);
await SendErrorAsync("No contest to stop on this channel.");
}
@@ -62,7 +62,7 @@ public partial class Games
_games.AddTypingArticle(ctx.User, text);
await SendConfirmAsync("Added new article for typing game.").ConfigureAwait(false);
await SendConfirmAsync("Added new article for typing game.");
}
[NadekoCommand, Aliases]
@@ -76,12 +76,11 @@ public partial class Games
if (!articles.Any())
{
await SendErrorAsync($"{ctx.User.Mention} `No articles found on that page.`").ConfigureAwait(false);
await SendErrorAsync($"{ctx.User.Mention} `No articles found on that page.`");
return;
}
var i = (page - 1) * 15;
await SendConfirmAsync("List of articles for Type Race", string.Join("\n", articles.Select(a => $"`#{++i}` - {a.Text.TrimTo(50)}")))
.ConfigureAwait(false);
await SendConfirmAsync("List of articles for Type Race", string.Join("\n", articles.Select(a => $"`#{++i}` - {a.Text.TrimTo(50)}")));
}
[NadekoCommand, Aliases]

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using NadekoBot.Modules.Games.Common;
using NadekoBot.Modules.Games.Services;
@@ -23,20 +23,20 @@ public partial class Games
var (options, _) = OptionsParser.ParseFrom(new TicTacToe.Options(), args);
var channel = (ITextChannel)ctx.Channel;
await _sem.WaitAsync(1000).ConfigureAwait(false);
await _sem.WaitAsync(1000);
try
{
if (_service.TicTacToeGames.TryGetValue(channel.Id, out var game))
{
var _ = Task.Run(async () =>
{
await game.Start((IGuildUser)ctx.User).ConfigureAwait(false);
await game.Start((IGuildUser)ctx.User);
});
return;
}
game = new(base.Strings, this._client, channel, (IGuildUser)ctx.User, options, _eb);
_service.TicTacToeGames.Add(channel.Id, game);
await ReplyConfirmLocalizedAsync(strs.ttt_created).ConfigureAwait(false);
await ReplyConfirmLocalizedAsync(strs.ttt_created);
game.OnEnded += g =>
{

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using NadekoBot.Modules.Games.Common.Trivia;
using NadekoBot.Modules.Games.Services;
@@ -48,18 +48,17 @@ public partial class Games
{
try
{
await trivia.StartGame().ConfigureAwait(false);
await trivia.StartGame();
}
finally
{
_service.RunningTrivias.TryRemove(channel.Guild.Id, out trivia);
await trivia.EnsureStopped().ConfigureAwait(false);
await trivia.EnsureStopped();
}
return;
}
await SendErrorAsync(GetText(strs.trivia_already_running) + "\n" + trivia.CurrentQuestion)
.ConfigureAwait(false);
await SendErrorAsync(GetText(strs.trivia_already_running) + "\n" + trivia.CurrentQuestion);
}
[NadekoCommand, Aliases]
@@ -68,11 +67,11 @@ public partial class Games
{
if (_service.RunningTrivias.TryGetValue(ctx.Guild.Id, out var trivia))
{
await SendConfirmAsync(GetText(strs.leaderboard), trivia.GetLeaderboard()).ConfigureAwait(false);
await SendConfirmAsync(GetText(strs.leaderboard), trivia.GetLeaderboard());
return;
}
await ReplyErrorLocalizedAsync(strs.trivia_none).ConfigureAwait(false);
await ReplyErrorLocalizedAsync(strs.trivia_none);
}
[NadekoCommand, Aliases]
@@ -83,11 +82,11 @@ public partial class Games
if (_service.RunningTrivias.TryGetValue(channel.Guild.Id, out var trivia))
{
await trivia.StopGame().ConfigureAwait(false);
await trivia.StopGame();
return;
}
await ReplyErrorLocalizedAsync(strs.trivia_none).ConfigureAwait(false);
await ReplyErrorLocalizedAsync(strs.trivia_none);
}
}
}