Fixed project being indented by tabs instead of spaces
This commit is contained in:
parent
dc072d2d58
commit
c084cbe368
34 changed files with 2103 additions and 2103 deletions
|
@ -1,4 +1,4 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.SlashCommands;
|
using DSharpPlus.SlashCommands;
|
||||||
using DSharpPlus.SlashCommands.Attributes;
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
@ -7,65 +7,65 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class AddCategoryCommand : ApplicationCommandModule
|
public class AddCategoryCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("addcategory", "Adds a category to the ticket bot letting users open tickets in them.")]
|
[SlashCommand("addcategory", "Adds a category to the ticket bot letting users open tickets in them.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("Title", "The name to display on buttons and in selection boxes.")] string title, [Option("Category", "The category to add.")] DiscordChannel category)
|
public async Task OnExecute(InteractionContext command, [Option("Title", "The name to display on buttons and in selection boxes.")] string title, [Option("Category", "The category to add.")] DiscordChannel category)
|
||||||
{
|
{
|
||||||
if (!category.IsCategory)
|
if (!category.IsCategory)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "That channel is not a category."
|
Description = "That channel is not a category."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(title))
|
if (string.IsNullOrWhiteSpace(title))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Invalid category title specified."
|
Description = "Invalid category title specified."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Database.TryGetCategory(category.Id, out Database.Category _))
|
if (Database.TryGetCategory(category.Id, out Database.Category _))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "That category is already registered."
|
Description = "That category is already registered."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Database.TryGetCategory(title, out Database.Category _))
|
if (Database.TryGetCategory(title, out Database.Category _))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "There is already a category with that title."
|
Description = "There is already a category with that title."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Database.AddCategory(title, category.Id))
|
if (Database.AddCategory(title, category.Id))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Category added."
|
Description = "Category added."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: Failed adding the category to the database."
|
Description = "Error: Failed adding the category to the database."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,74 +9,74 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class AddCommand : ApplicationCommandModule
|
public class AddCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("add", "Adds a user to a ticket")]
|
[SlashCommand("add", "Adds a user to a ticket")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("User", "User to add to ticket.")] DiscordUser user)
|
public async Task OnExecute(InteractionContext command, [Option("User", "User to add to ticket.")] DiscordUser user)
|
||||||
{
|
{
|
||||||
// Check if ticket exists in the database
|
// Check if ticket exists in the database
|
||||||
if (!Database.IsOpenTicket(command.Channel.Id))
|
if (!Database.IsOpenTicket(command.Channel.Id))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "This channel is not a ticket."
|
Description = "This channel is not a ticket."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordMember member;
|
DiscordMember member;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
member = (user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id));
|
member = (user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id));
|
||||||
|
|
||||||
if (member == null)
|
if (member == null)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Could not find that user in this server."
|
Description = "Could not find that user in this server."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Could not find that user in this server."
|
Description = "Could not find that user in this server."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await command.Channel.AddOverwriteAsync(member, Permissions.AccessChannels);
|
await command.Channel.AddOverwriteAsync(member, Permissions.AccessChannels);
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Added " + member.Mention + " to ticket."
|
Description = "Added " + member.Mention + " to ticket."
|
||||||
});
|
});
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
{
|
{
|
||||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = member.Mention + " was added to " + command.Channel.Mention +
|
Description = member.Mention + " was added to " + command.Channel.Mention +
|
||||||
" by " + command.Member.Mention + "."
|
" by " + command.Member.Mention + "."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Could not add " + member.Mention + " to ticket, unknown error occured."
|
Description = "Could not add " + member.Mention + " to ticket, unknown error occured."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,47 +7,47 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class AddMessageCommand : ApplicationCommandModule
|
public class AddMessageCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("addmessage", "Adds a new message for the 'say' command.")]
|
[SlashCommand("addmessage", "Adds a new message for the 'say' command.")]
|
||||||
public async Task OnExecute(InteractionContext command,
|
public async Task OnExecute(InteractionContext command,
|
||||||
[Option("Identifier", "The identifier word used in the /say command.")] string identifier,
|
[Option("Identifier", "The identifier word used in the /say command.")] string identifier,
|
||||||
[Option("Message", "The message the /say command will return.")] string message)
|
[Option("Message", "The message the /say command will return.")] string message)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(message))
|
if (string.IsNullOrEmpty(message))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "No message specified."
|
Description = "No message specified."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Database.TryGetMessage(identifier.ToLower(), out Database.Message _))
|
if (Database.TryGetMessage(identifier.ToLower(), out Database.Message _))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "There is already a message with that identifier."
|
Description = "There is already a message with that identifier."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Database.AddMessage(identifier, command.Member.Id, message))
|
if (Database.AddMessage(identifier, command.Member.Id, message))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Message added."
|
Description = "Message added."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: Failed adding the message to the database."
|
Description = "Error: Failed adding the message to the database."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,59 +9,59 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class AddStaffCommand : ApplicationCommandModule
|
public class AddStaffCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("addstaff", "Adds a new staff member.")]
|
[SlashCommand("addstaff", "Adds a new staff member.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("User", "User to add to staff.")] DiscordUser user)
|
public async Task OnExecute(InteractionContext command, [Option("User", "User to add to staff.")] DiscordUser user)
|
||||||
{
|
{
|
||||||
DiscordMember staffMember = null;
|
DiscordMember staffMember = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
staffMember = user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id);
|
staffMember = user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id);
|
||||||
|
|
||||||
if (staffMember == null)
|
if (staffMember == null)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Could not find that user in this server."
|
Description = "Could not find that user in this server."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Could not find that user in this server."
|
Description = "Could not find that user in this server."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await using MySqlConnection c = Database.GetConnection();
|
await using MySqlConnection c = Database.GetConnection();
|
||||||
MySqlCommand cmd = Database.IsStaff(staffMember.Id) ? new MySqlCommand(@"UPDATE staff SET name = @name WHERE user_id = @user_id", c) : new MySqlCommand(@"INSERT INTO staff (user_id, name) VALUES (@user_id, @name);", c);
|
MySqlCommand cmd = Database.IsStaff(staffMember.Id) ? new MySqlCommand(@"UPDATE staff SET name = @name WHERE user_id = @user_id", c) : new MySqlCommand(@"INSERT INTO staff (user_id, name) VALUES (@user_id, @name);", c);
|
||||||
|
|
||||||
c.Open();
|
c.Open();
|
||||||
cmd.Parameters.AddWithValue("@user_id", staffMember.Id);
|
cmd.Parameters.AddWithValue("@user_id", staffMember.Id);
|
||||||
cmd.Parameters.AddWithValue("@name", staffMember.DisplayName);
|
cmd.Parameters.AddWithValue("@name", staffMember.DisplayName);
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
cmd.Dispose();
|
cmd.Dispose();
|
||||||
|
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = staffMember.Mention + " was added to staff."
|
Description = staffMember.Mention + " was added to staff."
|
||||||
});
|
});
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
{
|
{
|
||||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = staffMember.Mention + " was added to staff.\n"
|
Description = staffMember.Mention + " was added to staff.\n"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -13,188 +13,188 @@ namespace SupportChild.Commands;
|
||||||
[SlashCommandGroup("admin", "Administrative commands.")]
|
[SlashCommandGroup("admin", "Administrative commands.")]
|
||||||
public class AdminCommands : ApplicationCommandModule
|
public class AdminCommands : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("listinvalid", "List tickets which channels have been deleted. Use /admin unsetticket <id> to remove them.")]
|
[SlashCommand("listinvalid", "List tickets which channels have been deleted. Use /admin unsetticket <id> to remove them.")]
|
||||||
public async Task ListInvalid(InteractionContext command)
|
public async Task ListInvalid(InteractionContext command)
|
||||||
{
|
{
|
||||||
if (!Database.TryGetOpenTickets(out List<Database.Ticket> openTickets))
|
if (!Database.TryGetOpenTickets(out List<Database.Ticket> openTickets))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Could not get any open tickets from database."
|
Description = "Could not get any open tickets from database."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all channels in all guilds the bot is part of
|
// Get all channels in all guilds the bot is part of
|
||||||
List<DiscordChannel> allChannels = new List<DiscordChannel>();
|
List<DiscordChannel> allChannels = new List<DiscordChannel>();
|
||||||
foreach (KeyValuePair<ulong, DiscordGuild> guild in SupportChild.discordClient.Guilds)
|
foreach (KeyValuePair<ulong, DiscordGuild> guild in SupportChild.discordClient.Guilds)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
allChannels.AddRange(await guild.Value.GetChannelsAsync());
|
allChannels.AddRange(await guild.Value.GetChannelsAsync());
|
||||||
}
|
}
|
||||||
catch (Exception) { /*ignored*/ }
|
catch (Exception) { /*ignored*/ }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check which tickets channels no longer exist
|
// Check which tickets channels no longer exist
|
||||||
List<string> listItems = new List<string>();
|
List<string> listItems = new List<string>();
|
||||||
foreach (Database.Ticket ticket in openTickets)
|
foreach (Database.Ticket ticket in openTickets)
|
||||||
{
|
{
|
||||||
if (allChannels.All(channel => channel.Id != ticket.channelID))
|
if (allChannels.All(channel => channel.Id != ticket.channelID))
|
||||||
{
|
{
|
||||||
listItems.Add("ID: **" + ticket.id.ToString("00000") + ":** <#" + ticket.channelID + ">\n");
|
listItems.Add("ID: **" + ticket.id.ToString("00000") + ":** <#" + ticket.channelID + ">\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listItems.Count == 0)
|
if (listItems.Count == 0)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "All tickets are valid!"
|
Description = "All tickets are valid!"
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||||
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||||
{
|
{
|
||||||
embeds.Add(new DiscordEmbedBuilder
|
embeds.Add(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Title = "Invalid tickets:",
|
Title = "Invalid tickets:",
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = message
|
Description = message
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the footers
|
// Add the footers
|
||||||
for (int i = 0; i < embeds.Count; i++)
|
for (int i = 0; i < embeds.Count; i++)
|
||||||
{
|
{
|
||||||
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||||
{
|
{
|
||||||
Text = $"Page {i + 1} / {embeds.Count}"
|
Text = $"Page {i + 1} / {embeds.Count}"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Page> listPages = new List<Page>();
|
List<Page> listPages = new List<Page>();
|
||||||
foreach (DiscordEmbedBuilder embed in embeds)
|
foreach (DiscordEmbedBuilder embed in embeds)
|
||||||
{
|
{
|
||||||
listPages.Add(new Page("", embed));
|
listPages.Add(new Page("", embed));
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("setticket", "Turns a channel into a ticket WARNING: Anyone will be able to delete the channel using /close.")]
|
[SlashCommand("setticket", "Turns a channel into a ticket WARNING: Anyone will be able to delete the channel using /close.")]
|
||||||
public async Task SetTicket(InteractionContext command, [Option("User", "(Optional) The owner of the ticket.")] DiscordUser user = null)
|
public async Task SetTicket(InteractionContext command, [Option("User", "(Optional) The owner of the ticket.")] DiscordUser user = null)
|
||||||
{
|
{
|
||||||
// Check if ticket exists in the database
|
// Check if ticket exists in the database
|
||||||
if (Database.IsOpenTicket(command.Channel.Id))
|
if (Database.IsOpenTicket(command.Channel.Id))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "This channel is already a ticket."
|
Description = "This channel is already a ticket."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordUser ticketUser = (user == null ? command.User : user);
|
DiscordUser ticketUser = (user == null ? command.User : user);
|
||||||
|
|
||||||
long id = Database.NewTicket(ticketUser.Id, 0, command.Channel.Id);
|
long id = Database.NewTicket(ticketUser.Id, 0, command.Channel.Id);
|
||||||
string ticketID = id.ToString("00000");
|
string ticketID = id.ToString("00000");
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Channel has been designated ticket " + ticketID + "."
|
Description = "Channel has been designated ticket " + ticketID + "."
|
||||||
});
|
});
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
{
|
{
|
||||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = command.Channel.Mention + " has been designated ticket " + ticketID + " by " + command.Member.Mention + "."
|
Description = command.Channel.Mention + " has been designated ticket " + ticketID + " by " + command.Member.Mention + "."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("unsetticket", "Deletes a ticket from the ticket system without deleting the channel.")]
|
[SlashCommand("unsetticket", "Deletes a ticket from the ticket system without deleting the channel.")]
|
||||||
public async Task UnsetTicket(InteractionContext command, [Option("TicketID", "(Optional) Ticket to unset. Uses the channel you are in by default.")] long ticketID = 0)
|
public async Task UnsetTicket(InteractionContext command, [Option("TicketID", "(Optional) Ticket to unset. Uses the channel you are in by default.")] long ticketID = 0)
|
||||||
{
|
{
|
||||||
Database.Ticket ticket;
|
Database.Ticket ticket;
|
||||||
|
|
||||||
if (ticketID == 0)
|
if (ticketID == 0)
|
||||||
{
|
{
|
||||||
// Check if ticket exists in the database
|
// Check if ticket exists in the database
|
||||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out ticket))
|
if (!Database.TryGetOpenTicket(command.Channel.Id, out ticket))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "This channel is not a ticket!"
|
Description = "This channel is not a ticket!"
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Check if ticket exists in the database
|
// Check if ticket exists in the database
|
||||||
if (!Database.TryGetOpenTicketByID((uint)ticketID, out ticket))
|
if (!Database.TryGetOpenTicketByID((uint)ticketID, out ticket))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "There is no ticket with this ticket ID."
|
Description = "There is no ticket with this ticket ID."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (Database.DeleteOpenTicket(ticket.id))
|
if (Database.DeleteOpenTicket(ticket.id))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Channel has been undesignated as a ticket."
|
Description = "Channel has been undesignated as a ticket."
|
||||||
});
|
});
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
{
|
{
|
||||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = command.Channel.Mention + " has been undesignated as a ticket by " + command.Member.Mention + "."
|
Description = command.Channel.Mention + " has been undesignated as a ticket by " + command.Member.Mention + "."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: Failed removing ticket from database."
|
Description = "Error: Failed removing ticket from database."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[SlashCommand("reload", "Reloads the bot config.")]
|
[SlashCommand("reload", "Reloads the bot config.")]
|
||||||
public async Task Reload(InteractionContext command)
|
public async Task Reload(InteractionContext command)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Reloading bot application..."
|
Description = "Reloading bot application..."
|
||||||
});
|
});
|
||||||
Logger.Log("Reloading bot...");
|
Logger.Log("Reloading bot...");
|
||||||
SupportChild.Reload();
|
SupportChild.Reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,94 +9,94 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class AssignCommand : ApplicationCommandModule
|
public class AssignCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("assign", "Assigns a staff member to this ticket.")]
|
[SlashCommand("assign", "Assigns a staff member to this ticket.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) User to assign to this ticket.")] DiscordUser user = null)
|
public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) User to assign to this ticket.")] DiscordUser user = null)
|
||||||
{
|
{
|
||||||
DiscordMember member = null;
|
DiscordMember member = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
member = user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id);
|
member = user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id);
|
||||||
|
|
||||||
if (member == null)
|
if (member == null)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Could not find that user in this server."
|
Description = "Could not find that user in this server."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Could not find that user in this server."
|
Description = "Could not find that user in this server."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if ticket exists in the database
|
// Check if ticket exists in the database
|
||||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "This channel is not a ticket."
|
Description = "This channel is not a ticket."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Database.IsStaff(member.Id))
|
if (!Database.IsStaff(member.Id))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: User is not registered as staff."
|
Description = "Error: User is not registered as staff."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Database.AssignStaff(ticket, member.Id))
|
if (!Database.AssignStaff(ticket, member.Id))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: Failed to assign " + member.Mention + " to ticket."
|
Description = "Error: Failed to assign " + member.Mention + " to ticket."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Assigned " + member.Mention + " to ticket."
|
Description = "Assigned " + member.Mention + " to ticket."
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Config.assignmentNotifications)
|
if (Config.assignmentNotifications)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await member.SendMessageAsync(new DiscordEmbedBuilder
|
await member.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "You have been assigned to a support ticket: " + command.Channel.Mention
|
Description = "You have been assigned to a support ticket: " + command.Channel.Mention
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (UnauthorizedException) { }
|
catch (UnauthorizedException) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
{
|
{
|
||||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = member.Mention + " was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
Description = member.Mention + " was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,47 +8,47 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class BlacklistCommand : ApplicationCommandModule
|
public class BlacklistCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("blacklist", "Blacklists a user from opening tickets.")]
|
[SlashCommand("blacklist", "Blacklists a user from opening tickets.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("User", "User to blacklist.")] DiscordUser user)
|
public async Task OnExecute(InteractionContext command, [Option("User", "User to blacklist.")] DiscordUser user)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!Database.Blacklist(user.Id, command.User.Id))
|
if (!Database.Blacklist(user.Id, command.User.Id))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = user.Mention + " is already blacklisted."
|
Description = user.Mention + " is already blacklisted."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Blacklisted " + user.Mention + "."
|
Description = "Blacklisted " + user.Mention + "."
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
{
|
{
|
||||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = user.Mention + " was blacklisted from opening tickets by " + command.Member.Mention + "."
|
Description = user.Mention + " was blacklisted from opening tickets by " + command.Member.Mention + "."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error occured while blacklisting " + user.Mention + "."
|
Description = "Error occured while blacklisting " + user.Mention + "."
|
||||||
}, true);
|
}, true);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,123 +12,123 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class CloseCommand : ApplicationCommandModule
|
public class CloseCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("close", "Closes a ticket.")]
|
[SlashCommand("close", "Closes a ticket.")]
|
||||||
public async Task OnExecute(InteractionContext command)
|
public async Task OnExecute(InteractionContext command)
|
||||||
{
|
{
|
||||||
// Check if ticket exists in the database
|
// Check if ticket exists in the database
|
||||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket _))
|
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket _))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "This channel is not a ticket."
|
Description = "This channel is not a ticket."
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordInteractionResponseBuilder confirmation = new DiscordInteractionResponseBuilder()
|
DiscordInteractionResponseBuilder confirmation = new DiscordInteractionResponseBuilder()
|
||||||
.AddEmbed(new DiscordEmbedBuilder
|
.AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Cyan,
|
Color = DiscordColor.Cyan,
|
||||||
Description = "Are you sure you wish to close this ticket? You cannot re-open it again later."
|
Description = "Are you sure you wish to close this ticket? You cannot re-open it again later."
|
||||||
})
|
})
|
||||||
.AddComponents(new DiscordButtonComponent(ButtonStyle.Danger, "supportchild_closeconfirm", "Confirm"));
|
.AddComponents(new DiscordButtonComponent(ButtonStyle.Danger, "supportchild_closeconfirm", "Confirm"));
|
||||||
|
|
||||||
|
|
||||||
await command.CreateResponseAsync(confirmation);
|
await command.CreateResponseAsync(confirmation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task OnConfirmed(DiscordInteraction interaction)
|
public static async Task OnConfirmed(DiscordInteraction interaction)
|
||||||
{
|
{
|
||||||
await interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate);
|
await interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate);
|
||||||
ulong channelID = interaction.Channel.Id;
|
ulong channelID = interaction.Channel.Id;
|
||||||
string channelName = interaction.Channel.Name;
|
string channelName = interaction.Channel.Name;
|
||||||
|
|
||||||
// Check if ticket exists in the database
|
// Check if ticket exists in the database
|
||||||
if (!Database.TryGetOpenTicket(channelID, out Database.Ticket ticket))
|
if (!Database.TryGetOpenTicket(channelID, out Database.Ticket ticket))
|
||||||
{
|
{
|
||||||
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "This channel is not a ticket."
|
Description = "This channel is not a ticket."
|
||||||
}));
|
}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build transcript
|
// Build transcript
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Transcriber.ExecuteAsync(interaction.Channel.Id, ticket.id);
|
await Transcriber.ExecuteAsync(interaction.Channel.Id, ticket.id);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Error("Exception occured when trying to save transcript while closing ticket: " + e);
|
Logger.Error("Exception occured when trying to save transcript while closing ticket: " + e);
|
||||||
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "ERROR: Could not save transcript file. Aborting..."
|
Description = "ERROR: Could not save transcript file. Aborting..."
|
||||||
}));
|
}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = interaction.Guild.GetChannel(Config.logChannel);
|
DiscordChannel logChannel = interaction.Guild.GetChannel(Config.logChannel);
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
{
|
{
|
||||||
DiscordEmbed embed = new DiscordEmbedBuilder
|
DiscordEmbed embed = new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Ticket " + ticket.id.ToString("00000") + " closed by " + interaction.User.Mention + ".\n",
|
Description = "Ticket " + ticket.id.ToString("00000") + " closed by " + interaction.User.Mention + ".\n",
|
||||||
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + channelName }
|
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + channelName }
|
||||||
};
|
};
|
||||||
|
|
||||||
await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
|
await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
|
||||||
DiscordMessageBuilder message = new DiscordMessageBuilder();
|
DiscordMessageBuilder message = new DiscordMessageBuilder();
|
||||||
message.WithEmbed(embed);
|
message.WithEmbed(embed);
|
||||||
message.AddFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
message.AddFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||||
|
|
||||||
await logChannel.SendMessageAsync(message);
|
await logChannel.SendMessageAsync(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.closingNotifications)
|
if (Config.closingNotifications)
|
||||||
{
|
{
|
||||||
DiscordEmbed embed = new DiscordEmbedBuilder
|
DiscordEmbed embed = new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Ticket " + ticket.id.ToString("00000") + " which you opened has now been closed, check the transcript for more info.\n",
|
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 }
|
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + channelName }
|
||||||
};
|
};
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DiscordMember staffMember = await interaction.Guild.GetMemberAsync(ticket.creatorID);
|
DiscordMember staffMember = await interaction.Guild.GetMemberAsync(ticket.creatorID);
|
||||||
await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
|
await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
|
||||||
|
|
||||||
DiscordMessageBuilder message = new DiscordMessageBuilder();
|
DiscordMessageBuilder message = new DiscordMessageBuilder();
|
||||||
message.WithEmbed(embed);
|
message.WithEmbed(embed);
|
||||||
message.AddFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
message.AddFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||||
|
|
||||||
await staffMember.SendMessageAsync(message);
|
await staffMember.SendMessageAsync(message);
|
||||||
}
|
}
|
||||||
catch (NotFoundException) { }
|
catch (NotFoundException) { }
|
||||||
catch (UnauthorizedException) { }
|
catch (UnauthorizedException) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
Database.ArchiveTicket(ticket);
|
Database.ArchiveTicket(ticket);
|
||||||
|
|
||||||
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Channel will be deleted in 3 seconds..."
|
Description = "Channel will be deleted in 3 seconds..."
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
await Task.Delay(3000);
|
await Task.Delay(3000);
|
||||||
|
|
||||||
// Delete the channel and database entry
|
// Delete the channel and database entry
|
||||||
await interaction.Channel.DeleteAsync("Ticket closed.");
|
await interaction.Channel.DeleteAsync("Ticket closed.");
|
||||||
|
|
||||||
Database.DeleteOpenTicket(ticket.id);
|
Database.DeleteOpenTicket(ticket.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus;
|
using DSharpPlus;
|
||||||
|
@ -10,72 +10,72 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class CreateButtonPanelCommand : ApplicationCommandModule
|
public class CreateButtonPanelCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("createbuttonpanel", "Creates a series of buttons which users can use to open new tickets in specific categories.")]
|
[SlashCommand("createbuttonpanel", "Creates a series of buttons which users can use to open new tickets in specific categories.")]
|
||||||
public async Task OnExecute(InteractionContext command)
|
public async Task OnExecute(InteractionContext command)
|
||||||
{
|
{
|
||||||
DiscordMessageBuilder builder = new DiscordMessageBuilder().WithContent(" ");
|
DiscordMessageBuilder builder = new DiscordMessageBuilder().WithContent(" ");
|
||||||
List<Database.Category> verifiedCategories = await Utilities.GetVerifiedChannels();
|
List<Database.Category> verifiedCategories = await Utilities.GetVerifiedChannels();
|
||||||
|
|
||||||
if (verifiedCategories.Count == 0)
|
if (verifiedCategories.Count == 0)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: No registered categories found."
|
Description = "Error: No registered categories found."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList();
|
verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList();
|
||||||
|
|
||||||
int nrOfButtons = 0;
|
int nrOfButtons = 0;
|
||||||
for (int nrOfButtonRows = 0; nrOfButtonRows < 5 && nrOfButtons < verifiedCategories.Count; nrOfButtonRows++)
|
for (int nrOfButtonRows = 0; nrOfButtonRows < 5 && nrOfButtons < verifiedCategories.Count; nrOfButtonRows++)
|
||||||
{
|
{
|
||||||
List<DiscordButtonComponent> buttonRow = new List<DiscordButtonComponent>();
|
List<DiscordButtonComponent> buttonRow = new List<DiscordButtonComponent>();
|
||||||
|
|
||||||
for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < verifiedCategories.Count; nrOfButtons++)
|
for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < verifiedCategories.Count; nrOfButtons++)
|
||||||
{
|
{
|
||||||
buttonRow.Add(new DiscordButtonComponent(ButtonStyle.Primary, "supportchild_newticketbutton " + verifiedCategories[nrOfButtons].id, verifiedCategories[nrOfButtons].name));
|
buttonRow.Add(new DiscordButtonComponent(ButtonStyle.Primary, "supportchild_newticketbutton " + verifiedCategories[nrOfButtons].id, verifiedCategories[nrOfButtons].name));
|
||||||
}
|
}
|
||||||
builder.AddComponents(buttonRow);
|
builder.AddComponents(buttonRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.Channel.SendMessageAsync(builder);
|
await command.Channel.SendMessageAsync(builder);
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Successfully created message, make sure to run this command again if you add new categories to the bot."
|
Description = "Successfully created message, make sure to run this command again if you add new categories to the bot."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task OnButtonUsed(DiscordInteraction interaction)
|
public static async Task OnButtonUsed(DiscordInteraction interaction)
|
||||||
{
|
{
|
||||||
await interaction.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral());
|
await interaction.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral());
|
||||||
|
|
||||||
if (!ulong.TryParse(interaction.Data.CustomId.Replace("supportchild_newticketbutton ", ""), out ulong categoryID) || categoryID == 0)
|
if (!ulong.TryParse(interaction.Data.CustomId.Replace("supportchild_newticketbutton ", ""), out ulong categoryID) || categoryID == 0)
|
||||||
{
|
{
|
||||||
Logger.Warn("Invalid ID: " + interaction.Data.CustomId.Replace("supportchild_newticketbutton ", ""));
|
Logger.Warn("Invalid ID: " + interaction.Data.CustomId.Replace("supportchild_newticketbutton ", ""));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
(bool success, string message) = await NewCommand.OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID);
|
(bool success, string message) = await NewCommand.OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID);
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = message
|
Description = message
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = message
|
Description = message
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus;
|
using DSharpPlus;
|
||||||
|
@ -10,70 +10,70 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class CreateSelectionBoxPanelCommand : ApplicationCommandModule
|
public class CreateSelectionBoxPanelCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("createselectionboxpanel", "Creates a selection box which users can use to open new tickets in specific categories.")]
|
[SlashCommand("createselectionboxpanel", "Creates a selection box which users can use to open new tickets in specific categories.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("Message", "(Optional) The message to show in the selection box.")] string message = null)
|
public async Task OnExecute(InteractionContext command, [Option("Message", "(Optional) The message to show in the selection box.")] string message = null)
|
||||||
{
|
{
|
||||||
DiscordMessageBuilder builder = new DiscordMessageBuilder()
|
DiscordMessageBuilder builder = new DiscordMessageBuilder()
|
||||||
.WithContent(" ")
|
.WithContent(" ")
|
||||||
.AddComponents(await GetSelectComponents(command, message ?? "Open new ticket..."));
|
.AddComponents(await GetSelectComponents(command, message ?? "Open new ticket..."));
|
||||||
|
|
||||||
await command.Channel.SendMessageAsync(builder);
|
await command.Channel.SendMessageAsync(builder);
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Successfully created message, make sure to run this command again if you add new categories to the bot."
|
Description = "Successfully created message, make sure to run this command again if you add new categories to the bot."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<List<DiscordSelectComponent>> GetSelectComponents(InteractionContext command, string placeholder)
|
public static async Task<List<DiscordSelectComponent>> GetSelectComponents(InteractionContext command, string placeholder)
|
||||||
{
|
{
|
||||||
List<Database.Category> verifiedCategories = await Utilities.GetVerifiedChannels();
|
List<Database.Category> verifiedCategories = await Utilities.GetVerifiedChannels();
|
||||||
|
|
||||||
if (verifiedCategories.Count == 0) return new List<DiscordSelectComponent>();
|
if (verifiedCategories.Count == 0) return new List<DiscordSelectComponent>();
|
||||||
|
|
||||||
verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList();
|
verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList();
|
||||||
List<DiscordSelectComponent> selectionComponents = new List<DiscordSelectComponent>();
|
List<DiscordSelectComponent> selectionComponents = new List<DiscordSelectComponent>();
|
||||||
int selectionOptions = 0;
|
int selectionOptions = 0;
|
||||||
for (int selectionBoxes = 0; selectionBoxes < 5 && selectionOptions < verifiedCategories.Count; selectionBoxes++)
|
for (int selectionBoxes = 0; selectionBoxes < 5 && selectionOptions < verifiedCategories.Count; selectionBoxes++)
|
||||||
{
|
{
|
||||||
List<DiscordSelectComponentOption> categoryOptions = new List<DiscordSelectComponentOption>();
|
List<DiscordSelectComponentOption> categoryOptions = new List<DiscordSelectComponentOption>();
|
||||||
|
|
||||||
for (; selectionOptions < 25 * (selectionBoxes + 1) && selectionOptions < verifiedCategories.Count; selectionOptions++)
|
for (; selectionOptions < 25 * (selectionBoxes + 1) && selectionOptions < verifiedCategories.Count; selectionOptions++)
|
||||||
{
|
{
|
||||||
categoryOptions.Add(new DiscordSelectComponentOption(verifiedCategories[selectionOptions].name, verifiedCategories[selectionOptions].id.ToString()));
|
categoryOptions.Add(new DiscordSelectComponentOption(verifiedCategories[selectionOptions].name, verifiedCategories[selectionOptions].id.ToString()));
|
||||||
}
|
}
|
||||||
selectionComponents.Add(new DiscordSelectComponent("supportchild_newticketselector" + selectionBoxes, placeholder, categoryOptions, false, 0, 1));
|
selectionComponents.Add(new DiscordSelectComponent("supportchild_newticketselector" + selectionBoxes, placeholder, categoryOptions, false, 0, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
return selectionComponents;
|
return selectionComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task OnSelectionMenuUsed(DiscordInteraction interaction)
|
public static async Task OnSelectionMenuUsed(DiscordInteraction interaction)
|
||||||
{
|
{
|
||||||
if (interaction.Data.Values == null || interaction.Data.Values.Length <= 0) return;
|
if (interaction.Data.Values == null || interaction.Data.Values.Length <= 0) return;
|
||||||
|
|
||||||
if (!ulong.TryParse(interaction.Data.Values[0], out ulong categoryID) || categoryID == 0) return;
|
if (!ulong.TryParse(interaction.Data.Values[0], out ulong categoryID) || categoryID == 0) return;
|
||||||
|
|
||||||
await interaction.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral());
|
await interaction.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral());
|
||||||
|
|
||||||
(bool success, string message) = await NewCommand.OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID);
|
(bool success, string message) = await NewCommand.OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID);
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = message
|
Description = message
|
||||||
}).AsEphemeral());
|
}).AsEphemeral());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = message
|
Description = message
|
||||||
}).AsEphemeral());
|
}).AsEphemeral());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,54 +10,54 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class ListAssignedCommand : ApplicationCommandModule
|
public class ListAssignedCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("listassigned", "Lists tickets assigned to a user.")]
|
[SlashCommand("listassigned", "Lists tickets assigned to a user.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) User to list tickets for.")] DiscordUser user = null)
|
public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) User to list tickets for.")] DiscordUser user = null)
|
||||||
{
|
{
|
||||||
DiscordUser listUser = user == null ? command.User : user;
|
DiscordUser listUser = user == null ? command.User : user;
|
||||||
|
|
||||||
if (!Database.TryGetAssignedTickets(listUser.Id, out List<Database.Ticket> assignedTickets))
|
if (!Database.TryGetAssignedTickets(listUser.Id, out List<Database.Ticket> assignedTickets))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "User does not have any assigned tickets."
|
Description = "User does not have any assigned tickets."
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<string> listItems = new List<string>();
|
List<string> listItems = new List<string>();
|
||||||
foreach (Database.Ticket ticket in assignedTickets)
|
foreach (Database.Ticket ticket in assignedTickets)
|
||||||
{
|
{
|
||||||
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||||
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||||
{
|
{
|
||||||
embeds.Add(new DiscordEmbedBuilder
|
embeds.Add(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Title = "Assigned tickets: ",
|
Title = "Assigned tickets: ",
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = message
|
Description = message
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the footers
|
// Add the footers
|
||||||
for (int i = 0; i < embeds.Count; i++)
|
for (int i = 0; i < embeds.Count; i++)
|
||||||
{
|
{
|
||||||
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||||
{
|
{
|
||||||
Text = $"Page {i + 1} / {embeds.Count}"
|
Text = $"Page {i + 1} / {embeds.Count}"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Page> listPages = new List<Page>();
|
List<Page> listPages = new List<Page>();
|
||||||
foreach (DiscordEmbedBuilder embed in embeds)
|
foreach (DiscordEmbedBuilder embed in embeds)
|
||||||
{
|
{
|
||||||
listPages.Add(new Page("", embed));
|
listPages.Add(new Page("", embed));
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,90 +10,90 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class ListCommand : ApplicationCommandModule
|
public class ListCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("list", "Lists tickets opened by a user.")]
|
[SlashCommand("list", "Lists tickets opened by a user.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) The user to get tickets by.")] DiscordUser user = null)
|
public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) The user to get tickets by.")] DiscordUser user = null)
|
||||||
{
|
{
|
||||||
DiscordUser listUser = user == null ? command.User : user;
|
DiscordUser listUser = user == null ? command.User : user;
|
||||||
|
|
||||||
List<DiscordEmbedBuilder> openEmbeds = new List<DiscordEmbedBuilder>();
|
List<DiscordEmbedBuilder> openEmbeds = new List<DiscordEmbedBuilder>();
|
||||||
if (Database.TryGetOpenTickets(listUser.Id, out List<Database.Ticket> openTickets))
|
if (Database.TryGetOpenTickets(listUser.Id, out List<Database.Ticket> openTickets))
|
||||||
{
|
{
|
||||||
List<string> listItems = new List<string>();
|
List<string> listItems = new List<string>();
|
||||||
foreach (Database.Ticket ticket in openTickets)
|
foreach (Database.Ticket ticket in openTickets)
|
||||||
{
|
{
|
||||||
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + ">\n");
|
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + ">\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||||
{
|
{
|
||||||
openEmbeds.Add(new DiscordEmbedBuilder
|
openEmbeds.Add(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = message
|
Description = message
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the titles
|
// Add the titles
|
||||||
for (int i = 0; i < openEmbeds.Count; i++)
|
for (int i = 0; i < openEmbeds.Count; i++)
|
||||||
{
|
{
|
||||||
openEmbeds[i].Title = $"Open tickets ({i + 1}/{openEmbeds.Count})";
|
openEmbeds[i].Title = $"Open tickets ({i + 1}/{openEmbeds.Count})";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<DiscordEmbedBuilder> closedEmbeds = new List<DiscordEmbedBuilder>();
|
List<DiscordEmbedBuilder> closedEmbeds = new List<DiscordEmbedBuilder>();
|
||||||
if (Database.TryGetClosedTickets(listUser.Id, out List<Database.Ticket> closedTickets))
|
if (Database.TryGetClosedTickets(listUser.Id, out List<Database.Ticket> closedTickets))
|
||||||
{
|
{
|
||||||
List<string> listItems = new List<string>();
|
List<string> listItems = new List<string>();
|
||||||
foreach (Database.Ticket ticket in closedTickets)
|
foreach (Database.Ticket ticket in closedTickets)
|
||||||
{
|
{
|
||||||
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** Ticket " + ticket.id.ToString("00000") + "\n");
|
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** Ticket " + ticket.id.ToString("00000") + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||||
{
|
{
|
||||||
closedEmbeds.Add(new DiscordEmbedBuilder
|
closedEmbeds.Add(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = message
|
Description = message
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the titles
|
// Add the titles
|
||||||
for (int i = 0; i < closedEmbeds.Count; i++)
|
for (int i = 0; i < closedEmbeds.Count; i++)
|
||||||
{
|
{
|
||||||
closedEmbeds[i].Title = $"Closed tickets ({i + 1}/{closedEmbeds.Count})";
|
closedEmbeds[i].Title = $"Closed tickets ({i + 1}/{closedEmbeds.Count})";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge the embed lists and add the footers
|
// Merge the embed lists and add the footers
|
||||||
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||||
embeds.AddRange(openEmbeds);
|
embeds.AddRange(openEmbeds);
|
||||||
embeds.AddRange(closedEmbeds);
|
embeds.AddRange(closedEmbeds);
|
||||||
for (int i = 0; i < embeds.Count; i++)
|
for (int i = 0; i < embeds.Count; i++)
|
||||||
{
|
{
|
||||||
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||||
{
|
{
|
||||||
Text = $"Page {i + 1} / {embeds.Count}"
|
Text = $"Page {i + 1} / {embeds.Count}"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (embeds.Count == 0)
|
if (embeds.Count == 0)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Cyan,
|
Color = DiscordColor.Cyan,
|
||||||
Description = "User does not have any open or closed tickets."
|
Description = "User does not have any open or closed tickets."
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Page> listPages = new List<Page>();
|
List<Page> listPages = new List<Page>();
|
||||||
foreach (DiscordEmbedBuilder embed in embeds)
|
foreach (DiscordEmbedBuilder embed in embeds)
|
||||||
{
|
{
|
||||||
listPages.Add(new Page("", embed));
|
listPages.Add(new Page("", embed));
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,51 +10,51 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class ListOpen : ApplicationCommandModule
|
public class ListOpen : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("listopen", "Lists all open tickets, oldest first.")]
|
[SlashCommand("listopen", "Lists all open tickets, oldest first.")]
|
||||||
public async Task OnExecute(InteractionContext command)
|
public async Task OnExecute(InteractionContext command)
|
||||||
{
|
{
|
||||||
if (!Database.TryGetOpenTickets(out List<Database.Ticket> openTickets))
|
if (!Database.TryGetOpenTickets(out List<Database.Ticket> openTickets))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Could not fetch any open tickets."
|
Description = "Could not fetch any open tickets."
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<string> listItems = new List<string>();
|
List<string> listItems = new List<string>();
|
||||||
foreach (Database.Ticket ticket in openTickets)
|
foreach (Database.Ticket ticket in openTickets)
|
||||||
{
|
{
|
||||||
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||||
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||||
{
|
{
|
||||||
embeds.Add(new DiscordEmbedBuilder
|
embeds.Add(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = message
|
Description = message
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the footers
|
// Add the footers
|
||||||
for (int i = 0; i < embeds.Count; i++)
|
for (int i = 0; i < embeds.Count; i++)
|
||||||
{
|
{
|
||||||
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||||
{
|
{
|
||||||
Text = $"Page {i + 1} / {embeds.Count}"
|
Text = $"Page {i + 1} / {embeds.Count}"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Page> listPages = new List<Page>();
|
List<Page> listPages = new List<Page>();
|
||||||
foreach (DiscordEmbedBuilder embed in embeds)
|
foreach (DiscordEmbedBuilder embed in embeds)
|
||||||
{
|
{
|
||||||
listPages.Add(new Page("", embed));
|
listPages.Add(new Page("", embed));
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,52 +10,52 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class ListUnassignedCommand : ApplicationCommandModule
|
public class ListUnassignedCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("listunassigned", "Lists unassigned tickets.")]
|
[SlashCommand("listunassigned", "Lists unassigned tickets.")]
|
||||||
public async Task OnExecute(InteractionContext command)
|
public async Task OnExecute(InteractionContext command)
|
||||||
{
|
{
|
||||||
if (!Database.TryGetAssignedTickets(0, out List<Database.Ticket> unassignedTickets))
|
if (!Database.TryGetAssignedTickets(0, out List<Database.Ticket> unassignedTickets))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "There are no unassigned tickets."
|
Description = "There are no unassigned tickets."
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<string> listItems = new List<string>();
|
List<string> listItems = new List<string>();
|
||||||
foreach (Database.Ticket ticket in unassignedTickets)
|
foreach (Database.Ticket ticket in unassignedTickets)
|
||||||
{
|
{
|
||||||
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||||
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||||
{
|
{
|
||||||
embeds.Add(new DiscordEmbedBuilder
|
embeds.Add(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Title = "Unassigned tickets: ",
|
Title = "Unassigned tickets: ",
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = message
|
Description = message
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the footers
|
// Add the footers
|
||||||
for (int i = 0; i < embeds.Count; i++)
|
for (int i = 0; i < embeds.Count; i++)
|
||||||
{
|
{
|
||||||
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||||
{
|
{
|
||||||
Text = $"Page {i + 1} / {embeds.Count}"
|
Text = $"Page {i + 1} / {embeds.Count}"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Page> listPages = new List<Page>();
|
List<Page> listPages = new List<Page>();
|
||||||
foreach (DiscordEmbedBuilder embed in embeds)
|
foreach (DiscordEmbedBuilder embed in embeds)
|
||||||
{
|
{
|
||||||
listPages.Add(new Page("", embed));
|
listPages.Add(new Page("", embed));
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,73 +11,73 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class MoveCommand : ApplicationCommandModule
|
public class MoveCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("move", "Moves a ticket to another category.")]
|
[SlashCommand("move", "Moves a ticket to another category.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("Category", "The category to move the ticket to. Only has to be the beginning of the name.")] string category)
|
public async Task OnExecute(InteractionContext command, [Option("Category", "The category to move the ticket to. Only has to be the beginning of the name.")] string category)
|
||||||
{
|
{
|
||||||
// Check if ticket exists in the database
|
// Check if ticket exists in the database
|
||||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket _))
|
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket _))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "This channel is not a ticket."
|
Description = "This channel is not a ticket."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(category))
|
if (string.IsNullOrEmpty(category))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: No category provided."
|
Description = "Error: No category provided."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IReadOnlyList<DiscordChannel> channels = await command.Guild.GetChannelsAsync();
|
IReadOnlyList<DiscordChannel> channels = await command.Guild.GetChannelsAsync();
|
||||||
IEnumerable<DiscordChannel> categories = channels.Where(x => x.IsCategory);
|
IEnumerable<DiscordChannel> categories = channels.Where(x => x.IsCategory);
|
||||||
DiscordChannel categoryChannel = categories.FirstOrDefault(x => x.Name.StartsWith(category.Trim(), StringComparison.OrdinalIgnoreCase));
|
DiscordChannel categoryChannel = categories.FirstOrDefault(x => x.Name.StartsWith(category.Trim(), StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
if (categoryChannel == null)
|
if (categoryChannel == null)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: Could not find a category by that name."
|
Description = "Error: Could not find a category by that name."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.Channel.Id == categoryChannel.Id)
|
if (command.Channel.Id == categoryChannel.Id)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: The ticket is already in that category."
|
Description = "Error: The ticket is already in that category."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await command.Channel.ModifyAsync(modifiedAttributes => modifiedAttributes.Parent = categoryChannel);
|
await command.Channel.ModifyAsync(modifiedAttributes => modifiedAttributes.Parent = categoryChannel);
|
||||||
}
|
}
|
||||||
catch (UnauthorizedException)
|
catch (UnauthorizedException)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: Not authorized to move this ticket to that category."
|
Description = "Error: Not authorized to move this ticket to that category."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Ticket was moved to " + categoryChannel.Mention
|
Description = "Ticket was moved to " + categoryChannel.Mention
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,265 +12,265 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class NewCommand : ApplicationCommandModule
|
public class NewCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("new", "Opens a new ticket.")]
|
[SlashCommand("new", "Opens a new ticket.")]
|
||||||
public async Task OnExecute(InteractionContext command)
|
public async Task OnExecute(InteractionContext command)
|
||||||
{
|
{
|
||||||
List<Database.Category> verifiedCategories = await Utilities.GetVerifiedChannels();
|
List<Database.Category> verifiedCategories = await Utilities.GetVerifiedChannels();
|
||||||
switch (verifiedCategories.Count)
|
switch (verifiedCategories.Count)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: No registered categories found."
|
Description = "Error: No registered categories found."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
case 1:
|
case 1:
|
||||||
await command.DeferAsync(true);
|
await command.DeferAsync(true);
|
||||||
(bool success, string message) = await OpenNewTicket(command.User.Id, command.Channel.Id, verifiedCategories[0].id);
|
(bool success, string message) = await OpenNewTicket(command.User.Id, command.Channel.Id, verifiedCategories[0].id);
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
await command.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
await command.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = message
|
Description = message
|
||||||
}).AsEphemeral());
|
}).AsEphemeral());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await command.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
await command.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = message
|
Description = message
|
||||||
}).AsEphemeral());
|
}).AsEphemeral());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
if (Config.newCommandUsesSelector)
|
if (Config.newCommandUsesSelector)
|
||||||
{
|
{
|
||||||
await CreateSelector(command, verifiedCategories);
|
await CreateSelector(command, verifiedCategories);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await CreateButtons(command, verifiedCategories);
|
await CreateButtons(command, verifiedCategories);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task CreateButtons(InteractionContext command, List<Database.Category> verifiedCategories)
|
public static async Task CreateButtons(InteractionContext command, List<Database.Category> verifiedCategories)
|
||||||
{
|
{
|
||||||
DiscordInteractionResponseBuilder builder = new DiscordInteractionResponseBuilder().WithContent(" ");
|
DiscordInteractionResponseBuilder builder = new DiscordInteractionResponseBuilder().WithContent(" ");
|
||||||
int nrOfButtons = 0;
|
int nrOfButtons = 0;
|
||||||
for (int nrOfButtonRows = 0; nrOfButtonRows < 5 && nrOfButtons < verifiedCategories.Count; nrOfButtonRows++)
|
for (int nrOfButtonRows = 0; nrOfButtonRows < 5 && nrOfButtons < verifiedCategories.Count; nrOfButtonRows++)
|
||||||
{
|
{
|
||||||
List<DiscordButtonComponent> buttonRow = new List<DiscordButtonComponent>();
|
List<DiscordButtonComponent> buttonRow = new List<DiscordButtonComponent>();
|
||||||
|
|
||||||
for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < verifiedCategories.Count; nrOfButtons++)
|
for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < verifiedCategories.Count; nrOfButtons++)
|
||||||
{
|
{
|
||||||
buttonRow.Add(new DiscordButtonComponent(ButtonStyle.Primary, "supportchild_newcommandbutton " + verifiedCategories[nrOfButtons].id, verifiedCategories[nrOfButtons].name));
|
buttonRow.Add(new DiscordButtonComponent(ButtonStyle.Primary, "supportchild_newcommandbutton " + verifiedCategories[nrOfButtons].id, verifiedCategories[nrOfButtons].name));
|
||||||
}
|
}
|
||||||
builder.AddComponents(buttonRow);
|
builder.AddComponents(buttonRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.CreateResponseAsync(builder.AsEphemeral());
|
await command.CreateResponseAsync(builder.AsEphemeral());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task CreateSelector(InteractionContext command, List<Database.Category> verifiedCategories)
|
public static async Task CreateSelector(InteractionContext command, List<Database.Category> verifiedCategories)
|
||||||
{
|
{
|
||||||
verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList();
|
verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList();
|
||||||
List<DiscordSelectComponent> selectionComponents = new List<DiscordSelectComponent>();
|
List<DiscordSelectComponent> selectionComponents = new List<DiscordSelectComponent>();
|
||||||
int selectionOptions = 0;
|
int selectionOptions = 0;
|
||||||
for (int selectionBoxes = 0; selectionBoxes < 5 && selectionOptions < verifiedCategories.Count; selectionBoxes++)
|
for (int selectionBoxes = 0; selectionBoxes < 5 && selectionOptions < verifiedCategories.Count; selectionBoxes++)
|
||||||
{
|
{
|
||||||
List<DiscordSelectComponentOption> categoryOptions = new List<DiscordSelectComponentOption>();
|
List<DiscordSelectComponentOption> categoryOptions = new List<DiscordSelectComponentOption>();
|
||||||
|
|
||||||
for (; selectionOptions < 25 * (selectionBoxes + 1) && selectionOptions < verifiedCategories.Count; selectionOptions++)
|
for (; selectionOptions < 25 * (selectionBoxes + 1) && selectionOptions < verifiedCategories.Count; selectionOptions++)
|
||||||
{
|
{
|
||||||
categoryOptions.Add(new DiscordSelectComponentOption(verifiedCategories[selectionOptions].name, verifiedCategories[selectionOptions].id.ToString()));
|
categoryOptions.Add(new DiscordSelectComponentOption(verifiedCategories[selectionOptions].name, verifiedCategories[selectionOptions].id.ToString()));
|
||||||
}
|
}
|
||||||
selectionComponents.Add(new DiscordSelectComponent("supportchild_newcommandselector" + selectionBoxes, "Open new ticket...", categoryOptions, false, 0, 1));
|
selectionComponents.Add(new DiscordSelectComponent("supportchild_newcommandselector" + selectionBoxes, "Open new ticket...", categoryOptions, false, 0, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.CreateResponseAsync(new DiscordInteractionResponseBuilder().AddComponents(selectionComponents).AsEphemeral());
|
await command.CreateResponseAsync(new DiscordInteractionResponseBuilder().AddComponents(selectionComponents).AsEphemeral());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task OnCategorySelection(DiscordInteraction interaction)
|
public static async Task OnCategorySelection(DiscordInteraction interaction)
|
||||||
{
|
{
|
||||||
string stringID;
|
string stringID;
|
||||||
switch (interaction.Data.ComponentType)
|
switch (interaction.Data.ComponentType)
|
||||||
{
|
{
|
||||||
case ComponentType.Button:
|
case ComponentType.Button:
|
||||||
stringID = interaction.Data.CustomId.Replace("supportchild_newcommandbutton ", "");
|
stringID = interaction.Data.CustomId.Replace("supportchild_newcommandbutton ", "");
|
||||||
break;
|
break;
|
||||||
case ComponentType.StringSelect:
|
case ComponentType.StringSelect:
|
||||||
if (interaction.Data.Values == null || interaction.Data.Values.Length <= 0) return;
|
if (interaction.Data.Values == null || interaction.Data.Values.Length <= 0) return;
|
||||||
stringID = interaction.Data.Values[0];
|
stringID = interaction.Data.Values[0];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ComponentType.ActionRow:
|
case ComponentType.ActionRow:
|
||||||
case ComponentType.FormInput:
|
case ComponentType.FormInput:
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ulong.TryParse(stringID, out ulong categoryID) || categoryID == 0) return;
|
if (!ulong.TryParse(stringID, out ulong categoryID) || categoryID == 0) return;
|
||||||
|
|
||||||
await interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate, new DiscordInteractionResponseBuilder().AsEphemeral());
|
await interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate, new DiscordInteractionResponseBuilder().AsEphemeral());
|
||||||
|
|
||||||
(bool success, string message) = await OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID);
|
(bool success, string message) = await OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID);
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = message
|
Description = message
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = message
|
Description = message
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<(bool, string)> OpenNewTicket(ulong userID, ulong commandChannelID, ulong categoryID)
|
public static async Task<(bool, string)> OpenNewTicket(ulong userID, ulong commandChannelID, ulong categoryID)
|
||||||
{
|
{
|
||||||
// Check if user is blacklisted
|
// Check if user is blacklisted
|
||||||
if (Database.IsBlacklisted(userID))
|
if (Database.IsBlacklisted(userID))
|
||||||
{
|
{
|
||||||
return (false, "You are banned from opening tickets.");
|
return (false, "You are banned from opening tickets.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Database.IsOpenTicket(commandChannelID))
|
if (Database.IsOpenTicket(commandChannelID))
|
||||||
{
|
{
|
||||||
return (false, "You cannot use this command in a ticket channel.");
|
return (false, "You cannot use this command in a ticket channel.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Database.IsStaff(userID) && Database.TryGetOpenTickets(userID, out List<Database.Ticket> ownTickets) && ownTickets.Count >= Config.ticketLimit)
|
if (!Database.IsStaff(userID) && Database.TryGetOpenTickets(userID, out List<Database.Ticket> ownTickets) && ownTickets.Count >= Config.ticketLimit)
|
||||||
{
|
{
|
||||||
return (false, "You have reached the limit for maximum open tickets.");
|
return (false, "You have reached the limit for maximum open tickets.");
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordChannel category = null;
|
DiscordChannel category = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
category = await SupportChild.discordClient.GetChannelAsync(categoryID);
|
category = await SupportChild.discordClient.GetChannelAsync(categoryID);
|
||||||
}
|
}
|
||||||
catch (Exception) { /*ignored*/ }
|
catch (Exception) { /*ignored*/ }
|
||||||
|
|
||||||
if (category == null)
|
if (category == null)
|
||||||
{
|
{
|
||||||
return (false, "Error: Could not find the category to place the ticket in.");
|
return (false, "Error: Could not find the category to place the ticket in.");
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordMember member = null;
|
DiscordMember member = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
member = await category.Guild.GetMemberAsync(userID);
|
member = await category.Guild.GetMemberAsync(userID);
|
||||||
}
|
}
|
||||||
catch (Exception) { /*ignored*/ }
|
catch (Exception) { /*ignored*/ }
|
||||||
|
|
||||||
if (member == null)
|
if (member == null)
|
||||||
{
|
{
|
||||||
return (false, "Error: Could not find you on the Discord server.");
|
return (false, "Error: Could not find you on the Discord server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordChannel ticketChannel = null;
|
DiscordChannel ticketChannel = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ticketChannel = await category.Guild.CreateChannelAsync("ticket", ChannelType.Text, category);
|
ticketChannel = await category.Guild.CreateChannelAsync("ticket", ChannelType.Text, category);
|
||||||
}
|
}
|
||||||
catch (Exception) { /* ignored */ }
|
catch (Exception) { /* ignored */ }
|
||||||
|
|
||||||
if (ticketChannel == null)
|
if (ticketChannel == null)
|
||||||
{
|
{
|
||||||
return (false, "Error occured while creating ticket, " + member.Mention +
|
return (false, "Error occured while creating ticket, " + member.Mention +
|
||||||
"!\nIs the channel limit reached in the server or ticket category?");
|
"!\nIs the channel limit reached in the server or ticket category?");
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong staffID = 0;
|
ulong staffID = 0;
|
||||||
if (Config.randomAssignment)
|
if (Config.randomAssignment)
|
||||||
{
|
{
|
||||||
staffID = Database.GetRandomActiveStaff(0)?.userID ?? 0;
|
staffID = Database.GetRandomActiveStaff(0)?.userID ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
long id = Database.NewTicket(member.Id, staffID, ticketChannel.Id);
|
long id = Database.NewTicket(member.Id, staffID, ticketChannel.Id);
|
||||||
string ticketID = id.ToString("00000");
|
string ticketID = id.ToString("00000");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await ticketChannel.ModifyAsync(modifiedAttributes => modifiedAttributes.Name = "ticket-" + ticketID);
|
await ticketChannel.ModifyAsync(modifiedAttributes => modifiedAttributes.Name = "ticket-" + ticketID);
|
||||||
}
|
}
|
||||||
catch (DiscordException e)
|
catch (DiscordException e)
|
||||||
{
|
{
|
||||||
Logger.Error("Exception occurred trying to modify channel: " + e);
|
Logger.Error("Exception occurred trying to modify channel: " + e);
|
||||||
Logger.Error("JsomMessage: " + e.JsonMessage);
|
Logger.Error("JsomMessage: " + e.JsonMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await ticketChannel.AddOverwriteAsync(member, Permissions.AccessChannels);
|
await ticketChannel.AddOverwriteAsync(member, Permissions.AccessChannels);
|
||||||
}
|
}
|
||||||
catch (DiscordException e)
|
catch (DiscordException e)
|
||||||
{
|
{
|
||||||
Logger.Error("Exception occurred trying to add channel permissions: " + e);
|
Logger.Error("Exception occurred trying to add channel permissions: " + e);
|
||||||
Logger.Error("JsomMessage: " + e.JsonMessage);
|
Logger.Error("JsomMessage: " + e.JsonMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
await ticketChannel.SendMessageAsync("Hello, " + member.Mention + "!\n" + Config.welcomeMessage);
|
await ticketChannel.SendMessageAsync("Hello, " + member.Mention + "!\n" + Config.welcomeMessage);
|
||||||
|
|
||||||
// Refreshes the channel as changes were made to it above
|
// Refreshes the channel as changes were made to it above
|
||||||
ticketChannel = await SupportChild.discordClient.GetChannelAsync(ticketChannel.Id);
|
ticketChannel = await SupportChild.discordClient.GetChannelAsync(ticketChannel.Id);
|
||||||
|
|
||||||
if (staffID != 0)
|
if (staffID != 0)
|
||||||
{
|
{
|
||||||
await ticketChannel.SendMessageAsync(new DiscordEmbedBuilder
|
await ticketChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Ticket was randomly assigned to <@" + staffID + ">."
|
Description = "Ticket was randomly assigned to <@" + staffID + ">."
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Config.assignmentNotifications)
|
if (Config.assignmentNotifications)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DiscordMember staffMember = await category.Guild.GetMemberAsync(staffID);
|
DiscordMember staffMember = await category.Guild.GetMemberAsync(staffID);
|
||||||
await staffMember.SendMessageAsync(new DiscordEmbedBuilder
|
await staffMember.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "You have been randomly assigned to a newly opened support ticket: " +
|
Description = "You have been randomly assigned to a newly opened support ticket: " +
|
||||||
ticketChannel.Mention
|
ticketChannel.Mention
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (DiscordException e)
|
catch (DiscordException e)
|
||||||
{
|
{
|
||||||
Logger.Error("Exception occurred assign random staff member: " + e);
|
Logger.Error("Exception occurred assign random staff member: " + e);
|
||||||
Logger.Error("JsomMessage: " + e.JsonMessage);
|
Logger.Error("JsomMessage: " + e.JsonMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = category.Guild.GetChannel(Config.logChannel);
|
DiscordChannel logChannel = category.Guild.GetChannel(Config.logChannel);
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
{
|
{
|
||||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Ticket " + ticketChannel.Mention + " opened by " + member.Mention + ".\n",
|
Description = "Ticket " + ticketChannel.Mention + " opened by " + member.Mention + ".\n",
|
||||||
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "Ticket " + ticketID }
|
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "Ticket " + ticketID }
|
||||||
};
|
};
|
||||||
await logChannel.SendMessageAsync(logMessage);
|
await logChannel.SendMessageAsync(logMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (true, "Ticket opened, " + member.Mention + "!\n" + ticketChannel.Mention);
|
return (true, "Ticket opened, " + member.Mention + "!\n" + ticketChannel.Mention);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,128 +12,128 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class RandomAssignCommand : ApplicationCommandModule
|
public class RandomAssignCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("rassign", "Randomly assigns a staff member to a ticket.")]
|
[SlashCommand("rassign", "Randomly assigns a staff member to a ticket.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("Role", "(Optional) Limit the random assignment to a specific role.")] DiscordRole role = null)
|
public async Task OnExecute(InteractionContext command, [Option("Role", "(Optional) Limit the random assignment to a specific role.")] DiscordRole role = null)
|
||||||
{
|
{
|
||||||
// Check if ticket exists in the database
|
// Check if ticket exists in the database
|
||||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: This channel is not a ticket."
|
Description = "Error: This channel is not a ticket."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a random staff member who is verified to have the correct role if applicable
|
// Get a random staff member who is verified to have the correct role if applicable
|
||||||
DiscordMember staffMember = await GetRandomVerifiedStaffMember(command, role, ticket);
|
DiscordMember staffMember = await GetRandomVerifiedStaffMember(command, role, ticket);
|
||||||
if (staffMember == null)
|
if (staffMember == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to assign the staff member to the ticket
|
// Attempt to assign the staff member to the ticket
|
||||||
if (!Database.AssignStaff(ticket, staffMember.Id))
|
if (!Database.AssignStaff(ticket, staffMember.Id))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: Failed to assign " + staffMember.Mention + " to ticket."
|
Description = "Error: Failed to assign " + staffMember.Mention + " to ticket."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Respond that the command was successful
|
// Respond that the command was successful
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Randomly assigned " + staffMember.Mention + " to ticket."
|
Description = "Randomly assigned " + staffMember.Mention + " to ticket."
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send a notification to the staff member if applicable
|
// Send a notification to the staff member if applicable
|
||||||
if (Config.assignmentNotifications)
|
if (Config.assignmentNotifications)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await staffMember.SendMessageAsync(new DiscordEmbedBuilder
|
await staffMember.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "You have been randomly assigned to a support ticket: " + command.Channel.Mention
|
Description = "You have been randomly assigned to a support ticket: " + command.Channel.Mention
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (UnauthorizedException) { }
|
catch (UnauthorizedException) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
{
|
{
|
||||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = staffMember.Mention + " was randomly assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
Description = staffMember.Mention + " was randomly assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<DiscordMember> GetRandomVerifiedStaffMember(InteractionContext command, DiscordRole targetRole, Database.Ticket ticket)
|
private static async Task<DiscordMember> GetRandomVerifiedStaffMember(InteractionContext command, DiscordRole targetRole, Database.Ticket ticket)
|
||||||
{
|
{
|
||||||
if (targetRole != null) // A role was provided
|
if (targetRole != null) // A role was provided
|
||||||
{
|
{
|
||||||
// Check if role rassign should override staff's active status
|
// Check if role rassign should override staff's active status
|
||||||
List<Database.StaffMember> staffMembers = Config.randomAssignRoleOverride
|
List<Database.StaffMember> staffMembers = Config.randomAssignRoleOverride
|
||||||
? Database.GetAllStaff(ticket.assignedStaffID, ticket.creatorID)
|
? Database.GetAllStaff(ticket.assignedStaffID, ticket.creatorID)
|
||||||
: Database.GetActiveStaff(ticket.assignedStaffID, ticket.creatorID);
|
: Database.GetActiveStaff(ticket.assignedStaffID, ticket.creatorID);
|
||||||
|
|
||||||
// Randomize the list before checking for roles in order to reduce number of API calls
|
// Randomize the list before checking for roles in order to reduce number of API calls
|
||||||
staffMembers.Shuffle();
|
staffMembers.Shuffle();
|
||||||
|
|
||||||
// Get the first staff member that has the role
|
// Get the first staff member that has the role
|
||||||
foreach (Database.StaffMember sm in staffMembers)
|
foreach (Database.StaffMember sm in staffMembers)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DiscordMember verifiedMember = await command.Guild.GetMemberAsync(sm.userID);
|
DiscordMember verifiedMember = await command.Guild.GetMemberAsync(sm.userID);
|
||||||
if (verifiedMember?.Roles?.Any(role => role.Id == targetRole.Id) ?? false)
|
if (verifiedMember?.Roles?.Any(role => role.Id == targetRole.Id) ?? false)
|
||||||
{
|
{
|
||||||
return verifiedMember;
|
return verifiedMember;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
command.Client.Logger.Log(LogLevel.Information, e, "Error occured trying to find a staff member in the rassign command.");
|
command.Client.Logger.Log(LogLevel.Information, e, "Error occured trying to find a staff member in the rassign command.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // No role was specified, any active staff will be picked
|
else // No role was specified, any active staff will be picked
|
||||||
{
|
{
|
||||||
Database.StaffMember staffEntry = Database.GetRandomActiveStaff(ticket.assignedStaffID, ticket.creatorID);
|
Database.StaffMember staffEntry = Database.GetRandomActiveStaff(ticket.assignedStaffID, ticket.creatorID);
|
||||||
if (staffEntry == null)
|
if (staffEntry == null)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: There are no other staff members to choose from."
|
Description = "Error: There are no other staff members to choose from."
|
||||||
}, true);
|
}, true);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the staff member from discord
|
// Get the staff member from discord
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return await command.Guild.GetMemberAsync(staffEntry.userID);
|
return await command.Guild.GetMemberAsync(staffEntry.userID);
|
||||||
}
|
}
|
||||||
catch (NotFoundException) { }
|
catch (NotFoundException) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a more generic error if we get to this point and still haven't found the staff member
|
// Send a more generic error if we get to this point and still haven't found the staff member
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: Could not find an applicable staff member."
|
Description = "Error: Could not find an applicable staff member."
|
||||||
}, true);
|
}, true);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.SlashCommands;
|
using DSharpPlus.SlashCommands;
|
||||||
using DSharpPlus.SlashCommands.Attributes;
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
@ -7,35 +7,35 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class RemoveCategoryCommand : ApplicationCommandModule
|
public class RemoveCategoryCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("removecategory", "Removes the ability for users to open tickets in a specific category.")]
|
[SlashCommand("removecategory", "Removes the ability for users to open tickets in a specific category.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("Category", "The category to remove.")] DiscordChannel channel)
|
public async Task OnExecute(InteractionContext command, [Option("Category", "The category to remove.")] DiscordChannel channel)
|
||||||
{
|
{
|
||||||
if (!Database.TryGetCategory(channel.Id, out Database.Category _))
|
if (!Database.TryGetCategory(channel.Id, out Database.Category _))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "That category is not registered."
|
Description = "That category is not registered."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Database.RemoveCategory(channel.Id))
|
if (Database.RemoveCategory(channel.Id))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Category removed."
|
Description = "Category removed."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: Failed removing the category from the database."
|
Description = "Error: Failed removing the category from the database."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,35 +7,35 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class RemoveMessageCommand : ApplicationCommandModule
|
public class RemoveMessageCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("removemessage", "Removes a message from the 'say' command.")]
|
[SlashCommand("removemessage", "Removes a message from the 'say' command.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("Identifier", "The identifier word used in the /say command.")] string identifier)
|
public async Task OnExecute(InteractionContext command, [Option("Identifier", "The identifier word used in the /say command.")] string identifier)
|
||||||
{
|
{
|
||||||
if (!Database.TryGetMessage(identifier.ToLower(), out Database.Message _))
|
if (!Database.TryGetMessage(identifier.ToLower(), out Database.Message _))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "There is no message with that identifier."
|
Description = "There is no message with that identifier."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Database.RemoveMessage(identifier))
|
if (Database.RemoveMessage(identifier))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Message removed."
|
Description = "Message removed."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: Failed removing the message from the database."
|
Description = "Error: Failed removing the message from the database."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,42 +8,42 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class RemoveStaffCommand : ApplicationCommandModule
|
public class RemoveStaffCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("removestaff", "Removes a staff member.")]
|
[SlashCommand("removestaff", "Removes a staff member.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("User", "User to remove from staff.")] DiscordUser user)
|
public async Task OnExecute(InteractionContext command, [Option("User", "User to remove from staff.")] DiscordUser user)
|
||||||
{
|
{
|
||||||
if (!Database.IsStaff(user.Id))
|
if (!Database.IsStaff(user.Id))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "User is already not registered as staff."
|
Description = "User is already not registered as staff."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await using MySqlConnection c = Database.GetConnection();
|
await using MySqlConnection c = Database.GetConnection();
|
||||||
c.Open();
|
c.Open();
|
||||||
MySqlCommand deletion = new MySqlCommand(@"DELETE FROM staff WHERE user_id=@user_id", c);
|
MySqlCommand deletion = new MySqlCommand(@"DELETE FROM staff WHERE user_id=@user_id", c);
|
||||||
deletion.Parameters.AddWithValue("@user_id", user.Id);
|
deletion.Parameters.AddWithValue("@user_id", user.Id);
|
||||||
deletion.Prepare();
|
deletion.Prepare();
|
||||||
deletion.ExecuteNonQuery();
|
deletion.ExecuteNonQuery();
|
||||||
|
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "User was removed from staff."
|
Description = "User was removed from staff."
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
{
|
{
|
||||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "User was removed from staff.\n"
|
Description = "User was removed from staff.\n"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,59 +9,59 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class SayCommand : ApplicationCommandModule
|
public class SayCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("say", "Prints a message with information from staff. Use without identifier to list all identifiers.")]
|
[SlashCommand("say", "Prints a message with information from staff. Use without identifier to list all identifiers.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("Identifier", "(Optional) The identifier word to summon a message.")] string identifier = null)
|
public async Task OnExecute(InteractionContext command, [Option("Identifier", "(Optional) The identifier word to summon a message.")] string identifier = null)
|
||||||
{
|
{
|
||||||
// Print list of all messages if no identifier is provided
|
// Print list of all messages if no identifier is provided
|
||||||
if (identifier == null)
|
if (identifier == null)
|
||||||
{
|
{
|
||||||
List<Database.Message> messages = Database.GetAllMessages();
|
List<Database.Message> messages = Database.GetAllMessages();
|
||||||
if (!messages.Any())
|
if (!messages.Any())
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "There are no messages registered."
|
Description = "There are no messages registered."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<string> listItems = new List<string>();
|
List<string> listItems = new List<string>();
|
||||||
foreach (Database.Message message in messages)
|
foreach (Database.Message message in messages)
|
||||||
{
|
{
|
||||||
listItems.Add("**" + message.identifier + "** Added by <@" + message.userID + ">\n");
|
listItems.Add("**" + message.identifier + "** Added by <@" + message.userID + ">\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkedList<string> listMessages = Utilities.ParseListIntoMessages(listItems);
|
LinkedList<string> listMessages = Utilities.ParseListIntoMessages(listItems);
|
||||||
foreach (string listMessage in listMessages)
|
foreach (string listMessage in listMessages)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Title = "Available messages: ",
|
Title = "Available messages: ",
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = listMessage
|
Description = listMessage
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Print specific message
|
// Print specific message
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!Database.TryGetMessage(identifier.ToLower(), out Database.Message message))
|
if (!Database.TryGetMessage(identifier.ToLower(), out Database.Message message))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "There is no message with that identifier."
|
Description = "There is no message with that identifier."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Cyan,
|
Color = DiscordColor.Cyan,
|
||||||
Description = message.message.Replace("\\n", "\n")
|
Description = message.message.Replace("\\n", "\n")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,35 +8,35 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class SetSummaryCommand : ApplicationCommandModule
|
public class SetSummaryCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("setsummary", "Sets a ticket's summary for the summary command.")]
|
[SlashCommand("setsummary", "Sets a ticket's summary for the summary command.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("Summary", "The ticket summary text.")] string summary)
|
public async Task OnExecute(InteractionContext command, [Option("Summary", "The ticket summary text.")] string summary)
|
||||||
{
|
{
|
||||||
ulong channelID = command.Channel.Id;
|
ulong channelID = command.Channel.Id;
|
||||||
// Check if ticket exists in the database
|
// Check if ticket exists in the database
|
||||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket _))
|
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket _))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "This channel is not a ticket."
|
Description = "This channel is not a ticket."
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await using MySqlConnection c = Database.GetConnection();
|
await using MySqlConnection c = Database.GetConnection();
|
||||||
c.Open();
|
c.Open();
|
||||||
MySqlCommand update = new MySqlCommand(@"UPDATE tickets SET summary = @summary WHERE channel_id = @channel_id", c);
|
MySqlCommand update = new MySqlCommand(@"UPDATE tickets SET summary = @summary WHERE channel_id = @channel_id", c);
|
||||||
update.Parameters.AddWithValue("@summary", summary);
|
update.Parameters.AddWithValue("@summary", summary);
|
||||||
update.Parameters.AddWithValue("@channel_id", channelID);
|
update.Parameters.AddWithValue("@channel_id", channelID);
|
||||||
update.Prepare();
|
update.Prepare();
|
||||||
update.ExecuteNonQuery();
|
update.ExecuteNonQuery();
|
||||||
update.Dispose();
|
update.Dispose();
|
||||||
|
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Summary set."
|
Description = "Summary set."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,20 +7,20 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class StatusCommand : ApplicationCommandModule
|
public class StatusCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("status", "Shows bot status and information.")]
|
[SlashCommand("status", "Shows bot status and information.")]
|
||||||
public async Task OnExecute(InteractionContext command)
|
public async Task OnExecute(InteractionContext command)
|
||||||
{
|
{
|
||||||
long openTickets = Database.GetNumberOfTickets();
|
long openTickets = Database.GetNumberOfTickets();
|
||||||
long closedTickets = Database.GetNumberOfClosedTickets();
|
long closedTickets = Database.GetNumberOfClosedTickets();
|
||||||
|
|
||||||
DiscordEmbed botInfo = new DiscordEmbedBuilder()
|
DiscordEmbed botInfo = new DiscordEmbedBuilder()
|
||||||
.WithAuthor("Emotion-stuff/supportchild @ Toastielab", "https://toastielab.dev/Emotions-stuff/SupportChild", "https://cdn.discordapp.com/attachments/765441543100170271/914327948667011132/Ellie_Concept_2_transparent_ver.png")
|
.WithAuthor("Emotion-stuff/supportchild @ Toastielab", "https://toastielab.dev/Emotions-stuff/SupportChild", "https://cdn.discordapp.com/attachments/765441543100170271/914327948667011132/Ellie_Concept_2_transparent_ver.png")
|
||||||
.WithTitle("Bot information")
|
.WithTitle("Bot information")
|
||||||
.WithColor(DiscordColor.Cyan)
|
.WithColor(DiscordColor.Cyan)
|
||||||
.AddField("Version:", SupportChild.GetVersion())
|
.AddField("Version:", SupportChild.GetVersion())
|
||||||
.AddField("Open tickets:", openTickets + "", true)
|
.AddField("Open tickets:", openTickets + "", true)
|
||||||
.AddField("Closed tickets:", closedTickets + " ", true);
|
.AddField("Closed tickets:", closedTickets + " ", true);
|
||||||
await command.CreateResponseAsync(botInfo);
|
await command.CreateResponseAsync(botInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,29 +7,29 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class SummaryCommand : ApplicationCommandModule
|
public class SummaryCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("summary", "Lists tickets assigned to a user.")]
|
[SlashCommand("summary", "Lists tickets assigned to a user.")]
|
||||||
public async Task OnExecute(InteractionContext command)
|
public async Task OnExecute(InteractionContext command)
|
||||||
{
|
{
|
||||||
if (Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
if (Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
||||||
{
|
{
|
||||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
||||||
.WithTitle("Channel information")
|
.WithTitle("Channel information")
|
||||||
.WithColor(DiscordColor.Cyan)
|
.WithColor(DiscordColor.Cyan)
|
||||||
.AddField("Ticket number:", ticket.id.ToString("00000"), true)
|
.AddField("Ticket number:", ticket.id.ToString("00000"), true)
|
||||||
.AddField("Ticket creator:", $"<@{ticket.creatorID}>", true)
|
.AddField("Ticket creator:", $"<@{ticket.creatorID}>", true)
|
||||||
.AddField("Assigned staff:", ticket.assignedStaffID == 0 ? "Unassigned." : $"<@{ticket.assignedStaffID}>", true)
|
.AddField("Assigned staff:", ticket.assignedStaffID == 0 ? "Unassigned." : $"<@{ticket.assignedStaffID}>", true)
|
||||||
.AddField("Creation time:", ticket.DiscordRelativeTime(), true)
|
.AddField("Creation time:", ticket.DiscordRelativeTime(), true)
|
||||||
.AddField("Summary:", string.IsNullOrEmpty(ticket.summary) ? "No summary." : ticket.summary.Replace("\\n", "\n"));
|
.AddField("Summary:", string.IsNullOrEmpty(ticket.summary) ? "No summary." : ticket.summary.Replace("\\n", "\n"));
|
||||||
await command.CreateResponseAsync(channelInfo);
|
await command.CreateResponseAsync(channelInfo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "This channel is not a ticket."
|
Description = "This channel is not a ticket."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,38 +7,38 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class ToggleActiveCommand : ApplicationCommandModule
|
public class ToggleActiveCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("toggleactive", "Toggles active status for a staff member.")]
|
[SlashCommand("toggleactive", "Toggles active status for a staff member.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) Staff member to toggle activity for.")] DiscordUser user = null)
|
public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) Staff member to toggle activity for.")] DiscordUser user = null)
|
||||||
{
|
{
|
||||||
DiscordUser staffUser = user == null ? command.User : user;
|
DiscordUser staffUser = user == null ? command.User : user;
|
||||||
|
|
||||||
// Check if ticket exists in the database
|
// Check if ticket exists in the database
|
||||||
if (!Database.TryGetStaff(staffUser.Id, out Database.StaffMember staffMember))
|
if (!Database.TryGetStaff(staffUser.Id, out Database.StaffMember staffMember))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = user == null ? "You have not been registered as staff." : "The user is not registered as staff."
|
Description = user == null ? "You have not been registered as staff." : "The user is not registered as staff."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Database.SetStaffActive(staffUser.Id, !staffMember.active))
|
if (Database.SetStaffActive(staffUser.Id, !staffMember.active))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = staffMember.active ? "Staff member is now set as inactive and will no longer be randomly assigned any support tickets." : "Staff member is now set as active and will be randomly assigned support tickets again."
|
Description = staffMember.active ? "Staff member is now set as inactive and will no longer be randomly assigned any support tickets." : "Staff member is now set as active and will be randomly assigned support tickets again."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: Unable to update active status in database."
|
Description = "Error: Unable to update active status in database."
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,119 +11,119 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class TranscriptCommand : ApplicationCommandModule
|
public class TranscriptCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("transcript", "Creates a transcript of a ticket.")]
|
[SlashCommand("transcript", "Creates a transcript of a ticket.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("Ticket", "(Optional) Ticket number to get transcript of.")] long ticketID = 0)
|
public async Task OnExecute(InteractionContext command, [Option("Ticket", "(Optional) Ticket number to get transcript of.")] long ticketID = 0)
|
||||||
{
|
{
|
||||||
await command.DeferAsync(true);
|
await command.DeferAsync(true);
|
||||||
Database.Ticket ticket;
|
Database.Ticket ticket;
|
||||||
if (ticketID == 0) // If there are no arguments use current channel
|
if (ticketID == 0) // If there are no arguments use current channel
|
||||||
{
|
{
|
||||||
if (Database.TryGetOpenTicket(command.Channel.Id, out ticket))
|
if (Database.TryGetOpenTicket(command.Channel.Id, out ticket))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Transcriber.ExecuteAsync(command.Channel.Id, ticket.id);
|
await Transcriber.ExecuteAsync(command.Channel.Id, ticket.id);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "ERROR: Could not save transcript file. Aborting..."
|
Description = "ERROR: Could not save transcript file. Aborting..."
|
||||||
}));
|
}));
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "This channel is not a ticket."
|
Description = "This channel is not a ticket."
|
||||||
}));
|
}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If the ticket is still open, generate a new fresh transcript
|
// If the ticket is still open, generate a new fresh transcript
|
||||||
if (Database.TryGetOpenTicketByID((uint)ticketID, out ticket) && ticket?.creatorID == command.Member.Id)
|
if (Database.TryGetOpenTicketByID((uint)ticketID, out ticket) && ticket?.creatorID == command.Member.Id)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Transcriber.ExecuteAsync(command.Channel.Id, ticket.id);
|
await Transcriber.ExecuteAsync(command.Channel.Id, ticket.id);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "ERROR: Could not save transcript file. Aborting..."
|
Description = "ERROR: Could not save transcript file. Aborting..."
|
||||||
}));
|
}));
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// If there is no open or closed ticket, send an error. If there is a closed ticket we will simply use the old transcript from when the ticket was closed.
|
// If there is no open or closed ticket, send an error. If there is a closed ticket we will simply use the old transcript from when the ticket was closed.
|
||||||
else if (!Database.TryGetClosedTicket((uint)ticketID, out ticket) || (ticket?.creatorID != command.Member.Id && !Database.IsStaff(command.Member.Id)))
|
else if (!Database.TryGetClosedTicket((uint)ticketID, out ticket) || (ticket?.creatorID != command.Member.Id && !Database.IsStaff(command.Member.Id)))
|
||||||
{
|
{
|
||||||
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Could not find a closed ticket with that number which you opened.\n(Use the /list command to see all your tickets)"
|
Description = "Could not find a closed ticket with that number which you opened.\n(Use the /list command to see all your tickets)"
|
||||||
}));
|
}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
{
|
{
|
||||||
await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
|
await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
|
||||||
|
|
||||||
DiscordMessageBuilder message = new DiscordMessageBuilder();
|
DiscordMessageBuilder message = new DiscordMessageBuilder();
|
||||||
message.WithEmbed(new DiscordEmbedBuilder
|
message.WithEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Ticket " + ticket.id.ToString("00000") + " transcript generated by " + command.Member.Mention + ".\n",
|
Description = "Ticket " + ticket.id.ToString("00000") + " transcript generated by " + command.Member.Mention + ".\n",
|
||||||
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + command.Channel.Name }
|
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + command.Channel.Name }
|
||||||
});
|
});
|
||||||
message.AddFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
message.AddFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||||
|
|
||||||
await logChannel.SendMessageAsync(message);
|
await logChannel.SendMessageAsync(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Send transcript in a direct message
|
// Send transcript in a direct message
|
||||||
await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
|
await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
|
||||||
|
|
||||||
DiscordMessageBuilder directMessage = new DiscordMessageBuilder();
|
DiscordMessageBuilder directMessage = new DiscordMessageBuilder();
|
||||||
directMessage.WithEmbed(new DiscordEmbedBuilder
|
directMessage.WithEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Transcript generated!\n"
|
Description = "Transcript generated!\n"
|
||||||
});
|
});
|
||||||
directMessage.AddFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
directMessage.AddFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||||
|
|
||||||
await command.Member.SendMessageAsync(directMessage);
|
await command.Member.SendMessageAsync(directMessage);
|
||||||
}
|
}
|
||||||
catch (UnauthorizedException)
|
catch (UnauthorizedException)
|
||||||
{
|
{
|
||||||
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Not allowed to send direct message to you, please check your privacy settings.\n"
|
Description = "Not allowed to send direct message to you, please check your privacy settings.\n"
|
||||||
}));
|
}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Transcript sent!\n"
|
Description = "Transcript sent!\n"
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,46 +7,46 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class UnassignCommand : ApplicationCommandModule
|
public class UnassignCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("unassign", "Unassigns a staff member from a ticket.")]
|
[SlashCommand("unassign", "Unassigns a staff member from a ticket.")]
|
||||||
public async Task OnExecute(InteractionContext command)
|
public async Task OnExecute(InteractionContext command)
|
||||||
{
|
{
|
||||||
// Check if ticket exists in the database
|
// Check if ticket exists in the database
|
||||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "This channel is not a ticket."
|
Description = "This channel is not a ticket."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Database.UnassignStaff(ticket))
|
if (!Database.UnassignStaff(ticket))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: Failed to unassign staff member from ticket."
|
Description = "Error: Failed to unassign staff member from ticket."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Unassigned staff member from ticket."
|
Description = "Unassigned staff member from ticket."
|
||||||
});
|
});
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
{
|
{
|
||||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Staff member was unassigned from " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
Description = "Staff member was unassigned from " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,47 +8,47 @@ namespace SupportChild.Commands;
|
||||||
|
|
||||||
public class UnblacklistCommand : ApplicationCommandModule
|
public class UnblacklistCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
[SlashRequireGuild]
|
[SlashRequireGuild]
|
||||||
[SlashCommand("unblacklist", "Unblacklists a user from opening tickets.")]
|
[SlashCommand("unblacklist", "Unblacklists a user from opening tickets.")]
|
||||||
public async Task OnExecute(InteractionContext command, [Option("User", "User to remove from blacklist.")] DiscordUser user)
|
public async Task OnExecute(InteractionContext command, [Option("User", "User to remove from blacklist.")] DiscordUser user)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!Database.Unblacklist(user.Id))
|
if (!Database.Unblacklist(user.Id))
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = user.Mention + " is not blacklisted."
|
Description = user.Mention + " is not blacklisted."
|
||||||
}, true);
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Removed " + user.Mention + " from blacklist."
|
Description = "Removed " + user.Mention + " from blacklist."
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
{
|
{
|
||||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = user.Mention + " was unblacklisted from opening tickets by " + command.Member.Mention + "."
|
Description = user.Mention + " was unblacklisted from opening tickets by " + command.Member.Mention + "."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error occured while removing " + user.Mention + " from blacklist."
|
Description = "Error occured while removing " + user.Mention + " from blacklist."
|
||||||
}, true);
|
}, true);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
130
Config.cs
130
Config.cs
|
@ -14,82 +14,82 @@ internal static class Config
|
||||||
internal static string token = "";
|
internal static string token = "";
|
||||||
internal static ulong logChannel;
|
internal static ulong logChannel;
|
||||||
internal static string welcomeMessage = "";
|
internal static string welcomeMessage = "";
|
||||||
internal static LogLevel logLevel = LogLevel.Information;
|
internal static LogLevel logLevel = LogLevel.Information;
|
||||||
internal static TimestampFormat timestampFormat = TimestampFormat.RelativeTime;
|
internal static TimestampFormat timestampFormat = TimestampFormat.RelativeTime;
|
||||||
internal static bool randomAssignment = false;
|
internal static bool randomAssignment = false;
|
||||||
internal static bool randomAssignRoleOverride = false;
|
internal static bool randomAssignRoleOverride = false;
|
||||||
internal static string presenceType = "Playing";
|
internal static string presenceType = "Playing";
|
||||||
internal static string presenceText = "";
|
internal static string presenceText = "";
|
||||||
internal static bool newCommandUsesSelector = false;
|
internal static bool newCommandUsesSelector = false;
|
||||||
internal static int ticketLimit = 5;
|
internal static int ticketLimit = 5;
|
||||||
|
|
||||||
internal static bool ticketUpdatedNotifications = false;
|
internal static bool ticketUpdatedNotifications = false;
|
||||||
internal static double ticketUpdatedNotificationDelay = 0.0;
|
internal static double ticketUpdatedNotificationDelay = 0.0;
|
||||||
internal static bool assignmentNotifications = false;
|
internal static bool assignmentNotifications = false;
|
||||||
internal static bool closingNotifications = false;
|
internal static bool closingNotifications = false;
|
||||||
|
|
||||||
internal static string hostName = "127.0.0.1";
|
internal static string hostName = "127.0.0.1";
|
||||||
internal static int port = 3306;
|
internal static int port = 3306;
|
||||||
internal static string database = "supportchild";
|
internal static string database = "supportchild";
|
||||||
internal static string username = "supportchild";
|
internal static string username = "supportchild";
|
||||||
internal static string password = "";
|
internal static string password = "";
|
||||||
|
|
||||||
public static void LoadConfig()
|
public static void LoadConfig()
|
||||||
{
|
{
|
||||||
// Writes default config to file if it does not already exist
|
// Writes default config to file if it does not already exist
|
||||||
if (!File.Exists("./config.yml"))
|
if (!File.Exists("./config.yml"))
|
||||||
{
|
{
|
||||||
File.WriteAllText("./config.yml", Encoding.UTF8.GetString(Resources.default_config));
|
File.WriteAllText("./config.yml", Encoding.UTF8.GetString(Resources.default_config));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads config contents into FileStream
|
// Reads config contents into FileStream
|
||||||
FileStream stream = File.OpenRead("./config.yml");
|
FileStream stream = File.OpenRead("./config.yml");
|
||||||
|
|
||||||
// Converts the FileStream into a YAML object
|
// Converts the FileStream into a YAML object
|
||||||
IDeserializer deserializer = new DeserializerBuilder().Build();
|
IDeserializer deserializer = new DeserializerBuilder().Build();
|
||||||
object yamlObject = deserializer.Deserialize(new StreamReader(stream)) ?? "";
|
object yamlObject = deserializer.Deserialize(new StreamReader(stream)) ?? "";
|
||||||
|
|
||||||
// Converts the YAML object into a JSON object as the YAML ones do not support traversal or selection of nodes by name
|
// Converts the YAML object into a JSON object as the YAML ones do not support traversal or selection of nodes by name
|
||||||
ISerializer serializer = new SerializerBuilder().JsonCompatible().Build();
|
ISerializer serializer = new SerializerBuilder().JsonCompatible().Build();
|
||||||
JObject json = JObject.Parse(serializer.Serialize(yamlObject));
|
JObject json = JObject.Parse(serializer.Serialize(yamlObject));
|
||||||
|
|
||||||
// Sets up the bot
|
// Sets up the bot
|
||||||
token = json.SelectToken("bot.token")?.Value<string>() ?? "";
|
token = json.SelectToken("bot.token")?.Value<string>() ?? "";
|
||||||
logChannel = json.SelectToken("bot.log-channel")?.Value<ulong>() ?? 0;
|
logChannel = json.SelectToken("bot.log-channel")?.Value<ulong>() ?? 0;
|
||||||
welcomeMessage = json.SelectToken("bot.welcome-message")?.Value<string>() ?? "";
|
welcomeMessage = json.SelectToken("bot.welcome-message")?.Value<string>() ?? "";
|
||||||
string stringLogLevel = json.SelectToken("bot.console-log-level")?.Value<string>() ?? "";
|
string stringLogLevel = json.SelectToken("bot.console-log-level")?.Value<string>() ?? "";
|
||||||
|
|
||||||
if (!Enum.TryParse(stringLogLevel, true, out logLevel))
|
if (!Enum.TryParse(stringLogLevel, true, out logLevel))
|
||||||
{
|
{
|
||||||
logLevel = LogLevel.Information;
|
logLevel = LogLevel.Information;
|
||||||
Logger.Warn("Log level '" + stringLogLevel + "' invalid, using 'Information' instead.");
|
Logger.Warn("Log level '" + stringLogLevel + "' invalid, using 'Information' instead.");
|
||||||
}
|
}
|
||||||
|
|
||||||
string stringTimestampFormat = json.SelectToken("bot.timestamp-format")?.Value<string>() ?? "RelativeTime";
|
string stringTimestampFormat = json.SelectToken("bot.timestamp-format")?.Value<string>() ?? "RelativeTime";
|
||||||
|
|
||||||
if (!Enum.TryParse(stringTimestampFormat, true, out timestampFormat))
|
if (!Enum.TryParse(stringTimestampFormat, true, out timestampFormat))
|
||||||
{
|
{
|
||||||
timestampFormat = TimestampFormat.RelativeTime;
|
timestampFormat = TimestampFormat.RelativeTime;
|
||||||
Logger.Warn("Timestamp '" + stringTimestampFormat + "' invalid, using 'RelativeTime' instead.");
|
Logger.Warn("Timestamp '" + stringTimestampFormat + "' invalid, using 'RelativeTime' instead.");
|
||||||
}
|
}
|
||||||
|
|
||||||
randomAssignment = json.SelectToken("bot.random-assignment")?.Value<bool>() ?? false;
|
randomAssignment = json.SelectToken("bot.random-assignment")?.Value<bool>() ?? false;
|
||||||
randomAssignRoleOverride = json.SelectToken("bot.random-assign-role-override")?.Value<bool>() ?? false;
|
randomAssignRoleOverride = json.SelectToken("bot.random-assign-role-override")?.Value<bool>() ?? false;
|
||||||
presenceType = json.SelectToken("bot.presence-type")?.Value<string>() ?? "Playing";
|
presenceType = json.SelectToken("bot.presence-type")?.Value<string>() ?? "Playing";
|
||||||
presenceText = json.SelectToken("bot.presence-text")?.Value<string>() ?? "";
|
presenceText = json.SelectToken("bot.presence-text")?.Value<string>() ?? "";
|
||||||
newCommandUsesSelector = json.SelectToken("bot.new-command-uses-selector")?.Value<bool>() ?? false;
|
newCommandUsesSelector = json.SelectToken("bot.new-command-uses-selector")?.Value<bool>() ?? false;
|
||||||
ticketLimit = json.SelectToken("bot.ticket-limit")?.Value<int>() ?? 5;
|
ticketLimit = json.SelectToken("bot.ticket-limit")?.Value<int>() ?? 5;
|
||||||
|
|
||||||
ticketUpdatedNotifications = json.SelectToken("notifications.ticket-updated")?.Value<bool>() ?? false;
|
ticketUpdatedNotifications = json.SelectToken("notifications.ticket-updated")?.Value<bool>() ?? false;
|
||||||
ticketUpdatedNotificationDelay = json.SelectToken("notifications.ticket-updated-delay")?.Value<double>() ?? 0.0;
|
ticketUpdatedNotificationDelay = json.SelectToken("notifications.ticket-updated-delay")?.Value<double>() ?? 0.0;
|
||||||
assignmentNotifications = json.SelectToken("notifications.assignment")?.Value<bool>() ?? false;
|
assignmentNotifications = json.SelectToken("notifications.assignment")?.Value<bool>() ?? false;
|
||||||
closingNotifications = json.SelectToken("notifications.closing")?.Value<bool>() ?? false;
|
closingNotifications = json.SelectToken("notifications.closing")?.Value<bool>() ?? false;
|
||||||
|
|
||||||
// Reads database info
|
// Reads database info
|
||||||
hostName = json.SelectToken("database.address")?.Value<string>() ?? "";
|
hostName = json.SelectToken("database.address")?.Value<string>() ?? "";
|
||||||
port = json.SelectToken("database.port")?.Value<int>() ?? 3306;
|
port = json.SelectToken("database.port")?.Value<int>() ?? 3306;
|
||||||
database = json.SelectToken("database.name")?.Value<string>() ?? "supportchild";
|
database = json.SelectToken("database.name")?.Value<string>() ?? "supportchild";
|
||||||
username = json.SelectToken("database.user")?.Value<string>() ?? "supportchild";
|
username = json.SelectToken("database.user")?.Value<string>() ?? "supportchild";
|
||||||
password = json.SelectToken("database.password")?.Value<string>() ?? "";
|
password = json.SelectToken("database.password")?.Value<string>() ?? "";
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -90,17 +90,17 @@ internal static class EventHandler
|
||||||
switch (e.Exception)
|
switch (e.Exception)
|
||||||
{
|
{
|
||||||
case SlashExecutionChecksFailedException checksFailedException:
|
case SlashExecutionChecksFailedException checksFailedException:
|
||||||
|
{
|
||||||
|
foreach (SlashCheckBaseAttribute attr in checksFailedException.FailedChecks)
|
||||||
{
|
{
|
||||||
foreach (SlashCheckBaseAttribute attr in checksFailedException.FailedChecks)
|
await e.Context.Channel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
await e.Context.Channel.SendMessageAsync(new DiscordEmbedBuilder
|
Color = DiscordColor.Red,
|
||||||
{
|
Description = ParseFailedCheck(attr)
|
||||||
Color = DiscordColor.Red,
|
});
|
||||||
Description = ParseFailedCheck(attr)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
case BadRequestException ex:
|
case BadRequestException ex:
|
||||||
Logger.Error("Command exception occured:\n" + e.Exception);
|
Logger.Error("Command exception occured:\n" + e.Exception);
|
||||||
|
@ -108,15 +108,15 @@ internal static class EventHandler
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
{
|
||||||
|
Logger.Error("Exception occured: " + e.Exception.GetType() + ": " + e.Exception);
|
||||||
|
await e.Context.Channel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Logger.Error("Exception occured: " + e.Exception.GetType() + ": " + e.Exception);
|
Color = DiscordColor.Red,
|
||||||
await e.Context.Channel.SendMessageAsync(new DiscordEmbedBuilder
|
Description = "Internal error occured, please report this to the developer."
|
||||||
{
|
});
|
||||||
Color = DiscordColor.Red,
|
return;
|
||||||
Description = "Internal error occured, please report this to the developer."
|
}
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
112
Logger.cs
112
Logger.cs
|
@ -1,4 +1,4 @@
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
|
@ -6,63 +6,63 @@ namespace SupportChild;
|
||||||
|
|
||||||
public static class Logger
|
public static class Logger
|
||||||
{
|
{
|
||||||
public static void Debug(string message)
|
public static void Debug(string message)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SupportChild.discordClient.Logger.Log(LogLevel.Debug, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
SupportChild.discordClient.Logger.Log(LogLevel.Debug, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
||||||
}
|
}
|
||||||
catch (NullReferenceException)
|
catch (NullReferenceException)
|
||||||
{
|
{
|
||||||
Console.WriteLine("[DEBUG] " + message);
|
Console.WriteLine("[DEBUG] " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Log(string message)
|
public static void Log(string message)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SupportChild.discordClient.Logger.Log(LogLevel.Information, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
SupportChild.discordClient.Logger.Log(LogLevel.Information, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
||||||
}
|
}
|
||||||
catch (NullReferenceException)
|
catch (NullReferenceException)
|
||||||
{
|
{
|
||||||
Console.WriteLine("[INFO] " + message);
|
Console.WriteLine("[INFO] " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Warn(string message)
|
public static void Warn(string message)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SupportChild.discordClient.Logger.Log(LogLevel.Warning, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
SupportChild.discordClient.Logger.Log(LogLevel.Warning, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
||||||
}
|
}
|
||||||
catch (NullReferenceException)
|
catch (NullReferenceException)
|
||||||
{
|
{
|
||||||
Console.WriteLine("[WARNING] " + message);
|
Console.WriteLine("[WARNING] " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Error(string message)
|
public static void Error(string message)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SupportChild.discordClient.Logger.Log(LogLevel.Error, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
SupportChild.discordClient.Logger.Log(LogLevel.Error, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
||||||
}
|
}
|
||||||
catch (NullReferenceException)
|
catch (NullReferenceException)
|
||||||
{
|
{
|
||||||
Console.WriteLine("[ERROR] " + message);
|
Console.WriteLine("[ERROR] " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Fatal(string message)
|
public static void Fatal(string message)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SupportChild.discordClient.Logger.Log(LogLevel.Critical, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
SupportChild.discordClient.Logger.Log(LogLevel.Critical, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
||||||
}
|
}
|
||||||
catch (NullReferenceException)
|
catch (NullReferenceException)
|
||||||
{
|
{
|
||||||
Console.WriteLine("[CRITICAL] " + message);
|
Console.WriteLine("[CRITICAL] " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
230
SupportChild.cs
230
SupportChild.cs
|
@ -14,136 +14,136 @@ namespace SupportChild;
|
||||||
|
|
||||||
internal static class SupportChild
|
internal static class SupportChild
|
||||||
{
|
{
|
||||||
// Sets up a dummy client to use for logging
|
// Sets up a dummy client to use for logging
|
||||||
public static DiscordClient discordClient = new DiscordClient(new DiscordConfiguration { Token = "DUMMY_TOKEN", TokenType = TokenType.Bot, MinimumLogLevel = LogLevel.Debug });
|
public static DiscordClient discordClient = new DiscordClient(new DiscordConfiguration { Token = "DUMMY_TOKEN", TokenType = TokenType.Bot, MinimumLogLevel = LogLevel.Debug });
|
||||||
private static SlashCommandsExtension commands = null;
|
private static SlashCommandsExtension commands = null;
|
||||||
|
|
||||||
private static void Main()
|
private static void Main()
|
||||||
{
|
{
|
||||||
MainAsync().GetAwaiter().GetResult();
|
MainAsync().GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task MainAsync()
|
private static async Task MainAsync()
|
||||||
{
|
{
|
||||||
Logger.Log("Starting " + Assembly.GetEntryAssembly()?.GetName().Name + " version " + GetVersion() + "...");
|
Logger.Log("Starting " + Assembly.GetEntryAssembly()?.GetName().Name + " version " + GetVersion() + "...");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Reload();
|
Reload();
|
||||||
|
|
||||||
// Block this task until the program is closed.
|
// Block this task until the program is closed.
|
||||||
await Task.Delay(-1);
|
await Task.Delay(-1);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Fatal("Fatal error:\n" + e);
|
Logger.Fatal("Fatal error:\n" + e);
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetVersion()
|
public static string GetVersion()
|
||||||
{
|
{
|
||||||
Version version = Assembly.GetEntryAssembly()?.GetName().Version;
|
Version version = Assembly.GetEntryAssembly()?.GetName().Version;
|
||||||
return version?.Major + "." + version?.Minor + "." + version?.Build + (version?.Revision == 0 ? "" : "-" + (char)(64 + version?.Revision ?? 0));
|
return version?.Major + "." + version?.Minor + "." + version?.Build + (version?.Revision == 0 ? "" : "-" + (char)(64 + version?.Revision ?? 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async void Reload()
|
public static async void Reload()
|
||||||
{
|
{
|
||||||
if (discordClient != null)
|
if (discordClient != null)
|
||||||
{
|
{
|
||||||
await discordClient.DisconnectAsync();
|
await discordClient.DisconnectAsync();
|
||||||
discordClient.Dispose();
|
discordClient.Dispose();
|
||||||
Logger.Log("Discord client disconnected.");
|
Logger.Log("Discord client disconnected.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log("Loading config \"" + Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "config.yml\"");
|
Logger.Log("Loading config \"" + Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "config.yml\"");
|
||||||
Config.LoadConfig();
|
Config.LoadConfig();
|
||||||
|
|
||||||
// Check if token is unset
|
// Check if token is unset
|
||||||
if (Config.token is "<add-token-here>" or "")
|
if (Config.token is "<add-token-here>" or "")
|
||||||
{
|
{
|
||||||
Logger.Fatal("You need to set your bot token in the config and start the bot again.");
|
Logger.Fatal("You need to set your bot token in the config and start the bot again.");
|
||||||
throw new ArgumentException("Invalid Discord bot token");
|
throw new ArgumentException("Invalid Discord bot token");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Database connection and setup
|
// Database connection and setup
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Logger.Log("Connecting to database... (" + Config.hostName + ":" + Config.port + ")");
|
Logger.Log("Connecting to database... (" + Config.hostName + ":" + Config.port + ")");
|
||||||
Database.SetConnectionString(Config.hostName, Config.port, Config.database, Config.username, Config.password);
|
Database.SetConnectionString(Config.hostName, Config.port, Config.database, Config.username, Config.password);
|
||||||
Database.SetupTables();
|
Database.SetupTables();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Fatal("Could not set up database tables, please confirm connection settings, status of the server and permissions of MySQL user. Error: " + e);
|
Logger.Fatal("Could not set up database tables, please confirm connection settings, status of the server and permissions of MySQL user. Error: " + e);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log("Setting up Discord client...");
|
Logger.Log("Setting up Discord client...");
|
||||||
|
|
||||||
// Setting up client configuration
|
// Setting up client configuration
|
||||||
DiscordConfiguration cfg = new DiscordConfiguration
|
DiscordConfiguration cfg = new DiscordConfiguration
|
||||||
{
|
{
|
||||||
Token = Config.token,
|
Token = Config.token,
|
||||||
TokenType = TokenType.Bot,
|
TokenType = TokenType.Bot,
|
||||||
MinimumLogLevel = Config.logLevel,
|
MinimumLogLevel = Config.logLevel,
|
||||||
AutoReconnect = true,
|
AutoReconnect = true,
|
||||||
Intents = DiscordIntents.All
|
Intents = DiscordIntents.All
|
||||||
};
|
};
|
||||||
|
|
||||||
discordClient = new DiscordClient(cfg);
|
discordClient = new DiscordClient(cfg);
|
||||||
|
|
||||||
Logger.Log("Hooking events...");
|
Logger.Log("Hooking events...");
|
||||||
discordClient.Ready += EventHandler.OnReady;
|
discordClient.Ready += EventHandler.OnReady;
|
||||||
discordClient.GuildAvailable += EventHandler.OnGuildAvailable;
|
discordClient.GuildAvailable += EventHandler.OnGuildAvailable;
|
||||||
discordClient.ClientErrored += EventHandler.OnClientError;
|
discordClient.ClientErrored += EventHandler.OnClientError;
|
||||||
discordClient.MessageCreated += EventHandler.OnMessageCreated;
|
discordClient.MessageCreated += EventHandler.OnMessageCreated;
|
||||||
discordClient.GuildMemberAdded += EventHandler.OnMemberAdded;
|
discordClient.GuildMemberAdded += EventHandler.OnMemberAdded;
|
||||||
discordClient.GuildMemberRemoved += EventHandler.OnMemberRemoved;
|
discordClient.GuildMemberRemoved += EventHandler.OnMemberRemoved;
|
||||||
discordClient.ComponentInteractionCreated += EventHandler.OnComponentInteractionCreated;
|
discordClient.ComponentInteractionCreated += EventHandler.OnComponentInteractionCreated;
|
||||||
|
|
||||||
discordClient.UseInteractivity(new InteractivityConfiguration
|
discordClient.UseInteractivity(new InteractivityConfiguration
|
||||||
{
|
{
|
||||||
PaginationBehaviour = PaginationBehaviour.Ignore,
|
PaginationBehaviour = PaginationBehaviour.Ignore,
|
||||||
PaginationDeletion = PaginationDeletion.DeleteMessage,
|
PaginationDeletion = PaginationDeletion.DeleteMessage,
|
||||||
Timeout = TimeSpan.FromMinutes(15)
|
Timeout = TimeSpan.FromMinutes(15)
|
||||||
});
|
});
|
||||||
|
|
||||||
Logger.Log("Registering commands...");
|
Logger.Log("Registering commands...");
|
||||||
commands = discordClient.UseSlashCommands();
|
commands = discordClient.UseSlashCommands();
|
||||||
|
|
||||||
commands.RegisterCommands<AddCategoryCommand>();
|
commands.RegisterCommands<AddCategoryCommand>();
|
||||||
commands.RegisterCommands<AddCommand>();
|
commands.RegisterCommands<AddCommand>();
|
||||||
commands.RegisterCommands<AddMessageCommand>();
|
commands.RegisterCommands<AddMessageCommand>();
|
||||||
commands.RegisterCommands<AddStaffCommand>();
|
commands.RegisterCommands<AddStaffCommand>();
|
||||||
commands.RegisterCommands<AssignCommand>();
|
commands.RegisterCommands<AssignCommand>();
|
||||||
commands.RegisterCommands<BlacklistCommand>();
|
commands.RegisterCommands<BlacklistCommand>();
|
||||||
commands.RegisterCommands<CloseCommand>();
|
commands.RegisterCommands<CloseCommand>();
|
||||||
commands.RegisterCommands<CreateButtonPanelCommand>();
|
commands.RegisterCommands<CreateButtonPanelCommand>();
|
||||||
commands.RegisterCommands<CreateSelectionBoxPanelCommand>();
|
commands.RegisterCommands<CreateSelectionBoxPanelCommand>();
|
||||||
commands.RegisterCommands<ListAssignedCommand>();
|
commands.RegisterCommands<ListAssignedCommand>();
|
||||||
commands.RegisterCommands<ListCommand>();
|
commands.RegisterCommands<ListCommand>();
|
||||||
commands.RegisterCommands<ListOpen>();
|
commands.RegisterCommands<ListOpen>();
|
||||||
commands.RegisterCommands<ListUnassignedCommand>();
|
commands.RegisterCommands<ListUnassignedCommand>();
|
||||||
commands.RegisterCommands<MoveCommand>();
|
commands.RegisterCommands<MoveCommand>();
|
||||||
commands.RegisterCommands<NewCommand>();
|
commands.RegisterCommands<NewCommand>();
|
||||||
commands.RegisterCommands<RandomAssignCommand>();
|
commands.RegisterCommands<RandomAssignCommand>();
|
||||||
commands.RegisterCommands<RemoveCategoryCommand>();
|
commands.RegisterCommands<RemoveCategoryCommand>();
|
||||||
commands.RegisterCommands<RemoveMessageCommand>();
|
commands.RegisterCommands<RemoveMessageCommand>();
|
||||||
commands.RegisterCommands<RemoveStaffCommand>();
|
commands.RegisterCommands<RemoveStaffCommand>();
|
||||||
commands.RegisterCommands<SayCommand>();
|
commands.RegisterCommands<SayCommand>();
|
||||||
commands.RegisterCommands<SetSummaryCommand>();
|
commands.RegisterCommands<SetSummaryCommand>();
|
||||||
commands.RegisterCommands<StatusCommand>();
|
commands.RegisterCommands<StatusCommand>();
|
||||||
commands.RegisterCommands<SummaryCommand>();
|
commands.RegisterCommands<SummaryCommand>();
|
||||||
commands.RegisterCommands<ToggleActiveCommand>();
|
commands.RegisterCommands<ToggleActiveCommand>();
|
||||||
commands.RegisterCommands<TranscriptCommand>();
|
commands.RegisterCommands<TranscriptCommand>();
|
||||||
commands.RegisterCommands<UnassignCommand>();
|
commands.RegisterCommands<UnassignCommand>();
|
||||||
commands.RegisterCommands<UnblacklistCommand>();
|
commands.RegisterCommands<UnblacklistCommand>();
|
||||||
commands.RegisterCommands<AdminCommands>();
|
commands.RegisterCommands<AdminCommands>();
|
||||||
|
|
||||||
Logger.Log("Hooking command events...");
|
Logger.Log("Hooking command events...");
|
||||||
commands.SlashCommandErrored += EventHandler.OnCommandError;
|
commands.SlashCommandErrored += EventHandler.OnCommandError;
|
||||||
|
|
||||||
Logger.Log("Connecting to Discord...");
|
Logger.Log("Connecting to Discord...");
|
||||||
await discordClient.ConnectAsync();
|
await discordClient.ConnectAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,43 +11,43 @@ namespace SupportChild;
|
||||||
|
|
||||||
internal static class Transcriber
|
internal static class Transcriber
|
||||||
{
|
{
|
||||||
internal static async Task ExecuteAsync(ulong channelID, uint ticketID)
|
internal static async Task ExecuteAsync(ulong channelID, uint ticketID)
|
||||||
{
|
{
|
||||||
DiscordClient discordClient = new DiscordClient(Config.token);
|
DiscordClient discordClient = new DiscordClient(Config.token);
|
||||||
ChannelExporter exporter = new ChannelExporter(discordClient);
|
ChannelExporter exporter = new ChannelExporter(discordClient);
|
||||||
|
|
||||||
if (!Directory.Exists("./transcripts"))
|
if (!Directory.Exists("./transcripts"))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory("./transcripts");
|
Directory.CreateDirectory("./transcripts");
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel channel = await discordClient.GetChannelAsync(new Snowflake(channelID));
|
Channel channel = await discordClient.GetChannelAsync(new Snowflake(channelID));
|
||||||
Guild guild = await discordClient.GetGuildAsync(channel.GuildId);
|
Guild guild = await discordClient.GetGuildAsync(channel.GuildId);
|
||||||
|
|
||||||
ExportRequest request = new ExportRequest(
|
ExportRequest request = new ExportRequest(
|
||||||
Guild: guild,
|
Guild: guild,
|
||||||
Channel: channel,
|
Channel: channel,
|
||||||
OutputPath: GetPath(ticketID),
|
OutputPath: GetPath(ticketID),
|
||||||
Format: ExportFormat.HtmlDark,
|
Format: ExportFormat.HtmlDark,
|
||||||
After: null,
|
After: null,
|
||||||
Before: null,
|
Before: null,
|
||||||
PartitionLimit: PartitionLimit.Null,
|
PartitionLimit: PartitionLimit.Null,
|
||||||
MessageFilter: MessageFilter.Null,
|
MessageFilter: MessageFilter.Null,
|
||||||
ShouldDownloadMedia: false,
|
ShouldDownloadMedia: false,
|
||||||
ShouldReuseMedia: false,
|
ShouldReuseMedia: false,
|
||||||
DateFormat: "yyyy-MMM-dd HH:mm"
|
DateFormat: "yyyy-MMM-dd HH:mm"
|
||||||
);
|
);
|
||||||
|
|
||||||
await exporter.ExportChannelAsync(request);
|
await exporter.ExportChannelAsync(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string GetPath(uint ticketNumber)
|
internal static string GetPath(uint ticketNumber)
|
||||||
{
|
{
|
||||||
return "./transcripts/" + GetFilename(ticketNumber);
|
return "./transcripts/" + GetFilename(ticketNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string GetFilename(uint ticketNumber)
|
internal static string GetFilename(uint ticketNumber)
|
||||||
{
|
{
|
||||||
return "ticket-" + ticketNumber.ToString("00000") + ".html";
|
return "ticket-" + ticketNumber.ToString("00000") + ".html";
|
||||||
}
|
}
|
||||||
}
|
}
|
98
Utilities.cs
98
Utilities.cs
|
@ -7,59 +7,59 @@ namespace SupportChild;
|
||||||
|
|
||||||
public static class Utilities
|
public static class Utilities
|
||||||
{
|
{
|
||||||
private static readonly Random rng = new Random();
|
private static readonly Random rng = new Random();
|
||||||
|
|
||||||
public static void Shuffle<T>(this IList<T> list)
|
public static void Shuffle<T>(this IList<T> list)
|
||||||
{
|
{
|
||||||
int n = list.Count;
|
int n = list.Count;
|
||||||
while (n > 1)
|
while (n > 1)
|
||||||
{
|
{
|
||||||
n--;
|
n--;
|
||||||
int k = rng.Next(n + 1);
|
int k = rng.Next(n + 1);
|
||||||
(list[k], list[n]) = (list[n], list[k]);
|
(list[k], list[n]) = (list[n], list[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LinkedList<string> ParseListIntoMessages(List<string> listItems)
|
public static LinkedList<string> ParseListIntoMessages(List<string> listItems)
|
||||||
{
|
{
|
||||||
LinkedList<string> messages = new LinkedList<string>();
|
LinkedList<string> messages = new LinkedList<string>();
|
||||||
|
|
||||||
foreach (string listItem in listItems)
|
foreach (string listItem in listItems)
|
||||||
{
|
{
|
||||||
if (messages.Last?.Value?.Length + listItem?.Length < 2048)
|
if (messages.Last?.Value?.Length + listItem?.Length < 2048)
|
||||||
{
|
{
|
||||||
messages.Last.Value += listItem;
|
messages.Last.Value += listItem;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
messages.AddLast(listItem);
|
messages.AddLast(listItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<List<Database.Category>> GetVerifiedChannels()
|
public static async Task<List<Database.Category>> GetVerifiedChannels()
|
||||||
{
|
{
|
||||||
List<Database.Category> verifiedCategories = new List<Database.Category>();
|
List<Database.Category> verifiedCategories = new List<Database.Category>();
|
||||||
foreach (Database.Category category in Database.GetAllCategories())
|
foreach (Database.Category category in Database.GetAllCategories())
|
||||||
{
|
{
|
||||||
DiscordChannel channel = null;
|
DiscordChannel channel = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
channel = await SupportChild.discordClient.GetChannelAsync(category.id);
|
channel = await SupportChild.discordClient.GetChannelAsync(category.id);
|
||||||
}
|
}
|
||||||
catch (Exception) { /*ignored*/ }
|
catch (Exception) { /*ignored*/ }
|
||||||
|
|
||||||
if (channel != null)
|
if (channel != null)
|
||||||
{
|
{
|
||||||
verifiedCategories.Add(category);
|
verifiedCategories.Add(category);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger.Warn("Category '" + category.name + "' (" + category.id + ") no longer exists! Ignoring...");
|
Logger.Warn("Category '" + category.name + "' (" + category.id + ") no longer exists! Ignoring...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return verifiedCategories;
|
return verifiedCategories;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue