This commit is contained in:
EmotionChild 2022-05-19 23:38:59 +12:00
parent c9180130f9
commit b565047517
28 changed files with 1634 additions and 1635 deletions

View file

@ -1,4 +1,4 @@
# To get started with Dependabot version updates, you'll need to specify which
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
@ -12,7 +12,7 @@ updates:
open-pull-requests-limit: 5
reviewers:
- EmotionChild
target-branch: "main"
target-branch: "development"
labels:
- "nuget"
- "dependencies"

View file

@ -1,4 +1,4 @@
name: .NET
name: .NET
on:
push:
@ -12,14 +12,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal

View file

@ -51,7 +51,7 @@ namespace SupportChild.Commands
return;
}
if (Database.AddMessage(identifier, command.Member.Id, message))
if(Database.AddMessage(identifier, command.Member.Id, message))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
@ -71,7 +71,6 @@ namespace SupportChild.Commands
await command.RespondAsync(error);
return;
}
}
}
}

View file

@ -9,88 +9,88 @@ using MySql.Data.MySqlClient;
namespace SupportChild.Commands
{
public class AddStaffCommand : BaseCommandModule
{
[Command("addstaff")]
[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;
}
public class AddStaffCommand : BaseCommandModule
{
[Command("addstaff")]
[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);
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;
}
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
{
member = await command.Guild.GetMemberAsync(userID);
}
catch (Exception)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Invalid ID/Mention. (Could not find user on this server)"
};
await command.RespondAsync(error);
return;
}
DiscordMember member;
try
{
member = await command.Guild.GetMemberAsync(userID);
}
catch (Exception)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Invalid ID/Mention. (Could not find user on this server)"
};
await command.RespondAsync(error);
return;
}
using (MySqlConnection c = Database.GetConnection())
{
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);
using (MySqlConnection c = Database.GetConnection())
{
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();
cmd.Parameters.AddWithValue("@user_id", userID);
cmd.Parameters.AddWithValue("@name", member.DisplayName);
cmd.ExecuteNonQuery();
cmd.Dispose();
c.Open();
cmd.Parameters.AddWithValue("@user_id", userID);
cmd.Parameters.AddWithValue("@name", member.DisplayName);
cmd.ExecuteNonQuery();
cmd.Dispose();
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = member.Mention + " was added to staff."
};
await command.RespondAsync(message);
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = member.Mention + " was added to staff."
};
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 = member.Mention + " was added to staff.\n",
};
await logChannel.SendMessageAsync(logMessage);
}
}
}
}
// 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 = member.Mention + " was added to staff.\n",
};
await logChannel.SendMessageAsync(logMessage);
}
}
}
}
}

View file

@ -8,128 +8,128 @@ using Microsoft.Extensions.Logging;
namespace SupportChild.Commands
{
public class AssignCommand : BaseCommandModule
{
[Command("assign")]
[Description("Assigns a staff member 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, "assign"))
{
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 assign command but did not have permission.");
return;
}
public class AssignCommand : BaseCommandModule
{
[Command("assign")]
[Description("Assigns a staff member 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, "assign"))
{
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 assign 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;
}
// 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;
}
ulong staffID;
string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);
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;
}
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;
}
DiscordMember staffMember = null;
try
{
staffMember = await command.Guild.GetMemberAsync(staffID);
}
catch (NotFoundException) { }
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 (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,
Description = "Error: User is not registered as staff."
};
await command.RespondAsync(error);
return;
}
if (!Database.IsStaff(staffMember.Id))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: User is not registered as staff."
};
await command.RespondAsync(error);
return;
}
if (!Database.AssignStaff(ticket, staffID))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Failed to assign " + staffMember.Mention + " to ticket."
};
await command.RespondAsync(error);
return;
}
if (!Database.AssignStaff(ticket, staffID))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Failed to assign " + staffMember.Mention + " to ticket."
};
await command.RespondAsync(error);
return;
}
DiscordEmbed feedback = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Assigned " + staffMember.Mention + " to ticket."
};
await command.RespondAsync(feedback);
DiscordEmbed feedback = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Assigned " + staffMember.Mention + " to ticket."
};
await command.RespondAsync(feedback);
if (Config.assignmentNotifications)
{
try
{
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "You have been assigned to a support ticket: " + command.Channel.Mention
};
await staffMember.SendMessageAsync(message);
}
catch (UnauthorizedException) { }
if (Config.assignmentNotifications)
{
try
{
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "You have been assigned to a support ticket: " + command.Channel.Mention
};
await staffMember.SendMessageAsync(message);
}
catch (UnauthorizedException) {}
}
}
// Log it if the log channel exists
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
if (logChannel != null)
{
DiscordEmbed logMessage = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = staffMember.Mention + " was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
};
await logChannel.SendMessageAsync(logMessage);
}
}
}
// Log it if the log channel exists
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
if (logChannel != null)
{
DiscordEmbed logMessage = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = staffMember.Mention + " was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
};
await logChannel.SendMessageAsync(logMessage);
}
}
}
}

View file

@ -8,92 +8,92 @@ using Microsoft.Extensions.Logging;
namespace SupportChild.Commands
{
public class BlacklistCommand : BaseCommandModule
{
[Command("blacklist")]
[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 (!Config.HasPermission(command.Member, "blacklist"))
{
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 blacklist command but did not have permission.");
return;
}
public class BlacklistCommand : BaseCommandModule
{
[Command("blacklist")]
[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 (!Config.HasPermission(command.Member, "blacklist"))
{
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 blacklist command but did not have permission.");
return;
}
string[] parsedArgs = Utilities.ParseIDs(command.RawArgumentString);
foreach (string parsedArg in parsedArgs)
{
if (ulong.TryParse(parsedArg, out ulong userId))
{
DiscordUser blacklistedUser = null;
try
{
blacklistedUser = await command.Client.GetUserAsync(userId);
}
catch (NotFoundException) { }
string[] parsedArgs = Utilities.ParseIDs(command.RawArgumentString);
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;
}
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;
}
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,
Description = "Blacklisted " + blacklistedUser.Mention + "."
};
await command.RespondAsync(message);
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Blacklisted " + blacklistedUser.Mention + "."
};
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 = blacklistedUser.Mention + " was blacklisted from opening tickets by " + command.Member.Mention + "."
};
await logChannel.SendMessageAsync(logMessage);
}
}
catch (Exception)
{
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error occured while blacklisting " + blacklistedUser.Mention + "."
};
await command.RespondAsync(message);
throw;
}
}
}
}
}
// 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 = blacklistedUser.Mention + " was blacklisted from opening tickets by " + command.Member.Mention + "."
};
await logChannel.SendMessageAsync(logMessage);
}
}
catch (Exception)
{
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error occured while blacklisting " + blacklistedUser.Mention + "."
};
await command.RespondAsync(message);
throw;
}
}
}
}
}
}

View file

@ -10,109 +10,109 @@ using Microsoft.Extensions.Logging;
namespace SupportChild.Commands
{
public class CloseCommand : BaseCommandModule
{
[Command("close")]
[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, "close"))
{
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 close command but did not have permission.");
return;
}
public class CloseCommand : BaseCommandModule
{
[Command("close")]
[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, "close"))
{
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 close command but did not have permission.");
return;
}
ulong channelID = command.Channel.Id;
string channelName = command.Channel.Name;
ulong channelID = command.Channel.Id;
string channelName = command.Channel.Name;
// Check if ticket exists in the database
if (!Database.TryGetOpenTicket(channelID, out Database.Ticket ticket))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "This channel is not a ticket."
};
await command.RespondAsync(error);
return;
}
// Check if ticket exists in the database
if (!Database.TryGetOpenTicket(channelID, out Database.Ticket ticket))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "This channel is not a ticket."
};
await command.RespondAsync(error);
return;
}
// Build transcript
try
{
await Transcriber.ExecuteAsync(command.Channel.Id, ticket.id);
}
catch (Exception)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "ERROR: Could not save transcript file. Aborting..."
};
await command.RespondAsync(error);
throw;
}
// Build transcript
try
{
await Transcriber.ExecuteAsync(command.Channel.Id, ticket.id);
}
catch (Exception)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "ERROR: Could not save transcript file. Aborting..."
};
await command.RespondAsync(error);
throw;
}
// Log it if the log channel exists
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
if (logChannel != null)
{
DiscordEmbed embed = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Ticket " + ticket.id.ToString("00000") + " closed by " + command.Member.Mention + ".\n",
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + channelName }
};
// Log it if the log channel exists
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
if (logChannel != null)
{
DiscordEmbed embed = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Ticket " + ticket.id.ToString("00000") + " closed by " + command.Member.Mention + ".\n",
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + channelName }
};
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 } });
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);
}
}
if (Config.closingNotifications)
{
DiscordEmbed embed = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Ticket " + ticket.id.ToString("00000") + " which you opened has now been closed, check the transcript for more info.\n",
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + channelName }
};
if (Config.closingNotifications)
{
DiscordEmbed embed = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Ticket " + ticket.id.ToString("00000") + " which you opened has now been closed, check the transcript for more info.\n",
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + channelName }
};
try
{
DiscordMember staffMember = await command.Guild.GetMemberAsync(ticket.creatorID);
try
{
DiscordMember staffMember = await command.Guild.GetMemberAsync(ticket.creatorID);
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 } });
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 staffMember.SendMessageAsync(message);
}
}
catch (NotFoundException) { }
catch (UnauthorizedException) { }
}
await staffMember.SendMessageAsync(message);
}
}
catch (NotFoundException) { }
catch (UnauthorizedException) { }
}
Database.ArchiveTicket(ticket);
Database.ArchiveTicket(ticket);
// Delete the channel and database entry
await command.Channel.DeleteAsync("Ticket closed.");
// Delete the channel and database entry
await command.Channel.DeleteAsync("Ticket closed.");
Database.DeleteOpenTicket(ticket.id);
}
}
Database.DeleteOpenTicket(ticket.id);
}
}
}

View file

@ -8,69 +8,69 @@ using Microsoft.Extensions.Logging;
namespace SupportChild.Commands
{
public class ListAssignedCommand : BaseCommandModule
{
[Command("listassigned")]
[Aliases("la")]
[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, "listassigned"))
{
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 listassigned command but did not have permission.");
return;
}
public class ListAssignedCommand : BaseCommandModule
{
[Command("listassigned")]
[Aliases("la")]
[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, "listassigned"))
{
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 listassigned command but did not have permission.");
return;
}
ulong staffID;
string[] parsedIDs = Utilities.ParseIDs(command.RawArgumentString);
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 (!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;
}
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;
}
List<string> listItems = new List<string>();
foreach (Database.Ticket ticket in assignedTickets)
{
listItems.Add("**" + ticket.FormattedCreatedTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
}
List<string> listItems = new List<string>();
foreach (Database.Ticket ticket in assignedTickets)
{
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("Assigned tickets: ")
.WithColor(DiscordColor.Green)
.WithDescription(message);
await command.RespondAsync(channelInfo);
}
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
foreach (string message in messages)
{
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
.WithTitle("Assigned tickets: ")
.WithColor(DiscordColor.Green)
.WithDescription(message);
await command.RespondAsync(channelInfo);
}
}
}
}
}
}

View file

@ -8,94 +8,94 @@ using Microsoft.Extensions.Logging;
namespace SupportChild.Commands
{
public class ListCommand : BaseCommandModule
{
[Command("list")]
[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;
}
public class ListCommand : BaseCommandModule
{
[Command("list")]
[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;
string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);
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;
}
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>();
foreach (Database.Ticket ticket in openTickets)
{
listItems.Add("**" + ticket.FormattedCreatedTime() + ":** <#" + ticket.channelID + ">\n");
}
if (Database.TryGetOpenTickets(userID, out List<Database.Ticket> openTickets))
{
List<string> listItems = new List<string>();
foreach (Database.Ticket ticket in openTickets)
{
listItems.Add("**" + ticket.FormattedCreatedTime() + ":** <#" + ticket.channelID + ">\n");
}
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
foreach (string message in messages)
{
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
.WithTitle("Open tickets: ")
.WithColor(DiscordColor.Green)
.WithDescription(message);
await command.RespondAsync(channelInfo);
}
}
else
{
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
.WithColor(DiscordColor.Green)
.WithDescription("User does not have any open tickets.");
await command.RespondAsync(channelInfo);
}
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
foreach (string message in messages)
{
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
.WithTitle("Open tickets: ")
.WithColor(DiscordColor.Green)
.WithDescription(message);
await command.RespondAsync(channelInfo);
}
}
else
{
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
.WithColor(DiscordColor.Green)
.WithDescription("User does not have any open tickets.");
await command.RespondAsync(channelInfo);
}
if (Database.TryGetClosedTickets(userID, out List<Database.Ticket> closedTickets))
{
List<string> listItems = new List<string>();
foreach (Database.Ticket ticket in closedTickets)
{
listItems.Add("**" + ticket.FormattedCreatedTime() + ":** Ticket " + ticket.id.ToString("00000") + "\n");
}
if (Database.TryGetClosedTickets(userID, out List<Database.Ticket> closedTickets))
{
List<string> listItems = new List<string>();
foreach (Database.Ticket ticket in closedTickets)
{
listItems.Add("**" + ticket.FormattedCreatedTime() + ":** Ticket " + ticket.id.ToString("00000") + "\n");
}
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
foreach (string message in messages)
{
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
.WithTitle("Closed tickets: ")
.WithColor(DiscordColor.Red)
.WithDescription(message);
await command.RespondAsync(channelInfo);
}
}
else
{
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
.WithColor(DiscordColor.Red)
.WithDescription("User does not have any closed tickets.");
await command.RespondAsync(channelInfo);
}
}
}
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
foreach (string message in messages)
{
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
.WithTitle("Closed tickets: ")
.WithColor(DiscordColor.Red)
.WithDescription(message);
await command.RespondAsync(channelInfo);
}
}
else
{
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
.WithColor(DiscordColor.Red)
.WithDescription("User does not have any closed tickets.");
await command.RespondAsync(channelInfo);
}
}
}
}

View file

@ -7,65 +7,65 @@ 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;
}
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 an integer between 5 and 100)"
};
await command.RespondAsync(error);
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;
}
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");
}
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);
}
}
}
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);
}
}
}
}

View file

@ -10,95 +10,95 @@ using Microsoft.Extensions.Logging;
namespace SupportChild.Commands
{
public class MoveCommand : BaseCommandModule
{
[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;
}
public class MoveCommand : BaseCommandModule
{
[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
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;
}
// 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;
}
if (string.IsNullOrEmpty(command.RawArgumentString))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: No category provided."
};
await command.RespondAsync(error);
return;
}
if (string.IsNullOrEmpty(command.RawArgumentString))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: No category provided."
};
await command.RespondAsync(error);
return;
}
IReadOnlyList<DiscordChannel> channels = await command.Guild.GetChannelsAsync();
IEnumerable<DiscordChannel> categories = channels.Where(x => x.IsCategory);
DiscordChannel category = categories.FirstOrDefault(x => x.Name.StartsWith(command.RawArgumentString.Trim(), StringComparison.OrdinalIgnoreCase));
IReadOnlyList<DiscordChannel> channels = await command.Guild.GetChannelsAsync();
IEnumerable<DiscordChannel> categories = channels.Where(x => x.IsCategory);
DiscordChannel category = categories.FirstOrDefault(x => x.Name.StartsWith(command.RawArgumentString.Trim(), StringComparison.OrdinalIgnoreCase));
if (category == null)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Could not find a category by that name."
};
await command.RespondAsync(error);
return;
}
if (category == null)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Could not find a category by that name."
};
await command.RespondAsync(error);
return;
}
if (command.Channel.Id == category.Id)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: The ticket is already in that category."
};
await command.RespondAsync(error);
return;
}
if (command.Channel.Id == category.Id)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: The ticket is already in that category."
};
await command.RespondAsync(error);
return;
}
try
{
await command.Channel.ModifyAsync(modifiedAttributes => modifiedAttributes.Parent = category);
}
catch (UnauthorizedException)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Not authorized to move this ticket to that category."
};
await command.RespondAsync(error);
return;
}
try
{
await command.Channel.ModifyAsync(modifiedAttributes => modifiedAttributes.Parent = category);
}
catch (UnauthorizedException)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Not authorized to move this ticket to that category."
};
await command.RespondAsync(error);
return;
}
DiscordEmbed feedback = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Ticket was moved to " + category.Mention
};
await command.RespondAsync(feedback);
}
}
DiscordEmbed feedback = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Ticket was moved to " + category.Mention
};
await command.RespondAsync(feedback);
}
}
}

View file

@ -9,142 +9,142 @@ using Microsoft.Extensions.Logging;
namespace SupportChild.Commands
{
public class NewCommand : BaseCommandModule
{
[Command("new")]
[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, "new"))
{
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 new command but did not have permission.");
return;
}
public class NewCommand : BaseCommandModule
{
[Command("new")]
[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, "new"))
{
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 new command but did not have permission.");
return;
}
// Check if user is blacklisted
if (Database.IsBlacklisted(command.User.Id))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "You are banned from opening tickets."
};
await command.RespondAsync(error);
return;
}
// Check if user is blacklisted
if (Database.IsBlacklisted(command.User.Id))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "You are banned from opening tickets."
};
await command.RespondAsync(error);
return;
}
if (Database.IsOpenTicket(command.Channel.Id))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "You cannot use this command in a ticket channel."
};
await command.RespondAsync(error);
return;
}
if (Database.IsOpenTicket(command.Channel.Id))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
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);
DiscordChannel ticketChannel;
DiscordChannel category = command.Guild.GetChannel(Config.ticketCategory);
DiscordChannel ticketChannel;
try
{
ticketChannel = await command.Guild.CreateChannelAsync("ticket", ChannelType.Text, category);
}
catch (Exception)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error occured while creating ticket, " + command.Member.Mention +
"!\nIs the channel limit reached in the server or ticket category?"
};
await command.RespondAsync(error);
return;
}
try
{
ticketChannel = await command.Guild.CreateChannelAsync("ticket", ChannelType.Text, category);
}
catch (Exception)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error occured while creating ticket, " + command.Member.Mention +
"!\nIs the channel limit reached in the server or ticket category?"
};
await command.RespondAsync(error);
return;
}
if (ticketChannel == null)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error occured while creating ticket, " + command.Member.Mention +
"!\nIs the channel limit reached in the server or ticket category?"
};
await command.RespondAsync(error);
return;
}
if (ticketChannel == null)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error occured while creating ticket, " + command.Member.Mention +
"!\nIs the channel limit reached in the server or ticket category?"
};
await command.RespondAsync(error);
return;
}
ulong staffID = 0;
if (Config.randomAssignment)
{
staffID = Database.GetRandomActiveStaff(0)?.userID ?? 0;
}
ulong staffID = 0;
if (Config.randomAssignment)
{
staffID = Database.GetRandomActiveStaff(0)?.userID ?? 0;
}
long id = Database.NewTicket(command.Member.Id, staffID, ticketChannel.Id);
string ticketID = id.ToString("00000");
await ticketChannel.ModifyAsync(modifiedAttributes => modifiedAttributes.Name = "ticket-" + ticketID);
await ticketChannel.AddOverwriteAsync(command.Member, Permissions.AccessChannels, Permissions.None);
long id = Database.NewTicket(command.Member.Id, staffID, ticketChannel.Id);
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);
await ticketChannel.SendMessageAsync("Hello, " + command.Member.Mention + "!\n" + Config.welcomeMessage);
// Refreshes the channel as changes were made to it above
ticketChannel = command.Guild.GetChannel(ticketChannel.Id);
// Refreshes the channel as changes were made to it above
ticketChannel = command.Guild.GetChannel(ticketChannel.Id);
if (staffID != 0)
{
DiscordEmbed assignmentMessage = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Ticket was randomly assigned to <@" + staffID + ">."
};
await ticketChannel.SendMessageAsync(assignmentMessage);
if (staffID != 0)
{
DiscordEmbed assignmentMessage = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Ticket was randomly assigned to <@" + staffID + ">."
};
await ticketChannel.SendMessageAsync(assignmentMessage);
if (Config.assignmentNotifications)
{
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "You have been randomly assigned to a newly opened support ticket: " +
ticketChannel.Mention
};
if (Config.assignmentNotifications)
{
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "You have been randomly assigned to a newly opened support ticket: " +
ticketChannel.Mention
};
try
{
DiscordMember staffMember = await command.Guild.GetMemberAsync(staffID);
await staffMember.SendMessageAsync(message);
}
catch (NotFoundException) { }
catch (UnauthorizedException) { }
}
}
try
{
DiscordMember staffMember = await command.Guild.GetMemberAsync(staffID);
await staffMember.SendMessageAsync(message);
}
catch (NotFoundException) {}
catch (UnauthorizedException) {}
}
}
DiscordEmbed response = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Ticket opened, " + command.Member.Mention + "!\n" + ticketChannel.Mention
};
await command.RespondAsync(response);
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
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
if (logChannel != null)
{
DiscordEmbed logMessage = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Ticket " + ticketChannel.Mention + " opened by " + command.Member.Mention + ".\n",
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "Ticket " + ticketID }
};
await logChannel.SendMessageAsync(logMessage);
}
}
}
// Log it if the log channel exists
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
if (logChannel != null)
{
DiscordEmbed logMessage = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Ticket " + ticketChannel.Mention + " opened by " + command.Member.Mention + ".\n",
Footer = new DiscordEmbedBuilder.EmbedFooter {Text = "Ticket " + ticketID}
};
await logChannel.SendMessageAsync(logMessage);
}
}
}
}

View file

@ -10,173 +10,173 @@ using Microsoft.Extensions.Logging;
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 : 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;
}
// 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;
}
// 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;
}
// Get a random staff member who is verified to have the correct role if applicable
DiscordMember staffMember = await GetRandomVerifiedStaffMember(command, ticket);
if (staffMember == null)
{
return;
}
// Get a random staff member who is verified to have the correct role if applicable
DiscordMember staffMember = await GetRandomVerifiedStaffMember(command, ticket);
if (staffMember == null)
{
return;
}
// Attempt to assign the staff member to the ticket
if (!Database.AssignStaff(ticket, staffMember.Id))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Failed to assign " + staffMember.Mention + " to ticket."
};
await command.RespondAsync(error);
return;
}
// Attempt to assign the staff member to the ticket
if (!Database.AssignStaff(ticket, staffMember.Id))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Failed to assign " + staffMember.Mention + " to ticket."
};
await command.RespondAsync(error);
return;
}
// Respond that the command was successful
DiscordEmbed feedback = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Randomly assigned " + staffMember.Mention + " to ticket."
};
await command.RespondAsync(feedback);
// Respond that the command was successful
DiscordEmbed feedback = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Randomly assigned " + staffMember.Mention + " to ticket."
};
await command.RespondAsync(feedback);
// Send a notification to the staff member if applicable
if (Config.assignmentNotifications)
{
try
{
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "You have been randomly assigned to a support ticket: " + command.Channel.Mention
};
await staffMember.SendMessageAsync(message);
}
catch (UnauthorizedException) { }
}
// Send a notification to the staff member if applicable
if (Config.assignmentNotifications)
{
try
{
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "You have been randomly assigned to a support ticket: " + command.Channel.Mention
};
await staffMember.SendMessageAsync(message);
}
catch (UnauthorizedException) {}
}
// Log it if the log channel exists
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
if (logChannel != null)
{
DiscordEmbed logMessage = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = staffMember.Mention + " was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
};
await logChannel.SendMessageAsync(logMessage);
}
}
// Log it if the log channel exists
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
if (logChannel != null)
{
DiscordEmbed logMessage = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = staffMember.Mention + " was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
};
await logChannel.SendMessageAsync(logMessage);
}
}
private async Task<DiscordMember> GetRandomVerifiedStaffMember(CommandContext command, Database.Ticket ticket)
{
if (command.RawArguments.Any()) // An argument was provided, check if this can be parsed into a role
{
ulong roleID = 0;
private async Task<DiscordMember> GetRandomVerifiedStaffMember(CommandContext command, Database.Ticket ticket)
{
if (command.RawArguments.Any()) // An argument was provided, check if this can be parsed into a role
{
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;
}
// 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 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
List<Database.StaffMember> staffMembers = Config.randomAssignRoleOverride
? Database.GetAllStaff(ticket.assignedStaffID)
: Database.GetActiveStaff(ticket.assignedStaffID);
// Check if role rassign should override staff's active status
List<Database.StaffMember> staffMembers = Config.randomAssignRoleOverride
? Database.GetAllStaff(ticket.assignedStaffID)
: Database.GetActiveStaff(ticket.assignedStaffID);
// Randomize the list before checking for roles in order to reduce number of API calls
staffMembers = Utilities.RandomizeList(staffMembers);
// Randomize the list before checking for roles in order to reduce number of API calls
staffMembers = Utilities.RandomizeList(staffMembers);
// Get the first staff member that has the role
foreach (Database.StaffMember sm in staffMembers)
{
try
{
DiscordMember verifiedMember = await command.Guild.GetMemberAsync(sm.userID);
if (verifiedMember?.Roles?.Any(role => role.Id == roleID) ?? false)
{
return verifiedMember;
}
}
catch (Exception e)
{
command.Client.Logger.Log(LogLevel.Information, e, "Error occured trying to find a staff member in the rassign command.");
}
}
}
else // No role was specified, any active staff will be picked
{
Database.StaffMember staffEntry = Database.GetRandomActiveStaff(ticket.assignedStaffID);
if (staffEntry == null)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: There are no other staff members to choose from."
};
await command.RespondAsync(error);
return null;
}
// Get the first staff member that has the role
foreach (Database.StaffMember sm in staffMembers)
{
try
{
DiscordMember verifiedMember = await command.Guild.GetMemberAsync(sm.userID);
if (verifiedMember?.Roles?.Any(role => role.Id == roleID) ?? false)
{
return verifiedMember;
}
}
catch (Exception e)
{
command.Client.Logger.Log(LogLevel.Information, e, "Error occured trying to find a staff member in the rassign command.");
}
}
}
else // No role was specified, any active staff will be picked
{
Database.StaffMember staffEntry = Database.GetRandomActiveStaff(ticket.assignedStaffID);
if (staffEntry == null)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: There are no other staff members to choose from."
};
await command.RespondAsync(error);
return null;
}
// Get the staff member from discord
try
{
return await command.Guild.GetMemberAsync(staffEntry.userID);
}
catch (NotFoundException) { }
}
// Get the staff member from discord
try
{
return await command.Guild.GetMemberAsync(staffEntry.userID);
}
catch (NotFoundException) { }
}
// Send a more generic error if we get to this point and still haven't found the staff member
DiscordEmbed err = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Could not find an applicable staff member."
};
await command.RespondAsync(err);
return null;
}
}
// Send a more generic error if we get to this point and still haven't found the staff member
DiscordEmbed err = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Could not find an applicable staff member."
};
await command.RespondAsync(err);
return null;
}
}
}

View file

@ -40,7 +40,7 @@ namespace SupportChild.Commands
return;
}
if (Database.RemoveMessage(identifier))
if(Database.RemoveMessage(identifier))
{
DiscordEmbed error = new DiscordEmbedBuilder
{

View file

@ -9,96 +9,96 @@ using MySql.Data.MySqlClient;
namespace SupportChild.Commands
{
public class RemoveStaffCommand : BaseCommandModule
{
[Command("removestaff")]
[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, "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;
}
public class RemoveStaffCommand : BaseCommandModule
{
[Command("removestaff")]
[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, "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);
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;
}
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;
}
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,
Description = "User is already not registered as staff."
};
await command.RespondAsync(error);
return;
}
if (!Database.IsStaff(userID))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "User is already not registered as staff."
};
await command.RespondAsync(error);
return;
}
using (MySqlConnection c = Database.GetConnection())
{
c.Open();
MySqlCommand deletion = new MySqlCommand(@"DELETE FROM staff WHERE user_id=@user_id", c);
deletion.Parameters.AddWithValue("@user_id", userID);
deletion.Prepare();
deletion.ExecuteNonQuery();
using (MySqlConnection c = Database.GetConnection())
{
c.Open();
MySqlCommand deletion = new MySqlCommand(@"DELETE FROM staff WHERE user_id=@user_id", c);
deletion.Parameters.AddWithValue("@user_id", userID);
deletion.Prepare();
deletion.ExecuteNonQuery();
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "User was removed from staff."
};
await command.RespondAsync(message);
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "User was removed from staff."
};
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 = "User was removed from staff.\n",
};
await logChannel.SendMessageAsync(logMessage);
}
}
}
}
// 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 = "User was removed from staff.\n",
};
await logChannel.SendMessageAsync(logMessage);
}
}
}
}
}

View file

@ -8,89 +8,89 @@ using System.Threading.Tasks;
namespace SupportChild.Commands
{
public class SayCommand : BaseCommandModule
{
[Command("say")]
[Cooldown(1, 2, CooldownBucketType.Channel)]
[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;
}
public class SayCommand : BaseCommandModule
{
[Command("say")]
[Cooldown(1, 2, CooldownBucketType.Channel)]
[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;
}
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);
}
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;
}
[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();
if (!messages.Any())
{
DiscordEmbed error = new DiscordEmbedBuilder()
.WithColor(DiscordColor.Red)
.WithDescription("There are no messages registered.");
await command.RespondAsync(error);
return;
}
List<Database.Message> messages = Database.GetAllMessages();
if (!messages.Any())
{
DiscordEmbed error = new DiscordEmbedBuilder()
.WithColor(DiscordColor.Red)
.WithDescription("There are no messages registered.");
await command.RespondAsync(error);
return;
}
List<string> listItems = new List<string>();
foreach (Database.Message message in messages)
{
listItems.Add("**" + message.identifier + "** Added by <@" + message.userID + ">\n");
}
List<string> listItems = new List<string>();
foreach (Database.Message message in messages)
{
listItems.Add("**" + message.identifier + "** Added by <@" + message.userID + ">\n");
}
LinkedList<string> listMessages = Utilities.ParseListIntoMessages(listItems);
foreach (string listMessage in listMessages)
{
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
.WithTitle("Available messages: ")
.WithColor(DiscordColor.Green)
.WithDescription(listMessage);
await command.RespondAsync(channelInfo);
}
}
}
LinkedList<string> listMessages = Utilities.ParseListIntoMessages(listItems);
foreach (string listMessage in listMessages)
{
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
.WithTitle("Available messages: ")
.WithColor(DiscordColor.Green)
.WithDescription(listMessage);
await command.RespondAsync(channelInfo);
}
}
}
}

View file

@ -8,91 +8,91 @@ 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;
}
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;
}
// 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);
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;
}
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);
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;
}
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);
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);
}
}
}
}
// 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);
}
}
}
}
}

View file

@ -8,71 +8,71 @@ using MySql.Data.MySqlClient;
namespace SupportChild.Commands
{
public class ToggleActiveCommand : BaseCommandModule
{
[Command("toggleactive")]
[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;
}
public class ToggleActiveCommand : BaseCommandModule
{
[Command("toggleactive")]
[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);
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;
}
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
if (!Database.TryGetStaff(staffID, out Database.StaffMember staffMember))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "You have not been registered as staff."
};
await command.RespondAsync(error);
return;
}
// Check if ticket exists in the database
if (!Database.TryGetStaff(staffID, out Database.StaffMember staffMember))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "You have not been registered as staff."
};
await command.RespondAsync(error);
return;
}
c.Open();
MySqlCommand update = new MySqlCommand(@"UPDATE staff SET active = @active WHERE user_id = @user_id", c);
update.Parameters.AddWithValue("@user_id", staffID);
update.Parameters.AddWithValue("@active", !staffMember.active);
update.Prepare();
update.ExecuteNonQuery();
c.Open();
MySqlCommand update = new MySqlCommand(@"UPDATE staff SET active = @active WHERE user_id = @user_id", c);
update.Parameters.AddWithValue("@user_id", staffID);
update.Parameters.AddWithValue("@active", !staffMember.active);
update.Prepare();
update.ExecuteNonQuery();
DiscordEmbed message = new DiscordEmbedBuilder
{
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."
};
await command.RespondAsync(message);
}
}
}
DiscordEmbed message = new DiscordEmbedBuilder
{
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."
};
await command.RespondAsync(message);
}
}
}
}

View file

@ -10,163 +10,163 @@ using Microsoft.Extensions.Logging;
namespace SupportChild.Commands
{
public class TranscriptCommand : BaseCommandModule
{
[Command("transcript")]
[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;
}
public class TranscriptCommand : BaseCommandModule
{
[Command("transcript")]
[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;
string strippedMessage = command.Message.Content.Replace(Config.prefix, "");
string[] parsedMessage = strippedMessage.Replace("<@!", "").Replace("<@", "").Replace(">", "").Split();
Database.Ticket ticket;
string strippedMessage = command.Message.Content.Replace(Config.prefix, "");
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))
{
try
{
await Transcriber.ExecuteAsync(command.Channel.Id, ticket.id);
}
catch (Exception)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "ERROR: Could not save transcript file. Aborting..."
};
await command.RespondAsync(error);
throw;
}
}
else
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "This channel is not a ticket."
};
await command.RespondAsync(error);
return;
}
}
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 there are no arguments use current channel
if (parsedMessage.Length < 2)
{
if (Database.TryGetOpenTicket(command.Channel.Id, out ticket))
{
try
{
await Transcriber.ExecuteAsync(command.Channel.Id, ticket.id);
}
catch (Exception)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "ERROR: Could not save transcript file. Aborting..."
};
await command.RespondAsync(error);
throw;
}
}
else
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "This channel is not a ticket."
};
await command.RespondAsync(error);
return;
}
}
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 (Database.TryGetOpenTicketByID(ticketID, out ticket) && ticket?.creatorID == command.Member.Id)
{
try
{
await Transcriber.ExecuteAsync(command.Channel.Id, ticket.id);
}
catch (Exception)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "ERROR: Could not save transcript file. Aborting..."
};
await command.RespondAsync(error);
throw;
}
// If the ticket is still open, generate a new fresh transcript
if (Database.TryGetOpenTicketByID(ticketID, out ticket) && ticket?.creatorID == command.Member.Id)
{
try
{
await Transcriber.ExecuteAsync(command.Channel.Id, ticket.id);
}
catch (Exception)
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "ERROR: Could not save transcript file. Aborting..."
};
await command.RespondAsync(error);
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.
else if (!Database.TryGetClosedTicket(ticketID, out ticket) || ticket?.creatorID != command.Member.Id && !Database.IsStaff(command.Member.Id))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
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)" : "")
};
await command.RespondAsync(error);
return;
}
}
}
// 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)))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
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)" : "")
};
await command.RespondAsync(error);
return;
}
}
// Log it if the log channel exists
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
if (logChannel != null)
{
DiscordEmbed embed = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Ticket " + ticket.id.ToString("00000") + " transcript generated by " + command.Member.Mention + ".\n",
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + command.Channel.Name }
};
// Log it if the log channel exists
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
if (logChannel != null)
{
DiscordEmbed embed = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Ticket " + ticket.id.ToString("00000") + " transcript generated by " + command.Member.Mention + ".\n",
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + command.Channel.Name }
};
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 } });
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
{
// Send transcript privately
DiscordEmbed directMessageEmbed = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Transcript generated, " + command.Member.Mention + "!\n"
};
try
{
// Send transcript privately
DiscordEmbed directMessageEmbed = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Transcript generated, " + command.Member.Mention + "!\n"
};
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 } });
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)
{
// Send transcript privately
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Not allowed to send direct message to you, " + command.Member.Mention + ", please check your privacy settings.\n"
};
await command.RespondAsync(error);
}
}
}
// Respond to message directly
DiscordEmbed response = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Transcript sent, " + command.Member.Mention + "!\n"
};
await command.RespondAsync(response);
}
catch (UnauthorizedException)
{
// Send transcript privately
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Not allowed to send direct message to you, " + command.Member.Mention + ", please check your privacy settings.\n"
};
await command.RespondAsync(error);
}
}
}
}

View file

@ -0,0 +1,71 @@
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using Microsoft.Extensions.Logging;
namespace SupportChild.Commands
{
public class UnassignCommand : BaseCommandModule
{
[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
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;
}
if (!Database.UnassignStaff(ticket))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Failed to unassign staff from ticket."
};
await command.RespondAsync(error);
return;
}
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Unassigned staff from 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 = "Staff was unassigned from " + command.Channel.Mention + " by " + command.Member.Mention + "."
};
await logChannel.SendMessageAsync(logMessage);
}
}
}
}

View file

@ -1,71 +0,0 @@
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using Microsoft.Extensions.Logging;
namespace SupportChild.Commands
{
public class UnassignCommand : BaseCommandModule
{
[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
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;
}
if (!Database.UnassignStaff(ticket))
{
DiscordEmbed error = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Failed to unassign staff from ticket."
};
await command.RespondAsync(error);
return;
}
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Unassigned staff from 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 = "Staff was unassigned from " + command.Channel.Mention + " by " + command.Member.Mention + "."
};
await logChannel.SendMessageAsync(logMessage);
}
}
}
}

View file

@ -8,92 +8,92 @@ using Microsoft.Extensions.Logging;
namespace SupportChild.Commands
{
public class UnblacklistCommand : BaseCommandModule
{
[Command("unblacklist")]
[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 (!Config.HasPermission(command.Member, "unblacklist"))
{
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 unblacklist command but did not have permission.");
return;
}
public class UnblacklistCommand : BaseCommandModule
{
[Command("unblacklist")]
[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 (!Config.HasPermission(command.Member, "unblacklist"))
{
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 unblacklist command but did not have permission.");
return;
}
string[] words = Utilities.ParseIDs(command.RawArgumentString);
foreach (string word in words)
{
if (ulong.TryParse(word, out ulong userId))
{
DiscordUser blacklistedUser = null;
try
{
blacklistedUser = await command.Client.GetUserAsync(userId);
}
catch (NotFoundException) { }
string[] words = Utilities.ParseIDs(command.RawArgumentString);
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;
}
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;
}
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,
Description = "Removed " + blacklistedUser.Mention + " from blacklist."
};
await command.RespondAsync(message);
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Removed " + blacklistedUser.Mention + " from blacklist."
};
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 = blacklistedUser.Mention + " was unblacklisted from opening tickets by " + command.Member.Mention + "."
};
await logChannel.SendMessageAsync(logMessage);
}
}
catch (Exception)
{
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error occured while removing " + blacklistedUser.Mention + " from blacklist."
};
await command.RespondAsync(message);
throw;
}
}
}
}
}
// 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 = blacklistedUser.Mention + " was unblacklisted from opening tickets by " + command.Member.Mention + "."
};
await logChannel.SendMessageAsync(logMessage);
}
}
catch (Exception)
{
DiscordEmbed message = new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error occured while removing " + blacklistedUser.Mention + " from blacklist."
};
await command.RespondAsync(message);
throw;
}
}
}
}
}
}

View file

@ -7,64 +7,64 @@ 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;
}
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;
}
// 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);
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);
}
}
}
}
// 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);
}
}
}
}
}