Ejemplo n.º 1
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}`");
                }
            }
        }
Ejemplo n.º 2
0
        public async Task ModMail(CommandContext ctx,
                                  [Description("The name of the server that you want to open the Mod Mail with. *Spaces are replaced with `-`*")] string serverName = null)
        {
            if (ctx.Guild is null)
            {
                if (serverName == null)
                {
                    serverName = "no server!";
                }
                var ModMailServers = DB.DBLists.ServerSettings.Where(w => w.ModMailID != 0);
                Dictionary <DiscordGuild, string> GuildNameDict = new();
                StringBuilder GuildNameString = new();
                GuildNameString.AppendLine("The mod-mail is only available on certain servers, here are the server names you can use:");
                foreach (var item in ModMailServers)
                {
                    DiscordGuild Guild = await Program.Client.GetGuildAsync((ulong)item.ID_Server);

                    GuildNameDict.Add(Guild, Guild.Name.Replace(' ', '-').ToLower());
                    GuildNameString.AppendLine($"`{Guild.Name.Replace(' ', '-').ToLower()}`");
                }
                GuildNameString.AppendLine($"To start a modmail write `{Program.CFGJson.CommandPrefix}modmail server-name-here`");
                if (!GuildNameDict.Values.Contains(serverName.Replace(' ', '-').ToLower()))
                {
                    await ctx.RespondAsync(GuildNameString.ToString());
                }
                else
                {
                    DiscordGuild Guild       = GuildNameDict.FirstOrDefault(w => w.Value.ToLower() == serverName.ToLower()).Key;
                    bool         serverCheck = true;
                    try
                    {
                        await Guild.GetMemberAsync(ctx.User.Id);
                    }
                    catch
                    {
                        await ctx.RespondAsync("You are not in this server. If you think this is an error, please make sure you are set as online and are in fact in the server.");

                        serverCheck = false;
                    }
                    if (serverCheck && DB.DBLists.ModMail.FirstOrDefault(w => w.User_ID == ctx.User.Id && w.IsActive) == null)
                    {
                        Random     r        = new();
                        string     colorID  = string.Format("#{0:X6}", r.Next(0x1000000));
                        DB.ModMail newEntry = new()
                        {
                            Server_ID   = Guild.Id,
                            User_ID     = ctx.User.Id,
                            LastMSGTime = DateTime.Now,
                            ColorHex    = colorID,
                            IsActive    = true,
                            HasChatted  = false
                        };

                        DBLists.InsertModMail(newEntry);
                        await ctx.RespondAsync($"**----------------------------------------------------**\n" +
                                               $"Modmail entry **open** with `{serverName.ToLower()}`. Continue to write as you would normaly ;)\n*Mod Mail will time out in {Automation.ModMail.TimeoutMinutes} minutes after last message is sent.*");

                        DiscordChannel      MMChannel      = Guild.GetChannel((ulong)ModMailServers.FirstOrDefault(w => w.ID_Server == Guild.Id).ModMailID);
                        DiscordEmbedBuilder ModeratorEmbed = new()
                        {
                            Author = new DiscordEmbedBuilder.EmbedAuthor
                            {
                                Name    = $"{ctx.User.Username} ({ctx.User.Id})",
                                IconUrl = ctx.User.AvatarUrl
                            },
                            Title = $"[NEW] Mod Mail created by {ctx.User.Username}.",
                            Color = new DiscordColor(colorID)
                        };
                        await MMChannel.SendMessageAsync(embed : ModeratorEmbed);

                        Program.Client.Logger.LogInformation(CustomLogEvents.ModMail, $"New Mod Mail entry created by {ctx.User.Username}({ctx.User.Id}) for {serverName}");
                    }
                    else
                    {
                        await ctx.RespondAsync("Seems like you already have an active session ongoing, please close the previous one to start a new one.");
                    }
                }
            }
            else
            {
                await ctx.RespondAsync($"{ctx.Member.Mention}, You can only open a mod mail in Live bot Direct Messages");
            }
        }