Ejemplo n.º 1
0
        private async Task CheckTicketTyping(SocketUser arg1, ISocketMessageChannel arg2)
        {
            if(CurrentTickets.Any(x => x.DMChannelID == arg2.Id))
            {
                var ticket = CurrentTickets.Find(x => x.DMChannelID == arg2.Id);

                var tchan = client.GetGuild(Global.SwissGuildId).GetTextChannel(ticket.TicketChannel);
                if (ticket.DMTyping.Typing)
                {
                    ticket.DMTyping.TypingObject.Dispose();
                    ticket.DMTyping.Typing = false;
                }
                ticket.DMTyping.Typing = true;
                ticket.DMTyping.TypingObject = tchan.EnterTypingState();
            }
            //else if(CurrentTickets.Any(x => x.TicketChannel == arg2.Id))
            //{
            //    var ticket = CurrentTickets.Find(x => x.TicketChannel == arg2.Id);
            //    var tchan = await client.GetDMChannelAsync(ticket.DMChannelID);
            //    if (ticket.TicketTyping.Typing)
            //    {
            //        ticket.TicketTyping.TypingObject.Dispose();
            //        ticket.TicketTyping.Typing = false;
            //    }
            //    var tp = tchan.EnterTypingState();
            //    ticket.TicketTyping.Typing = true;
            //    ticket.TicketTyping.TypingObject = tp;
            
        }
Ejemplo n.º 2
0
 public async Task SnippetHandler(SocketMessage arg)
 {
     if (!CurrentTickets.Any(x => x.TicketChannel == arg.Channel.Id))
         return;
     var ticket = CurrentTickets.Find(x => x.TicketChannel == arg.Channel.Id);
     if (!arg.Content.StartsWith('!') && !arg.Content.Contains(' '))
         return;
     if (arg.Content == "!snippets")
         return;
     
     string snipname = arg.Content;
    
     if (Snippets.ContainsKey(snipname))
     {
         var dmchan = await client.GetUser(ticket.UserID).GetOrCreateDMChannelAsync();
         string snipval = Snippets[snipname];
         await arg.DeleteAsync();
         ticket.Transcript.AddMessage(snipval, arg.Author, arg.Id, arg.Timestamp);
         await dmchan.SendMessageAsync($"**[Staff] {arg.Author.ToString()}** - {snipval}");
         await arg.Channel.SendMessageAsync($"**[Staff] {arg.Author.ToString()}** - {snipval}");
     }
     else
     {
         //await arg.Channel.SendMessageAsync("", false, new EmbedBuilder()
         //{
         //    Title = "Invalid snippet!",
         //    Description = $"Looks like the snippet \"{arg.Content}\" Doesn't exist! For a list of snippets, do `!snippets`",
         //    Color = Color.Red
         //}.Build());
     }
 }
Ejemplo n.º 3
0
 public async Task Welcome()
 {
     if (!HasExecutePermission)
         return;
     if (CurrentTickets.Any(x => x.TicketChannel == Context.Channel.Id))
     {
         var ticket = CurrentTickets.Find(x => x.TicketChannel == Context.Channel.Id);
         if(!ticket.Welcomed)
         {
             var dmchan = await Context.Client.GetUser(ticket.UserID).GetOrCreateDMChannelAsync();
             var usr = Context.Message.Author as SocketGuildUser;
             await Context.Message.DeleteAsync();
             ticket.Transcript.AddMessage("Hello! Swiss001 Support! How May I help you?", usr, Context.Message.Id, Context.Message.Timestamp);
             string msg = $"**[Staff] {(usr.Nickname == null ? usr.ToString() : usr.Nickname)}** - Hello! Swiss001 Support! How May I help you?";
             await Context.Guild.GetTextChannel(ticket.TicketChannel).SendMessageAsync(msg);
             await dmchan.SendMessageAsync(msg);
             ticket.Welcomed = true;
         
         }
         else
         {
             var msg = await Context.Channel.SendMessageAsync("The user has been welcomed, are you sure you want to still want to send them another welcome message?");
             await msg.AddReactionsAsync(new IEmote[] { new Emoji("✅"), new Emoji("❌") });
             WelcomeMessages.Add(msg.Id);
         }
     }
 }
            public async Task anonRespond(params string[] args)
            {
                if (!HasExecutePermission)
                {
                    return;
                }
                if (CurrentTickets.Any(x => x.TicketChannel == Context.Channel.Id))
                {
                    var ticket = CurrentTickets.Find(x => x.TicketChannel == Context.Channel.Id);
                    var dmchan = await Context.Client.GetUser(ticket.UserID).GetOrCreateDMChannelAsync();

                    await Context.Message.DeleteAsync();

                    string msg = $"**Staff** - {string.Join(" ", args)}";
                    if (Context.Message.Attachments.Count > 0)
                    {
                        foreach (var attc in Context.Message.Attachments)
                        {
                            msg += $"\n**Attachment** - {attc.Url}";
                        }
                    }
                    await dmchan.SendMessageAsync(msg);

                    await Context.Channel.SendMessageAsync(msg);
                }
            }
Ejemplo n.º 5
0
            public async Task Close()
            {
                Global.ConsoleLog("Has Permission: " + HasExecutePermission);
                if (!HasExecutePermission)
                    return;
                if (CurrentTickets.Any(x => x.TicketChannel == Context.Channel.Id))
                {
                    var ticket = CurrentTickets.Find(x => x.TicketChannel == Context.Channel.Id);

                    if (closingState.Keys.Any(x => x.Key == Context.Channel.Id))
                    {
                        Global.ConsoleLog("No Closing state");

                        return;
                    }
                    var cmsg = await Context.Channel.SendMessageAsync("This thread will be closed in 5 seconds. If you wish to cancel this, please click the X mark.");

                    await cmsg.AddReactionAsync(new Emoji("❌"));
                    var t = new Timer() { AutoReset = false, Interval = 5000, Enabled = true };
                    t.Elapsed += async (object s, ElapsedEventArgs a) =>
                    {
                        var chan = Context.Channel as SocketTextChannel;
                        closingState.Remove(closingState.Keys.First(x => x.Key == chan.Id));
                        CurrentTickets.Remove(ticket);

                        var ts = ticket.Transcript.CompileAndSave();

                        await Global.Client.GetGuild(Global.SwissGuildId).GetTextChannel(770875781823463424).SendMessageAsync("", false, new EmbedBuilder()
                        {
                            Title = "New ticket transcript",
                            Description = $"New [transcript](https://api.swissdev.team/apprentice/v1/tickets/{ts.id}/{ts.timestamp}) from <@{ticket.UserID}>",
                            Fields = new List<EmbedFieldBuilder>()
                            {
                                new EmbedFieldBuilder()
                                {
                                    Name = "Notice",
                                    Value = "To view tickets you have to sign in with discord, The only information i recieve is Username, Profile, and User ID. I use this information to check if you are staff. Links will not allow non staff members to view tickets.\nYou can view all tickets [here](https://api.swissdev.team/apprentice/v1/tickets)"
                                }
                            },
                            Color = Color.Green
                        }.WithCurrentTimestamp().Build());

                        await chan.DeleteAsync(new RequestOptions() { AuditLogReason = "Ticket Closed" });
                        var dmUser = Context.Client.GetUser(ticket.UserID);
                        if(dmUser != null)
                        {
                            var dmchan = await dmUser.GetOrCreateDMChannelAsync();
                            if (dmchan != null)
                                await dmchan.SendMessageAsync("Your ticket with the staff team is now closed. If you wish to open another ticket, please send a message.");
                        }
                       
                        Global.SaveSupportTickets();
                    };
                    closingState.Add(new KeyValuePair<ulong, ulong>(Context.Channel.Id, cmsg.Id), t);
                    
                }
                else
                    Global.ConsoleLog("cant find chan for close");
            }
Ejemplo n.º 6
0
            public async Task Respond(params string[] args)
            {
                if (!HasExecutePermission)
                {
                    return;
                }
                if (CurrentTickets.Any(x => x.TicketChannel == Context.Channel.Id))
                {
                    var ticket = CurrentTickets.Find(x => x.TicketChannel == Context.Channel.Id);
                    var dmchan = await Context.Client.GetUser(ticket.UserID).GetOrCreateDMChannelAsync();

                    if (dmchan == null)
                    {
                        await Context.Channel.SendMessageAsync("", false, new EmbedBuilder()
                        {
                            Title       = $"Looks like we cant slide into <@{ticket.UserID}> dm's",
                            Description = "They either blocked us or have left the server :("
                        }.Build());

                        return;
                    }
                    var    usr = Context.Guild.GetUser(Context.Message.Author.Id);
                    string msg = $"**[Staff] {(usr.Nickname == null ? usr.ToString() : usr.Nickname)}** - {string.Join(" ", args)}";


                    if (Context.Message.Attachments.Count > 0)
                    {
                        foreach (var attc in Context.Message.Attachments)
                        {
                            var bt = new WebClient().DownloadData(new Uri(attc.ProxyUrl));
                            File.WriteAllBytes(Environment.CurrentDirectory + $"{Path.DirectorySeparatorChar}{attc.Filename}", bt);
                            await dmchan.SendFileAsync(Environment.CurrentDirectory + $"{Path.DirectorySeparatorChar}{attc.Filename}", msg);

                            await Context.Channel.SendFileAsync(Environment.CurrentDirectory + $"{Path.DirectorySeparatorChar}{attc.Filename}", msg);
                        }
                    }
                    else
                    {
                        try
                        {
                            await dmchan.SendMessageAsync(msg);
                        }
                        catch (Exception e)
                        {
                            await Context.Channel.SendMessageAsync("", false, new EmbedBuilder()
                            {
                                Title       = $"Looks like we cant slide into <@{ticket.UserID}> dm's",
                                Description = "They either blocked us or have left the server :("
                            }.Build());

                            return;
                        }
                        await Context.Channel.SendMessageAsync(msg);
                    }
                    await Context.Message.DeleteAsync();
                }
            }
Ejemplo n.º 7
0
 private async Task Client_Ready()
 {
     foreach (var item in CurrentTickets.ToList())
     {
         if (!Global.SwissGuild.Channels.Any(x => x.Id == item.TicketChannel))
         {
             CurrentTickets.Remove(item);
         }
     }
     Console.WriteLine("Cleared ticket cache");
     Global.SaveSupportTickets();
 }
Ejemplo n.º 8
0
            public async Task Close()
            {
                Global.ConsoleLog("Has Permission: " + HasExecutePermission);
                if (!HasExecutePermission)
                {
                    return;
                }
                if (CurrentTickets.Any(x => x.TicketChannel == Context.Channel.Id))
                {
                    var ticket = CurrentTickets.Find(x => x.TicketChannel == Context.Channel.Id);

                    if (closingState.Keys.Any(x => x.Key == Context.Channel.Id))
                    {
                        Global.ConsoleLog("No Closing state");

                        return;
                    }
                    var cmsg = await Context.Channel.SendMessageAsync("This thread will be closed in 5 seconds. If you wish to cancel this, please click the X mark.");

                    await cmsg.AddReactionAsync(new Emoji("❌"));

                    var t = new Timer()
                    {
                        AutoReset = false, Interval = 5000, Enabled = true
                    };
                    t.Elapsed += async(object s, ElapsedEventArgs a) =>
                    {
                        var chan = Context.Channel as SocketTextChannel;
                        closingState.Remove(closingState.Keys.First(x => x.Key == chan.Id));
                        CurrentTickets.Remove(ticket);
                        await chan.DeleteAsync(new RequestOptions()
                        {
                            AuditLogReason = "Ticket Closed"
                        });

                        var dmchan = await Context.Client.GetUser(ticket.UserID).GetOrCreateDMChannelAsync();

                        if (dmchan != null)
                        {
                            await dmchan.SendMessageAsync("Your ticket with the staff team is now closed. If you wish to open another ticket, please send a message.");
                        }
                        Global.SaveSupportTickets();
                    };
                    closingState.Add(new KeyValuePair <ulong, ulong>(Context.Channel.Id, cmsg.Id), t);
                }
                else
                {
                    Global.ConsoleLog("cant find chan for close");
                }
            }
Ejemplo n.º 9
0
 private async Task CheckSupportChannel(SocketChannel arg)
 {
     if(CurrentTickets.Any(x => x.TicketChannel == arg.Id))
     {
         var ticket = CurrentTickets.Find(x => x.TicketChannel == arg.Id);
         var usr = client.GetGuild(Global.SwissGuildId).GetUser(ticket.UserID);
         CurrentTickets.Remove(ticket);
         if(usr != null)
         {
             try
             {
                 await usr.SendMessageAsync("Your ticket with the staff team is now closed. If you wish to open another ticket, please send a message.");
             }
             catch { };
         }
     }
 }
Ejemplo n.º 10
0
 private async Task CheckNewThread(SocketMessage arg)
 {
     if (arg.Author.IsBot)
         return;
     if(arg.Channel.GetType() == typeof(SocketDMChannel))
     {
         if (BlockedUsers.Any(x => x == arg.Author.Id))
         {
             return;
         }
         if (CurrentTickets.Any(x => x.DMChannelID == arg.Channel.Id))
         {
             var ticket = CurrentTickets.Find(x => x.DMChannelID == arg.Channel.Id);
             ticket.DMTyping.Typing = false;
             if (ticket.DMTyping.TypingObject != null)
                 ticket.DMTyping.TypingObject.Dispose();
             string msg = $"**[Ticketer] {arg.Author}** - {arg.Content.Replace("@everyone", "~~@ everyone~~").Replace("@here", "~~@ here~~")}";
             var tkchan = client.GetGuild(Global.SwissGuildId).GetTextChannel(ticket.TicketChannel);
             await tkchan.SendMessageAsync(msg);
             ticket.Transcript.AddMessage(arg);
             if (arg.Attachments.Count > 0)
             {
                 foreach (var attc in arg.Attachments)
                 {
                     var bt = new WebClient().DownloadData(new Uri(attc.ProxyUrl));
                     File.WriteAllBytes(Environment.CurrentDirectory + $"{Path.DirectorySeparatorChar}{attc.Filename}", bt);
                     await tkchan.SendFileAsync(Environment.CurrentDirectory + $"{Path.DirectorySeparatorChar}{attc.Filename}", $"**[Ticketer]**");
                 }
             }
             
     
         }
         else if (!Setups.ContainsKey(arg.Author.Id))
         {
             var msg = await arg.Channel.SendMessageAsync("Hello " + arg.Author.Mention + ", if you want to open a support ticket please click the checkmark, otherwise to delete this message click the X");
             await msg.AddReactionsAsync(new IEmote[] { new Emoji("✅"), new Emoji("❌") });
             Setups.Add(arg.Channel.Id, new KeyValuePair<ulong, string>(msg.Id, arg.Content));
         }
         
     }
     else if(CurrentTickets.Any(x => x.TicketChannel == arg.Channel.Id))
     {
         //check snippets
         await SnippetHandler(arg);
     }
 }
Ejemplo n.º 11
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();
        }   
Ejemplo n.º 12
0
        private async Task CheckInitThread(Cacheable<IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3)
        {
            var usr = await arg2.GetUserAsync(arg3.UserId);
            if (usr.IsBot)
                return;

            if (Setups.ContainsKey(arg2.Id))
            {
                var msg = await arg2.GetMessageAsync(Setups[arg2.Id].Key);

                //checkmark
                if (arg3.Emote.Equals(new Emoji("✅")))
                {
                    if (client.GetGuild(Global.SwissGuildId).Users.Any(x => x.Id == usr.Id))
                    {
                        if (BlockedUsers.Any(x => x == usr.Id))
                        {
                            await arg2.SendMessageAsync("", false, new EmbedBuilder()
                            {
                                Title = "You are blocked!",
                                Description = "Looks like your blocked from creating support tickets :/",
                                Color = Color.Red
                            }.Build());
                            Setups.Remove(arg2.Id);
                            await msg.DeleteAsync();
                            return;
                        }
                        else
                        {
                            await msg.DeleteAsync();
                            var tmpmsg = await arg2.SendMessageAsync("**Creating support ticket with the staff team...**");
                            await CreateNewTicket(arg2, usr, Setups[arg2.Id].Value);
                            await tmpmsg.ModifyAsync(x => x.Embed = new EmbedBuilder()
                            {
                                Title = "Congrats! You are now talking with staff!",
                                Description = "Please note staff **Can** take moderation action for anything you say in a ticket. The same rules apply as the server.\n_This ticket may also be archived and used for training purposes._",
                                Color = Color.Green
                            }.Build());
                        }
                    }
                    else
                    {
                        await usr.SendMessageAsync("", false, new EmbedBuilder()
                        {
                            Title = "Sorry... :(",
                            Description = "The staff team does not accept tickets from users who are not in the server.",
                            Color = Color.Red
                        }.Build());
                    }

                }
                else if (arg3.Emote.Equals(new Emoji("❌"))) // xmark
                {
                    Setups.Remove(arg2.Id);
                    await msg.DeleteAsync();
                }
            }
            else if (closingState.Keys.Any(x => x.Key == arg2.Id))
            {
                var o = closingState.First(x => x.Key.Key == arg2.Id);
                var msg = await arg2.GetMessageAsync(o.Key.Value);

                if (arg3.Emote.Equals(new Emoji("❌")))
                {
                    o.Value.Stop();
                    o.Value.Dispose();
                    closingState.Remove(o.Key);
                    await msg.DeleteAsync();
                }
            }
            else if (WelcomeMessages.Contains(arg3.MessageId))
            {
                if (arg3.Emote.Equals(new Emoji("❌")))
                {
                    var msg = await arg2.GetMessageAsync(arg3.MessageId);
                    await msg.DeleteAsync();
                }
                if (arg3.Emote.Equals(new Emoji("✅")))
                {
                    var ticket = CurrentTickets.Find(x => x.TicketChannel == arg2.Id);
                    var msg = await arg2.GetMessageAsync(arg3.MessageId);
                    var dmchan = await client.GetUser(ticket.UserID).GetOrCreateDMChannelAsync();
                    var gusr = usr as SocketGuildUser;
                    await msg.DeleteAsync();
                    string tmsg = $"**[Staff] {(gusr.Nickname == null ? usr.ToString() : gusr.Nickname)}** - Hello! Swiss001 Support! How May I help you?";
                    await arg2.SendMessageAsync(tmsg);
                    await dmchan.SendMessageAsync(tmsg);
                }
            }
        }
Ejemplo n.º 13
0
        private async Task CheckNewThread(SocketMessage arg)
        {
            if (arg.Author.IsBot)
            {
                return;
            }

            if (arg.Author.Id == client.CurrentUser.Id)
            {
                return;
            }

            if (arg.Channel is SocketDMChannel channel)
            {
                if (BlockedUsers.Any(x => x == arg.Author.Id))
                {
                    return;
                }
                if (CurrentTickets.Any(x => x.DMChannelID == arg.Channel.Id))
                {
                    var ticket = CurrentTickets.Find(x => x.DMChannelID == arg.Channel.Id);
                    ticket.DMTyping.Typing = false;
                    if (ticket.DMTyping.TypingObject != null)
                    {
                        ticket.DMTyping.TypingObject.Dispose();
                    }

                    var content = arg.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);
                    }

                    string msg    = $"**[Ticketer] {arg.Author}** - {content}";
                    var    tkchan = client.GetGuild(Global.SwissGuildId).GetTextChannel(ticket.TicketChannel);
                    await tkchan.SendMessageAsync(msg);

                    ticket.Transcript.AddMessage(arg);
                    if (arg.Attachments.Count > 0)
                    {
                        foreach (var attc in arg.Attachments)
                        {
                            var bt = new WebClient().DownloadData(new Uri(attc.ProxyUrl));
                            File.WriteAllBytes(Environment.CurrentDirectory + $"{Path.DirectorySeparatorChar}{attc.Filename}", bt);
                            await tkchan.SendFileAsync(Environment.CurrentDirectory + $"{Path.DirectorySeparatorChar}{attc.Filename}", $"**[Ticketer]**");
                        }
                    }
                }
                else
                {
                    if (Regex.IsMatch(arg.Content, @"training (\d{17}|\d{18})$"))
                    {
                        if (!Program.UserHasPerm(arg.Author.Id))
                        {
                            return;
                        }

                        var m = Regex.Match(arg.Content, @"training (\d{17}|\d{18})$");

                        var uid = m.Groups[1].Value;

                        var tmpmsg = await channel.SendMessageAsync("**Creating training ticket with the staff team...**");

                        await CreateNewTicket(channel, arg.Author, arg.Content, true, uid);

                        await tmpmsg.ModifyAsync(x => x.Embed = new EmbedBuilder()
                        {
                            Title       = "Training started",
                            Description = $"Training ticket with <@{uid}>",
                            Color       = Color.Green
                        }.Build());

                        return;
                    }
                    else
                    {
                        var msg = await arg.Channel.SendMessageAsync("Hello " + arg.Author.Mention + ", if you want to open a support ticket please click the checkmark, otherwise to delete this message click the X");

                        await msg.AddReactionsAsync(new IEmote[] { new Emoji("✅"), new Emoji("❌") });
                    }
                }
            }
            else if (CurrentTickets.Any(x => x.TicketChannel == arg.Channel.Id))
            {
                //check snippets
                await SnippetHandler(arg);
            }
        }
Ejemplo n.º 14
0
        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();
        }