Updated commands
This commit is contained in:
parent
0e5a93a6a6
commit
94df384934
32 changed files with 1926 additions and 2059 deletions
71
SupportChild/Commands/AddCategoryCommand.cs
Normal file
71
SupportChild/Commands/AddCategoryCommand.cs
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DSharpPlus.Entities;
|
||||||
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class AddCategoryCommand : ApplicationCommandModule
|
||||||
|
{
|
||||||
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
|
{
|
||||||
|
if (!category.IsCategory)
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "That channel is not a category."
|
||||||
|
}, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(title))
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "Invalid category title specified."
|
||||||
|
}, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Database.TryGetCategory(category.Id, out Database.Category _))
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "That category is already registered."
|
||||||
|
}, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Database.TryGetCategory(title, out Database.Category _))
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "There is already a category with that title."
|
||||||
|
}, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Database.AddCategory(title, category.Id))
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = "Category added."
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "Error: Failed adding the category to the database."
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,107 +1,82 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus;
|
using DSharpPlus;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class AddCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class AddCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("add", "Adds a user to a ticket")]
|
||||||
|
public async Task OnExecute(InteractionContext command, [Option("User", "User to add to ticket.")] DiscordUser user)
|
||||||
{
|
{
|
||||||
[Command("add")]
|
|
||||||
[Description("Adds a user to a ticket.")]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "add"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the add command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] parsedArgs = Utilities.ParseIDs(command.RawArgumentString);
|
DiscordMember member;
|
||||||
foreach (string parsedArg in parsedArgs)
|
|
||||||
{
|
|
||||||
if (!ulong.TryParse(parsedArg, out ulong userID))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Invalid ID/Mention. (Could not convert to numerical)"
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscordMember mentionedMember;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mentionedMember = await command.Guild.GetMemberAsync(userID);
|
member = (user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id));
|
||||||
|
|
||||||
|
if (member == null)
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "Could not find that user in this server."
|
||||||
|
}, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Invalid ID/Mention. (Could not find user on this server)"
|
Description = "Could not find that user in this server."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(error);
|
return;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await command.Channel.AddOverwriteAsync(mentionedMember, Permissions.AccessChannels, Permissions.None);
|
await command.Channel.AddOverwriteAsync(member, Permissions.AccessChannels);
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Added " + mentionedMember.Mention + " to ticket."
|
Description = "Added " + member.Mention + " to ticket."
|
||||||
};
|
});
|
||||||
await command.RespondAsync(message);
|
|
||||||
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = mentionedMember.Mention + " was added to " + command.Channel.Mention +
|
Description = member.Mention + " was added to " + command.Channel.Mention +
|
||||||
" by " + command.Member.Mention + "."
|
" by " + command.Member.Mention + "."
|
||||||
};
|
});
|
||||||
await logChannel.SendMessageAsync(logMessage);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Could not add <@" + parsedArg + "> to ticket, unknown error occured."
|
Description = "Could not add " + member.Mention + " to ticket, unknown error occured."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,76 +1,53 @@
|
||||||
using DSharpPlus.CommandsNext;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class AddMessageCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class AddMessageCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("addmessage", "Adds a new message for the 'say' command.")]
|
||||||
|
public async Task OnExecute(InteractionContext command,
|
||||||
|
[Option("Identifier", "The identifier word used in the /say command.")] string identifier,
|
||||||
|
[Option("Message", "The message the /say command will return.")] string message)
|
||||||
{
|
{
|
||||||
[Command("addmessage")]
|
|
||||||
[Description("Adds a new message for the 'say' command.")]
|
|
||||||
public async Task OnExecute(CommandContext command, string identifier, [RemainingText] string message)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "addmessage"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the addmessage command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(message))
|
if (string.IsNullOrEmpty(message))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "No message specified."
|
Description = "No message specified."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Database.TryGetMessage(identifier.ToLower(), out Database.Message _))
|
if (Database.TryGetMessage(identifier.ToLower(), out Database.Message _))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Database.AddMessage(identifier, command.Member.Id, message))
|
if (Database.AddMessage(identifier, command.Member.Id, message))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Message added."
|
Description = "Message added."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,96 +1,67 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
using MySql.Data.MySqlClient;
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class AddStaffCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class AddStaffCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("addstaff", "Adds a new staff member.")]
|
||||||
|
public async Task OnExecute(InteractionContext command, [Option("User", "User to add to staff.")] DiscordUser user)
|
||||||
{
|
{
|
||||||
[Command("addstaff")]
|
DiscordMember staffMember = null;
|
||||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "addstaff"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the addstaff command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ulong userID;
|
|
||||||
string[] parsedArgs = Utilities.ParseIDs(commandArgs);
|
|
||||||
|
|
||||||
if (!parsedArgs.Any())
|
|
||||||
{
|
|
||||||
userID = command.Member.Id;
|
|
||||||
}
|
|
||||||
else if (!ulong.TryParse(parsedArgs[0], out userID))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Invalid ID/Mention. (Could not convert to numerical)"
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscordMember member;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
member = await command.Guild.GetMemberAsync(userID);
|
staffMember = user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id);
|
||||||
|
|
||||||
|
if (staffMember == null)
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "Could not find that user in this server."
|
||||||
|
}, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Invalid ID/Mention. (Could not find user on this server)"
|
Description = "Could not find that user in this server."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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(userID) ? 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", userID);
|
cmd.Parameters.AddWithValue("@user_id", staffMember.Id);
|
||||||
cmd.Parameters.AddWithValue("@name", member.DisplayName);
|
cmd.Parameters.AddWithValue("@name", staffMember.DisplayName);
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
cmd.Dispose();
|
cmd.Dispose();
|
||||||
|
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = member.Mention + " was added to staff."
|
Description = staffMember.Mention + " was added to staff."
|
||||||
};
|
});
|
||||||
await command.RespondAsync(message);
|
|
||||||
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = member.Mention + " was added to staff.\n",
|
Description = staffMember.Mention + " was added to staff.\n"
|
||||||
};
|
});
|
||||||
await logChannel.SendMessageAsync(logMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
200
SupportChild/Commands/AdminCommands.cs
Normal file
200
SupportChild/Commands/AdminCommands.cs
Normal file
|
@ -0,0 +1,200 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DSharpPlus.Entities;
|
||||||
|
using DSharpPlus.Interactivity;
|
||||||
|
using DSharpPlus.Interactivity.Extensions;
|
||||||
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
[SlashCommandGroup("admin", "Administrative commands.")]
|
||||||
|
public class AdminCommands : ApplicationCommandModule
|
||||||
|
{
|
||||||
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("listinvalid", "List tickets which channels have been deleted. Use /admin unsetticket <id> to remove them.")]
|
||||||
|
public async Task ListInvalid(InteractionContext command)
|
||||||
|
{
|
||||||
|
if (!Database.TryGetOpenTickets(out List<Database.Ticket> openTickets))
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "Could not get any open tickets from database."
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all channels in all guilds the bot is part of
|
||||||
|
List<DiscordChannel> allChannels = new List<DiscordChannel>();
|
||||||
|
foreach (KeyValuePair<ulong, DiscordGuild> guild in SupportChild.discordClient.Guilds)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
allChannels.AddRange(await guild.Value.GetChannelsAsync());
|
||||||
|
}
|
||||||
|
catch (Exception) { /*ignored*/ }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check which tickets channels no longer exist
|
||||||
|
List<string> listItems = new List<string>();
|
||||||
|
foreach (Database.Ticket ticket in openTickets)
|
||||||
|
{
|
||||||
|
if (allChannels.All(channel => channel.Id != ticket.channelID))
|
||||||
|
{
|
||||||
|
listItems.Add("ID: **" + ticket.id.ToString("00000") + ":** <#" + ticket.channelID + ">\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listItems.Count == 0)
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = "All tickets are valid!"
|
||||||
|
}, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||||
|
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||||
|
{
|
||||||
|
embeds.Add(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Title = "Invalid tickets:",
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the footers
|
||||||
|
for (int i = 0; i < embeds.Count; i++)
|
||||||
|
{
|
||||||
|
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||||
|
{
|
||||||
|
Text = $"Page {i + 1} / {embeds.Count}"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Page> listPages = new List<Page>();
|
||||||
|
foreach (DiscordEmbedBuilder embed in embeds)
|
||||||
|
{
|
||||||
|
listPages.Add(new Page("", embed));
|
||||||
|
}
|
||||||
|
|
||||||
|
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||||
|
}
|
||||||
|
|
||||||
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
|
{
|
||||||
|
// Check if ticket exists in the database
|
||||||
|
if (Database.IsOpenTicket(command.Channel.Id))
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "This channel is already a ticket."
|
||||||
|
}, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DiscordUser ticketUser = (user == null ? command.User : user);
|
||||||
|
|
||||||
|
long id = Database.NewTicket(ticketUser.Id, 0, command.Channel.Id);
|
||||||
|
string ticketID = id.ToString("00000");
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = "Channel has been designated ticket " + ticketID + "."
|
||||||
|
});
|
||||||
|
|
||||||
|
// Log it if the log channel exists
|
||||||
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||||
|
if (logChannel != null)
|
||||||
|
{
|
||||||
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = command.Channel.Mention + " has been designated ticket " + ticketID + " by " + command.Member.Mention + "."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
|
{
|
||||||
|
Database.Ticket ticket;
|
||||||
|
|
||||||
|
if (ticketID == 0)
|
||||||
|
{
|
||||||
|
// Check if ticket exists in the database
|
||||||
|
if (!Database.TryGetOpenTicket(command.Channel.Id, out ticket))
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "This channel is not a ticket!"
|
||||||
|
}, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Check if ticket exists in the database
|
||||||
|
if (!Database.TryGetOpenTicketByID((uint)ticketID, out ticket))
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "There is no ticket with this ticket ID."
|
||||||
|
}, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (Database.DeleteOpenTicket(ticket.id))
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = "Channel has been undesignated as a ticket."
|
||||||
|
});
|
||||||
|
|
||||||
|
// Log it if the log channel exists
|
||||||
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||||
|
if (logChannel != null)
|
||||||
|
{
|
||||||
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = command.Channel.Mention + " has been undesignated as a ticket by " + command.Member.Mention + "."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "Error: Failed removing ticket from database."
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[SlashCommand("reload", "Reloads the bot config.")]
|
||||||
|
public async Task Reload(InteractionContext command)
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = "Reloading bot application..."
|
||||||
|
});
|
||||||
|
Logger.Log("Reloading bot...");
|
||||||
|
SupportChild.Reload();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,135 +1,102 @@
|
||||||
using System.Linq;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.Exceptions;
|
using DSharpPlus.Exceptions;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class AssignCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class AssignCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
{
|
{
|
||||||
[Command("assign")]
|
DiscordMember member = null;
|
||||||
[Description("Assigns a staff member to a ticket.")]
|
try
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
{
|
||||||
// Check if the user has permission to use this command.
|
member = user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id);
|
||||||
if (!Config.HasPermission(command.Member, "assign"))
|
|
||||||
|
if (member == null)
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "You do not have permission to use this command."
|
Description = "Could not find that user in this server."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(error);
|
return;
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the assign command but did not have permission.");
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "Could not find that user in this server."
|
||||||
|
}, 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))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong staffID;
|
if (!Database.IsStaff(member.Id))
|
||||||
string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);
|
|
||||||
|
|
||||||
if (!parsedMessage.Any())
|
|
||||||
{
|
{
|
||||||
staffID = command.Member.Id;
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
}
|
|
||||||
else if (!ulong.TryParse(parsedMessage[0], out staffID))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Invalid ID/Mention. (Could not convert to numerical)"
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscordMember staffMember = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
staffMember = await command.Guild.GetMemberAsync(staffID);
|
|
||||||
}
|
|
||||||
catch (NotFoundException) { }
|
|
||||||
|
|
||||||
if (staffMember == null)
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Error: Could not find user."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Database.IsStaff(staffMember.Id))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Database.AssignStaff(ticket, staffID))
|
if (!Database.AssignStaff(ticket, member.Id))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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 " + member.Mention + " to ticket."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordEmbed feedback = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Assigned " + staffMember.Mention + " to ticket."
|
Description = "Assigned " + member.Mention + " to ticket."
|
||||||
};
|
});
|
||||||
await command.RespondAsync(feedback);
|
|
||||||
|
|
||||||
if (Config.assignmentNotifications)
|
if (Config.assignmentNotifications)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DiscordEmbed message = 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
|
||||||
};
|
});
|
||||||
await staffMember.SendMessageAsync(message);
|
|
||||||
}
|
}
|
||||||
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)
|
||||||
{
|
{
|
||||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = staffMember.Mention + " was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
Description = member.Mention + " was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
||||||
};
|
});
|
||||||
await logChannel.SendMessageAsync(logMessage);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,99 +1,54 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.Exceptions;
|
using DSharpPlus.SlashCommands;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class BlacklistCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class BlacklistCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("blacklist", "Blacklists a user from opening tickets.")]
|
||||||
|
public async Task OnExecute(InteractionContext command, [Option("User", "User to blacklist.")] DiscordUser user)
|
||||||
{
|
{
|
||||||
[Command("blacklist")]
|
try
|
||||||
[Description("Blacklists a user from opening tickets.")]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
{
|
||||||
// Check if the user has permission to use this command.
|
if (!Database.Blacklist(user.Id, command.User.Id))
|
||||||
if (!Config.HasPermission(command.Member, "blacklist"))
|
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "You do not have permission to use this command."
|
Description = user.Mention + " is already blacklisted."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the blacklist command but did not have permission.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] parsedArgs = Utilities.ParseIDs(command.RawArgumentString);
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
foreach (string parsedArg in parsedArgs)
|
|
||||||
{
|
|
||||||
if (ulong.TryParse(parsedArg, out ulong userId))
|
|
||||||
{
|
|
||||||
DiscordUser blacklistedUser = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
blacklistedUser = await command.Client.GetUserAsync(userId);
|
|
||||||
}
|
|
||||||
catch (NotFoundException) { }
|
|
||||||
|
|
||||||
if (blacklistedUser == null)
|
|
||||||
{
|
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Error: Could not find user."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(message);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!Database.Blacklist(blacklistedUser.Id, command.User.Id))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = blacklistedUser.Mention + " is already blacklisted."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Blacklisted " + blacklistedUser.Mention + "."
|
Description = "Blacklisted " + user.Mention + "."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(message);
|
|
||||||
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = blacklistedUser.Mention + " was blacklisted from opening tickets by " + command.Member.Mention + "."
|
Description = user.Mention + " was blacklisted from opening tickets by " + command.Member.Mention + "."
|
||||||
};
|
});
|
||||||
await logChannel.SendMessageAsync(logMessage);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error occured while blacklisting " + blacklistedUser.Mention + "."
|
Description = "Error occured while blacklisting " + user.Mention + "."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(message);
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -2,84 +2,94 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
using DSharpPlus;
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.Exceptions;
|
using DSharpPlus.Exceptions;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class CloseCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class CloseCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("close", "Closes a ticket.")]
|
||||||
|
public async Task OnExecute(InteractionContext command)
|
||||||
{
|
{
|
||||||
[Command("close")]
|
// Check if ticket exists in the database
|
||||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket _))
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
{
|
||||||
// Check if the user has permission to use this command.
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
if (!Config.HasPermission(command.Member, "close"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "You do not have permission to use this command."
|
Description = "This channel is not a ticket."
|
||||||
};
|
});
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the close command but did not have permission.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong channelID = command.Channel.Id;
|
DiscordInteractionResponseBuilder confirmation = new DiscordInteractionResponseBuilder()
|
||||||
string channelName = command.Channel.Name;
|
.AddEmbed(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Cyan,
|
||||||
|
Description = "Are you sure you wish to close this ticket? You cannot re-open it again later."
|
||||||
|
})
|
||||||
|
.AddComponents(new DiscordButtonComponent(ButtonStyle.Danger, "supportboi_closeconfirm", "Confirm"));
|
||||||
|
|
||||||
|
|
||||||
|
await command.CreateResponseAsync(confirmation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task OnConfirmed(DiscordInteraction interaction)
|
||||||
|
{
|
||||||
|
await interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate);
|
||||||
|
ulong channelID = interaction.Channel.Id;
|
||||||
|
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))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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."
|
||||||
};
|
}));
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build transcript
|
// Build transcript
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Transcriber.ExecuteAsync(command.Channel.Id, ticket.id);
|
await Transcriber.ExecuteAsync(interaction.Channel.Id, ticket.id);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
Logger.Error("Exception occured when trying to save transcript while closing ticket: " + e);
|
||||||
|
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..."
|
||||||
};
|
}));
|
||||||
await command.RespondAsync(error);
|
return;
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = command.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 " + command.Member.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 }
|
||||||
};
|
};
|
||||||
|
|
||||||
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.WithFiles(new Dictionary<string, Stream>() { { Transcriber.GetFilename(ticket.id), file } });
|
message.WithFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||||
|
|
||||||
await logChannel.SendMessageAsync(message);
|
await logChannel.SendMessageAsync(message);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (Config.closingNotifications)
|
if (Config.closingNotifications)
|
||||||
{
|
{
|
||||||
|
@ -92,27 +102,33 @@ namespace SupportChild.Commands
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DiscordMember staffMember = await command.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);
|
||||||
|
|
||||||
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.WithFiles(new Dictionary<string, Stream>() { { Transcriber.GetFilename(ticket.id), file } });
|
message.WithFiles(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
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = "Channel will be deleted in 3 seconds..."
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
await Task.Delay(3000);
|
||||||
|
|
||||||
// Delete the channel and database entry
|
// Delete the channel and database entry
|
||||||
await command.Channel.DeleteAsync("Ticket closed.");
|
await interaction.Channel.DeleteAsync("Ticket closed.");
|
||||||
|
|
||||||
Database.DeleteOpenTicket(ticket.id);
|
Database.DeleteOpenTicket(ticket.id);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
81
SupportChild/Commands/CreateButtonPanelCommand.cs
Normal file
81
SupportChild/Commands/CreateButtonPanelCommand.cs
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DSharpPlus;
|
||||||
|
using DSharpPlus.Entities;
|
||||||
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class CreateButtonPanelCommand : ApplicationCommandModule
|
||||||
|
{
|
||||||
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("createbuttonpanel", "Creates a series of buttons which users can use to open new tickets in specific categories.")]
|
||||||
|
public async Task OnExecute(InteractionContext command)
|
||||||
|
{
|
||||||
|
DiscordMessageBuilder builder = new DiscordMessageBuilder().WithContent(" ");
|
||||||
|
List<Database.Category> verifiedCategories = await Utilities.GetVerifiedChannels();
|
||||||
|
|
||||||
|
if (verifiedCategories.Count == 0)
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "Error: No registered categories found."
|
||||||
|
}, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList();
|
||||||
|
|
||||||
|
int nrOfButtons = 0;
|
||||||
|
for (int nrOfButtonRows = 0; nrOfButtonRows < 5 && nrOfButtons < verifiedCategories.Count; nrOfButtonRows++)
|
||||||
|
{
|
||||||
|
List<DiscordButtonComponent> buttonRow = new List<DiscordButtonComponent>();
|
||||||
|
|
||||||
|
for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < verifiedCategories.Count; nrOfButtons++)
|
||||||
|
{
|
||||||
|
buttonRow.Add(new DiscordButtonComponent(ButtonStyle.Primary, "supportboi_newticketbutton " + verifiedCategories[nrOfButtons].id, verifiedCategories[nrOfButtons].name));
|
||||||
|
}
|
||||||
|
builder.AddComponents(buttonRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
await command.Channel.SendMessageAsync(builder);
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = "Successfully created message, make sure to run this command again if you add new categories to the bot."
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task OnButtonUsed(DiscordInteraction interaction)
|
||||||
|
{
|
||||||
|
await interaction.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral());
|
||||||
|
|
||||||
|
if (!ulong.TryParse(interaction.Data.CustomId.Replace("supportboi_newticketbutton ", ""), out ulong categoryID) || categoryID == 0)
|
||||||
|
{
|
||||||
|
Logger.Warn("Invalid ID: " + interaction.Data.CustomId.Replace("supportboi_newticketbutton ", ""));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
(bool success, string message) = await NewCommand.OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = message
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = message
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
79
SupportChild/Commands/CreateSelectionBoxPanelCommand.cs
Normal file
79
SupportChild/Commands/CreateSelectionBoxPanelCommand.cs
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DSharpPlus;
|
||||||
|
using DSharpPlus.Entities;
|
||||||
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class CreateSelectionBoxPanelCommand : ApplicationCommandModule
|
||||||
|
{
|
||||||
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
|
{
|
||||||
|
DiscordMessageBuilder builder = new DiscordMessageBuilder()
|
||||||
|
.WithContent(" ")
|
||||||
|
.AddComponents(await GetSelectComponents(command, message ?? "Open new ticket..."));
|
||||||
|
|
||||||
|
await command.Channel.SendMessageAsync(builder);
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = "Successfully created message, make sure to run this command again if you add new categories to the bot."
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<List<DiscordSelectComponent>> GetSelectComponents(InteractionContext command, string placeholder)
|
||||||
|
{
|
||||||
|
List<Database.Category> verifiedCategories = await Utilities.GetVerifiedChannels();
|
||||||
|
|
||||||
|
if (verifiedCategories.Count == 0) return new List<DiscordSelectComponent>();
|
||||||
|
|
||||||
|
verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList();
|
||||||
|
List<DiscordSelectComponent> selectionComponents = new List<DiscordSelectComponent>();
|
||||||
|
int selectionOptions = 0;
|
||||||
|
for (int selectionBoxes = 0; selectionBoxes < 5 && selectionOptions < verifiedCategories.Count; selectionBoxes++)
|
||||||
|
{
|
||||||
|
List<DiscordSelectComponentOption> categoryOptions = new List<DiscordSelectComponentOption>();
|
||||||
|
|
||||||
|
for (; selectionOptions < 25 * (selectionBoxes + 1) && selectionOptions < verifiedCategories.Count; selectionOptions++)
|
||||||
|
{
|
||||||
|
categoryOptions.Add(new DiscordSelectComponentOption(verifiedCategories[selectionOptions].name, verifiedCategories[selectionOptions].id.ToString()));
|
||||||
|
}
|
||||||
|
selectionComponents.Add(new DiscordSelectComponent("supportboi_newticketselector" + selectionBoxes, placeholder, categoryOptions, false, 0, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectionComponents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task OnSelectionMenuUsed(DiscordInteraction interaction)
|
||||||
|
{
|
||||||
|
if (interaction.Data.Values == null || interaction.Data.Values.Length <= 0) return;
|
||||||
|
|
||||||
|
if (!ulong.TryParse(interaction.Data.Values[0], out ulong categoryID) || categoryID == 0) return;
|
||||||
|
|
||||||
|
await interaction.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral());
|
||||||
|
|
||||||
|
(bool success, string message) = await NewCommand.OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = message
|
||||||
|
}).AsEphemeral());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = message
|
||||||
|
}).AsEphemeral());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,76 +1,63 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.Interactivity;
|
||||||
|
using DSharpPlus.Interactivity.Extensions;
|
||||||
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class ListAssignedCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class ListAssignedCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
{
|
{
|
||||||
[Command("listassigned")]
|
DiscordUser listUser = user == null ? command.User : user;
|
||||||
[Aliases("la")]
|
|
||||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
if (!Database.TryGetAssignedTickets(listUser.Id, out List<Database.Ticket> assignedTickets))
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
{
|
||||||
// Check if the user has permission to use this command.
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
if (!Config.HasPermission(command.Member, "listassigned"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "You do not have permission to use this command."
|
Description = "User does not have any assigned tickets."
|
||||||
};
|
});
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the listassigned command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ulong staffID;
|
|
||||||
string[] parsedIDs = Utilities.ParseIDs(command.RawArgumentString);
|
|
||||||
|
|
||||||
if (!parsedIDs.Any())
|
|
||||||
{
|
|
||||||
staffID = command.Member.Id;
|
|
||||||
}
|
|
||||||
else if (!ulong.TryParse(parsedIDs[0], out staffID))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Invalid ID/Mention. (Could not convert to numerical)"
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Database.TryGetAssignedTickets(staffID, out List<Database.Ticket> assignedTickets))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder()
|
|
||||||
.WithColor(DiscordColor.Red)
|
|
||||||
.WithDescription("User does not have any assigned tickets.");
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
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.FormattedCreatedTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
|
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||||
foreach (string message in messages)
|
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||||
{
|
{
|
||||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
embeds.Add(new DiscordEmbedBuilder
|
||||||
.WithTitle("Assigned tickets: ")
|
{
|
||||||
.WithColor(DiscordColor.Green)
|
Title = "Assigned tickets: ",
|
||||||
.WithDescription(message);
|
Color = DiscordColor.Green,
|
||||||
await command.RespondAsync(channelInfo);
|
Description = message
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the footers
|
||||||
|
for (int i = 0; i < embeds.Count; i++)
|
||||||
|
{
|
||||||
|
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||||
|
{
|
||||||
|
Text = $"Page {i + 1} / {embeds.Count}"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Page> listPages = new List<Page>();
|
||||||
|
foreach (DiscordEmbedBuilder embed in embeds)
|
||||||
|
{
|
||||||
|
listPages.Add(new Page("", embed));
|
||||||
|
}
|
||||||
|
|
||||||
|
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,101 +1,99 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.Interactivity;
|
||||||
|
using DSharpPlus.Interactivity.Extensions;
|
||||||
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class ListCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class ListCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
{
|
{
|
||||||
[Command("list")]
|
DiscordUser listUser = user == null ? command.User : user;
|
||||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "list"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the list command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ulong userID;
|
List<DiscordEmbedBuilder> openEmbeds = new List<DiscordEmbedBuilder>();
|
||||||
string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);
|
if (Database.TryGetOpenTickets(listUser.Id, out List<Database.Ticket> openTickets))
|
||||||
|
|
||||||
if (!parsedMessage.Any())
|
|
||||||
{
|
|
||||||
userID = command.Member.Id;
|
|
||||||
}
|
|
||||||
else if (!ulong.TryParse(parsedMessage[0], out userID))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Invalid ID/Mention. (Could not convert to numerical)"
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Database.TryGetOpenTickets(userID, 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.FormattedCreatedTime() + ":** <#" + ticket.channelID + ">\n");
|
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + ">\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
|
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||||
foreach (string message in messages)
|
|
||||||
{
|
{
|
||||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
openEmbeds.Add(new DiscordEmbedBuilder
|
||||||
.WithTitle("Open tickets: ")
|
|
||||||
.WithColor(DiscordColor.Green)
|
|
||||||
.WithDescription(message);
|
|
||||||
await command.RespondAsync(channelInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
Color = DiscordColor.Green,
|
||||||
.WithColor(DiscordColor.Green)
|
Description = message
|
||||||
.WithDescription("User does not have any open tickets.");
|
});
|
||||||
await command.RespondAsync(channelInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Database.TryGetClosedTickets(userID, out List<Database.Ticket> closedTickets))
|
// Add the titles
|
||||||
|
for (int i = 0; i < openEmbeds.Count; i++)
|
||||||
|
{
|
||||||
|
openEmbeds[i].Title = $"Open tickets ({i + 1}/{openEmbeds.Count})";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<DiscordEmbedBuilder> closedEmbeds = new List<DiscordEmbedBuilder>();
|
||||||
|
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.FormattedCreatedTime() + ":** Ticket " + ticket.id.ToString("00000") + "\n");
|
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** Ticket " + ticket.id.ToString("00000") + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
|
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||||
foreach (string message in messages)
|
|
||||||
{
|
{
|
||||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
closedEmbeds.Add(new DiscordEmbedBuilder
|
||||||
.WithTitle("Closed tickets: ")
|
|
||||||
.WithColor(DiscordColor.Red)
|
|
||||||
.WithDescription(message);
|
|
||||||
await command.RespondAsync(channelInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
Color = DiscordColor.Red,
|
||||||
.WithColor(DiscordColor.Red)
|
Description = message
|
||||||
.WithDescription("User does not have any closed tickets.");
|
});
|
||||||
await command.RespondAsync(channelInfo);
|
}
|
||||||
|
|
||||||
|
// Add the titles
|
||||||
|
for (int i = 0; i < closedEmbeds.Count; i++)
|
||||||
|
{
|
||||||
|
closedEmbeds[i].Title = $"Closed tickets ({i + 1}/{closedEmbeds.Count})";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Merge the embed lists and add the footers
|
||||||
|
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||||
|
embeds.AddRange(openEmbeds);
|
||||||
|
embeds.AddRange(closedEmbeds);
|
||||||
|
for (int i = 0; i < embeds.Count; i++)
|
||||||
|
{
|
||||||
|
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||||
|
{
|
||||||
|
Text = $"Page {i + 1} / {embeds.Count}"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (embeds.Count == 0)
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Cyan,
|
||||||
|
Description = "User does not have any open or closed tickets."
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Page> listPages = new List<Page>();
|
||||||
|
foreach (DiscordEmbedBuilder embed in embeds)
|
||||||
|
{
|
||||||
|
listPages.Add(new Page("", embed));
|
||||||
|
}
|
||||||
|
|
||||||
|
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,71 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
|
||||||
{
|
|
||||||
public class ListOldestCommand : BaseCommandModule
|
|
||||||
{
|
|
||||||
[Command("listoldest")]
|
|
||||||
[Aliases("lo")]
|
|
||||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "listoldest"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the listoldest command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int listLimit = 20;
|
|
||||||
if (!string.IsNullOrEmpty(command.RawArgumentString?.Trim() ?? ""))
|
|
||||||
{
|
|
||||||
if (!int.TryParse(command.RawArgumentString?.Trim(), out listLimit) || listLimit < 5 || listLimit > 100)
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Invalid list amount. (Must be integer between 5 and 100)"
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Database.TryGetOldestTickets(command.Member.Id, out List<Database.Ticket> openTickets, listLimit))
|
|
||||||
{
|
|
||||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
|
||||||
.WithColor(DiscordColor.Red)
|
|
||||||
.WithDescription("Could not fetch any open tickets.");
|
|
||||||
await command.RespondAsync(channelInfo);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<string> listItems = new List<string>();
|
|
||||||
foreach (Database.Ticket ticket in openTickets)
|
|
||||||
{
|
|
||||||
listItems.Add("**" + ticket.FormattedCreatedTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
|
|
||||||
foreach (string message in messages)
|
|
||||||
{
|
|
||||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
|
||||||
.WithTitle("The " + openTickets.Count + " oldest open tickets: ")
|
|
||||||
.WithColor(DiscordColor.Green)
|
|
||||||
.WithDescription(message?.Trim());
|
|
||||||
await command.RespondAsync(channelInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
60
SupportChild/Commands/ListOpen.cs
Normal file
60
SupportChild/Commands/ListOpen.cs
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DSharpPlus.Entities;
|
||||||
|
using DSharpPlus.Interactivity;
|
||||||
|
using DSharpPlus.Interactivity.Extensions;
|
||||||
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class ListOpen : ApplicationCommandModule
|
||||||
|
{
|
||||||
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("listopen", "Lists all open tickets, oldest first.")]
|
||||||
|
public async Task OnExecute(InteractionContext command)
|
||||||
|
{
|
||||||
|
if (!Database.TryGetOpenTickets(out List<Database.Ticket> openTickets))
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "Could not fetch any open tickets."
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<string> listItems = new List<string>();
|
||||||
|
foreach (Database.Ticket ticket in openTickets)
|
||||||
|
{
|
||||||
|
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||||
|
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||||
|
{
|
||||||
|
embeds.Add(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the footers
|
||||||
|
for (int i = 0; i < embeds.Count; i++)
|
||||||
|
{
|
||||||
|
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||||
|
{
|
||||||
|
Text = $"Page {i + 1} / {embeds.Count}"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Page> listPages = new List<Page>();
|
||||||
|
foreach (DiscordEmbedBuilder embed in embeds)
|
||||||
|
{
|
||||||
|
listPages.Add(new Page("", embed));
|
||||||
|
}
|
||||||
|
|
||||||
|
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,55 +1,61 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.Interactivity;
|
||||||
|
using DSharpPlus.Interactivity.Extensions;
|
||||||
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class ListUnassignedCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class ListUnassignedCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("listunassigned", "Lists unassigned tickets.")]
|
||||||
|
public async Task OnExecute(InteractionContext command)
|
||||||
{
|
{
|
||||||
[Command("listunassigned")]
|
|
||||||
[Aliases("lu")]
|
|
||||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "listunassigned"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the listunassigned command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Database.TryGetAssignedTickets(0, out List<Database.Ticket> unassignedTickets))
|
if (!Database.TryGetAssignedTickets(0, out List<Database.Ticket> unassignedTickets))
|
||||||
{
|
{
|
||||||
DiscordEmbed response = new DiscordEmbedBuilder()
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
.WithColor(DiscordColor.Green)
|
{
|
||||||
.WithDescription("There are no unassigned tickets.");
|
Color = DiscordColor.Green,
|
||||||
await command.RespondAsync(response);
|
Description = "There are no unassigned tickets."
|
||||||
|
});
|
||||||
|
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.FormattedCreatedTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
|
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||||
foreach (string message in messages)
|
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||||
{
|
{
|
||||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
embeds.Add(new DiscordEmbedBuilder
|
||||||
.WithTitle("Unassigned tickets: ")
|
{
|
||||||
.WithColor(DiscordColor.Green)
|
Title = "Unassigned tickets: ",
|
||||||
.WithDescription(message?.Trim());
|
Color = DiscordColor.Green,
|
||||||
await command.RespondAsync(channelInfo);
|
Description = message
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the footers
|
||||||
|
for (int i = 0; i < embeds.Count; i++)
|
||||||
|
{
|
||||||
|
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||||
|
{
|
||||||
|
Text = $"Page {i + 1} / {embeds.Count}"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Page> listPages = new List<Page>();
|
||||||
|
foreach (DiscordEmbedBuilder embed in embeds)
|
||||||
|
{
|
||||||
|
listPages.Add(new Page("", embed));
|
||||||
|
}
|
||||||
|
|
||||||
|
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,103 +2,82 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.Exceptions;
|
using DSharpPlus.Exceptions;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class MoveCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class MoveCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
{
|
{
|
||||||
[Command("move")]
|
|
||||||
[Description("Moves a ticket to another category.")]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "move"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the move command but did not have permission.");
|
|
||||||
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 _))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(command.RawArgumentString))
|
if (string.IsNullOrEmpty(category))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: No category provided."
|
Description = "Error: No category provided."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(error);
|
|
||||||
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 category = categories.FirstOrDefault(x => x.Name.StartsWith(command.RawArgumentString.Trim(), StringComparison.OrdinalIgnoreCase));
|
DiscordChannel categoryChannel = categories.FirstOrDefault(x => x.Name.StartsWith(category.Trim(), StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
if (category == null)
|
if (categoryChannel == null)
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.Channel.Id == category.Id)
|
if (command.Channel.Id == categoryChannel.Id)
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await command.Channel.ModifyAsync(modifiedAttributes => modifiedAttributes.Parent = category);
|
await command.Channel.ModifyAsync(modifiedAttributes => modifiedAttributes.Parent = categoryChannel);
|
||||||
}
|
}
|
||||||
catch (UnauthorizedException)
|
catch (UnauthorizedException)
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordEmbed feedback = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Ticket was moved to " + category.Mention
|
Description = "Ticket was moved to " + categoryChannel.Mention
|
||||||
};
|
});
|
||||||
await command.RespondAsync(feedback);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,85 +1,199 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus;
|
using DSharpPlus;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.Exceptions;
|
using DSharpPlus.Exceptions;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class NewCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class NewCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("new", "Opens a new ticket.")]
|
||||||
|
public async Task OnExecute(InteractionContext command)
|
||||||
{
|
{
|
||||||
[Command("new")]
|
List<Database.Category> verifiedCategories = await Utilities.GetVerifiedChannels();
|
||||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
switch (verifiedCategories.Count)
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
{
|
||||||
// Check if the user has permission to use this command.
|
case 0:
|
||||||
if (!Config.HasPermission(command.Member, "new"))
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "You do not have permission to use this command."
|
Description = "Error: No registered categories found."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(error);
|
return;
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the new command but did not have permission.");
|
case 1:
|
||||||
|
await command.DeferAsync(true);
|
||||||
|
(bool success, string message) = await OpenNewTicket(command.User.Id, command.Channel.Id, verifiedCategories[0].id);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
await command.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = message
|
||||||
|
}).AsEphemeral());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await command.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = message
|
||||||
|
}).AsEphemeral());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
if (Config.newCommandUsesSelector)
|
||||||
|
{
|
||||||
|
await CreateSelector(command, verifiedCategories);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await CreateButtons(command, verifiedCategories);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task CreateButtons(InteractionContext command, List<Database.Category> verifiedCategories)
|
||||||
|
{
|
||||||
|
DiscordInteractionResponseBuilder builder = new DiscordInteractionResponseBuilder().WithContent(" ");
|
||||||
|
int nrOfButtons = 0;
|
||||||
|
for (int nrOfButtonRows = 0; nrOfButtonRows < 5 && nrOfButtons < verifiedCategories.Count; nrOfButtonRows++)
|
||||||
|
{
|
||||||
|
List<DiscordButtonComponent> buttonRow = new List<DiscordButtonComponent>();
|
||||||
|
|
||||||
|
for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < verifiedCategories.Count; nrOfButtons++)
|
||||||
|
{
|
||||||
|
buttonRow.Add(new DiscordButtonComponent(ButtonStyle.Primary, "supportboi_newcommandbutton " + verifiedCategories[nrOfButtons].id, verifiedCategories[nrOfButtons].name));
|
||||||
|
}
|
||||||
|
builder.AddComponents(buttonRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
await command.CreateResponseAsync(builder.AsEphemeral());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task CreateSelector(InteractionContext command, List<Database.Category> verifiedCategories)
|
||||||
|
{
|
||||||
|
verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList();
|
||||||
|
List<DiscordSelectComponent> selectionComponents = new List<DiscordSelectComponent>();
|
||||||
|
int selectionOptions = 0;
|
||||||
|
for (int selectionBoxes = 0; selectionBoxes < 5 && selectionOptions < verifiedCategories.Count; selectionBoxes++)
|
||||||
|
{
|
||||||
|
List<DiscordSelectComponentOption> categoryOptions = new List<DiscordSelectComponentOption>();
|
||||||
|
|
||||||
|
for (; selectionOptions < 25 * (selectionBoxes + 1) && selectionOptions < verifiedCategories.Count; selectionOptions++)
|
||||||
|
{
|
||||||
|
categoryOptions.Add(new DiscordSelectComponentOption(verifiedCategories[selectionOptions].name, verifiedCategories[selectionOptions].id.ToString()));
|
||||||
|
}
|
||||||
|
selectionComponents.Add(new DiscordSelectComponent("supportboi_newcommandselector" + selectionBoxes, "Open new ticket...", categoryOptions, false, 0, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
await command.CreateResponseAsync(new DiscordInteractionResponseBuilder().AddComponents(selectionComponents).AsEphemeral());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task OnCategorySelection(DiscordInteraction interaction)
|
||||||
|
{
|
||||||
|
string stringID;
|
||||||
|
switch (interaction.Data.ComponentType)
|
||||||
|
{
|
||||||
|
case ComponentType.Button:
|
||||||
|
stringID = interaction.Data.CustomId.Replace("supportboi_newcommandbutton ", "");
|
||||||
|
break;
|
||||||
|
case ComponentType.Select:
|
||||||
|
if (interaction.Data.Values == null || interaction.Data.Values.Length <= 0) return;
|
||||||
|
stringID = interaction.Data.Values[0];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ComponentType.ActionRow:
|
||||||
|
case ComponentType.FormInput:
|
||||||
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ulong.TryParse(stringID, out ulong categoryID) || categoryID == 0) return;
|
||||||
|
|
||||||
|
await interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate, new DiscordInteractionResponseBuilder().AsEphemeral());
|
||||||
|
|
||||||
|
(bool success, string message) = await OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = message
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = message
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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(command.User.Id))
|
if (Database.IsBlacklisted(userID))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
return (false, "You are banned from opening tickets.");
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You are banned from opening tickets."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Database.IsOpenTicket(command.Channel.Id))
|
if (Database.IsOpenTicket(commandChannelID))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
return (false, "You cannot use this command in a ticket channel.");
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You cannot use this command in a ticket channel."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordChannel category = command.Guild.GetChannel(Config.ticketCategory);
|
if (!Database.IsStaff(userID) && Database.TryGetOpenTickets(userID, out List<Database.Ticket> ownTickets) && ownTickets.Count >= Config.ticketLimit)
|
||||||
DiscordChannel ticketChannel;
|
{
|
||||||
|
return (false, "You have reached the limit for maximum open tickets.");
|
||||||
|
}
|
||||||
|
|
||||||
|
DiscordChannel category = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
category = await SupportChild.discordClient.GetChannelAsync(categoryID);
|
||||||
|
}
|
||||||
|
catch (Exception) { /*ignored*/ }
|
||||||
|
|
||||||
|
if (category == null)
|
||||||
|
{
|
||||||
|
return (false, "Error: Could not find the category to place the ticket in.");
|
||||||
|
}
|
||||||
|
|
||||||
|
DiscordMember member = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
member = await category.Guild.GetMemberAsync(userID);
|
||||||
|
}
|
||||||
|
catch (Exception) { /*ignored*/ }
|
||||||
|
|
||||||
|
if (member == null)
|
||||||
|
{
|
||||||
|
return (false, "Error: Could not find you on the Discord server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
DiscordChannel ticketChannel = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ticketChannel = await command.Guild.CreateChannelAsync("ticket", ChannelType.Text, category);
|
ticketChannel = await category.Guild.CreateChannelAsync("ticket", ChannelType.Text, category);
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Error occured while creating ticket, " + command.Member.Mention +
|
|
||||||
"!\nIs the channel limit reached in the server or ticket category?"
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
catch (Exception) { /* ignored */ }
|
||||||
|
|
||||||
if (ticketChannel == null)
|
if (ticketChannel == null)
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
return (false, "Error occured while creating ticket, " + member.Mention +
|
||||||
{
|
"!\nIs the channel limit reached in the server or ticket category?");
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Error occured while creating ticket, " + command.Member.Mention +
|
|
||||||
"!\nIs the channel limit reached in the server or ticket category?"
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong staffID = 0;
|
ulong staffID = 0;
|
||||||
|
@ -88,63 +202,75 @@ namespace SupportChild.Commands
|
||||||
staffID = Database.GetRandomActiveStaff(0)?.userID ?? 0;
|
staffID = Database.GetRandomActiveStaff(0)?.userID ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
long id = Database.NewTicket(command.Member.Id, staffID, ticketChannel.Id);
|
long id = Database.NewTicket(member.Id, staffID, ticketChannel.Id);
|
||||||
string ticketID = id.ToString("00000");
|
string ticketID = id.ToString("00000");
|
||||||
await ticketChannel.ModifyAsync(modifiedAttributes => modifiedAttributes.Name = "ticket-" + ticketID);
|
|
||||||
await ticketChannel.AddOverwriteAsync(command.Member, Permissions.AccessChannels, Permissions.None);
|
|
||||||
|
|
||||||
await ticketChannel.SendMessageAsync("Hello, " + command.Member.Mention + "!\n" + Config.welcomeMessage);
|
try
|
||||||
|
{
|
||||||
|
await ticketChannel.ModifyAsync(modifiedAttributes => modifiedAttributes.Name = "ticket-" + ticketID);
|
||||||
|
}
|
||||||
|
catch (DiscordException e)
|
||||||
|
{
|
||||||
|
Logger.Error("Exception occurred trying to modify channel: " + e);
|
||||||
|
Logger.Error("JsomMessage: " + e.JsonMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await ticketChannel.AddOverwriteAsync(member, Permissions.AccessChannels);
|
||||||
|
}
|
||||||
|
catch (DiscordException e)
|
||||||
|
{
|
||||||
|
Logger.Error("Exception occurred trying to add channel permissions: " + e);
|
||||||
|
Logger.Error("JsomMessage: " + e.JsonMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = command.Guild.GetChannel(ticketChannel.Id);
|
ticketChannel = await SupportChild.discordClient.GetChannelAsync(ticketChannel.Id);
|
||||||
|
|
||||||
if (staffID != 0)
|
if (staffID != 0)
|
||||||
{
|
{
|
||||||
DiscordEmbed assignmentMessage = 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 + ">."
|
||||||
};
|
});
|
||||||
await ticketChannel.SendMessageAsync(assignmentMessage);
|
|
||||||
|
|
||||||
if (Config.assignmentNotifications)
|
if (Config.assignmentNotifications)
|
||||||
{
|
{
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
try
|
||||||
|
{
|
||||||
|
DiscordMember staffMember = await category.Guild.GetMemberAsync(staffID);
|
||||||
|
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
|
||||||
};
|
});
|
||||||
|
}
|
||||||
try
|
catch (DiscordException e)
|
||||||
{
|
{
|
||||||
DiscordMember staffMember = await command.Guild.GetMemberAsync(staffID);
|
Logger.Error("Exception occurred assign random staff member: " + e);
|
||||||
await staffMember.SendMessageAsync(message);
|
Logger.Error("JsomMessage: " + e.JsonMessage);
|
||||||
}
|
}
|
||||||
catch (NotFoundException) {}
|
|
||||||
catch (UnauthorizedException) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordEmbed response = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Green,
|
|
||||||
Description = "Ticket opened, " + command.Member.Mention + "!\n" + ticketChannel.Mention
|
|
||||||
};
|
|
||||||
await command.RespondAsync(response);
|
|
||||||
|
|
||||||
// Log it if the log channel exists
|
// Log it if the log channel exists
|
||||||
DiscordChannel logChannel = command.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 " + command.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,47 +2,33 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.Exceptions;
|
using DSharpPlus.Exceptions;
|
||||||
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
{
|
|
||||||
public class RandomAssignCommand : BaseCommandModule
|
|
||||||
{
|
|
||||||
[Command("rassign")]
|
|
||||||
[Description("Randomly assigns a staff member to a ticket.")]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArguments)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "rassign"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the rassign command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public class RandomAssignCommand : ApplicationCommandModule
|
||||||
|
{
|
||||||
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
|
{
|
||||||
// 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))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "This channel is not a ticket."
|
Description = "Error: This channel is not a ticket."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(error);
|
|
||||||
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, ticket);
|
DiscordMember staffMember = await GetRandomVerifiedStaffMember(command, role, ticket);
|
||||||
if (staffMember == null)
|
if (staffMember == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -51,84 +37,58 @@ namespace SupportChild.Commands
|
||||||
// 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))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Respond that the command was successful
|
// Respond that the command was successful
|
||||||
DiscordEmbed feedback = 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."
|
||||||
};
|
});
|
||||||
await command.RespondAsync(feedback);
|
|
||||||
|
|
||||||
// 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
|
||||||
{
|
{
|
||||||
DiscordEmbed message = 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
|
||||||
};
|
});
|
||||||
await staffMember.SendMessageAsync(message);
|
|
||||||
}
|
}
|
||||||
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)
|
||||||
{
|
{
|
||||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = staffMember.Mention + " was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
Description = staffMember.Mention + " was randomly assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
||||||
};
|
});
|
||||||
await logChannel.SendMessageAsync(logMessage);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<DiscordMember> GetRandomVerifiedStaffMember(CommandContext command, Database.Ticket ticket)
|
private static async Task<DiscordMember> GetRandomVerifiedStaffMember(InteractionContext command, DiscordRole targetRole, Database.Ticket ticket)
|
||||||
{
|
{
|
||||||
if (command.RawArguments.Any()) // An argument was provided, check if this can be parsed into a role
|
if (targetRole != null) // A role was provided
|
||||||
{
|
{
|
||||||
ulong roleID = 0;
|
|
||||||
|
|
||||||
// Try to parse either discord mention or ID
|
|
||||||
string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);
|
|
||||||
if (!ulong.TryParse(parsedMessage[0], out roleID))
|
|
||||||
{
|
|
||||||
// Try to find role by name
|
|
||||||
roleID = Utilities.GetRoleByName(command.Guild, command.RawArgumentString)?.Id ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if a role was found
|
|
||||||
if (roleID == 0)
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Could not find a role by that name/ID."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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)
|
? Database.GetAllStaff(ticket.assignedStaffID, ticket.creatorID)
|
||||||
: Database.GetActiveStaff(ticket.assignedStaffID);
|
: 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 = Utilities.RandomizeList(staffMembers);
|
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)
|
||||||
|
@ -136,7 +96,7 @@ namespace SupportChild.Commands
|
||||||
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 == roleID) ?? false)
|
if (verifiedMember?.Roles?.Any(role => role.Id == targetRole.Id) ?? false)
|
||||||
{
|
{
|
||||||
return verifiedMember;
|
return verifiedMember;
|
||||||
}
|
}
|
||||||
|
@ -149,15 +109,14 @@ namespace SupportChild.Commands
|
||||||
}
|
}
|
||||||
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);
|
Database.StaffMember staffEntry = Database.GetRandomActiveStaff(ticket.assignedStaffID, ticket.creatorID);
|
||||||
if (staffEntry == null)
|
if (staffEntry == null)
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,13 +129,11 @@ namespace SupportChild.Commands
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
DiscordEmbed err = 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);
|
||||||
await command.RespondAsync(err);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,38 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
|
||||||
{
|
|
||||||
public class ReloadCommand : BaseCommandModule
|
|
||||||
{
|
|
||||||
[Command("reload")]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "reload"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the reload command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Green,
|
|
||||||
Description = "Reloading bot application..."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(message);
|
|
||||||
Console.WriteLine("Reloading bot...");
|
|
||||||
SupportChild.instance.Reload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
41
SupportChild/Commands/RemoveCategoryCommand.cs
Normal file
41
SupportChild/Commands/RemoveCategoryCommand.cs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DSharpPlus.Entities;
|
||||||
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class RemoveCategoryCommand : ApplicationCommandModule
|
||||||
|
{
|
||||||
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
|
{
|
||||||
|
if (!Database.TryGetCategory(channel.Id, out Database.Category _))
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "That category is not registered."
|
||||||
|
}, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Database.RemoveCategory(channel.Id))
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = "Category removed."
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "Error: Failed removing the category from the database."
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,66 +1,41 @@
|
||||||
using DSharpPlus.CommandsNext;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class RemoveMessageCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class RemoveMessageCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
{
|
{
|
||||||
[Command("removemessage")]
|
|
||||||
[Description("Removes a message from the 'say' command.")]
|
|
||||||
public async Task OnExecute(CommandContext command, string identifier)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "removemessage"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the removemessage command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Database.TryGetMessage(identifier.ToLower(), out Database.Message _))
|
if (!Database.TryGetMessage(identifier.ToLower(), out Database.Message _))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Database.RemoveMessage(identifier))
|
if (Database.RemoveMessage(identifier))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Message removed."
|
Description = "Message removed."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,104 +1,49 @@
|
||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
using MySql.Data.MySqlClient;
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class RemoveStaffCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class RemoveStaffCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("removestaff", "Removes a staff member.")]
|
||||||
|
public async Task OnExecute(InteractionContext command, [Option("User", "User to remove from staff.")] DiscordUser user)
|
||||||
{
|
{
|
||||||
[Command("removestaff")]
|
if (!Database.IsStaff(user.Id))
|
||||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
{
|
||||||
// Check if the user has permission to use this command.
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
if (!Config.HasPermission(command.Member, "removestaff"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the removestaff command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ulong userID;
|
|
||||||
string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);
|
|
||||||
|
|
||||||
if (!parsedMessage.Any())
|
|
||||||
{
|
|
||||||
userID = command.Member.Id;
|
|
||||||
}
|
|
||||||
else if (!ulong.TryParse(parsedMessage[0], out userID))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Invalid ID/Mention. (Could not convert to numerical)"
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await command.Client.GetUserAsync(userID);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Invalid ID/Mention. (Could not find user on Discord)"
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Database.IsStaff(userID))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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", userID);
|
deletion.Parameters.AddWithValue("@user_id", user.Id);
|
||||||
deletion.Prepare();
|
deletion.Prepare();
|
||||||
deletion.ExecuteNonQuery();
|
deletion.ExecuteNonQuery();
|
||||||
|
|
||||||
DiscordEmbed message = 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);
|
||||||
await command.RespondAsync(message);
|
|
||||||
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
DiscordEmbed logMessage = 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"
|
||||||
};
|
});
|
||||||
await logChannel.SendMessageAsync(logMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,78 +1,29 @@
|
||||||
using DSharpPlus.CommandsNext;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class SayCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class SayCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
{
|
{
|
||||||
[Command("say")]
|
// Print list of all messages if no identifier is provided
|
||||||
[Cooldown(1, 2, CooldownBucketType.Channel)]
|
if (identifier == null)
|
||||||
[Description("Prints a message with information from staff.")]
|
|
||||||
public async Task OnExecute(CommandContext command, string identifier)
|
|
||||||
{
|
{
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "say"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the say command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Database.TryGetMessage(identifier.ToLower(), out Database.Message message))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "There is no message with that identifier."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscordEmbed reply = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = message.message
|
|
||||||
};
|
|
||||||
await command.RespondAsync(reply);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Command("say")]
|
|
||||||
[Cooldown(1, 2.0, CooldownBucketType.Channel)]
|
|
||||||
[Description("Prints a list of staff messages.")]
|
|
||||||
public async Task OnExecute(CommandContext command)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "say"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the say command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
List<Database.Message> messages = Database.GetAllMessages();
|
List<Database.Message> messages = Database.GetAllMessages();
|
||||||
if (!messages.Any())
|
if (!messages.Any())
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder()
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
.WithColor(DiscordColor.Red)
|
{
|
||||||
.WithDescription("There are no messages registered.");
|
Color = DiscordColor.Red,
|
||||||
await command.RespondAsync(error);
|
Description = "There are no messages registered."
|
||||||
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,12 +36,32 @@ namespace SupportChild.Commands
|
||||||
LinkedList<string> listMessages = Utilities.ParseListIntoMessages(listItems);
|
LinkedList<string> listMessages = Utilities.ParseListIntoMessages(listItems);
|
||||||
foreach (string listMessage in listMessages)
|
foreach (string listMessage in listMessages)
|
||||||
{
|
{
|
||||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
.WithTitle("Available messages: ")
|
{
|
||||||
.WithColor(DiscordColor.Green)
|
Title = "Available messages: ",
|
||||||
.WithDescription(listMessage);
|
Color = DiscordColor.Green,
|
||||||
await command.RespondAsync(channelInfo);
|
Description = listMessage
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Print specific message
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!Database.TryGetMessage(identifier.ToLower(), out Database.Message message))
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "There is no message with that identifier."
|
||||||
|
}, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Cyan,
|
||||||
|
Description = message.message.Replace("\\n", "\n")
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,48 +1,30 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
using MySql.Data.MySqlClient;
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
{
|
|
||||||
public class SetSummaryCommand : BaseCommandModule
|
|
||||||
{
|
|
||||||
[Command("setsummary")]
|
|
||||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "setsummary"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the setsummary command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public class SetSummaryCommand : ApplicationCommandModule
|
||||||
|
{
|
||||||
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
|
{
|
||||||
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 ticket))
|
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket _))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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."
|
||||||
};
|
});
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string summary = command.Message.Content.Replace(Config.prefix + "setsummary", "").Trim();
|
await using MySqlConnection c = Database.GetConnection();
|
||||||
|
|
||||||
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);
|
||||||
|
@ -51,13 +33,10 @@ namespace SupportChild.Commands
|
||||||
update.ExecuteNonQuery();
|
update.ExecuteNonQuery();
|
||||||
update.Dispose();
|
update.Dispose();
|
||||||
|
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Summary set."
|
Description = "Summary set."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,98 +0,0 @@
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
|
||||||
{
|
|
||||||
public class SetTicketCommand :BaseCommandModule
|
|
||||||
{
|
|
||||||
[Command("setticket")]
|
|
||||||
[Description("Turns a channel into a ticket, warning: this will let anyone with write access delete the channel using the close command.")]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
using (MySqlConnection c = Database.GetConnection())
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "setticket"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the setticket command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if ticket exists in the database
|
|
||||||
if (Database.IsOpenTicket(command.Channel.Id))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "This channel is already a ticket."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ulong userID;
|
|
||||||
string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);
|
|
||||||
|
|
||||||
if (!parsedMessage.Any())
|
|
||||||
{
|
|
||||||
userID = command.Member.Id;
|
|
||||||
}
|
|
||||||
else if (!ulong.TryParse(parsedMessage[0], out userID))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Invalid ID/Mention. (Could not convert to numerical)"
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscordUser user = await command.Client.GetUserAsync(userID);
|
|
||||||
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Invalid ID/Mention."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
long id = Database.NewTicket(userID, 0, command.Channel.Id);
|
|
||||||
string ticketID = id.ToString("00000");
|
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Green,
|
|
||||||
Description = "Channel has been designated ticket " + ticketID + "."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(message);
|
|
||||||
|
|
||||||
// Log it if the log channel exists
|
|
||||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
|
||||||
if (logChannel != null)
|
|
||||||
{
|
|
||||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Green,
|
|
||||||
Description = command.Channel.Mention + " has been designated ticket " + ticketID + " by " + command.Member.Mention + "."
|
|
||||||
};
|
|
||||||
await logChannel.SendMessageAsync(logMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,41 +1,26 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class StatusCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class StatusCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("status", "Shows bot status and information.")]
|
||||||
|
public async Task OnExecute(InteractionContext command)
|
||||||
{
|
{
|
||||||
[Command("status")]
|
|
||||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "status"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the status command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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("EmotionChild/SupportChild @ GitHub", "https://github.com/EmotionChild/SupportChild", "https://cdn.emotionchild.com/Ellie.png")
|
.WithAuthor("KarlofDuty/SupportBoi @ GitHub", "https://github.com/EmotionChild/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(), false)
|
.AddField("Version:", SupportChild.GetVersion())
|
||||||
.AddField("Open tickets:", openTickets + "", true)
|
.AddField("Open tickets:", openTickets + "", true)
|
||||||
.AddField("Closed tickets (1.1.0+ tickets only):", closedTickets + " ", true);
|
.AddField("Closed tickets:", closedTickets + " ", true);
|
||||||
await command.RespondAsync(botInfo);
|
await command.CreateResponseAsync(botInfo);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,51 +1,35 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class SummaryCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class SummaryCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("summary", "Lists tickets assigned to a user.")]
|
||||||
|
public async Task OnExecute(InteractionContext command)
|
||||||
{
|
{
|
||||||
[Command("summary")]
|
|
||||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "summary"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the summary command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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(), 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.createdTime.ToString(Config.timestampFormat), true)
|
.AddField("Creation time:", ticket.DiscordRelativeTime(), true)
|
||||||
.AddField("Summary:", string.IsNullOrEmpty(ticket.summary) ? "No summary." : ticket.summary, false);
|
.AddField("Summary:", string.IsNullOrEmpty(ticket.summary) ? "No summary." : ticket.summary.Replace("\\n", "\n"));
|
||||||
await command.RespondAsync(channelInfo);
|
await command.CreateResponseAsync(channelInfo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,78 +1,44 @@
|
||||||
using System.Linq;
|
using System.Threading.Tasks;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands;
|
||||||
using MySql.Data.MySqlClient;
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class ToggleActiveCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class ToggleActiveCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
{
|
{
|
||||||
[Command("toggleactive")]
|
DiscordUser staffUser = user == null ? command.User : user;
|
||||||
[Aliases("ta")]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
using (MySqlConnection c = Database.GetConnection())
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "toggleactive"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the toggleactive command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ulong staffID;
|
|
||||||
string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);
|
|
||||||
|
|
||||||
if (!parsedMessage.Any())
|
|
||||||
{
|
|
||||||
staffID = command.Member.Id;
|
|
||||||
}
|
|
||||||
else if (!ulong.TryParse(parsedMessage[0], out staffID))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Invalid ID/Mention. (Could not convert to numerical)"
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if ticket exists in the database
|
// Check if ticket exists in the database
|
||||||
if (!Database.TryGetStaff(staffID, out Database.StaffMember staffMember))
|
if (!Database.TryGetStaff(staffUser.Id, out Database.StaffMember staffMember))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "You have not been registered as staff."
|
Description = user == null ? "You have not been registered as staff." : "The user is not registered as staff."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Open();
|
if (Database.SetStaffActive(staffUser.Id, !staffMember.active))
|
||||||
MySqlCommand update = new MySqlCommand(@"UPDATE staff SET active = @active WHERE user_id = @user_id", c);
|
{
|
||||||
update.Parameters.AddWithValue("@user_id", staffID);
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
update.Parameters.AddWithValue("@active", !staffMember.active);
|
|
||||||
update.Prepare();
|
|
||||||
update.ExecuteNonQuery();
|
|
||||||
|
|
||||||
DiscordEmbed message = 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);
|
||||||
await command.RespondAsync(message);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Red,
|
||||||
|
Description = "Error: Unable to update active status in database."
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,39 +2,22 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.Exceptions;
|
using DSharpPlus.Exceptions;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class TranscriptCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class TranscriptCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[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)
|
||||||
{
|
{
|
||||||
[Command("transcript")]
|
await command.DeferAsync(true);
|
||||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "transcript"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the transcript command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Database.Ticket ticket;
|
Database.Ticket ticket;
|
||||||
string strippedMessage = command.Message.Content.Replace(Config.prefix, "");
|
if (ticketID == 0) // If there are no arguments use current channel
|
||||||
string[] parsedMessage = strippedMessage.Replace("<@!", "").Replace("<@", "").Replace(">", "").Split();
|
|
||||||
|
|
||||||
// If there are no arguments use current channel
|
|
||||||
if (parsedMessage.Length < 2)
|
|
||||||
{
|
{
|
||||||
if (Database.TryGetOpenTicket(command.Channel.Id, out ticket))
|
if (Database.TryGetOpenTicket(command.Channel.Id, out ticket))
|
||||||
{
|
{
|
||||||
|
@ -44,42 +27,28 @@ namespace SupportChild.Commands
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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..."
|
||||||
};
|
}));
|
||||||
await command.RespondAsync(error);
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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."
|
||||||
};
|
}));
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Check if argument is numerical, if not abort
|
|
||||||
if (!uint.TryParse(parsedMessage[1], out uint ticketID))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Argument must be a number."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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(ticketID, out ticket) && ticket?.creatorID == command.Member.Id)
|
if (Database.TryGetOpenTicketByID((uint)ticketID, out ticket) && ticket?.creatorID == command.Member.Id)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -87,25 +56,23 @@ namespace SupportChild.Commands
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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..."
|
||||||
};
|
}));
|
||||||
await command.RespondAsync(error);
|
|
||||||
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(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)))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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." + (Config.HasPermission(command.Member, "list") ? "\n(Use the " + Config.prefix + "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)"
|
||||||
};
|
}));
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,59 +81,49 @@ namespace SupportChild.Commands
|
||||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||||
if (logChannel != null)
|
if (logChannel != null)
|
||||||
{
|
{
|
||||||
DiscordEmbed embed = new DiscordEmbedBuilder
|
await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
|
||||||
|
|
||||||
|
DiscordMessageBuilder message = new DiscordMessageBuilder();
|
||||||
|
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.WithFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||||
using (FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read))
|
|
||||||
{
|
|
||||||
DiscordMessageBuilder message = new DiscordMessageBuilder();
|
|
||||||
message.WithEmbed(embed);
|
|
||||||
message.WithFiles(new Dictionary<string, Stream>() { { Transcriber.GetFilename(ticket.id), file } });
|
|
||||||
|
|
||||||
await logChannel.SendMessageAsync(message);
|
await logChannel.SendMessageAsync(message);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Send transcript privately
|
// Send transcript in a direct message
|
||||||
DiscordEmbed directMessageEmbed = new DiscordEmbedBuilder
|
await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
|
||||||
|
|
||||||
|
DiscordMessageBuilder directMessage = new DiscordMessageBuilder();
|
||||||
|
directMessage.WithEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Transcript generated, " + command.Member.Mention + "!\n"
|
Description = "Transcript generated!\n"
|
||||||
};
|
});
|
||||||
|
directMessage.WithFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||||
using (FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read))
|
|
||||||
{
|
|
||||||
DiscordMessageBuilder directMessage = new DiscordMessageBuilder();
|
|
||||||
directMessage.WithEmbed(directMessageEmbed);
|
|
||||||
directMessage.WithFiles(new Dictionary<string, Stream>() { { Transcriber.GetFilename(ticket.id), file } });
|
|
||||||
|
|
||||||
await command.Member.SendMessageAsync(directMessage);
|
await command.Member.SendMessageAsync(directMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Respond to message directly
|
|
||||||
DiscordEmbed response = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Green,
|
|
||||||
Description = "Transcript sent, " + command.Member.Mention + "!\n"
|
|
||||||
};
|
|
||||||
await command.RespondAsync(response);
|
|
||||||
}
|
|
||||||
catch (UnauthorizedException)
|
catch (UnauthorizedException)
|
||||||
{
|
{
|
||||||
// Send transcript privately
|
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Not allowed to send direct message to you, " + command.Member.Mention + ", please check your privacy settings.\n"
|
Description = "Not allowed to send direct message to you, please check your privacy settings.\n"
|
||||||
};
|
}));
|
||||||
await command.RespondAsync(error);
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = "Transcript sent!\n"
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,71 +1,52 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands;
|
||||||
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class UnassignCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class UnassignCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("unassign", "Unassigns a staff member from a ticket.")]
|
||||||
|
public async Task OnExecute(InteractionContext command)
|
||||||
{
|
{
|
||||||
[Command("unassign")]
|
|
||||||
[Description("Unassigns a staff member from a ticket.")]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "unassign"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the unassign command but did not have permission.");
|
|
||||||
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))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = 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);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Database.UnassignStaff(ticket))
|
if (!Database.UnassignStaff(ticket))
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error: Failed to unassign staff from ticket."
|
Description = "Error: Failed to unassign staff member from ticket."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Unassigned staff from ticket."
|
Description = "Unassigned staff member from ticket."
|
||||||
};
|
});
|
||||||
await command.RespondAsync(message);
|
|
||||||
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Staff was unassigned from " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
Description = "Staff member was unassigned from " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
||||||
};
|
});
|
||||||
await logChannel.SendMessageAsync(logMessage);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,99 +1,54 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.Exceptions;
|
using DSharpPlus.SlashCommands;
|
||||||
using Microsoft.Extensions.Logging;
|
using DSharpPlus.SlashCommands.Attributes;
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
namespace SupportChild.Commands;
|
||||||
|
|
||||||
|
public class UnblacklistCommand : ApplicationCommandModule
|
||||||
{
|
{
|
||||||
public class UnblacklistCommand : BaseCommandModule
|
[SlashRequireGuild]
|
||||||
|
[SlashCommand("unblacklist", "Unblacklists a user from opening tickets.")]
|
||||||
|
public async Task OnExecute(InteractionContext command, [Option("User", "User to remove from blacklist.")] DiscordUser user)
|
||||||
{
|
{
|
||||||
[Command("unblacklist")]
|
try
|
||||||
[Description("Un-blacklists a user from opening tickets.")]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
{
|
||||||
// Check if the user has permission to use this command.
|
if (!Database.Unblacklist(user.Id))
|
||||||
if (!Config.HasPermission(command.Member, "unblacklist"))
|
|
||||||
{
|
{
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "You do not have permission to use this command."
|
Description = user.Mention + " is not blacklisted."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the unblacklist command but did not have permission.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] words = Utilities.ParseIDs(command.RawArgumentString);
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
foreach (string word in words)
|
|
||||||
{
|
|
||||||
if (ulong.TryParse(word, out ulong userId))
|
|
||||||
{
|
|
||||||
DiscordUser blacklistedUser = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
blacklistedUser = await command.Client.GetUserAsync(userId);
|
|
||||||
}
|
|
||||||
catch (NotFoundException) { }
|
|
||||||
|
|
||||||
if (blacklistedUser == null)
|
|
||||||
{
|
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "Error: Could not find user."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(message);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!Database.Unblacklist(blacklistedUser.Id))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = blacklistedUser.Mention + " is not blacklisted."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Removed " + blacklistedUser.Mention + " from blacklist."
|
Description = "Removed " + user.Mention + " from blacklist."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(message);
|
|
||||||
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = blacklistedUser.Mention + " was unblacklisted from opening tickets by " + command.Member.Mention + "."
|
Description = user.Mention + " was unblacklisted from opening tickets by " + command.Member.Mention + "."
|
||||||
};
|
});
|
||||||
await logChannel.SendMessageAsync(logMessage);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Error occured while removing " + blacklistedUser.Mention + " from blacklist."
|
Description = "Error occured while removing " + user.Mention + " from blacklist."
|
||||||
};
|
}, true);
|
||||||
await command.RespondAsync(message);
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,70 +0,0 @@
|
||||||
using System.Threading.Tasks;
|
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using DSharpPlus.Entities;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
|
|
||||||
namespace SupportChild.Commands
|
|
||||||
{
|
|
||||||
public class UnsetTicketCommand : BaseCommandModule
|
|
||||||
{
|
|
||||||
[Command("unsetticket")]
|
|
||||||
[Description(
|
|
||||||
"Deletes a channel from the ticket system without deleting the channel.")]
|
|
||||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
|
||||||
{
|
|
||||||
using (MySqlConnection c = Database.GetConnection())
|
|
||||||
{
|
|
||||||
// Check if the user has permission to use this command.
|
|
||||||
if (!Config.HasPermission(command.Member, "unsetticket"))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "You do not have permission to use this command."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the unsetticket command but did not have permission.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if ticket exists in the database
|
|
||||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
|
||||||
{
|
|
||||||
DiscordEmbed error = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Red,
|
|
||||||
Description = "This channel is not a ticket."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Open();
|
|
||||||
MySqlCommand deletion = new MySqlCommand(@"DELETE FROM tickets WHERE channel_id=@channel_id", c);
|
|
||||||
deletion.Parameters.AddWithValue("@channel_id", command.Channel.Id);
|
|
||||||
deletion.Prepare();
|
|
||||||
deletion.ExecuteNonQuery();
|
|
||||||
DiscordEmbed message = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Green,
|
|
||||||
Description = "Channel has been undesignated as a ticket."
|
|
||||||
};
|
|
||||||
await command.RespondAsync(message);
|
|
||||||
|
|
||||||
// Log it if the log channel exists
|
|
||||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
|
||||||
if (logChannel != null)
|
|
||||||
{
|
|
||||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
|
||||||
{
|
|
||||||
Color = DiscordColor.Green,
|
|
||||||
Description = command.Channel.Mention + " has been undesignated as a ticket by " + command.Member.Mention + "."
|
|
||||||
};
|
|
||||||
await logChannel.SendMessageAsync(logMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue