public async Task SendModMail([Remainder] string Message) { if (RestrictionsDB.IsUserRestricted(Context.User, Databases.UserRestrictions.Restriction.Modmail)) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("You aren't permitted to send modmails!") .WithDescription("You have been blacklisted from using this service. If you think this is a mistake, feel free to personally contact an administrator") .SendEmbed(Context.Channel); return; } if (Message.Length > 1250) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("Your modmail message is too big!") .WithDescription("Please try to summarise your modmail a touch! If you are unable to, try send it in two different messages! " + $"This character count should be under 1250 characters. This is due to how Discord handles embeds and the added information we need to apply to the embed. " + $"The current modmail message character count is {Message.Length}.") .SendEmbed(Context.Channel); return; } string Tracker = CreateToken(); Attachment Attachment = Context.Message.Attachments.FirstOrDefault(); string ProxyURL = string.Empty; if (Attachment != null) { ProxyURL = await Attachment.ProxyUrl.GetProxiedImage(Tracker, DiscordSocketClient, ProposalService.ProposalConfiguration); } IUserMessage UsrMessage = await(DiscordSocketClient.GetChannel(ModerationConfiguration.ModMailChannelID) as ITextChannel).SendMessageAsync( embed: BuildEmbed(EmojiEnum.Unknown) .WithTitle($"Anonymous Modmail #{ModMailDB.ModMail.Count() + 1}") .WithDescription(Message) .WithImageUrl(ProxyURL) .WithCurrentTimestamp() .WithFooter(Tracker) .Build() ); ModMail ModMail = new() { Message = Message, UserID = Context.User.Id, MessageID = UsrMessage.Id, Tracker = Tracker }; ModMailDB.ModMail.Add(ModMail); ModMailDB.SaveChanges(); await BuildEmbed(EmojiEnum.Love) .WithTitle("Successfully Sent Modmail") .WithDescription($"Haiya! Your message has been sent to the staff team.\n\n" + $"Your modmail token is: `{ModMail.Tracker}`, which is what the moderators use to reply to you. " + $"Only give this out to a moderator if you wish to be identified.\n\n" + $"Thank you~! - {DiscordSocketClient.GetGuild(BotConfiguration.GuildID).Name} Staff Team <3") .WithFooter(ModMail.Tracker) .WithCurrentTimestamp() .SendEmbed(Context.Channel); }
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) ); } }