Beispiel #1
0
        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}**");
                }
            }
        }
Beispiel #2
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        public override async Task <bool> ExecuteCheckAsync(CommandContext ctx, bool help)
        {
            if (ctx.Guild.Id != Program.cfgjson.ServerID)
            {
                return(false);
            }

            var level = Warnings.GetPermLevel(ctx.Member);

            if (level >= this.TargetLvl)
            {
                return(true);
            }
            else
            if (!help)
            {
                await ctx.RespondAsync($"{Program.cfgjson.Emoji.NoPermissions} Invalid permissions to use command **{ctx.Command.Name}**!");
            }
            return(false);
        }
Beispiel #3
0
        public async Task WarnCmd(
            CommandContext ctx,
            [Description("The channel you wish for the warning message to appear in.")] DiscordChannel targetChannel,
            [Description("The user you are warning. Accepts many formats.")] DiscordUser targetUser,
            [RemainingText, Description("The reason for giving this warning.")] string reason = null
            )
        {
            DiscordMember targetMember;

            try
            {
                targetMember = await ctx.Guild.GetMemberAsync(targetUser.Id);

                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;
                }
            }
            catch
            {
                // do nothing :/
            }

            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 targetChannel.SendMessageAsync($"{Program.cfgjson.Emoji.Warning} {targetUser.Mention} was warned: **{reason.Replace("`", "\\`").Replace("*", "\\*")}**", false, null);

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

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