Exemple #1
0
        public async Task OnExecute(CommandContext command)
        {
            // Check if the user has permission to use this command.
            if (!Config.HasPermission(command.Member, "assign"))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "You do not have permission to use this command."
                };
                await command.RespondAsync("", false, error);

                command.Client.DebugLogger.LogMessage(LogLevel.Info, "SupportBoi", "User tried to use the assign command but did not have permission.", DateTime.UtcNow);
                return;
            }

            // Check if ticket exists in the database
            if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "This channel is not a ticket."
                };
                await command.RespondAsync("", false, error);

                return;
            }

            ulong staffID;

            string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);

            if (!parsedMessage.Any())
            {
                staffID = command.Member.Id;
            }
            else if (!ulong.TryParse(parsedMessage[0], out staffID))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Invalid ID/Mention. (Could not convert to numerical)"
                };
                await command.RespondAsync("", false, error);

                return;
            }

            DiscordMember staffMember = null;

            try
            {
                staffMember = await command.Guild.GetMemberAsync(staffID);
            }
            catch (NotFoundException) {  }

            if (staffMember == null)
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Error: Could not find user."
                };
                await command.RespondAsync("", false, error);

                return;
            }

            if (!Database.IsStaff(staffMember.Id))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Error: User is not registered as staff."
                };
                await command.RespondAsync("", false, error);

                return;
            }

            if (!Database.AssignStaff(ticket, staffID))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Error: Failed to assign " + staffMember.Mention + " to ticket."
                };
                await command.RespondAsync("", false, error);

                return;
            }

            DiscordEmbed feedback = new DiscordEmbedBuilder
            {
                Color       = DiscordColor.Green,
                Description = "Assigned " + staffMember.Mention + " to ticket."
            };
            await command.RespondAsync("", false, feedback);

            if (Config.assignmentNotifications)
            {
                try
                {
                    DiscordEmbed message = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Green,
                        Description = "You have been assigned to a support ticket: " + command.Channel.Mention
                    };
                    await staffMember.SendMessageAsync("", false, message);
                }
                catch (UnauthorizedException) {}
            }

            // Log it if the log channel exists
            DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);

            if (logChannel != null)
            {
                DiscordEmbed logMessage = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = staffMember.Mention + " was was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
                };
                await logChannel.SendMessageAsync("", false, logMessage);
            }

            if (Config.sheetsEnabled)
            {
                DiscordMember user = null;
                try
                {
                    user = await command.Guild.GetMemberAsync(ticket.creatorID);
                }
                catch (NotFoundException) { }

                Sheets.DeleteTicketQueued(ticket.id);
                Sheets.AddTicketQueued(user, command.Channel, ticket.id.ToString(), staffMember.Id.ToString(), staffMember.DisplayName, ticket.createdTime, null, ticket.summary);
            }
        }
Exemple #2
0
        public async Task OnExecute(CommandContext command)
        {
            // Check if the user has permission to use this command.
            if (!Config.HasPermission(command.Member, "unassign"))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "You do not have permission to use this command."
                };
                await command.RespondAsync("", false, error);

                command.Client.DebugLogger.LogMessage(LogLevel.Info, "SupportBoi", "User tried to use the unassign command but did not have permission.", DateTime.UtcNow);
                return;
            }

            // Check if ticket exists in the database
            if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "This channel is not a ticket."
                };
                await command.RespondAsync("", false, error);

                return;
            }

            if (!Database.UnassignStaff(ticket))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Error: Failed to unassign staff from ticket."
                };
                await command.RespondAsync("", false, error);

                return;
            }

            DiscordEmbed message = new DiscordEmbedBuilder
            {
                Color       = DiscordColor.Green,
                Description = "Unassigned staff from ticket."
            };
            await command.RespondAsync("", false, message);

            // Log it if the log channel exists
            DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);

            if (logChannel != null)
            {
                DiscordEmbed logMessage = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = "Staff was unassigned from " + command.Channel.Mention + " by " + command.Member.Mention + "."
                };
                await logChannel.SendMessageAsync("", false, logMessage);
            }

            if (Config.sheetsEnabled)
            {
                DiscordMember user = null;
                try
                {
                    user = await command.Guild.GetMemberAsync(ticket.creatorID);
                }
                catch (NotFoundException) { }

                Sheets.DeleteTicketQueued(ticket.id);
                Sheets.AddTicketQueued(user, command.Channel, ticket.id.ToString(), null, null, ticket.createdTime, null, ticket.summary);
            }
        }
        public async Task OnExecute(CommandContext command)
        {
            using (MySqlConnection c = Database.GetConnection())
            {
                // Check if the user has permission to use this command.
                if (!Config.HasPermission(command.Member, "setticket"))
                {
                    DiscordEmbed error = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Red,
                        Description = "You do not have permission to use this command."
                    };
                    await command.RespondAsync("", false, error);

                    command.Client.DebugLogger.LogMessage(LogLevel.Info, "SupportBoi", "User tried to use the setticket command but did not have permission.", DateTime.UtcNow);
                    return;
                }

                // Check if ticket exists in the database
                if (Database.IsOpenTicket(command.Channel.Id))
                {
                    DiscordEmbed error = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Red,
                        Description = "This channel is already a ticket."
                    };
                    await command.RespondAsync("", false, error);

                    return;
                }

                ulong    userID;
                string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);

                if (!parsedMessage.Any())
                {
                    userID = command.Member.Id;
                }
                else if (!ulong.TryParse(parsedMessage[0], out userID))
                {
                    DiscordEmbed error = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Red,
                        Description = "Invalid ID/Mention. (Could not convert to numerical)"
                    };
                    await command.RespondAsync("", false, error);

                    return;
                }

                DiscordUser user = await command.Client.GetUserAsync(userID);

                if (user == null)
                {
                    DiscordEmbed error = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Red,
                        Description = "Invalid ID/Mention."
                    };
                    await command.RespondAsync("", false, error);

                    return;
                }

                long         id       = Database.NewTicket(userID, 0, command.Channel.Id);
                string       ticketID = id.ToString("00000");
                DiscordEmbed message  = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = "Channel has been designated ticket " + ticketID + "."
                };
                await command.RespondAsync("", false, message);

                // Log it if the log channel exists
                DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
                if (logChannel != null)
                {
                    DiscordEmbed logMessage = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Green,
                        Description = command.Channel.Mention + " has been designated ticket " + ticketID + " by " + command.Member.Mention + "."
                    };
                    await logChannel.SendMessageAsync("", false, logMessage);
                }

                Sheets.AddTicketQueued(command.Member, command.Channel, id.ToString(), command.Member.Id.ToString(), command.Member.DisplayName);
            }
        }
        public async Task OnExecute(CommandContext command)
        {
            // Check if the user has permission to use this command.
            if (!Config.HasPermission(command.Member, "rassign"))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "You do not have permission to use this command."
                };
                await command.RespondAsync("", false, error);

                command.Client.DebugLogger.LogMessage(LogLevel.Info, "SupportBoi", "User tried to use the rassign command but did not have permission.", DateTime.UtcNow);
                return;
            }

            // Check if ticket exists in the database
            if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "This channel is not a ticket."
                };
                await command.RespondAsync("", false, error);

                return;
            }

            Database.StaffMember staffEntry = Database.GetRandomActiveStaff(ticket.assignedStaffID);

            if (staffEntry == null)
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Error: There are no other staff to choose from."
                };
                await command.RespondAsync("", false, error);

                return;
            }

            DiscordMember staffMember = null;

            try
            {
                staffMember = await command.Guild.GetMemberAsync(staffEntry.userID);
            }
            catch (NotFoundException) { }

            if (staffMember == null)
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Error: Could not find user."
                };
                await command.RespondAsync("", false, error);

                return;
            }

            if (!Database.AssignStaff(ticket, staffEntry.userID))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Error: Failed to assign " + staffMember.Mention + " to ticket."
                };
                await command.RespondAsync("", false, error);

                return;
            }

            DiscordEmbed feedback = new DiscordEmbedBuilder
            {
                Color       = DiscordColor.Green,
                Description = "Randomly assigned " + staffMember.Mention + " to ticket."
            };
            await command.RespondAsync("", false, feedback);

            if (Config.assignmentNotifications)
            {
                try
                {
                    DiscordEmbed message = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Green,
                        Description = "You have been randomly assigned to a support ticket: " + command.Channel.Mention
                    };
                    await staffMember.SendMessageAsync("", false, message);
                }
                catch (UnauthorizedException) {}
            }

            // Log it if the log channel exists
            DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);

            if (logChannel != null)
            {
                DiscordEmbed logMessage = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = staffMember.Mention + " was was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
                };
                await logChannel.SendMessageAsync("", false, logMessage);
            }

            if (Config.sheetsEnabled)
            {
                DiscordMember user = null;
                try
                {
                    user = await command.Guild.GetMemberAsync(ticket.creatorID);
                }
                catch (NotFoundException) { }

                Sheets.DeleteTicketQueued(ticket.id);
                Sheets.AddTicketQueued(user, command.Channel, ticket.id.ToString(), staffMember.Id.ToString(), staffMember.DisplayName, ticket.createdTime, null, ticket.summary);
            }
        }
Exemple #5
0
        public async Task OnExecute(CommandContext command)
        {
            // Check if the user has permission to use this command.
            if (!Config.HasPermission(command.Member, "new"))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "You do not have permission to use this command."
                };
                await command.RespondAsync("", false, error);

                command.Client.DebugLogger.LogMessage(LogLevel.Info, "SupportBoi",
                                                      "User tried to use the new command but did not have permission.", DateTime.UtcNow);
                return;
            }

            // Check if user is blacklisted
            if (Database.IsBlacklisted(command.User.Id))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "You are banned from opening tickets."
                };
                await command.RespondAsync("", false, error);

                return;
            }

            DiscordChannel category = command.Guild.GetChannel(Config.ticketCategory);
            DiscordChannel ticketChannel;

            try
            {
                ticketChannel = await command.Guild.CreateChannelAsync("ticket", ChannelType.Text, category);
            }
            catch (Exception)
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Error occured while creating ticket, " + command.Member.Mention +
                                  "!\nIs the channel limit reached in the server or ticket category?"
                };
                await command.RespondAsync("", false, error);

                return;
            }

            if (ticketChannel == null)
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Error occured while creating ticket, " + command.Member.Mention +
                                  "!\nIs the channel limit reached in the server or ticket category?"
                };
                await command.RespondAsync("", false, error);

                return;
            }

            ulong staffID = 0;

            if (Config.randomAssignment)
            {
                staffID = Database.GetRandomActiveStaff(0)?.userID ?? 0;
            }

            long   id       = Database.NewTicket(command.Member.Id, staffID, ticketChannel.Id);
            string ticketID = id.ToString("00000");
            await ticketChannel.ModifyAsync("ticket-" + ticketID);

            await ticketChannel.AddOverwriteAsync(command.Member, Permissions.AccessChannels, Permissions.None);

            await ticketChannel.SendMessageAsync("Hello, " + command.Member.Mention + "!\n" + Config.welcomeMessage);

            // Refreshes the channel as changes were made to it above
            ticketChannel = command.Guild.GetChannel(ticketChannel.Id);

            if (staffID != 0)
            {
                DiscordEmbed assignmentMessage = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = "Ticket was randomly assigned to <@" + staffID + ">."
                };
                await ticketChannel.SendMessageAsync("", false, assignmentMessage);

                if (Config.assignmentNotifications)
                {
                    DiscordEmbed message = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Green,
                        Description = "You have been randomly assigned to a newly opened support ticket: " +
                                      ticketChannel.Mention
                    };

                    try
                    {
                        DiscordMember staffMember = await command.Guild.GetMemberAsync(staffID);

                        await staffMember.SendMessageAsync("", false, message);
                    }
                    catch (NotFoundException)
                    {
                    }
                    catch (UnauthorizedException)
                    {
                    }
                }
            }

            DiscordEmbed response = new DiscordEmbedBuilder
            {
                Color       = DiscordColor.Green,
                Description = "Ticket opened, " + command.Member.Mention + "!\n" + ticketChannel.Mention
            };
            await command.RespondAsync("", false, response);

            // Log it if the log channel exists
            DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);

            if (logChannel != null)
            {
                DiscordEmbed logMessage = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = "Ticket " + ticketChannel.Mention + " opened by " + command.Member.Mention + ".\n",
                    Footer      = new DiscordEmbedBuilder.EmbedFooter {
                        Text = "Ticket " + ticketID
                    }
                };
                await logChannel.SendMessageAsync("", false, logMessage);
            }

            // Adds the ticket to the google sheets document if enabled
            Sheets.AddTicketQueued(command.Member, ticketChannel, id.ToString(), staffID.ToString(),
                                   Database.TryGetStaff(staffID, out Database.StaffMember staffMemberEntry)
                                        ? staffMemberEntry.userID.ToString()
                                        : null);
        }