Пример #1
0
        /// <summary>
        /// Handles a mention event
        /// </summary>
        /// <param name="user">The user who sent the mentioning message</param>
        /// <param name="messageEMs">Amount of EMs inside that message</param>
        private static async Task HandleMention(SocketGuildUser user, int messageEMs)
        {
            bool firstInfraction = true;
            int  totalEMs        = messageEMs;


            List <MentionEvent> removeEvents = new List <MentionEvent>();

            foreach (MentionEvent oldEvent in MentionEvents)
            {
                if (!oldEvent.IsValid)
                {
                    removeEvents.Add(oldEvent);
                    continue;
                }
                if (oldEvent.UserId == user.Id)
                {
                    firstInfraction = false;
                    totalEMs       += oldEvent.EffectiveMentions;
                }
            }
            foreach (MentionEvent removeEvent in removeEvents)
            {
                MentionEvents.Remove(removeEvent);
            }

            MentionEvent mentionEvent = new MentionEvent(user.Id, messageEMs);

            MentionEvents.Add(mentionEvent);

            if (totalEMs >= EM_MUTE_LIMIT && !firstInfraction)
            {
                UserModerationLog userModLog = GuildModerationLog.GetOrCreateUserModerationLog(user.Guild.Id, user.Id, out GuildModerationLog guildModLog);

                await userModLog.AddMute(user, DateTimeOffset.MaxValue, null);

                IDMChannel dmChannel = await user.GetOrCreateDMChannelAsync();

                await dmChannel.SendMessageAsync(embed : MuteEmbed.Build());

                await AdminTaskInteractiveMessage.CreateAdminTaskMessage($"Muted User {user} for exceeding the EM limits", $"User: {user.Mention}\nEffective Mentions: `{totalEMs}/{EM_MUTE_LIMIT}`");
            }
            else if (totalEMs >= EM_WARNING_LIMIT)
            {
                // Handle Warning
                IDMChannel dmChannel = await user.GetOrCreateDMChannelAsync();

                await dmChannel.SendMessageAsync(embed : WarningEmbed.Build());
            }
        }
Пример #2
0
        protected override async Task ExecuteGuild(IGuildCommandContext context, object parsedArgs)
        {
            ArgumentContainer args = parsedArgs as ArgumentContainer;

            // Generate UserModerationEntry

            UserModerationEntry entry;

            if (args.MuteUntil == DateTimeOffset.MaxValue)
            {
                entry = new UserModerationEntry(context.Guild.Id, ModerationType.Muted, DateTimeOffset.UtcNow, context.GuildUser, args.Reason, "Duration: perma");
            }
            else
            {
                entry = new UserModerationEntry(context.Guild.Id, ModerationType.Muted, DateTimeOffset.UtcNow, context.GuildUser, args.Reason, "Duration: " + args.Duration.ToHumanTimeString());
            }
            UserModerationLog userLog = GuildModerationLog.GetOrCreateUserModerationLog(context.Guild.Id, args.TargetUser.Id, out _);

            await userLog.AddMute(args.TargetUser, args.MuteUntil, entry);

            // Report success

            await context.Channel.SendEmbedAsync($"Muted {args.TargetUser.Mention} ({args.TargetUser.Id}) for `{args.Reason}`");
        }