Ejemplo n.º 1
0
        public async Task Mute(IGuildUser userToMute, [Remainder] string reason = "No reason.")
        {
            var guild = await GuildRepository.FetchGuildAsync(Context.Guild.Id);

            var mutedRole = Context.Guild.GetRole((ulong)guild.MutedRoleId);

            if (mutedRole == null)
            {
                throw new Exception($"You may not mute users if the muted role is not valid.\nPlease use the " +
                                    $"`{guild.Prefix}SetMutedRole` command to change that.");
            }
            if (await IsModAsync(userToMute))
            {
                throw new Exception("You cannot mute another mod!");
            }
            await InformSubjectAsync(Context.User, "Mute", userToMute, reason);

            await userToMute.AddRoleAsync(mutedRole);

            await MuteRepository.AddMuteAsync(userToMute.Id, Context.Guild.Id, Config.DEFAULT_MUTE_TIME);

            await Logger.ModLog(Context, "Mute", new Color(255, 114, 14), reason, userToMute, $"\n**Length:** {Config.DEFAULT_MUTE_TIME.TotalHours} hours");

            await ReplyAsync($"{Context.User.Mention} has successfully muted {userToMute.Mention}!");
        }
Ejemplo n.º 2
0
        public async Task CustomMute(double hours, IGuildUser userToMute, [Remainder] string reason = "No reason.")
        {
            if (hours > 168)
            {
                throw new Exception("You may not mute a user for more than a week.");
            }
            if (hours < 1)
            {
                throw new Exception("You may not mute a user for less than 1 hour.");
            }
            using (var db = new DbContext())
            {
                string time = "hours";
                if (hours == 1)
                {
                    time = "hour";
                }
                var guildRepo = new GuildRepository(db);
                var guild     = await guildRepo.FetchGuildAsync(Context.Guild.Id);

                var mutedRole = Context.Guild.GetRole(guild.MutedRoleId);
                if (mutedRole == null)
                {
                    throw new Exception($"You may not mute users if the muted role is not valid.\nPlease use the " +
                                        $"{guild.Prefix}SetMutedRole command to change that.");
                }
                var muteRepo = new MuteRepository(db);
                if (await IsMod(userToMute))
                {
                    throw new Exception("You cannot mute another mod!");
                }
                await InformSubject(Context.User, "Mute", userToMute, reason);

                await userToMute.AddRoleAsync(mutedRole);

                await muteRepo.AddMuteAsync(userToMute.Id, Context.Guild.Id, TimeSpan.FromHours(hours), DateTime.Now);

                await Logger.ModLog(Context, "Mute", new Color(255, 114, 14), reason, userToMute, $"\n**Length:** {hours} {time}");
                await ReplyAsync($"{Context.User.Mention} has successfully muted {userToMute.Mention} for {hours} {time}!");
            }
        }