private Task _client_UserPresenceUpdated(IGuildUser usr, IPresence before, IPresence after) { LogSetting logSetting; if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) || !logSetting.LogUserPresence || before.Status == after.Status) { return(Task.CompletedTask); } ITextChannel logChannel; if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogChannelType.UserPresence)) == null) { return(Task.CompletedTask); } string str; if (before.Status != after.Status) { str = $"π΅`{prettyCurrentTime}`π€__**{usr.Username}**__ is now **{after.Status}**."; } else { str = $"πΎ`{prettyCurrentTime}`π€__**{usr.Username}**__ is now playing **{after.Game}**."; } UserPresenceUpdates.AddOrUpdate(logChannel, new List <string>() { str }, (id, list) => { list.Add(str); return(list); }); return(Task.CompletedTask); }
private static async void _client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState before, SocketVoiceState after) { try { var usr = iusr as IGuildUser; if (usr == null) { return; } var beforeVch = before.VoiceChannel; var afterVch = after.VoiceChannel; if (beforeVch == afterVch) { return; } LogSetting logSetting; if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) || (logSetting.LogVoicePresenceId == null)) { return; } ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresence)) == null) { return; } string str = null; if (beforeVch?.Guild == afterVch?.Guild) { str = $"π`{prettyCurrentTime}`π€__**{usr.Username}#{usr.Discriminator}**__ moved from **{beforeVch.Name}** to **{afterVch.Name}** voice channel."; } else if (beforeVch == null) { str = $"π`{prettyCurrentTime}`π€__**{usr.Username}#{usr.Discriminator}**__ has joined **{afterVch.Name}** voice channel."; } else if (afterVch == null) { str = $"π`{prettyCurrentTime}`π€__**{usr.Username}#{usr.Discriminator}**__ has left **{beforeVch.Name}** voice channel."; } if (str != null) { UserPresenceUpdates.AddOrUpdate(logChannel, new List <string>() { str }, (id, list) => { list.Add(str); return(list); }); } } catch (Exception ex) { _log.Warn(ex); } }
private Task _client_UserVoiceStateUpdated(IUser iusr, IVoiceState before, IVoiceState after) { var usr = iusr as IGuildUser; if (usr == null) { return(Task.CompletedTask); } var beforeVch = before.VoiceChannel; var afterVch = after.VoiceChannel; if (beforeVch == afterVch) { return(Task.CompletedTask); } LogSetting logSetting; if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) || !logSetting.LogVoicePresence) { return(Task.CompletedTask); } ITextChannel logChannel; if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogChannelType.Voice)) == null) { return(Task.CompletedTask); } string str = null; if (beforeVch?.Guild == afterVch?.Guild) { str = $"π`{prettyCurrentTime}`π€__**{usr.Username}#{usr.Discriminator}**__ moved from **{beforeVch.Name}** to **{afterVch.Name}** voice channel."; } else if (beforeVch == null) { str = $"π`{prettyCurrentTime}`π€__**{usr.Username}#{usr.Discriminator}**__ has joined **{afterVch.Name}** voice channel."; } else if (afterVch == null) { str = $"π`{prettyCurrentTime}`π€__**{usr.Username}#{usr.Discriminator}**__ has left **{beforeVch.Name}** voice channel."; } if (str != null) { UserPresenceUpdates.AddOrUpdate(logChannel, new List <string>() { str }, (id, list) => { list.Add(str); return(list); }); } return(Task.CompletedTask); }
private static async void _client_UserPresenceUpdated(Optional <SocketGuild> optGuild, SocketUser usr, SocketPresence before, SocketPresence after) { try { var guild = optGuild.IsSpecified ? optGuild.Value : null; if (guild == null) { return; } LogSetting logSetting; if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting) || (logSetting.LogUserPresenceId == null) || before.Status == after.Status) { return; } ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserPresence)) == null) { return; } string str; if (before.Status != after.Status) { str = $"π΅`{prettyCurrentTime}`π€__**{usr.Username}**__ is now **{after.Status}**."; } else { str = $"πΎ`{prettyCurrentTime}`π€__**{usr.Username}**__ is now playing **{after.Game}**."; } UserPresenceUpdates.AddOrUpdate(logChannel, new List <string>() { str }, (id, list) => { list.Add(str); return(list); }); } catch { } }