From 6bc4bb7803a3633ec2ecb38686008d43e86b5311 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Fri, 16 Jun 2017 01:55:14 +0200 Subject: [PATCH] moved some stuff around --- .../Modules/Gambling/Commands/AnimalRacing.cs | 14 ++++++---- .../Gambling/Commands/CurrencyEvents.cs | 2 +- .../Modules/Games/Commands/Acropobia.cs | 4 +-- .../Games/Commands/Hangman/HangmanGame.cs | 4 +-- .../Games/Commands/Models/TypingGame.cs | 4 +-- .../Games/Commands/Trivia/TriviaGame.cs | 4 +-- src/NadekoBot/Modules/NadekoModule.cs | 28 +++++++++++-------- src/NadekoBot/Services/CommandHandler.cs | 1 - src/NadekoBot/Services/Games/GamesService.cs | 11 ++++---- .../Services/Searches/SearchesService.cs | 4 +-- 10 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs index 70b0dd14..4db985e5 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs @@ -250,12 +250,16 @@ namespace NadekoBot.Modules.Gambling private Task Client_MessageReceived(SocketMessage imsg) { - var msg = imsg as SocketUserMessage; - if (msg == null) + var _ = Task.Run(() => + { + var msg = imsg as SocketUserMessage; + if (msg == null) + return Task.CompletedTask; + if ((msg.Author.Id == _client.CurrentUser.Id) || !(imsg.Channel is ITextChannel) || imsg.Channel != _raceChannel) + return Task.CompletedTask; + Interlocked.Increment(ref _messagesSinceGameStarted); return Task.CompletedTask; - if ((msg.Author.Id == _client.CurrentUser.Id) || !(imsg.Channel is ITextChannel) || imsg.Channel != _raceChannel) - return Task.CompletedTask; - Interlocked.Increment(ref _messagesSinceGameStarted); + }); return Task.CompletedTask; } diff --git a/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs b/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs index 9ae419be..76369c15 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs @@ -122,7 +122,7 @@ namespace NadekoBot.Modules.Gambling }); } - return Task.Delay(0); + return Task.CompletedTask; } public async Task FlowerReactionEvent(ICommandContext context, int amount) diff --git a/src/NadekoBot/Modules/Games/Commands/Acropobia.cs b/src/NadekoBot/Modules/Games/Commands/Acropobia.cs index dd1c49b2..0d8e337f 100644 --- a/src/NadekoBot/Modules/Games/Commands/Acropobia.cs +++ b/src/NadekoBot/Modules/Games/Commands/Acropobia.cs @@ -184,9 +184,8 @@ $@"-- await End().ConfigureAwait(false); } - private async Task PotentialAcro(SocketMessage arg) + private Task PotentialAcro(SocketMessage arg) { - await Task.Yield(); var _ = Task.Run(async () => { try @@ -285,6 +284,7 @@ $@"-- _log.Warn(ex); } }); + return Task.CompletedTask; } public async Task End() diff --git a/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs b/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs index 7cecf927..24ca87c9 100644 --- a/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs +++ b/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs @@ -117,9 +117,8 @@ namespace NadekoBot.Modules.Games.Hangman await GameChannel.EmbedAsync(embed.WithOkColor()).ConfigureAwait(false); } - private async Task PotentialGuess(SocketMessage msg) + private Task PotentialGuess(SocketMessage msg) { - await Task.Yield(); var _ = Task.Run(async () => { try @@ -194,6 +193,7 @@ namespace NadekoBot.Modules.Games.Hangman } catch (Exception ex) { _log.Warn(ex); } }); + return Task.CompletedTask; } public string GetHangman() => $@". ┌─────┐ diff --git a/src/NadekoBot/Modules/Games/Commands/Models/TypingGame.cs b/src/NadekoBot/Modules/Games/Commands/Models/TypingGame.cs index eff53fb4..db670fd2 100644 --- a/src/NadekoBot/Modules/Games/Commands/Models/TypingGame.cs +++ b/src/NadekoBot/Modules/Games/Commands/Models/TypingGame.cs @@ -107,9 +107,8 @@ namespace NadekoBot.Modules.Games.Models _client.MessageReceived += AnswerReceived; } - private async Task AnswerReceived(SocketMessage imsg) + private Task AnswerReceived(SocketMessage imsg) { - await Task.Yield(); var _ = Task.Run(async () => { try @@ -145,6 +144,7 @@ namespace NadekoBot.Modules.Games.Models } catch (Exception ex) { _log.Warn(ex); } }); + return Task.CompletedTask; } private bool Judge(int errors, int textLength) => errors <= textLength / 25; diff --git a/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs b/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs index 8a89dbbf..ea6e1e2c 100644 --- a/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs +++ b/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs @@ -178,9 +178,8 @@ namespace NadekoBot.Modules.Games.Trivia try { await Channel.SendConfirmAsync(GetText("trivia_game"), GetText("trivia_stopping")).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } } - private async Task PotentialGuess(SocketMessage imsg) + private Task PotentialGuess(SocketMessage imsg) { - await Task.Yield(); var _ = Task.Run(async () => { try @@ -242,6 +241,7 @@ namespace NadekoBot.Modules.Games.Trivia } catch (Exception ex) { _log.Warn(ex); } }); + return Task.CompletedTask; } public string GetLeaderboard() diff --git a/src/NadekoBot/Modules/NadekoModule.cs b/src/NadekoBot/Modules/NadekoModule.cs index 1282fd5a..cfc96dce 100644 --- a/src/NadekoBot/Modules/NadekoModule.cs +++ b/src/NadekoBot/Modules/NadekoModule.cs @@ -14,10 +14,10 @@ namespace NadekoBot.Modules { protected readonly Logger _log; protected CultureInfo _cultureInfo; - + public readonly string ModuleTypeName; public readonly string LowerModuleTypeName; - + public NadekoStrings _strings { get; set; } public CommandHandler _cmdHandler { get; set; } public ILocalization _localization { get; set; } @@ -34,7 +34,7 @@ namespace NadekoBot.Modules protected override void BeforeExecute() { - _cultureInfo =_localization.GetCultureInfo(Context.Guild?.Id); + _cultureInfo = _localization.GetCultureInfo(Context.Guild?.Id); } //public Task ReplyConfirmLocalized(string titleKey, string textKey, string url = null, string footer = null) @@ -56,7 +56,7 @@ namespace NadekoBot.Modules // var text = NadekoBot.ResponsesResourceManager.GetString(textKey, cultureInfo); // return Context.Channel.SendErrorAsync(title, text, url, footer); //} - + protected string GetText(string key) => _strings.GetText(key, _cultureInfo, LowerModuleTypeName); @@ -111,16 +111,20 @@ namespace NadekoBot.Modules Task MessageReceived(SocketMessage arg) { - if (!(arg is SocketUserMessage userMsg) || - !(userMsg.Channel is ITextChannel chan) || - userMsg.Author.Id != userId || - userMsg.Channel.Id != channelId) + var _ = Task.Run(() => { - return Task.CompletedTask; - } + if (!(arg is SocketUserMessage userMsg) || + !(userMsg.Channel is ITextChannel chan) || + userMsg.Author.Id != userId || + userMsg.Channel.Id != channelId) + { + return Task.CompletedTask; + } - userInputTask.SetResult(arg.Content); - userMsg.DeleteAfter(1); + userInputTask.SetResult(arg.Content); + userMsg.DeleteAfter(1); + return Task.CompletedTask; + }); return Task.CompletedTask; } } diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index 193515b1..2177ce01 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -187,7 +187,6 @@ namespace NadekoBot.Services private async Task MessageReceivedHandler(SocketMessage msg) { - await Task.Yield(); try { if (msg.Author.IsBot || !_bot.Ready) //no bots, wait until bot connected and initialized diff --git a/src/NadekoBot/Services/Games/GamesService.cs b/src/NadekoBot/Services/Games/GamesService.cs index 03b247fa..24139906 100644 --- a/src/NadekoBot/Services/Games/GamesService.cs +++ b/src/NadekoBot/Services/Games/GamesService.cs @@ -97,19 +97,18 @@ namespace NadekoBot.Services.Games private string GetText(ITextChannel ch, string key, params object[] rep) => _strings.GetText(key, ch.GuildId, "Games".ToLowerInvariant(), rep); - private async Task PotentialFlowerGeneration(SocketMessage imsg) + private Task PotentialFlowerGeneration(SocketMessage imsg) { - await Task.Yield(); var msg = imsg as SocketUserMessage; if (msg == null || msg.Author.IsBot) - return; + return Task.CompletedTask; var channel = imsg.Channel as ITextChannel; if (channel == null) - return; + return Task.CompletedTask; if (!GenerationChannels.Contains(channel.Id)) - return; + return Task.CompletedTask; var _ = Task.Run(async () => { @@ -159,7 +158,7 @@ namespace NadekoBot.Services.Games LogManager.GetCurrentClassLogger().Warn(ex); } }); - return; + return Task.CompletedTask; } } } diff --git a/src/NadekoBot/Services/Searches/SearchesService.cs b/src/NadekoBot/Services/Searches/SearchesService.cs index f37f9ec4..864c9522 100644 --- a/src/NadekoBot/Services/Searches/SearchesService.cs +++ b/src/NadekoBot/Services/Searches/SearchesService.cs @@ -39,9 +39,8 @@ namespace NadekoBot.Services.Searches _log = LogManager.GetCurrentClassLogger(); //translate commands - _client.MessageReceived += async (msg) => + _client.MessageReceived += (msg) => { - await Task.Yield(); var _ = Task.Run(async () => { try @@ -70,6 +69,7 @@ namespace NadekoBot.Services.Searches } catch { } }); + return Task.CompletedTask; }; //pokemon commands