Example #1
0
 async Task UnmuteUser(Punishment punishment)
 {
     try
     {
         await _client.EditUser(punishment.User, null, null, punishment.RolesBefore);
     } 
     catch (Exception ex)
     {
         _botServices.Logging.LogError(string.Format("Failed to unmute user: '******'", punishment.User.Name), ex);
         throw;
     }
 }
Example #2
0
        public void PunishUser(Punishment punishment)
        {
            _punishmentRepository.Insert(punishment);

            NotifyUserPunished(new UserPunishedEventArgs { Punishment = punishment });
        }
Example #3
0
        async Task MuteUser(Server server, Channel channel, User user, DateTime expiresOn)
        {
            try
            {
                // TODO: need to check if client has permissions and user is not the owner
                var mutedRole = server.Roles.SingleOrDefault(r => r.Name == "Muted") 
                    ?? await CreateMutedRole(server);

                var punishment = new Punishment
                {
                    Id = Guid.NewGuid(),
                    Server = server,
                    Channel = channel,
                    User = user,
                    RolesBefore = user.Roles,
                    RolesAfter = new List<Role> { mutedRole },
                    ExpiresOn = expiresOn,
                    PunishmentType = PunishmentType.Mute,
                    Actioned = false
                };

                _botServices.Defence.PunishUser(punishment);

                await _client.EditUser(user, null, null, punishment.RolesAfter);
            } 
            catch (Exception ex)
            {
                _botServices.Logging.LogError(string.Format("Failed to add '{0} to the muted role'", user.Name), ex);
                throw;
            }
        }