Exemple #1
0
        public async Task CreateNewTicket(ISocketMessageChannel chan, IUser user, string omsg)
        {
            var ticket = new SupportTicket()
            {
                DMChannelID = chan.Id,
                UserID = user.Id,
                DMTyping = new TypingState()
                {
                    Typing = false,
                    TypingObject = null
                }
            };
            var guilduser = client.GetGuild(Global.SwissGuildId).GetUser(user.Id);
            //create new ticket channel
            var ticketchan = await client.GetGuild(Global.SwissGuildId).CreateTextChannelAsync($"{user.Username}-{user.Discriminator}", x => x.CategoryId = Global.TicketCategoryID);
            var logs = ModDatabase.currentLogs.Users.Any(x => x.userId == user.Id) ? ModDatabase.currentLogs.Users.First(x => x.userId == user.Id) : null;

            ticket.Transcript = new TicketTranscript(ticket, omsg);

            var embed = new EmbedBuilder()
            {
                Title = $"**New support ticket from {user}**",
                Description = $"To view ticket snippets, do `!snippets` or `*snippets`",
                Author = new EmbedAuthorBuilder() { Name = user.ToString(), IconUrl = user.GetAvatarUrl() },
                Fields = new List<EmbedFieldBuilder>()
                {
                    { new EmbedFieldBuilder()
                    {
                        Name = "User",
                        Value = $"Name: {user}\nNickname: {guilduser.Nickname}\nID: {guilduser.Id}\nMention: {guilduser.Mention}\nCreated at: {guilduser.CreatedAt.UtcDateTime.ToString("f")} UTC\nJoined at: {guilduser.JoinedAt.Value.ToString("f")} UTC",
                    } },
                    { new EmbedFieldBuilder()
                    {
                        Name = "Roles",
                        Value = 
                        string.Join("\n", guilduser.Roles.OrderBy(x => x.Position).Select(x => x.Mention)).Length > 1024 
                        ? $"Unable to display all roles, listing top ten:\n{string.Join("\n", guilduser.Roles.OrderBy(x => x.Position).Select(x => x.Mention).Take(10))}" 
                        : string.Join("\n", guilduser.Roles.Select(x => x.Mention))
                    } },

                },
                Color = Color.DarkPurple
            };
            if(logs == null)
            {
                embed.AddField("Modlogs", "None");
            }
            else
            {
                string mlogs = "None <3";
                foreach(var mlog in logs.Logs.OrderBy(x => x.Date).Reverse())
                {
                    if (mlogs == "None <3")
                        mlogs = "";
                    mlogs += $"**{mlog.Action.ToString()}** on **{mlog.Date}**\n**Reason:** {mlog.Reason}\n**Moderator:** <@{mlog.ModeratorID}>\n\n";
                }
                embed.AddField("Modlogs", mlogs.Length > 1024 ? $"Modlogs too long, listing top 5\n\n{string.Join("\n\n", mlogs.Split("\n\n").Take(5))}" : string.Join("\n\n", mlogs.Split("\n\n")));
            }

            var msg = await ticketchan.SendMessageAsync("@here", false, embed.Build());
            await ticketchan.SendMessageAsync($"**\nV----------------START-OF-TICKET----------------V**\n\n**[Ticketer] {user}** - " + omsg);
            await msg.PinAsync();
            ticket.TicketChannel = ticketchan.Id;
            CurrentTickets.Add(ticket);
            Global.SaveSupportTickets();
        }   
        public async Task CreateNewTicket(ISocketMessageChannel chan, IUser user, string omsg, bool training = false, string tId = null)
        {
            var ticket = new SupportTicket()
            {
                DMChannelID = chan.Id,
                UserID      = user.Id,
                DMTyping    = new TypingState()
                {
                    Typing       = false,
                    TypingObject = null
                }
            };
            var guilduser = client.GetGuild(Global.SwissGuildId).GetUser(user.Id);
            //create new ticket channel
            var ticketchan = await client.GetGuild(Global.SwissGuildId).CreateTextChannelAsync($"{user.Username}-{user.Discriminator}{(training ? "-training" : "")}", x => x.CategoryId = Global.TicketCategoryID);

            var logs = ModDatabase.currentLogs.Users.Any(x => x.userId == user.Id) ? ModDatabase.currentLogs.Users.First(x => x.userId == user.Id) : null;

            ticket.Transcript = new TicketTranscript(ticket, omsg);

            var embed = new EmbedBuilder()
            {
                Title       = $"**New support ticket from {user}**",
                Description = $"To view ticket snippets, do `!snippets` or `*snippets`",
                Author      = new EmbedAuthorBuilder()
                {
                    Name = user.ToString(), IconUrl = user.GetAvatarUrl()
                },
                Fields = new List <EmbedFieldBuilder>()
                {
                    { new EmbedFieldBuilder()
                      {
                          Name  = "User",
                          Value = $"Name: {user}\nNickname: {guilduser.Nickname}\nID: {guilduser.Id}\nMention: {guilduser.Mention}\nCreated at: {guilduser.CreatedAt.UtcDateTime.ToString("f")} UTC\nJoined at: {guilduser.JoinedAt.Value.ToString("f")} UTC",
                      } },
                    { new EmbedFieldBuilder()
                      {
                          Name  = "Roles",
                          Value =
                              string.Join("\n", guilduser.Roles.OrderBy(x => x.Position).Select(x => x.Mention)).Length > 1024
                        ? $"Unable to display all roles, listing top ten:\n{string.Join("\n", guilduser.Roles.OrderBy(x => x.Position).Select(x => x.Mention).Take(10))}"
                        : string.Join("\n", guilduser.Roles.Select(x => x.Mention))
                      } },
                },
                Color = Color.DarkPurple
            };

            if (logs == null)
            {
                embed.AddField("Modlogs", "None");
            }
            else
            {
                string mlogs = "None <3";
                foreach (var mlog in logs.Logs.OrderBy(x => x.Date).Reverse())
                {
                    if (mlogs == "None <3")
                    {
                        mlogs = "";
                    }
                    mlogs += $"**{mlog.Action.ToString()}** on **{mlog.Date}**\n**Reason:** {mlog.Reason}\n**Moderator:** <@{mlog.ModeratorID}>\n\n";
                }
                embed.AddField("Modlogs", mlogs.Length > 1024 ? $"Modlogs too long, listing top 5\n\n{string.Join("\n\n", mlogs.Split("\n\n").Take(5))}" : string.Join("\n\n", mlogs.Split("\n\n")));
            }

            var msg = await ticketchan.SendMessageAsync(training?$"<@{tId}>" : "@here", false, embed.Build());

            var content = omsg;

            if (omsg != null)
            {
                content = content.Replace("@everyone", "~~@ everyone~~").Replace("@here", "~~@ here~~");

                List <(string old, string newS)> d = new List <(string old, string newS)>();
                if (Regex.IsMatch(content, @"<@&(\d{17}|\d{18})>"))
                {
                    var mtch = Regex.Matches(content, @"(<@&(\d{17}|\d{18})>)");
                    foreach (Match m in mtch)
                    {
                        var role = Global.SwissGuild.Roles.FirstOrDefault(x => x.Id == ulong.Parse(m.Groups[2].Value));

                        if (role != null)
                        {
                            d.Add((m.Value, $"~~@{role.Name}~~"));
                        }
                    }
                }

                foreach (var item in d)
                {
                    content = content.Replace(item.old, item.newS);
                }
            }

            if (training)
            {
                await ticketchan.SendMessageAsync($"**\nV-----------START-OF-TRAINING TICKET-----------V**\n\n");
            }
            else
            {
                await ticketchan.SendMessageAsync($"**\nV----------------START-OF-TICKET----------------V**\n\n**[Ticketer] {user}** - " + content);
            }

            await msg.PinAsync();

            ticket.TicketChannel = ticketchan.Id;
            CurrentTickets.Add(ticket);
            Global.SaveSupportTickets();
        }