Exemple #1
0
        //Announce users leaving the guild if enabled
        private async Task UserLeaveGuild(DiscordClient client, GuildMemberRemoveEventArgs e)
        {
            if (e.Member.IsCurrent)
            {
                return;
            }

            var GuildSettings = await this.Config.FindGuildSettings(e.Guild);

            DiscordChannel channel;

            //Check notification settings
            switch (GuildSettings.NotificationChannel)
            {
            case 0:
                return;

            case 1:
                channel = e.Guild.GetDefaultChannel();
                break;

            default:
                channel = e.Guild.GetChannel(GuildSettings.NotificationChannel);
                break;
            }
            if (channel == null)
            {
                return;
            }

            //Check if the user was banned
            DiscordBan UserBan = await e.Guild.GetBanAsync(e.Member);

            if (UserBan != null)
            {
                await channel.SendMessageAsync($"{e.Member.Mention} ({e.Member.Username}#{e.Member.Discriminator}) was banned from the guild with the reason `{UserBan.Reason}`");

                return;
            }

            //Check if the user was kicked
            //The only way to determine this is through the audit logs which can make this inconsistent
            var L = await e.Guild.GetAuditLogsAsync(1, action_type : AuditLogActionType.Kick);

            DiscordAuditLogKickEntry LastKick = (DiscordAuditLogKickEntry)L.FirstOrDefault();

            if (LastKick != null && LastKick.Target == e.Member)
            {
                await channel.SendMessageAsync($"{e.Member.Mention} ({e.Member.Username}#{e.Member.Discriminator}) was kicked from the guild with the reason `{LastKick.Reason}`");

                return;
            }

            //The user left on their own
            await channel.SendMessageAsync($"{e.Member.Mention} ({e.Member.Username}#{e.Member.Discriminator}) left the guild.");
        }
Exemple #2
0
        public async Task <CommandResult> Run(string action, DiscordUser user)
        {
            GuildData guild = this.GetData <GuildData>(Context.Guild.Id.ToString());

            if (guild == null)
            {
                guild = new GuildData();
            }

            if (action == "add")
            {
                guild.Hackbans.Add(new Hackban(user.Id, Context.Author.Id));
                this.SetData(Context.Guild.Id.ToString(), guild);

                DiscordMember member;
                if ((member = Context.Guild.Members.FirstOrDefault(m => m.Id == user.Id)) != null)
                {
                    await member.BanAsync(reason : $"Hackban by {Context.Author.Username}#{Context.Author.Discriminator} via WamBot");
                }
                return($"Hackbanned {user.Mention} ({user.Username}#{user.Discriminator})");
            }
            else if (action == "remove")
            {
                guild.Hackbans.RemoveAll(g => g.User == user.Id);
                this.SetData(Context.Guild.Id.ToString(), guild);

                DiscordBan ban = (await Context.Guild.GetBansAsync()).FirstOrDefault(b => b.User.Id == user.Id);
                if (ban != null)
                {
                    await ban.User.UnbanAsync(Context.Guild, $"Revoked hackban by {Context.Author.Username}#{Context.Author.Discriminator} via WamBot");
                }

                return($"Removed hackban for {user.Mention} ({user.Username}#{user.Discriminator})");
            }
            else
            {
                return("Available actions: add, remove.");
            }
        }