Exemplo n.º 1
0
        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, "unsetticket"))
                {
                    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 unsetticket 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;
                }

                c.Open();
                MySqlCommand deletion = new MySqlCommand(@"DELETE FROM tickets WHERE channel_id=@channel_id", c);
                deletion.Parameters.AddWithValue("@channel_id", command.Channel.Id);
                deletion.Prepare();
                deletion.ExecuteNonQuery();
                DiscordEmbed message = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = "Channel has been undesignated as a 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 = command.Channel.Mention + " has been undesignated as a ticket by " + command.Member.Mention + "."
                    };
                    await logChannel.SendMessageAsync("", false, logMessage);
                }

                Sheets.DeleteTicketQueued(ticket.id);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        public async Task OnExecute(CommandContext command)
        {
            // Check if the user has permission to use this command.
            if (!Config.HasPermission(command.Member, "close"))
            {
                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 close command but did not have permission.", DateTime.UtcNow);
                return;
            }

            ulong  channelID   = command.Channel.Id;
            string channelName = command.Channel.Name;

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

                return;
            }

            // Build transcript
            try
            {
                await Transcriber.ExecuteAsync(command.Channel.Id.ToString(), ticket.id);
            }
            catch (Exception)
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "ERROR: Could not save transcript file. Aborting..."
                };
                await command.RespondAsync("", false, error);

                throw;
            }
            string filePath = Transcriber.GetPath(ticket.id);

            // 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 " + ticket.id.ToString("00000") + " closed by " + command.Member.Mention + ".\n",
                    Footer      = new DiscordEmbedBuilder.EmbedFooter {
                        Text = '#' + channelName
                    }
                };
                await logChannel.SendFileAsync(filePath, "", false, logMessage);
            }

            if (Config.closingNotifications)
            {
                DiscordEmbed message = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = "Ticket " + ticket.id.ToString("00000") + " which you opened has now been closed, check the transcript for more info.\n",
                    Footer      = new DiscordEmbedBuilder.EmbedFooter {
                        Text = '#' + channelName
                    }
                };

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

                    DiscordMessage dm = await staffMember.SendFileAsync(filePath, "", false, message);

                    await dm.CreateReactionAsync(DiscordEmoji.FromName(command.Client, ":one:"));

                    await dm.CreateReactionAsync(DiscordEmoji.FromName(command.Client, ":two:"));

                    await dm.CreateReactionAsync(DiscordEmoji.FromName(command.Client, ":three:"));

                    await dm.CreateReactionAsync(DiscordEmoji.FromName(command.Client, ":four:"));

                    await dm.CreateReactionAsync(DiscordEmoji.FromName(command.Client, ":five:"));
                }
                catch (NotFoundException) { }
                catch (UnauthorizedException) { }
            }

            using (MySqlConnection c = Database.GetConnection())
            {
                // Create an entry in the ticket history database
                MySqlCommand archiveTicket = new MySqlCommand(@"INSERT INTO ticket_history (id, created_time, closed_time, creator_id, assigned_staff_id, summary, channel_id, rating) VALUES (@id, @created_time, now(), @creator_id, @assigned_staff_id, @summary, @channel_id, @rating);", c);
                archiveTicket.Parameters.AddWithValue("@id", ticket.id);
                archiveTicket.Parameters.AddWithValue("@created_time", ticket.createdTime);
                archiveTicket.Parameters.AddWithValue("@creator_id", ticket.creatorID);
                archiveTicket.Parameters.AddWithValue("@assigned_staff_id", ticket.assignedStaffID);
                archiveTicket.Parameters.AddWithValue("@summary", ticket.summary);
                archiveTicket.Parameters.AddWithValue("@channel_id", channelID);
                archiveTicket.Parameters.AddWithValue("@rating", 0);

                c.Open();
                archiveTicket.ExecuteNonQuery();

                // Delete the channel and database entry
                await command.Channel.DeleteAsync("Ticket closed.");

                MySqlCommand deletion = new MySqlCommand(@"DELETE FROM tickets WHERE channel_id=@channel_id", c);
                deletion.Parameters.AddWithValue("@channel_id", channelID);
                deletion.Prepare();
                deletion.ExecuteNonQuery();

                Sheets.DeleteTicketQueued(ticket.id);
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        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);
            }
        }