示例#1
0
        public async Task <bool> MassMention(SocketUserMessage msg, SocketTextChannel channel)
        {
            if (msg.MentionedUsers.Distinct().Where(x => x != msg.Author).Where(x => x.IsBot == false).Count() + msg.MentionedRoles.Distinct().Where(x => x.IsMentionable == true).Count() >= 10)
            {
                SocketGuildUser    user = channel.Guild.GetUser(msg.Author.Id);
                EmbedAuthorBuilder auth = new EmbedAuthorBuilder()
                {
                    Name    = $"Case {Ban.CaseCount(channel.Guild.Id) + 1} | Mute | {user.Username}#{user.Discriminator}",
                    IconUrl = user.GetAvatarUrl(),
                };
                EmbedBuilder embed = new EmbedBuilder()
                {
                    Color  = new Color(255, 0, 0),
                    Author = auth
                };
                EmbedFooterBuilder footer = new EmbedFooterBuilder()
                {
                    Text = $"ID: {user.Id}"
                };
                SocketTextChannel banlog = user.Guild.GetTextChannel(263474494327226388);
                SocketRole        role   = user.Guild.GetRole(308331455602229268);

                RequestOptions options = new RequestOptions()
                {
                    AuditLogReason = $"Muting User | Reason: Auto - Mass mention | Mod: {Client.CurrentUser.Username}#{Client.CurrentUser.Discriminator}"
                };
                await user.AddRoleAsync(role, options);

                embed.WithCurrentTimestamp();
                embed.WithFooter(footer);
                embed.AddField(y =>
                {
                    y.Name     = "User";
                    y.Value    = user.Mention;
                    y.IsInline = true;
                });
                embed.AddField(y =>
                {
                    y.Name     = "Moderator";
                    y.Value    = Client.CurrentUser.Mention;
                    y.IsInline = true;
                });
                embed.AddField(y =>
                {
                    y.Name     = "Length";
                    y.Value    = $"10 minutes";
                    y.IsInline = true;
                });
                embed.AddField(y =>
                {
                    y.Name     = "Reason";
                    y.Value    = "Auto - Mass mention";
                    y.IsInline = true;
                });
                string content = Format.Sanitize(msg.Content).Length > 252
                    ? Format.Sanitize(msg.Content).SplitInParts(252).ElementAt(0) + "..."
                    : Format.Sanitize(msg.Content);
                embed.AddField(y =>
                {
                    y.Name     = "Message";
                    y.Value    = $"**{content}**";
                    y.IsInline = true;
                });
                Ban ban = new Ban()
                {
                    GuildID     = long.Parse(channel.Guild.Id.ToString()),
                    Case        = Ban.CaseCount(channel.Guild.Id) + 1,
                    UserID      = long.Parse(user.Id.ToString()),
                    Username    = user.Username + "#" + user.Discriminator,
                    Type        = "Mute",
                    ModeratorID = long.Parse(Client.CurrentUser.Id.ToString()),
                    Moderator   = Client.CurrentUser.Username + "#" + Client.CurrentUser.Discriminator,
                    Reason      = "Auto - Mass mention - " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToUniversalTime().ToShortTimeString()
                };
                Ban.Add(ban);
                try
                {
                    await user.SendMessageAsync($"You have been muted in **{Format.Sanitize(channel.Guild.Name)}** by {Client.CurrentUser.Mention} for **mass mentioning** and for a length of **10** minutes.");
                }
                catch (Discord.Net.HttpException)
                {
                    //cant send message
                }
                MutedUser.Add(channel.Guild.Id, user.Id);
                await channel.SendMessageAsync($"**{user.Username}#{user.Discriminator}** was muted.");

                await banlog.SendMessageAsync("", false, embed.Build());

                Task task = Task.Run(async() =>
                {
                    await Task.Delay(600000);
                    SocketGuildUser usr = user as SocketGuildUser;
                    if (usr.Roles.Any(e => e.Name.ToUpperInvariant() == "Muted".ToUpperInvariant()))
                    {
                        options.AuditLogReason = "Unmuting User | Reason: Mute expired";
                        await user.RemoveRoleAsync(role, options);
                        EmbedAuthorBuilder auth2 = new EmbedAuthorBuilder()
                        {
                            Name    = $"Case {Ban.CaseCount(channel.Guild.Id) + 1} | Unmute | {user.Username}#{user.Discriminator}",
                            IconUrl = user.GetAvatarUrl(),
                        };
                        EmbedBuilder embed2 = new EmbedBuilder()
                        {
                            Color  = new Color(0, 255, 0),
                            Author = auth2
                        };
                        EmbedFooterBuilder footer2 = new EmbedFooterBuilder()
                        {
                            Text = $"ID: {user.Id}"
                        };
                        embed2.WithCurrentTimestamp();
                        embed2.WithFooter(footer2);
                        embed2.AddField(y =>
                        {
                            y.Name     = "User";
                            y.Value    = user.Mention;
                            y.IsInline = true;
                        });
                        embed2.AddField(y =>
                        {
                            y.Name     = "Moderator";
                            y.Value    = Client.CurrentUser.Mention;
                            y.IsInline = true;
                        });
                        embed2.AddField(y =>
                        {
                            y.Name     = "Reason";
                            y.Value    = "Auto";
                            y.IsInline = true;
                        });
                        await banlog.SendMessageAsync("", false, embed2.Build());
                        try
                        {
                            await user.SendMessageAsync($"You are now unmuted in **{Format.Sanitize(channel.Guild.Name)}**.");
                        }
                        catch (Discord.Net.HttpException)
                        {
                            //cant send message
                        }
                        ban.Type   = "Unmute";
                        ban.Reason = "Auto - " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToUniversalTime().ToShortTimeString();
                        Ban.Add(ban);
                        MutedUser.Remove(channel.Guild.Id, user.Id);
                    }
                    else
                    {
                        MutedUser.Remove(channel.Guild.Id, user.Id);
                    }
                });
                return(true);
            }
            else if (msg.MentionedUsers.Distinct().Where(x => x != msg.Author).Where(x => x.IsBot == false).Count() + msg.MentionedRoles.Distinct().Where(x => x.IsMentionable == true).Count() >= 5)
            {
                return(true);
            }
            return(false);
        }