Esempio n. 1
0
            private Task _client_ChannelDestroyed(IChannel ich)
            {
                var ch = ich as IGuildChannel;

                if (ch == null)
                {
                    return(Task.CompletedTask);
                }

                LogSetting logSetting;

                if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out logSetting) ||
                    !logSetting.IsLogging ||
                    !logSetting.ChannelDestroyed ||
                    logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == ch.Id))
                {
                    return(Task.CompletedTask);
                }

                ITextChannel logChannel;

                if ((logChannel = TryGetLogChannel(ch.Guild, logSetting)) == null)
                {
                    return(Task.CompletedTask);
                }

                var task = Task.Run(async() =>
                {
                    try { await logChannel.SendMessageAsync($"❗`{prettyCurrentTime}` `{(ch is IVoiceChannel ? "Voice" : "Text")} Channel Deleted:` **#{ch.Name}** ({ch.Id})").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
                });

                return(Task.CompletedTask);
            }
Esempio n. 2
0
            private static async void MuteCommands_UserMuted(IGuildUser usr, MuteCommands.MuteType muteType)
            {
                try
                {
                    LogSetting logSetting;
                    if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) ||
                        (logSetting.UserMutedId == null))
                    {
                        return;
                    }

                    ITextChannel logChannel;
                    if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null)
                    {
                        return;
                    }
                    string mutes = "";
                    switch (muteType)
                    {
                    case MuteCommands.MuteType.Voice:
                        mutes = "voice chat";
                        break;

                    case MuteCommands.MuteType.Chat:
                        mutes = "text chat";
                        break;

                    case MuteCommands.MuteType.All:
                        mutes = "text and voice chat";
                        break;
                    }
                    await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🔇 **| User muted from the {mutes}. |** 🆔 `{usr.Id}`").ConfigureAwait(false);
                }
                catch (Exception ex) { _log.Warn(ex); }
            }
Esempio n. 3
0
            private static async void _client_ChannelCreated(IChannel ich)
            {
                try
                {
                    var ch = ich as IGuildChannel;
                    if (ch == null)
                    {
                        return;
                    }

                    LogSetting logSetting;
                    if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out logSetting) ||
                        (logSetting.ChannelCreatedId == null))
                    {
                        return;
                    }

                    ITextChannel logChannel;
                    if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelCreated)) == null)
                    {
                        return;
                    }

                    await logChannel.SendMessageAsync($"🕓`{prettyCurrentTime}`🆕 **| {(ch is IVoiceChannel ? "Voice" : "Text")} Channel Created: #⃣ {ch.Name}** `({ch.Id})`").ConfigureAwait(false);
                }
                catch (Exception ex) { _log.Warn(ex); }
            }
Esempio n. 4
0
            private Task _client_UserBanned(IUser usr, IGuild guild)
            {
                LogSetting logSetting;

                if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting) ||
                    !logSetting.IsLogging ||
                    !logSetting.UserBanned)
                {
                    return(Task.CompletedTask);
                }

                ITextChannel logChannel;

                if ((logChannel = TryGetLogChannel(guild, logSetting)) == null)
                {
                    return(Task.CompletedTask);
                }

                var task = Task.Run(async() =>
                {
                    try { await logChannel.SendMessageAsync($"‼️🕕`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__🚫 **| USER BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
                });

                return(Task.CompletedTask);
            }
Esempio n. 5
0
            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);
            }
Esempio n. 6
0
            public async Task LogIgnore(IUserMessage imsg)
            {
                var channel = (ITextChannel)imsg.Channel;
                int removed;

                using (var uow = DbHandler.UnitOfWork())
                {
                    var        config     = uow.GuildConfigs.For(channel.Guild.Id);
                    LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
                    removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id);
                    config.LogSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id);
                    if (removed == 0)
                    {
                        var toAdd = new IgnoredLogChannel {
                            ChannelId = channel.Id
                        };
                        logSetting.IgnoredChannels.Add(toAdd);
                        config.LogSetting.IgnoredChannels.Add(toAdd);
                    }
                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                if (removed == 0)
                {
                    await channel.SendMessageAsync($"🆗 Logging will **now ignore** #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false);
                }
                else
                {
                    await channel.SendMessageAsync($"ℹ️ Logging will **no longer ignore** #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false);
                }
            }
Esempio n. 7
0
            public async Task LogServer(IUserMessage msg)
            {
                var        channel = (ITextChannel)msg.Channel;
                LogSetting logSetting;

                using (var uow = DbHandler.UnitOfWork())
                {
                    logSetting = uow.GuildConfigs.For(channel.Guild.Id).LogSetting;
                    GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting);
                    logSetting.IsLogging = !logSetting.IsLogging;
                    if (logSetting.IsLogging)
                    {
                        logSetting.ChannelId = channel.Id;
                    }
                    await uow.CompleteAsync();
                }

                if (logSetting.IsLogging)
                {
                    await channel.SendMessageAsync("✅ **Logging enabled.**").ConfigureAwait(false);
                }
                else
                {
                    await channel.SendMessageAsync("ℹ️ **Logging disabled.**").ConfigureAwait(false);
                }
            }
Esempio n. 8
0
            private Task _client_UserBanned(IUser usr, IGuild guild)
            {
                LogSetting logSetting;

                if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting) ||
                    !logSetting.IsLogging ||
                    !logSetting.UserBanned)
                {
                    return(Task.CompletedTask);
                }

                ITextChannel logChannel;

                if ((logChannel = TryGetLogChannel(guild, logSetting)) == null)
                {
                    return(Task.CompletedTask);
                }

                var task = Task.Run(async() =>
                {
                    try { await logChannel.SendMessageAsync($"❗`{prettyCurrentTime}`❌`User banned:` **{usr.Username}** ({usr.Id})").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
                });

                return(Task.CompletedTask);
            }
Esempio n. 9
0
            public async Task VoicePresence(IUserMessage imsg)
            {
                var  channel = (ITextChannel)imsg.Channel;
                bool enabled;

                using (var uow = DbHandler.UnitOfWork())
                {
                    var logSetting = uow.GuildConfigs.For(channel.Guild.Id).LogSetting;
                    GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting);
                    enabled = logSetting.LogVoicePresence = !logSetting.LogVoicePresence;
                    if (enabled)
                    {
                        logSetting.VoicePresenceChannelId = channel.Id;
                    }
                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                if (enabled)
                {
                    await channel.SendMessageAsync($"✅ Logging **voice presence** updates in #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false);
                }
                else
                {
                    await channel.SendMessageAsync($"ℹ️ Stopped logging **voice presence** updates.").ConfigureAwait(false);
                }
            }
Esempio n. 10
0
            public async Task LogServer(PermissionAction action)
            {
                var        channel = (ITextChannel)Context.Channel;
                LogSetting logSetting;

                using (var uow = DbHandler.UnitOfWork())
                {
                    logSetting = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id).LogSetting;
                    GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting);
                    logSetting.LogOtherId                                                                =
                        logSetting.MessageUpdatedId                                                      =
                            logSetting.MessageDeletedId                                                  =
                                logSetting.UserJoinedId                                                  =
                                    logSetting.UserLeftId                                                =
                                        logSetting.UserBannedId                                          =
                                            logSetting.UserUnbannedId                                    =
                                                logSetting.UserUpdatedId                                 =
                                                    logSetting.ChannelCreatedId                          =
                                                        logSetting.ChannelDestroyedId                    =
                                                            logSetting.ChannelUpdatedId                  =
                                                                logSetting.LogUserPresenceId             =
                                                                    logSetting.LogVoicePresenceId        =
                                                                        logSetting.LogVoicePresenceTTSId = (action.Value ? channel.Id : (ulong?)null);

                    await uow.CompleteAsync().ConfigureAwait(false);
                }
                if (action.Value)
                {
                    await channel.SendMessageAsync("✅ Logging all events on this channel.").ConfigureAwait(false);
                }
                else
                {
                    await channel.SendMessageAsync("ℹ️ Logging disabled.").ConfigureAwait(false);
                }
            }
Esempio n. 11
0
            private Task _client_ChannelCreated(IChannel ich)
            {
                var ch = ich as IGuildChannel;

                if (ch == null)
                {
                    return(Task.CompletedTask);
                }

                LogSetting logSetting;

                if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out logSetting) ||
                    !logSetting.IsLogging ||
                    !logSetting.ChannelCreated)
                {
                    return(Task.CompletedTask);
                }

                ITextChannel logChannel;

                if ((logChannel = TryGetLogChannel(ch.Guild, logSetting)) == null)
                {
                    return(Task.CompletedTask);
                }

                var task = Task.Run(async() =>
                {
                    try { await logChannel.SendMessageAsync($"🕓`{prettyCurrentTime}`🆕 **| {(ch is IVoiceChannel ? "Voice" : "Text")} Channel Created: #⃣ {ch.Name}** `({ch.Id})`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
                });

                return(Task.CompletedTask);
            }
Esempio n. 12
0
        private Task _client_MessageUpdated(Cacheable <IMessage, ulong> optmsg, SocketMessage imsg2, ISocketMessageChannel ch)
        {
            var _ = Task.Run(async() =>
            {
                try
                {
                    if (!(imsg2 is IUserMessage after) || after.IsAuthor(_client))
                    {
                        return;
                    }

                    var before = (optmsg.HasValue ? optmsg.Value : null) as IUserMessage;
                    if (before == null)
                    {
                        return;
                    }

                    if (!(ch is ITextChannel channel))
                    {
                        return;
                    }

                    if (before.Content == after.Content)
                    {
                        return;
                    }

                    if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out LogSetting logSetting) ||
                        (logSetting.MessageUpdatedId == null) ||
                        logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id))
                    {
                        return;
                    }

                    ITextChannel logChannel;
                    if ((logChannel = await TryGetLogChannel(channel.Guild, logSetting, LogType.MessageUpdated).ConfigureAwait(false)) == null || logChannel.Id == after.Channel.Id)
                    {
                        return;
                    }

                    var embed = new EmbedBuilder()
                                .WithOkColor()
                                .WithTitle("📝 " + GetText(logChannel.Guild, "msg_update", ((ITextChannel)after.Channel).Name))
                                .WithDescription(after.Author.ToString())
                                .AddField(efb => efb.WithName(GetText(logChannel.Guild, "old_msg")).WithValue(string.IsNullOrWhiteSpace(before.Content) ? "-" : before.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false))
                                .AddField(efb => efb.WithName(GetText(logChannel.Guild, "new_msg")).WithValue(string.IsNullOrWhiteSpace(after.Content) ? "-" : after.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false))
                                .AddField(efb => efb.WithName("Id").WithValue(after.Id.ToString()).WithIsInline(false))
                                .WithFooter(efb => efb.WithText(CurrentTime(channel.Guild)));

                    await logChannel.EmbedAsync(embed).ConfigureAwait(false);
                }
                catch
                {
                    // ignored
                }
            });

            return(Task.CompletedTask);
        }
Esempio n. 13
0
            private Task _client_UserUpdated(IGuildUser before, IGuildUser after)
            {
                LogSetting logSetting;

                if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting) ||
                    !logSetting.IsLogging ||
                    !logSetting.UserUpdated)
                {
                    return(Task.CompletedTask);
                }

                ITextChannel logChannel;

                if ((logChannel = TryGetLogChannel(before.Guild, logSetting)) == null)
                {
                    return(Task.CompletedTask);
                }

                var task = Task.Run(async() =>
                {
                    try
                    {
                        string str = $"🕔`{prettyCurrentTime}`";
                        if (before.Username != after.Username)
                        {
                            str += $"**Name Changed**👤`{before.Username}#{before.Discriminator}`\n\t\t`New:`{after.ToString()}`";
                        }
                        else if (before.Nickname != after.Nickname)
                        {
                            str += $"**Nickname Changed**👤`{before.Username}#{before.Discriminator}`\n\t\t`Old:` {before.Nickname}#{before.Discriminator}\n\t\t`New:` {after.Nickname}#{after.Discriminator}";
                        }
                        else if (before.AvatarUrl != after.AvatarUrl)
                        {
                            str += $"**Avatar Changed**👤`{before.Username}#{before.Discriminator}`\n\t {await _google.ShortenUrl(before.AvatarUrl)} `=>` {await _google.ShortenUrl(after.AvatarUrl)}";
                        }
                        else if (!before.Roles.SequenceEqual(after.Roles))
                        {
                            if (before.Roles.Count() < after.Roles.Count())
                            {
                                var diffRoles = after.Roles.Where(r => !before.Roles.Contains(r)).Select(r => "`" + r.Name + "`");
                                str          += $"**User's Roles changed ⚔➕**👤`{before.ToString()}`\n\tNow has {string.Join(", ", diffRoles)} role.";
                            }
                            else if (before.Roles.Count() > after.Roles.Count())
                            {
                                var diffRoles = before.Roles.Where(r => !after.Roles.Contains(r)).Select(r => "`" + r.Name + "`");
                                str          += $"**User's Roles changed ⚔➖**👤`{before.ToString()}`\n\tNo longer has {string.Join(", ", diffRoles)} role.";
                            }
                        }
                        else
                        {
                            return;
                        }
                        try { await logChannel.SendMessageAsync(str).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
                    }
                    catch { }
                });

                return(Task.CompletedTask);
            }
Esempio n. 14
0
        private Task _client_ChannelUpdated(IChannel cbefore, IChannel cafter)
        {
            var _ = Task.Run(async() =>
            {
                try
                {
                    var before = cbefore as IGuildChannel;
                    if (before == null)
                    {
                        return;
                    }
                    var after = (IGuildChannel)cafter;

                    if (!GuildLogSettings.TryGetValue(before.Guild.Id, out LogSetting logSetting) ||
                        (logSetting.ChannelUpdatedId == null) ||
                        logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == after.Id))
                    {
                        return;
                    }

                    ITextChannel logChannel;
                    if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.ChannelUpdated)) == null)
                    {
                        return;
                    }

                    var embed = new EmbedBuilder().WithOkColor().WithFooter(efb => efb.WithText(CurrentTime(before.Guild)));

                    var beforeTextChannel = cbefore as ITextChannel;
                    var afterTextChannel  = cafter as ITextChannel;

                    if (before.Name != after.Name)
                    {
                        embed.WithTitle("ℹ️ " + GetText(logChannel.Guild, "ch_name_change"))
                        .WithDescription($"{after} | {after.Id}")
                        .AddField(efb => efb.WithName(GetText(logChannel.Guild, "ch_old_name")).WithValue(before.Name));
                    }
                    else if (beforeTextChannel?.Topic != afterTextChannel?.Topic)
                    {
                        embed.WithTitle("ℹ️ " + GetText(logChannel.Guild, "ch_topic_change"))
                        .WithDescription($"{after} | {after.Id}")
                        .AddField(efb => efb.WithName(GetText(logChannel.Guild, "old_topic")).WithValue(beforeTextChannel?.Topic ?? "-"))
                        .AddField(efb => efb.WithName(GetText(logChannel.Guild, "new_topic")).WithValue(afterTextChannel?.Topic ?? "-"));
                    }
                    else
                    {
                        return;
                    }

                    await logChannel.EmbedAsync(embed).ConfigureAwait(false);
                }
                catch
                {
                    // ignored
                }
            });

            return(Task.CompletedTask);
        }
Esempio n. 15
0
        public Task TriggeredAntiProtection(PunishmentAction action, ProtectionType protection, params IGuildUser[] users)
        {
            var _ = Task.Run(async() =>
            {
                try
                {
                    if (users.Length == 0)
                    {
                        return;
                    }

                    if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out LogSetting logSetting) ||
                        (logSetting.LogOtherId == null))
                    {
                        return;
                    }
                    ITextChannel logChannel;
                    if ((logChannel = await TryGetLogChannel(users.First().Guild, logSetting, LogType.Other)) == null)
                    {
                        return;
                    }

                    var punishment = "";
                    switch (action)
                    {
                    case PunishmentAction.Mute:
                        punishment = "🔇 " + GetText(logChannel.Guild, "muted_pl").ToUpperInvariant();
                        break;

                    case PunishmentAction.Kick:
                        punishment = "👢 " + GetText(logChannel.Guild, "kicked_pl").ToUpperInvariant();
                        break;

                    case PunishmentAction.Softban:
                        punishment = "☣ " + GetText(logChannel.Guild, "soft_banned_pl").ToUpperInvariant();
                        break;

                    case PunishmentAction.Ban:
                        punishment = "⛔️ " + GetText(logChannel.Guild, "banned_pl").ToUpperInvariant();
                        break;
                    }

                    var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName($"🛡 Anti-{protection}"))
                                .WithTitle(GetText(logChannel.Guild, "users") + " " + punishment)
                                .WithDescription(string.Join("\n", users.Select(u => u.ToString())))
                                .WithFooter(fb => fb.WithText(CurrentTime(logChannel.Guild)))
                                .WithOkColor();

                    await logChannel.EmbedAsync(embed).ConfigureAwait(false);
                }
                catch
                {
                    // ignored
                }
            });

            return(Task.CompletedTask);
        }
Esempio n. 16
0
            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);
                }
            }
Esempio n. 17
0
            private Task _client_UserJoined(IGuildUser usr)
            {
                LogSetting logSetting;

                if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) ||
                    !logSetting.IsLogging ||
                    !logSetting.UserJoined)
                {
                    return(Task.CompletedTask);
                }

                ITextChannel logChannel;

                if ((logChannel = TryGetLogChannel(usr.Guild, logSetting)) == null)
                {
                    return(Task.CompletedTask);
                }

                var task = Task.Run(async() =>
                {
                    bool muted = false;
                    try
                    {
                        // Serialize the list to a file
                        string path = @"/root/muted.dat";
                        // Open the file to read from.
                        using (StreamReader sr = File.OpenText(path))
                        {
                            string s = "";
                            while ((s = sr.ReadLine()) != null)
                            {
                                if (usr.Id == Convert.ToUInt64(s))
                                {
                                    await usr.AddRolesAsync(await GetMuteRole(usr.Guild).ConfigureAwait(false)).ConfigureAwait(false);
                                    muted = true;
                                    break;
                                }
                                else
                                {
                                    muted = false;
                                }
                            }
                        }
                    } catch { }
                    if (muted)
                    {
                        try { await logChannel.SendMessageAsync($"`{prettyCurrentTime}`❗`[MUTED] User joined:` **{usr.Username}** ({usr.Id})").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
                    }
                    else
                    {
                        try { await logChannel.SendMessageAsync($"`{prettyCurrentTime}`❗`User joined:` **{usr.Username}** ({usr.Id})").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
                    }
                });

                return(Task.CompletedTask);
            }
Esempio n. 18
0
            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);
            }
Esempio n. 19
0
        private Task _client_UserVoiceStateUpdated_TTS(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
        {
            var _ = Task.Run(async() =>
            {
                try
                {
                    var usr = iusr as IGuildUser;
                    if (usr == null)
                    {
                        return;
                    }

                    var beforeVch = before.VoiceChannel;
                    var afterVch  = after.VoiceChannel;

                    if (beforeVch == afterVch)
                    {
                        return;
                    }

                    if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting) ||
                        (logSetting.LogVoicePresenceTTSId == null))
                    {
                        return;
                    }

                    ITextChannel logChannel;
                    if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresenceTTS)) == null)
                    {
                        return;
                    }

                    var str = "";
                    if (beforeVch?.Guild == afterVch?.Guild)
                    {
                        str = GetText(logChannel.Guild, "moved", usr.Username, beforeVch?.Name, afterVch?.Name);
                    }
                    else if (beforeVch == null)
                    {
                        str = GetText(logChannel.Guild, "joined", usr.Username, afterVch.Name);
                    }
                    else if (afterVch == null)
                    {
                        str = GetText(logChannel.Guild, "left", usr.Username, beforeVch.Name);
                    }
                    var toDelete = await logChannel.SendMessageAsync(str, true).ConfigureAwait(false);
                    toDelete.DeleteAfter(5);
                }
                catch
                {
                    // ignored
                }
            });

            return(Task.CompletedTask);
        }
Esempio n. 20
0
        private Task _client_MessageDeleted(Cacheable <IMessage, ulong> optMsg, ISocketMessageChannel ch)
        {
            var _ = Task.Run(async() =>
            {
                try
                {
                    var msg = (optMsg.HasValue ? optMsg.Value : null) as IUserMessage;
                    if (msg == null || msg.IsAuthor(_client))
                    {
                        return;
                    }

                    var channel = ch as ITextChannel;
                    if (channel == null)
                    {
                        return;
                    }

                    if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out LogSetting logSetting) ||
                        (logSetting.MessageDeletedId == null) ||
                        logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id))
                    {
                        return;
                    }

                    ITextChannel logChannel;
                    if ((logChannel = await TryGetLogChannel(channel.Guild, logSetting, LogType.MessageDeleted)) == null || logChannel.Id == msg.Id)
                    {
                        return;
                    }

                    var resolvedMessage = msg.Resolve(userHandling: TagHandling.FullName);
                    var embed           = new EmbedBuilder()
                                          .WithOkColor()
                                          .WithTitle("🗑 " + GetText(logChannel.Guild, "msg_del", ((ITextChannel)msg.Channel).Name))
                                          .WithDescription(msg.Author.ToString())
                                          .AddField(efb => efb.WithName(GetText(logChannel.Guild, "content")).WithValue(string.IsNullOrWhiteSpace(resolvedMessage) ? "-" : resolvedMessage).WithIsInline(false))
                                          .AddField(efb => efb.WithName("Id").WithValue(msg.Id.ToString()).WithIsInline(false))
                                          .WithFooter(efb => efb.WithText(CurrentTime(channel.Guild)));
                    if (msg.Attachments.Any())
                    {
                        embed.AddField(efb => efb.WithName(GetText(logChannel.Guild, "attachments")).WithValue(string.Join(", ", msg.Attachments.Select(a => a.Url))).WithIsInline(false));
                    }

                    await logChannel.EmbedAsync(embed).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    _log.Warn(ex);
                    // ignored
                }
            });

            return(Task.CompletedTask);
        }
Esempio n. 21
0
            private Task _client_ChannelUpdated(IChannel cbefore, IChannel cafter)
            {
                var before = cbefore as IGuildChannel;

                if (before == null)
                {
                    return(Task.CompletedTask);
                }
                var after = (IGuildChannel)cafter;

                LogSetting logSetting;

                if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting) ||
                    !logSetting.IsLogging ||
                    !logSetting.ChannelUpdated ||
                    logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == after.Id))
                {
                    return(Task.CompletedTask);
                }

                ITextChannel logChannel;

                if ((logChannel = TryGetLogChannel(before.Guild, logSetting)) == null)
                {
                    return(Task.CompletedTask);
                }

                var task = Task.Run(async() =>
                {
                    try
                    {
                        if (before.Name != after.Name)
                        {
                            //await logChannel.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Name Changed** `#{after.Name}` ({after.Id})
                            await logChannel.SendMessageAsync($@"🕓`{prettyCurrentTime}`ℹ️ **| Channel Name Changed |** #⃣ `{after.Name} ({after.Id})`
    `Old:` {before.Name}
    **`New:`** {after.Name}").ConfigureAwait(false);
                        }
                        else if ((before as ITextChannel).Topic != (after as ITextChannel).Topic)
                        {
                            //await logChannel.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Topic Changed** `#{after.Name}` ({after.Id})
                            await logChannel.SendMessageAsync($@"🕘`{prettyCurrentTime}`ℹ️ **| Channel Topic Changed |** #⃣ `{after.Name} ({after.Id})`
    `Old:` {((ITextChannel)before).Topic}
    **`New:`** {((ITextChannel)after).Topic}").ConfigureAwait(false);
                        }
                    }
                    catch { }
                });

                return(Task.CompletedTask);
            }
Esempio n. 22
0
            private Task _client_MessageUpdated(Optional <IMessage> optmsg, IMessage imsg2)
            {
                var after = imsg2 as IUserMessage;

                if (after == null || after.IsAuthor())
                {
                    return(Task.CompletedTask);
                }

                var before = (optmsg.IsSpecified ? optmsg.Value : null) as IUserMessage;

                if (before == null)
                {
                    return(Task.CompletedTask);
                }

                var channel = after.Channel as ITextChannel;

                if (channel == null)
                {
                    return(Task.CompletedTask);
                }

                LogSetting logSetting;

                if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting) ||
                    !logSetting.IsLogging ||
                    !logSetting.MessageUpdated ||
                    logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id))
                {
                    return(Task.CompletedTask);
                }

                ITextChannel logChannel;

                if ((logChannel = TryGetLogChannel(channel.Guild, logSetting)) == null || logChannel.Id == after.Channel.Id)
                {
                    return(Task.CompletedTask);
                }

                var task = Task.Run(async() =>
                {
                    //try { await logChannel.SendMessageAsync($@"🕔`{prettyCurrentTime}` **Message** 📝 `#{channel.Name}`
//👤`{before.Author.Username}`
                    try { await logChannel.SendMessageAsync($@"🕔`{prettyCurrentTime}`👤__**{before.Author.Username}#{before.Author.Discriminator}**__ **| 📝 Edited Message |** 🆔 `{before.Author.Id}` #⃣ `{channel.Name}`
        `Old:` {before.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator).SanitizeMentions()}
        **`New:`** {after.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator).SanitizeMentions()}").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
                });

                return(Task.CompletedTask);
            }
Esempio n. 23
0
            private Task _client_MessageDeleted(ulong arg1, Optional <IMessage> imsg)
            {
                var msg = (imsg.IsSpecified ? imsg.Value : null) as IUserMessage;

                if (msg == null || msg.IsAuthor())
                {
                    return(Task.CompletedTask);
                }

                var channel = msg.Channel as ITextChannel;

                if (channel == null)
                {
                    return(Task.CompletedTask);
                }

                LogSetting logSetting;

                if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting) ||
                    !logSetting.IsLogging ||
                    !logSetting.MessageDeleted ||
                    logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id))
                {
                    return(Task.CompletedTask);
                }

                ITextChannel logChannel;

                if ((logChannel = TryGetLogChannel(channel.Guild, logSetting)) == null || logChannel.Id == msg.Id)
                {
                    return(Task.CompletedTask);
                }

                var task = Task.Run(async() =>
                {
                    try
                    {
                        var str = $@"🕔`{prettyCurrentTime}`👤__**{msg.Author.Username}#{msg.Author.Discriminator}**__ **| Deleted Message |** 🆔 `{msg.Author.Id}` #⃣ `{channel.Name}`
🗑 {msg.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator)}";
                        if (msg.Attachments.Any())
                        {
                            str += $"{Environment.NewLine}📎 {string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))}";
                        }
                        await logChannel.SendMessageAsync(str.SanitizeMentions()).ConfigureAwait(false);
                    }
                    catch (Exception ex) { _log.Warn(ex); }
                });

                return(Task.CompletedTask);
            }
Esempio n. 24
0
            private static async void _client_UserVoiceStateUpdated_TTS(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.LogVoicePresenceTTSId == null))
                    {
                        return;
                    }

                    ITextChannel logChannel;
                    if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresenceTTS)) == null)
                    {
                        return;
                    }

                    string str = null;
                    if (beforeVch?.Guild == afterVch?.Guild)
                    {
                        str = $"{usr.Username} moved from {beforeVch.Name} to {afterVch.Name}";
                    }
                    else if (beforeVch == null)
                    {
                        str = $"{usr.Username} has joined {afterVch.Name}";
                    }
                    else if (afterVch == null)
                    {
                        str = $"{usr.Username} has left {beforeVch.Name}";
                    }
                    var toDelete = await logChannel.SendMessageAsync(str, true).ConfigureAwait(false);

                    toDelete.DeleteAfter(5);
                }
                catch { }
            }
Esempio n. 25
0
            private static ITextChannel TryGetLogChannel(IGuild guild, LogSetting logSetting, LogChannelType logChannelType = LogChannelType.Text)
            {
                ulong id = 0;

                switch (logChannelType)
                {
                case LogChannelType.Text:
                    id = logSetting.ChannelId;
                    break;

                case LogChannelType.Voice:
                    id = logSetting.VoicePresenceChannelId;
                    break;

                case LogChannelType.UserPresence:
                    id = logSetting.UserPresenceChannelId;
                    break;
                }
                var channel = guild.GetTextChannel(id);

                if (channel == null)
                {
                    using (var uow = DbHandler.UnitOfWork())
                    {
                        var newLogSetting = uow.GuildConfigs.For(guild.Id).LogSetting;
                        switch (logChannelType)
                        {
                        case LogChannelType.Text:
                            logSetting.IsLogging = false;
                            break;

                        case LogChannelType.Voice:
                            logSetting.LogVoicePresence = false;
                            break;

                        case LogChannelType.UserPresence:
                            logSetting.LogUserPresence = false;
                            break;
                        }
                        GuildLogSettings.AddOrUpdate(guild.Id, newLogSetting, (gid, old) => newLogSetting);
                        uow.Complete();
                        return(null);
                    }
                }
                else
                {
                    return(channel);
                }
            }
Esempio n. 26
0
        private void MuteCommands_UserUnmuted(IGuildUser usr, MuteType muteType)
        {
            var _ = Task.Run(async() =>
            {
                try
                {
                    if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting) ||
                        (logSetting.UserMutedId == null))
                    {
                        return;
                    }

                    ITextChannel logChannel;
                    if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null)
                    {
                        return;
                    }

                    var mutes            = "";
                    var unmutedLocalized = GetText(logChannel.Guild, "unmuted_sn");
                    switch (muteType)
                    {
                    case MuteType.Voice:
                        mutes = "🔊 " + GetText(logChannel.Guild, "xmuted_voice", unmutedLocalized);
                        break;

                    case MuteType.Chat:
                        mutes = "🔊 " + GetText(logChannel.Guild, "xmuted_text", unmutedLocalized);
                        break;

                    case MuteType.All:
                        mutes = "🔊 " + GetText(logChannel.Guild, "xmuted_text_and_voice", unmutedLocalized);
                        break;
                    }

                    var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName(mutes))
                                .WithTitle($"{usr.Username}#{usr.Discriminator} | {usr.Id}")
                                .WithFooter(fb => fb.WithText($"{CurrentTime(usr.Guild)}"))
                                .WithOkColor();

                    await logChannel.EmbedAsync(embed).ConfigureAwait(false);
                }
                catch
                {
                    // ignored
                }
            });
        }
Esempio n. 27
0
        private Task _client_ChannelDestroyed(IChannel ich)
        {
            var _ = Task.Run(async() =>
            {
                try
                {
                    var ch = ich as IGuildChannel;
                    if (ch == null)
                    {
                        return;
                    }

                    if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out LogSetting logSetting) ||
                        (logSetting.ChannelDestroyedId == null) ||
                        logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == ch.Id))
                    {
                        return;
                    }

                    ITextChannel logChannel;
                    if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelDestroyed)) == null)
                    {
                        return;
                    }
                    string title;
                    if (ch is IVoiceChannel)
                    {
                        title = GetText(logChannel.Guild, "voice_chan_destroyed");
                    }
                    else
                    {
                        title = GetText(logChannel.Guild, "text_chan_destroyed");
                    }
                    await logChannel.EmbedAsync(new EmbedBuilder()
                                                .WithOkColor()
                                                .WithTitle("🆕 " + title)
                                                .WithDescription($"{ch.Name} | {ch.Id}")
                                                .WithFooter(efb => efb.WithText(CurrentTime(ch.Guild)))).ConfigureAwait(false);
                }
                catch
                {
                    // ignored
                }
            });

            return(Task.CompletedTask);
        }
Esempio n. 28
0
            private static async void _client_MessageUpdated(Optional <SocketMessage> optmsg, SocketMessage imsg2)
            {
                try
                {
                    var after = imsg2 as IUserMessage;
                    if (after == null || after.IsAuthor())
                    {
                        return;
                    }

                    var before = (optmsg.IsSpecified ? optmsg.Value : null) as IUserMessage;
                    if (before == null)
                    {
                        return;
                    }

                    var channel = after.Channel as ITextChannel;
                    if (channel == null)
                    {
                        return;
                    }

                    if (before.Content == after.Content)
                    {
                        return;
                    }

                    LogSetting logSetting;
                    if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting) ||
                        (logSetting.MessageUpdatedId == null) ||
                        logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id))
                    {
                        return;
                    }

                    ITextChannel logChannel;
                    if ((logChannel = await TryGetLogChannel(channel.Guild, logSetting, LogType.MessageUpdated)) == null || logChannel.Id == after.Channel.Id)
                    {
                        return;
                    }
                    await logChannel.SendMessageAsync($@"🕔`{prettyCurrentTime}`👤__**{before.Author.Username}#{before.Author.Discriminator}**__ **| 📝 Edited Message |** 🆔 `{before.Author.Id}` #⃣ `{channel.Name}`
        `Old:` {before.Resolve(userHandling: TagHandling.FullName).SanitizeMentions()}
        **`New:`** {after.Resolve(userHandling: TagHandling.FullName).SanitizeMentions()}").ConfigureAwait(false);
                }
                catch (Exception ex) { _log.Warn(ex); }
            }
        private Task _client_ChannelCreated(IChannel ich)
        {
            var _ = Task.Run(async() =>
            {
                try
                {
                    if (!(ich is IGuildChannel ch))
                    {
                        return;
                    }

                    if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out var logSetting) ||
                        logSetting.ChannelCreatedId == null)
                    {
                        return;
                    }

                    ITextChannel logChannel;
                    if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelCreated)) == null)
                    {
                        return;
                    }
                    string title;
                    if (ch is IVoiceChannel)
                    {
                        title = GetText(logChannel.Guild, "voice_chan_created");
                    }
                    else
                    {
                        title = GetText(logChannel.Guild, "text_chan_created");
                    }
                    await logChannel.EmbedAsync(new EmbedBuilder()
                                                .WithOkColor()
                                                .WithTitle("🆕 " + title)
                                                .WithDescription($"{ch.Name} | {ch.Id}")
                                                .WithFooter(efb => efb.WithText(CurrentTime(ch.Guild)))).ConfigureAwait(false);
                }
                catch (Exception ex) { _log.Warn(ex); }
            });

            return(Task.CompletedTask);
        }
Esempio n. 30
0
            public static async Task TriggeredAntiProtection(IGuildUser[] users, PunishmentAction action, ProtectionType protection)
            {
                if (users.Length == 0)
                {
                    return;
                }

                LogSetting logSetting;

                if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out logSetting) ||
                    !logSetting.IsLogging)
                {
                    return;
                }
                ITextChannel logChannel;

                if ((logChannel = TryGetLogChannel(users.First().Guild, logSetting)) == null)
                {
                    return;
                }

                var punishment = "";

                if (action == PunishmentAction.Mute)
                {
                    punishment = "🔇 MUTED";
                    //punishment = "MUTED";
                }
                else if (action == PunishmentAction.Kick)
                {
                    punishment = "☣ SOFT-BANNED (KICKED)";
                    //punishment = "KICKED";
                }
                else if (action == PunishmentAction.Ban)
                {
                    punishment = "⛔️ BANNED";
                    //punishment = "BANNED";
                }
                await logChannel.SendMessageAsync(String.Join("\n", users.Select(user => $"‼️ {Format.Bold(user.ToString())} got **{punishment}** due to __**{protection}**__ protection on **{user.Guild.Name}** server.")))
                //await logChannel.SendMessageAsync(String.Join("\n",users.Select(user=>$"{Format.Bold(user.ToString())} was **{punishment}** due to `{protection}` protection on **{user.Guild.Name}** server.")))
                .ConfigureAwait(false);
            }