예제 #1
0
        private static ActiveTimedEvent BuildActiveTimedEvent(UserDisciplinaryEventStorage eventStorage)
        {
            var activeEvent = new ActiveTimedEvent();

            activeEvent.DisciplinaryEvent = eventStorage.DiscipinaryEventType;
            activeEvent.TimeToTrigger     = eventStorage.DateToRemove.Subtract(eventStorage.DateInserted).TotalMinutes;
            activeEvent.UserId            = eventStorage.UserID;
            return(activeEvent);
        }
예제 #2
0
        public async Task WarnUserAsync(ulong userID, SocketGuildChannel chnl, [Remainder] string reason = "")
        {
            try
            {
                SocketGuildUser user    = Context.Guild.GetUser(userID);
                var             channel = chnl as ITextChannel;
                if (user == null)
                {
                    await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}");

                    return;
                }
                if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser))
                {
                    return;
                }

                UserDisciplinaryEventStorage obj = new UserDisciplinaryEventStorage()
                {
                    DateInserted         = DateTime.UtcNow,
                    DateToRemove         = DateTime.UtcNow.AddDays(ConfigManager.GetIntegerProperty(PropertyItem.WarnDuration)),
                    DiscipinaryEventType = DisciplinaryEventEnum.WarnEvent,
                    ModeratorID          = Context.Message.Author.Id,
                    Reason = reason,
                    UserID = user.Id
                };
                UserStorage newUser = new UserStorage()
                {
                    UserID   = user.Id,
                    UserName = user.Username
                };
                await TimedEventManager.CreateEvent(obj, newUser);

                int warnCount = await StorageManager.GetRecentWarningsAsync(user.Id);

                string maxWarns = ConfigManager.GetProperty(PropertyItem.MaxWarns);
                if (string.IsNullOrEmpty(reason))
                {
                    await channel.SendMessageAsync($"{user.Mention} {BotDialogs.WarnMessageNoReason}🚫\n{warnCount}/{maxWarns} warnings.");
                }
                else
                {
                    await channel.SendMessageAsync($"{user.Mention} {BotDialogs.WarnMessageReason} 🚫\n{warnCount}/{maxWarns} warnings.\n{reason}");
                }
                await AutoModeratorManager.CheckForWarnThreshold(user, Context, warnCount, channel);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.WarnException, ex);
            }
        }
예제 #3
0
        private async Task MuteUserAsync(ulong userID, TimeSpan timeSpan, [Remainder] string reason = "no reason specified")
        {
            try
            {
                SocketGuildUser user = Context.Guild.GetUser(userID);
                if (user == null)
                {
                    await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}");

                    return;
                }

                if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser))
                {
                    return;
                }

                var mutedRole = DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted);
                await user.AddRoleAsync(mutedRole);

                UserDisciplinaryEventStorage newEvent = new UserDisciplinaryEventStorage()
                {
                    DateInserted         = DateTime.UtcNow,
                    DateToRemove         = (DateTimeOffset.UtcNow + timeSpan).DateTime,
                    DiscipinaryEventType = DisciplinaryEventEnum.MuteEvent,
                    ModeratorID          = Context.Message.Author.Id,
                    Reason = reason,
                    UserID = user.Id
                };
                UserStorage newUser = new UserStorage()
                {
                    UserID   = user.Id,
                    UserName = user.Username
                };

                bool existing = await TimedEventManager.CreateEvent(newEvent, newUser);

                await DiscordContextOverseer.LogModerationAction(userID, "Muted", Context.Message.Author.Id, reason, Utilities.ShortTimeSpanFormatting(timeSpan));

                var embed = Utilities.BuildDefaultEmbed(DisciplinaryEventEnum.MuteEvent, timeSpan, reason, user.Username, existing);
                await DiscordContextSeymour.GetMainChannel().SendMessageAsync("", false, embed);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.MuteException, ex);
            }
        }
예제 #4
0
        private async Task BanUserAsync(ulong userID, TimeSpan timeSpan, [Remainder] string reason = "no reason specified")
        {
            try
            {
                SocketGuildUser user = Context.Guild.GetUser(userID);
                if (user == null)
                {
                    await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}");

                    return;
                }
                string kickTargetName = user.Username;
                if (!await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser))
                {
                    await user.BanAsync(reason : reason);
                }
                else
                {
                    return;
                }

                var embed = Utilities.BuildDefaultEmbed(DisciplinaryEventEnum.BanEvent, timeSpan, reason, kickTargetName, false);
                await Context.Channel.SendMessageAsync("", false, embed);

                UserDisciplinaryEventStorage obj = new UserDisciplinaryEventStorage()
                {
                    DateInserted         = DateTime.UtcNow,
                    DateToRemove         = (DateTimeOffset.UtcNow + timeSpan).DateTime,
                    DiscipinaryEventType = DisciplinaryEventEnum.BanEvent,
                    ModeratorID          = Context.Message.Author.Id,
                    Reason = reason,
                    UserID = Context.Message.Author.Id
                };
                UserStorage newUser = new UserStorage()
                {
                    UserID   = Context.Message.Author.Id,
                    UserName = Context.Message.Author.Username
                };

                await TimedEventManager.CreateEvent(obj, newUser);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.BanException, ex);
            }
        }
예제 #5
0
        public async static Task CreateEvent(DisciplinaryEventEnum eventType, ulong moderatorId, string reason, ulong userId, string userName, DateTime end)
        {
            UserDisciplinaryEventStorage newEvent = new UserDisciplinaryEventStorage()
            {
                DateInserted         = DateTime.UtcNow,
                DateToRemove         = end,
                DiscipinaryEventType = eventType,
                ModeratorID          = moderatorId,
                Reason = reason,
                UserID = userId
            };
            UserStorage newUser = new UserStorage()
            {
                UserID   = userId,
                UserName = userName
            };

            await HandleEventCreated(newEvent, newUser);
        }
예제 #6
0
        private static async Task <bool> HandleEventCreated(UserDisciplinaryEventStorage newEvent, UserStorage newUser)
        {
            try
            {
                var newActiveEvent = BuildActiveTimedEvent(newEvent);
                ActiveEvents.Add(newActiveEvent);
                var result = await StorageManager.StoreTimedEventAsync(newEvent, newUser);

                newActiveEvent.DisciplinaryEventId = result.Key;
                newActiveEvent.Reason = newEvent.Reason;

                return(result.Value);
            }
            catch (Exception ex)
            {
                await ExceptionManager.LogExceptionAsync(ex);

                throw;
            }
        }
예제 #7
0
        private async Task RestrictUserAsync(SocketGuildUser user, TimeSpan timeSpan, [Remainder] string reason = "no reason specified")
        {
            try
            {
                if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser))
                {
                    return;
                }

                var limitedRole = DiscordContextSeymour.GrabRole(MordhauRoleEnum.Restricted);
                await user.AddRoleAsync(limitedRole);

                UserDisciplinaryEventStorage newEvent = new UserDisciplinaryEventStorage()
                {
                    DateInserted         = DateTime.UtcNow,
                    DateToRemove         = (DateTimeOffset.UtcNow + timeSpan).DateTime,
                    DiscipinaryEventType = DisciplinaryEventEnum.RestrictedUserEvent,
                    ModeratorID          = Context.Message.Author.Id,
                    Reason = reason,
                    UserID = user.Id
                };
                UserStorage newUser = new UserStorage()
                {
                    UserID   = user.Id,
                    UserName = user.Username
                };

                bool existing = await TimedEventManager.CreateEvent(newEvent, newUser);

                var embed = Utilities.BuildDefaultEmbed(DisciplinaryEventEnum.RestrictedUserEvent, timeSpan, reason, user.Username, existing, Context.Message.Author.Username);
                await Context.Channel.SendMessageAsync("", false, embed);

                await DiscordContextOverseer.LogModerationAction(user.Id, "Restricted", Context.Message.Author.Id, reason, Utilities.ShortTimeSpanFormatting(timeSpan));
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.LimitException, ex);
            }
        }
예제 #8
0
        public static async Task <KeyValuePair <ulong, bool> > StoreTimedEventAsync(UserDisciplinaryEventStorage newEvent, UserStorage newUser)
        {
            try
            {
                using (UserContext db = new UserContext())
                {
                    var findResult = await db.UserStorageTable.FindAsync(newUser.UserID);

                    if (findResult == null)
                    {
                        await db.UserStorageTable.AddAsync(newUser);
                    }

                    var existingDisciplinaryEvent = await db.UserDisciplinaryEventStorageTable.AsQueryable().FirstOrDefaultAsync(x => x.UserID == newUser.UserID && x.DiscipinaryEventType == newEvent.DiscipinaryEventType);

                    if (existingDisciplinaryEvent != null && newEvent.DiscipinaryEventType != DisciplinaryEventEnum.WarnEvent)
                    {
                        existingDisciplinaryEvent = newEvent;
                        await db.SaveChangesAsync();

                        return(new KeyValuePair <ulong, bool>(newEvent.DisciplineEventID, true));
                    }
                    else
                    {
                        await db.UserDisciplinaryEventStorageTable.AddAsync(newEvent);

                        await db.SaveChangesAsync();

                        return(new KeyValuePair <ulong, bool>(newEvent.DisciplineEventID, false));
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.StorageException, ex);
                throw;
            }
        }
예제 #9
0
 public async static Task <bool> CreateEvent(UserDisciplinaryEventStorage newEvent, UserStorage newUser)
 {
     return(await HandleEventCreated(newEvent, newUser));
 }