From c603efa6439103b30039ca9997563a534206f3bf Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 15 Jan 2017 02:28:33 +0100 Subject: [PATCH] new sharded client --- .../Administration/Commands/LogCommand.cs | 28 +++++++++---------- .../Administration/Commands/MuteCommands.cs | 2 +- .../Commands/PlayingRotateCommands.cs | 2 +- .../Commands/ServerGreetCommands.cs | 4 +-- .../Commands/VoicePlusTextCommands.cs | 2 +- .../Modules/Gambling/Commands/AnimalRacing.cs | 8 +++--- .../Modules/Games/Commands/Acropobia.cs | 2 +- .../Games/Commands/Hangman/HangmanGame.cs | 2 +- .../Games/Commands/PlantAndPickCommands.cs | 2 +- .../Modules/Games/Commands/PollCommands.cs | 2 +- .../Games/Commands/SpeedTypingCommands.cs | 2 +- .../Games/Commands/Trivia/TriviaGame.cs | 2 +- src/NadekoBot/Modules/Music/Music.cs | 2 +- src/NadekoBot/Modules/Utility/Utility.cs | 2 +- src/NadekoBot/Services/CommandHandler.cs | 4 +-- .../Discord/SocketMessageEventWrapper.cs | 12 ++++++-- src/NadekoBot/Services/Impl/StatsService.cs | 8 ++++++ src/NadekoBot/ShardedDiscordClient.cs | 4 +-- 18 files changed, 51 insertions(+), 39 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index 31dfbdc8..96ecee55 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -94,7 +94,7 @@ namespace NadekoBot.Modules.Administration MuteCommands.UserUnmuted += MuteCommands_UserUnmuted; } - private static async void _client_UserUpdated(SocketUser before, SocketUser uAfter) + private static async Task _client_UserUpdated(SocketUser before, SocketUser uAfter) { try { @@ -162,7 +162,7 @@ namespace NadekoBot.Modules.Administration { } } - private static async void _client_UserVoiceStateUpdated_TTS(SocketUser iusr, SocketVoiceState before, SocketVoiceState after) + private static async Task _client_UserVoiceStateUpdated_TTS(SocketUser iusr, SocketVoiceState before, SocketVoiceState after) { try { @@ -317,7 +317,7 @@ namespace NadekoBot.Modules.Administration catch { } } - private static async void _client_GuildUserUpdated(SocketGuildUser before, SocketGuildUser after) + private static async Task _client_GuildUserUpdated(SocketGuildUser before, SocketGuildUser after) { try { @@ -360,7 +360,7 @@ namespace NadekoBot.Modules.Administration catch { } } - private static async void _client_ChannelUpdated(IChannel cbefore, IChannel cafter) + private static async Task _client_ChannelUpdated(IChannel cbefore, IChannel cafter) { try { @@ -403,7 +403,7 @@ namespace NadekoBot.Modules.Administration catch { } } - private static async void _client_ChannelDestroyed(IChannel ich) + private static async Task _client_ChannelDestroyed(IChannel ich) { try { @@ -430,7 +430,7 @@ namespace NadekoBot.Modules.Administration catch { } } - private static async void _client_ChannelCreated(IChannel ich) + private static async Task _client_ChannelCreated(IChannel ich) { try { @@ -456,7 +456,7 @@ namespace NadekoBot.Modules.Administration catch (Exception ex) { _log.Warn(ex); } } - private static async void _client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState before, SocketVoiceState after) + private static async Task _client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState before, SocketVoiceState after) { try { @@ -498,7 +498,7 @@ namespace NadekoBot.Modules.Administration catch { } } - private static async void _client_UserPresenceUpdated(Optional optGuild, SocketUser usr, SocketPresence before, SocketPresence after) + private static async Task _client_UserPresenceUpdated(Optional optGuild, SocketUser usr, SocketPresence before, SocketPresence after) { try { @@ -532,7 +532,7 @@ namespace NadekoBot.Modules.Administration catch { } } - private static async void _client_UserLeft(IGuildUser usr) + private static async Task _client_UserLeft(IGuildUser usr) { try { @@ -556,7 +556,7 @@ namespace NadekoBot.Modules.Administration catch { } } - private static async void _client_UserJoined(IGuildUser usr) + private static async Task _client_UserJoined(IGuildUser usr) { try { @@ -580,7 +580,7 @@ namespace NadekoBot.Modules.Administration catch (Exception ex) { _log.Warn(ex); } } - private static async void _client_UserUnbanned(IUser usr, IGuild guild) + private static async Task _client_UserUnbanned(IUser usr, IGuild guild) { try { @@ -604,7 +604,7 @@ namespace NadekoBot.Modules.Administration catch (Exception ex) { _log.Warn(ex); } } - private static async void _client_UserBanned(IUser usr, IGuild guild) + private static async Task _client_UserBanned(IUser usr, IGuild guild) { try { @@ -627,7 +627,7 @@ namespace NadekoBot.Modules.Administration catch (Exception ex) { _log.Warn(ex); } } - private static async void _client_MessageDeleted(ulong arg1, Optional imsg) + private static async Task _client_MessageDeleted(ulong arg1, Optional imsg) { try @@ -664,7 +664,7 @@ namespace NadekoBot.Modules.Administration catch { } } - private static async void _client_MessageUpdated(Optional optmsg, SocketMessage imsg2) + private static async Task _client_MessageUpdated(Optional optmsg, SocketMessage imsg2) { try { diff --git a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs index b4993bf2..fc69d1cb 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs @@ -55,7 +55,7 @@ namespace NadekoBot.Modules.Administration _log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s"); } - private static async void Client_UserJoined(IGuildUser usr) + private static async Task Client_UserJoined(IGuildUser usr) { try { diff --git a/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs b/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs index f8817db9..89eeb2c5 100644 --- a/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs @@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Administration public static Dictionary> PlayingPlaceholders { get; } = new Dictionary> { - {"%servers%", () => NadekoBot.Client.GetGuildsCount().ToString()}, + {"%servers%", () => NadekoBot.Client.GetGuildCount().ToString()}, {"%users%", () => NadekoBot.Client.GetGuilds().Sum(s => s.Users.Count).ToString()}, {"%playing%", () => { var cnt = Music.Music.MusicPlayers.Count(kvp => kvp.Value.CurrentSong != null); diff --git a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs index 80b8c394..9fa0971c 100644 --- a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs @@ -26,7 +26,7 @@ namespace NadekoBot.Modules.Administration _log = LogManager.GetCurrentClassLogger(); } //todo optimize ASAP - private static async void UserLeft(IGuildUser user) + private static async Task UserLeft(IGuildUser user) { try { @@ -58,7 +58,7 @@ namespace NadekoBot.Modules.Administration catch { } } - private static async void UserJoined(IGuildUser user) + private static async Task UserJoined(IGuildUser user) { try { diff --git a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs index 1d76b1e7..a52a2c60 100644 --- a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs @@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Administration _log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s"); } - private static async void UserUpdatedEventHandler(SocketUser iuser, SocketVoiceState before, SocketVoiceState after) + private static async Task UserUpdatedEventHandler(SocketUser iuser, SocketVoiceState before, SocketVoiceState after) { var user = (iuser as SocketGuildUser); var guild = user?.Guild; diff --git a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs index c8e612f6..f2b6404c 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs @@ -207,15 +207,15 @@ namespace NadekoBot.Modules.Gambling } - private void Client_MessageReceived(SocketMessage imsg) + private Task Client_MessageReceived(SocketMessage imsg) { var msg = imsg as SocketUserMessage; if (msg == null) - return; + return Task.CompletedTask; if (msg.IsAuthor() || !(imsg.Channel is ITextChannel) || imsg.Channel != raceChannel) - return; + return Task.CompletedTask; messagesSinceGameStarted++; - return; + return Task.CompletedTask; } private async Task CheckForFullGameAsync(CancellationToken cancelToken) diff --git a/src/NadekoBot/Modules/Games/Commands/Acropobia.cs b/src/NadekoBot/Modules/Games/Commands/Acropobia.cs index 4160754b..2a7307bb 100644 --- a/src/NadekoBot/Modules/Games/Commands/Acropobia.cs +++ b/src/NadekoBot/Modules/Games/Commands/Acropobia.cs @@ -168,7 +168,7 @@ namespace NadekoBot.Modules.Games await End().ConfigureAwait(false); } - private async void PotentialAcro(SocketMessage arg) + private async Task PotentialAcro(SocketMessage arg) { try { diff --git a/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs b/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs index b209ecdc..4dcb54e9 100644 --- a/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs +++ b/src/NadekoBot/Modules/Games/Commands/Hangman/HangmanGame.cs @@ -114,7 +114,7 @@ namespace NadekoBot.Modules.Games.Commands.Hangman await GameChannel.EmbedAsync(embed.WithOkColor()).ConfigureAwait(false); } - private async void PotentialGuess(SocketMessage msg) + private async Task PotentialGuess(SocketMessage msg) { try { diff --git a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs index 6bc9eb4e..3782fe78 100644 --- a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs @@ -51,7 +51,7 @@ namespace NadekoBot.Modules.Games .SelectMany(c => c.GenerateCurrencyChannelIds.Select(obj => obj.ChannelId))); } - private static async void PotentialFlowerGeneration(SocketMessage imsg) + private static async Task PotentialFlowerGeneration(SocketMessage imsg) { try { diff --git a/src/NadekoBot/Modules/Games/Commands/PollCommands.cs b/src/NadekoBot/Modules/Games/Commands/PollCommands.cs index 01d0477c..3088546c 100644 --- a/src/NadekoBot/Modules/Games/Commands/PollCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PollCommands.cs @@ -153,7 +153,7 @@ namespace NadekoBot.Modules.Games await originalMessage.Channel.EmbedAsync(GetStats("POLL CLOSED")).ConfigureAwait(false); } - private async void Vote(SocketMessage imsg) + private async Task Vote(SocketMessage imsg) { try { diff --git a/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs b/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs index bb69063f..47724820 100644 --- a/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs @@ -106,7 +106,7 @@ namespace NadekoBot.Modules.Games NadekoBot.Client.MessageReceived += AnswerReceived; } - private async void AnswerReceived(SocketMessage imsg) + private async Task AnswerReceived(SocketMessage imsg) { try { diff --git a/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs b/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs index ce8f0ebc..e9469358 100644 --- a/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs +++ b/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs @@ -143,7 +143,7 @@ namespace NadekoBot.Modules.Games.Trivia try { await channel.SendConfirmAsync("Trivia Game", "Stopping after this question.").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } } - private async void PotentialGuess(SocketMessage imsg) + private async Task PotentialGuess(SocketMessage imsg) { try { diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index efdd9e6a..b27afe25 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -37,7 +37,7 @@ namespace NadekoBot.Modules.Music Directory.CreateDirectory(MusicDataPath); } - private static async void Client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState oldState, SocketVoiceState newState) + private static async Task Client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState oldState, SocketVoiceState newState) { var usr = iusr as SocketGuildUser; if (usr == null || diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 4730b433..ef075c78 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -283,7 +283,7 @@ namespace NadekoBot.Modules.Utility .AddField(efb => efb.WithName(Format.Bold("Memory")).WithValue($"{stats.Heap} MB").WithIsInline(true)) .AddField(efb => efb.WithName(Format.Bold("Owner ID(s)")).WithValue(string.Join("\n", NadekoBot.Credentials.OwnerIds)).WithIsInline(true)) .AddField(efb => efb.WithName(Format.Bold("Uptime")).WithValue(stats.GetUptimeString("\n")).WithIsInline(true)) - .AddField(efb => efb.WithName(Format.Bold("Presence")).WithValue($"{NadekoBot.Client.GetGuildsCount()} Servers\n{stats.TextChannels} Text Channels\n{stats.VoiceChannels} Voice Channels").WithIsInline(true)) + .AddField(efb => efb.WithName(Format.Bold("Presence")).WithValue($"{NadekoBot.Client.GetGuildCount()} Servers\n{stats.TextChannels} Text Channels\n{stats.VoiceChannels} Voice Channels").WithIsInline(true)) #if !GLOBAL_NADEKO .WithFooter(efb => efb.WithText($"Playing {Music.Music.MusicPlayers.Where(mp => mp.Value.CurrentSong != null).Count()} songs, {Music.Music.MusicPlayers.Sum(mp => mp.Value.Playlist.Count)} queued.")) #endif diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index bb1c54f1..16bf8e89 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -180,7 +180,7 @@ namespace NadekoBot.Services return false; } - private async void MessageReceivedHandler(SocketMessage msg) + private async Task MessageReceivedHandler(SocketMessage msg) { try { @@ -228,7 +228,7 @@ namespace NadekoBot.Services string messageContent = usrMsg.Content; // execute the command and measure the time it took - var exec = await ExecuteCommand(new CommandContext(_client.MainClient, usrMsg), messageContent, DependencyMap.Empty, MultiMatchHandling.Best); + var exec = await ExecuteCommand(new CommandContext(_client, usrMsg), messageContent, DependencyMap.Empty, MultiMatchHandling.Best); execTime = Environment.TickCount - execTime; if (exec.Result.IsSuccess) diff --git a/src/NadekoBot/Services/Discord/SocketMessageEventWrapper.cs b/src/NadekoBot/Services/Discord/SocketMessageEventWrapper.cs index b73961a0..57153ac2 100644 --- a/src/NadekoBot/Services/Discord/SocketMessageEventWrapper.cs +++ b/src/NadekoBot/Services/Discord/SocketMessageEventWrapper.cs @@ -26,7 +26,7 @@ namespace NadekoBot.Services.Discord NadekoBot.Client.ReactionsCleared += Discord_ReactionsCleared; } - private void Discord_ReactionsCleared(ulong messageId, Optional reaction) + private Task Discord_ReactionsCleared(ulong messageId, Optional reaction) { try { @@ -34,9 +34,11 @@ namespace NadekoBot.Services.Discord OnReactionsCleared?.Invoke(); } catch { } + + return Task.CompletedTask; } - private void Discord_ReactionRemoved(ulong messageId, Optional arg2, SocketReaction reaction) + private Task Discord_ReactionRemoved(ulong messageId, Optional arg2, SocketReaction reaction) { try { @@ -44,9 +46,11 @@ namespace NadekoBot.Services.Discord OnReactionRemoved?.Invoke(reaction); } catch { } + + return Task.CompletedTask; } - private void Discord_ReactionAdded(ulong messageId, Optional message, SocketReaction reaction) + private Task Discord_ReactionAdded(ulong messageId, Optional message, SocketReaction reaction) { try { @@ -54,6 +58,8 @@ namespace NadekoBot.Services.Discord OnReactionAdded?.Invoke(reaction); } catch { } + + return Task.CompletedTask; } public void UnsubAll() diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index 3424b7ba..b65f3219 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -46,6 +46,8 @@ namespace NadekoBot.Services.Impl ++_textChannels; else if (c is IVoiceChannel) ++_voiceChannels; + + return Task.CompletedTask; }; this.client.ChannelDestroyed += (c) => @@ -54,6 +56,8 @@ namespace NadekoBot.Services.Impl --_textChannels; else if (c is IVoiceChannel) --_voiceChannels; + + return Task.CompletedTask; }; this.client.JoinedGuild += (g) => @@ -62,6 +66,8 @@ namespace NadekoBot.Services.Impl var vc = g.Channels.Count - tc; _textChannels += tc; _voiceChannels += vc; + + return Task.CompletedTask; }; this.client.LeftGuild += (g) => @@ -70,6 +76,8 @@ namespace NadekoBot.Services.Impl var vc = g.Channels.Count - tc; _textChannels -= tc; _voiceChannels -= vc; + + return Task.CompletedTask; }; this.carbonitexTimer = new Timer(async (state) => diff --git a/src/NadekoBot/ShardedDiscordClient.cs b/src/NadekoBot/ShardedDiscordClient.cs index 268a9a54..0a6e747a 100644 --- a/src/NadekoBot/ShardedDiscordClient.cs +++ b/src/NadekoBot/ShardedDiscordClient.cs @@ -180,9 +180,7 @@ namespace NadekoBot public Task SetStream(string name, string url) => Task.WhenAll(Clients.Select(ms => ms.SetGameAsync(name, url, StreamType.Twitch))); - public Task SetStatus(SettableUserStatus status) => Task.WhenAll(Clients.Select(ms => ms.SetStatusAsync(SettableUserStatusToUserStatus(status)))); - - + //public Task SetStatus(SettableUserStatus status) => Task.WhenAll(Clients.Select(ms => ms.SetStatusAsync(SettableUserStatusToUserStatus(status)))); } public enum SettableUserStatus