new sharded client

This commit is contained in:
Kwoth 2017-01-15 02:28:33 +01:00
parent 3926bc707b
commit c603efa643
18 changed files with 51 additions and 39 deletions

View File

@ -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<SocketGuild> optGuild, SocketUser usr, SocketPresence before, SocketPresence after)
private static async Task _client_UserPresenceUpdated(Optional<SocketGuild> 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<SocketMessage> imsg)
private static async Task _client_MessageDeleted(ulong arg1, Optional<SocketMessage> imsg)
{
try
@ -664,7 +664,7 @@ namespace NadekoBot.Modules.Administration
catch { }
}
private static async void _client_MessageUpdated(Optional<SocketMessage> optmsg, SocketMessage imsg2)
private static async Task _client_MessageUpdated(Optional<SocketMessage> optmsg, SocketMessage imsg2)
{
try
{

View File

@ -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
{

View File

@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Administration
public static Dictionary<string, Func<string>> PlayingPlaceholders { get; } =
new Dictionary<string, Func<string>> {
{"%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);

View File

@ -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
{

View File

@ -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;

View File

@ -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)

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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 ||

View File

@ -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

View File

@ -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)

View File

@ -26,7 +26,7 @@ namespace NadekoBot.Services.Discord
NadekoBot.Client.ReactionsCleared += Discord_ReactionsCleared;
}
private void Discord_ReactionsCleared(ulong messageId, Optional<SocketUserMessage> reaction)
private Task Discord_ReactionsCleared(ulong messageId, Optional<SocketUserMessage> reaction)
{
try
{
@ -34,9 +34,11 @@ namespace NadekoBot.Services.Discord
OnReactionsCleared?.Invoke();
}
catch { }
return Task.CompletedTask;
}
private void Discord_ReactionRemoved(ulong messageId, Optional<SocketUserMessage> arg2, SocketReaction reaction)
private Task Discord_ReactionRemoved(ulong messageId, Optional<SocketUserMessage> 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<SocketUserMessage> message, SocketReaction reaction)
private Task Discord_ReactionAdded(ulong messageId, Optional<SocketUserMessage> message, SocketReaction reaction)
{
try
{
@ -54,6 +58,8 @@ namespace NadekoBot.Services.Discord
OnReactionAdded?.Invoke(reaction);
}
catch { }
return Task.CompletedTask;
}
public void UnsubAll()

View File

@ -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) =>

View File

@ -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