public async Task ModmailGetUser(string Token, [Remainder] string Reason)
        {
            ModMail ModMail = ModMailDB.ModMail.Find(Token);

            if (ModMail == null)
            {
                await BuildEmbed(EmojiEnum.Annoyed)
                .WithTitle("Invalid Token!")
                .WithDescription("I wasn't able to find a modmail with that token!")
                .SendEmbed(Context.Channel);

                return;
            }

            if (Reason.Length > 200)
            {
                await BuildEmbed(EmojiEnum.Annoyed)
                .WithTitle("Your unlock reason is to long!")
                .WithDescription(
                    "Modmail unlock reasons should only be brief and concise. " +
                    "Unlocks usually follow a given warning or a DM response. " +
                    "You should write your full write up in that. <3")
                .WithCurrentTimestamp()
                .SendEmbed(Context.Channel);

                return;
            }

            await SendForAdminApproval(
                UnlockModmail,
                new() { { "Token", Token }, { "Reason", Reason } },
Exemplo n.º 2
0
        public async Task Reply(CommandContext ctx,
                                [Description("Mod Mail entry ID")] long ModMailID,
                                [Description("Text that is being sent to the user via DM")][RemainingText] string reply)
        {
            await ctx.Message.DeleteAsync();

            await ctx.TriggerTypingAsync();

            ModMail MMEntry = DBLists.ModMail.FirstOrDefault(w => w.ID == ModMailID && w.Server_ID == ctx.Guild.Id);

            if (MMEntry == null)
            {
                await ctx.RespondAsync($"{ctx.User.Mention} Could not find the mod mail entry.");
            }
            else
            {
                if (MMEntry.IsActive)
                {
                    DiscordEmbedBuilder embed = new()
                    {
                        Author = new DiscordEmbedBuilder.EmbedAuthor
                        {
                            IconUrl = ctx.User.AvatarUrl,
                            Name    = ctx.User.Username
                        },
                        Title       = $"[REPLY] #{MMEntry.ID} Mod Mail Response",
                        Description = $"{ctx.Member.Username} - {reply}",
                        Color       = new DiscordColor(MMEntry.ColorHex)
                    };
                    try
                    {
                        DiscordMember member = await ctx.Guild.GetMemberAsync((ulong)MMEntry.User_ID);

                        await member.SendMessageAsync($"{ctx.Member.Username} - {reply}");
                    }
                    catch
                    {
                        embed.Description = $"User has left the server, blocked the bot or closed their DMs. Could not send a response!\nHere is what you said `{reply}`";
                        embed.Title       = $"[ERROR] {embed.Title}";
                    }
                    MMEntry.LastMSGTime = DateTime.Now;
                    DBLists.UpdateModMail(MMEntry);

                    DiscordChannel MMChannel = ctx.Guild.GetChannel((ulong)DBLists.ServerSettings.FirstOrDefault(w => w.ID_Server == ctx.Guild.Id).ModMailID);
                    await MMChannel.SendMessageAsync(embed : embed);

                    Program.Client.Logger.LogInformation(CustomLogEvents.ModMail, $"An admin has responded to Mod Mail entry #{MMEntry.ID}");
                }
                else
                {
                    await ctx.RespondAsync($"{ctx.User.Mention}, Mod Mail has timed out, message not sent to user.\n" +
                                           $"Here is what you said `{reply}`");
                }
            }
        }
Exemplo n.º 3
0
        public async Task sendModMail([Summary("Message Content")][Remainder] string content = "")
        {
            try
            {
                if (string.IsNullOrEmpty(content))
                {
                    EmbedBuilder b;
                    b = new EmbedBuilder()
                    {
                        Description = $"Usage: `modmail [message]`",
                        Color       = Color.Magenta
                    };
                    await Context.Message.Author.SendMessageAsync("", false, b.Build());
                }

                // get values
                ModMail serverConfig         = _floofDb.ModMails.Find(SERVER_ID);
                IGuild  guild                = Context.Client.GetGuild(SERVER_ID);                             // can return null
                Discord.ITextChannel channel = await guild.GetTextChannelAsync((ulong)serverConfig.ChannelId); // can return null

                IRole role = null;

                if (!Context.User.MutualGuilds.Contains(guild)) // the modmail server is not a mutual server
                {
                    return;
                }

                if (serverConfig == null || serverConfig.IsEnabled == false || guild == null || channel == null) // not configured
                {
                    await Context.Channel.SendMessageAsync("Modmail is not configured on this server.");

                    return;
                }

                if (serverConfig.ModRoleId != null)
                {
                    role = guild.GetRole((ulong)serverConfig.ModRoleId); // can return null
                }

                if (content.Length > 500)
                {
                    await Context.Message.Author.SendMessageAsync("Mod mail content cannot exceed 500 characters");

                    return;
                }

                // form embed
                SocketUser   sender  = Context.Message.Author;
                EmbedBuilder builder = new EmbedBuilder()
                {
                    Title       = "⚠️ | MOD MAIL ALERT!",
                    Description = $"Modmail from: {sender.Mention} ({sender.Username}#{sender.Discriminator})",
                    Color       = Discord.Color.Gold
                };
                builder.WithCurrentTimestamp();
                builder.AddField("Message Content", $"```{content}```");
                string messageContent = (role == null) ? "Mod mail" : role.Mention; // role id can be set in database but deleted from server
                await Context.Channel.SendMessageAsync("Alerting all mods!");

                await channel.SendMessageAsync(messageContent, false, builder.Build());
            }
            catch (Exception ex)
            {
                await Context.Channel.SendMessageAsync(ex.ToString());

                return;
            }
        }
Exemplo n.º 4
0
        public async Task UserDMCommand(string Token, [Remainder] string Message)
        {
            ModMail ModMail = ModMailDB.ModMail.Find(Token);

            IUser User = null;

            if (ModMail != null)
            {
                User = DiscordSocketClient.GetUser(ModMail.UserID);
            }

            if (ModMail == null || User == null)
            {
                await BuildEmbed(EmojiEnum.Annoyed)
                .WithTitle("Could Not Find Token!")
                .WithDescription("Haiya! I couldn't find the modmail for the given token. Are you sure this exists in the database? " +
                                 "The token should be given as the footer of the embed. Make sure this is the token and not the modmail number.")
                .WithCurrentTimestamp()
                .SendEmbed(Context.Channel);
            }
            else
            {
                SocketChannel SocketChannel = DiscordSocketClient.GetChannel(ModerationConfiguration.ModMailChannelID);

                if (SocketChannel is SocketTextChannel TextChannel)
                {
                    IMessage MailMessage = await TextChannel.GetMessageAsync(ModMail.MessageID);

                    if (MailMessage is IUserMessage MailMSG)
                    {
                        try {
                            await MailMSG.ModifyAsync(MailMSGs => MailMSGs.Embed = MailMessage.Embeds.FirstOrDefault().ToEmbedBuilder()
                                                      .WithColor(Color.Green)
                                                      .AddField($"Replied By: {Context.User.Username}", Message.Length > 300 ? $"{Message.Substring(0, 300)} ..." : Message)
                                                      .Build()
                                                      );
                        } catch (InvalidOperationException) {
                            IMessage Messaged = await MailMSG.Channel.SendMessageAsync(embed : MailMSG.Embeds.FirstOrDefault().ToEmbedBuilder().Build());

                            ModMail.MessageID = Messaged.Id;
                            ModMailDB.SaveChanges();
                        }
                    }
                    else
                    {
                        throw new Exception($"Woa, this is strange! The message required isn't a socket user message! Are you sure this message exists? ModMail Type: {MailMessage.GetType()}");
                    }
                }
                else
                {
                    throw new Exception($"Eek! The given channel of {SocketChannel} turned out *not* to be an instance of SocketTextChannel, rather {SocketChannel.GetType().Name}!");
                }

                await BuildEmbed(EmojiEnum.Love)
                .WithTitle("Modmail User DM")
                .WithDescription(Message)
                .AddField("Sent By", Context.User.GetUserInformation())
                .SendDMAttachedEmbed(Context.Channel, BotConfiguration, User,
                                     BuildEmbed(EmojiEnum.Unknown)
                                     .WithTitle($"Modmail From {Context.Guild.Name}")
                                     .WithDescription(Message)
                                     .WithCurrentTimestamp()
                                     .WithFooter(Token)
                                     );
            }
        }