示例#1
0
文件: Mutes.cs 项目: yorii/Cliptok
        public async Task UnmuteCmd(CommandContext ctx, DiscordUser targetUser)
        {
            DiscordGuild   guild      = ctx.Guild;
            DiscordChannel logChannel = await Program.discord.GetChannelAsync(Program.cfgjson.LogChannel);

            // todo: store per-guild
            DiscordRole   mutedRole = guild.GetRole(Program.cfgjson.MutedRole);
            DiscordMember member    = await guild.GetMemberAsync(targetUser.Id);

            if ((await Program.db.HashExistsAsync("mutes", targetUser.Id)) || member.Roles.Contains(mutedRole))
            {
                await Mutes.UnmuteUserAsync(targetUser);

                await ctx.RespondAsync($"{Program.cfgjson.Emoji.Information} Successfully unmuted **{targetUser.Username}#{targetUser.Discriminator}**.");
            }
            else
            {
                try
                {
                    await Mutes.UnmuteUserAsync(targetUser);

                    await ctx.RespondAsync($"{Program.cfgjson.Emoji.Warning} According to Discord that user is not muted, but I tried to unnmute them anyway. Hope it works.");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} That user doesn't appear to be muted, *and* an error ocurred while attempting to unmute them anyway. Please contact the bot owner, the error has been logged.");
                }
            }
        }
示例#2
0
文件: Mutes.cs 项目: yorii/Cliptok
        public async Task MuteCmd(CommandContext ctx, DiscordMember targetMember, [RemainingText] string timeAndReason = "No reason specificed.")
        {
            if (Warnings.GetPermLevel(ctx.Member) == ServerPermLevel.TrialMod && (Warnings.GetPermLevel(targetMember) >= ServerPermLevel.TrialMod || targetMember.IsBot))
            {
                await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {ctx.User.Mention}, as a Trial Moderator you cannot perform moderation actions on other staff members or bots.");

                return;
            }

            await ctx.Message.DeleteAsync();

            TimeSpan muteDuration = default;
            string   possibleTime = timeAndReason.Split(' ').First();

            if (possibleTime.Length != 1)
            {
                string reason = timeAndReason;
                // Everything BUT the last character should be a number.
                string possibleNum = possibleTime.Remove(possibleTime.Length - 1);
                if (int.TryParse(possibleNum, out int timeLength))
                {
                    char possibleTimePeriod = possibleTime.Last();
                    muteDuration = ModCmds.ParseTime(possibleTimePeriod, timeLength);
                }
                else
                {
                    muteDuration = default;
                }

                if (muteDuration != default || possibleNum == "0")
                {
                    if (!timeAndReason.Contains(" "))
                    {
                        reason = "No reason specified.";
                    }
                    else
                    {
                        reason = timeAndReason.Substring(timeAndReason.IndexOf(' ') + 1, timeAndReason.Length - (timeAndReason.IndexOf(' ') + 1));
                    }
                }

                // await ctx.RespondAsync($"debug: {possibleNum}, {possibleTime}, {muteDuration.ToString()}, {reason}");
                Mutes.MuteUserAsync(targetMember, reason, ctx.User.Id, ctx.Guild, null, muteDuration);
                reason = reason.Replace("`", "\\`").Replace("*", "\\*");
                if (muteDuration == default)
                {
                    await ctx.RespondAsync($"{Program.cfgjson.Emoji.Muted} {targetMember.Mention} has been muted: **{reason}**");
                }
                else
                {
                    await ctx.RespondAsync($"{Program.cfgjson.Emoji.Muted} {targetMember.Mention} has been muted for **{Warnings.TimeToPrettyFormat(muteDuration, false)}**: **{reason}**");
                }
            }
        }
示例#3
0
        public async Task UnmuteCmd(CommandContext ctx, DiscordUser targetUser)
        {
            DiscordGuild guild = await Program.discord.GetGuildAsync(ctx.Guild.Id);

            DiscordChannel logChannel = await Program.discord.GetChannelAsync(Program.cfgjson.LogChannel);

            // todo: store per-guild
            DiscordRole   mutedRole = guild.GetRole(Program.cfgjson.MutedRole);
            DiscordMember member    = await guild.GetMemberAsync(targetUser.Id);

            if ((await Program.db.HashExistsAsync("mutes", targetUser.Id)) || member.Roles.Contains(mutedRole))
            {
                await Mutes.UnmuteUserAsync(targetUser);

                await ctx.RespondAsync($"{Program.cfgjson.Emoji.Information} Successfully unmuted **{targetUser.Username}#{targetUser.Discriminator}**");
            }
            else
            {
                await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} That user isn't muted!");
            }
        }
示例#4
0
        public async Task WarnCmd(
            CommandContext ctx,
            [Description("The user you are warning. Accepts many formats.")] DiscordUser targetUser,
            [RemainingText, Description("The reason for giving this warning.")] string reason = null
            )
        {
            await ctx.Message.DeleteAsync();

            if (reason == null)
            {
                await ctx.Member.SendMessageAsync($"{Program.cfgjson.Emoji.Warning} Reason must be included for the warning command to work.");

                return;
            }
            DiscordMessage msg = await ctx.RespondAsync($"{Program.cfgjson.Emoji.Warning} {targetUser.Mention} was warned: **{reason.Replace("`", "\\`").Replace("*", "\\*")}**");

            UserWarning warning = await GiveWarningAsync(targetUser, ctx.User, reason, MessageLink(msg));

            await Program.logChannel.SendMessageAsync($"{Program.cfgjson.Emoji.Warning} New warning for {targetUser.Mention}!", false, await FancyWarnEmbedAsync(warning, true, 0xFEC13D, false));

            // automute handling
            var warningsOutput = Program.db.HashGetAll(targetUser.Id.ToString()).ToDictionary(
                x => x.Name.ToString(),
                x => JsonConvert.DeserializeObject <UserWarning>(x.Value)
                );

            // Realistically this wouldn't ever be 0, but we'll set it below.
            int warnsSinceThreshold = 0;

            foreach (KeyValuePair <string, UserWarning> entry in warningsOutput)
            {
                UserWarning entryWarning = entry.Value;
                TimeSpan    span         = DateTime.Now - entryWarning.WarnTimestamp;
                if (span.Days <= Program.cfgjson.WarningDaysThreshold)
                {
                    warnsSinceThreshold += 1;
                }
            }

            int toMuteHours = 0;

            var keys      = Program.cfgjson.AutoMuteThresholds.Keys.OrderBy(key => Convert.ToUInt64(key));
            int chosenKey = 0;

            foreach (string key in keys)
            {
                int keyInt = int.Parse(key);
                if (keyInt <= warnsSinceThreshold && keyInt > chosenKey)
                {
                    toMuteHours = Program.cfgjson.AutoMuteThresholds[key];
                    chosenKey   = keyInt;
                }
            }

            if (toMuteHours > 0)
            {
                DiscordMember member = await ctx.Guild.GetMemberAsync(targetUser.Id);

                await Mutes.MuteUserAsync(member, TimeSpan.FromHours(toMuteHours), $"Automute after {warnsSinceThreshold} warnings in the past {Program.cfgjson.WarningDaysThreshold} hours.", ctx.User.Id, ctx.Guild, ctx.Channel);
            }
        }
示例#5
0
        public static async Task <UserWarning> GiveWarningAsync(DiscordUser targetUser, DiscordUser modUser, string reason, string contextLink, DiscordChannel channel)
        {
            DiscordGuild guild     = channel.Guild;
            ulong        warningId = (ulong)Program.db.StringGet("totalWarnings");

            // TODO: fix this hell
            if (warningId == 0)
            {
                Program.db.StringSet("totalWarnings", "1");
                warningId = 1;
            }
            else
            {
                warningId += 1;
            }

            UserWarning warning = new UserWarning()
            {
                TargetUserId  = targetUser.Id,
                ModUserId     = modUser.Id,
                WarnReason    = reason,
                WarnTimestamp = DateTime.Now,
                WarningId     = warningId,
                ContextLink   = contextLink
            };

            Program.db.StringSet("totalWarnings", warningId);
            Program.db.HashSet(targetUser.Id.ToString(), warning.WarningId, JsonConvert.SerializeObject(warning));
            try
            {
                DiscordMember member = await guild.GetMemberAsync(targetUser.Id);

                await member.SendMessageAsync($"{Program.cfgjson.Emoji.Warning} You were warned in **{guild.Name}**, reason: **{reason}**");
            }
            catch
            {
                // We failed to DM the user, this isn't important to note.
            }

            await Program.logChannel.SendMessageAsync($"{Program.cfgjson.Emoji.Warning} New warning for {targetUser.Mention}!", false, await FancyWarnEmbedAsync(warning, true, 0xFEC13D, false));

            // automute handling
            var warningsOutput = Program.db.HashGetAll(targetUser.Id.ToString()).ToDictionary(
                x => x.Name.ToString(),
                x => JsonConvert.DeserializeObject <UserWarning>(x.Value)
                );

            // Realistically this wouldn't ever be 0, but we'll set it below.
            int warnsSinceThreshold = 0;

            foreach (KeyValuePair <string, UserWarning> entry in warningsOutput)
            {
                UserWarning entryWarning = entry.Value;
                TimeSpan    span         = DateTime.Now - entryWarning.WarnTimestamp;
                if (span.Days <= Program.cfgjson.WarningDaysThreshold)
                {
                    warnsSinceThreshold += 1;
                }
            }

            int toMuteHours = 0;

            var keys      = Program.cfgjson.AutoMuteThresholds.Keys.OrderBy(key => Convert.ToUInt64(key));
            int chosenKey = 0;

            foreach (string key in keys)
            {
                int keyInt = int.Parse(key);
                if (keyInt <= warnsSinceThreshold && keyInt > chosenKey)
                {
                    toMuteHours = Program.cfgjson.AutoMuteThresholds[key];
                    chosenKey   = keyInt;
                }
            }

            if (toMuteHours > 0)
            {
                DiscordMember member = await guild.GetMemberAsync(targetUser.Id);

                await Mutes.MuteUserAsync(member, $"Automute after {warnsSinceThreshold} warnings in the past {Program.cfgjson.WarningDaysThreshold} days.", modUser.Id, guild, channel, TimeSpan.FromHours(toMuteHours));
            }


            return(warning);
        }