version 1.3.0
Development
This commit is contained in:
commit
afbb5cdfba
44 changed files with 3357 additions and 3431 deletions
26
.github/workflows/auto-approve.yml
vendored
Normal file
26
.github/workflows/auto-approve.yml
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
name: Auto approve
|
||||
|
||||
on: pull_request
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
auto-approve:
|
||||
|
||||
name: Auto approve Pull Request
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
# for hmarr/auto-approve-action to approve PRs
|
||||
permissions:
|
||||
pull-requests: write
|
||||
|
||||
# Only run this on the main repo
|
||||
if: github.event.pull_request.head.repo.full_name == 'EmotionChild/SupportChild'
|
||||
|
||||
steps:
|
||||
- name: Approve via actions
|
||||
uses: hmarr/auto-approve-action@v2.2.1
|
||||
if: github.actor == 'EmotionChild' || github.actor == 'dependabot[bot]'
|
||||
with:
|
||||
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
71
SupportChild/Commands/AddCategoryCommand.cs
Normal file
71
SupportChild/Commands/AddCategoryCommand.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
using System.Threading.Tasks;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class AddCategoryCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("addcategory", "Adds a category to the ticket bot letting users open tickets in them.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("Title", "The name to display on buttons and in selection boxes.")] string title, [Option("Category", "The category to add.")] DiscordChannel category)
|
||||
{
|
||||
if (!category.IsCategory)
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "That channel is not a category."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(title))
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Invalid category title specified."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Database.TryGetCategory(category.Id, out Database.Category _))
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "That category is already registered."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Database.TryGetCategory(title, out Database.Category _))
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "There is already a category with that title."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Database.AddCategory(title, category.Id))
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Category added."
|
||||
}, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: Failed adding the category to the database."
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,107 +1,82 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
{
|
||||
public class AddCommand : BaseCommandModule
|
||||
{
|
||||
[Command("add")]
|
||||
[Description("Adds a user to a ticket.")]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "add"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You do not have permission to use this command."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the add command but did not have permission.");
|
||||
return;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class AddCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("add", "Adds a user to a ticket")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("User", "User to add to ticket.")] DiscordUser user)
|
||||
{
|
||||
// Check if ticket exists in the database
|
||||
if (!Database.IsOpenTicket(command.Channel.Id))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "This channel is not a ticket."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
string[] parsedArgs = Utilities.ParseIDs(command.RawArgumentString);
|
||||
foreach (string parsedArg in parsedArgs)
|
||||
{
|
||||
if (!ulong.TryParse(parsedArg, out ulong userID))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Invalid ID/Mention. (Could not convert to numerical)"
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
continue;
|
||||
}
|
||||
|
||||
DiscordMember mentionedMember;
|
||||
DiscordMember member;
|
||||
try
|
||||
{
|
||||
mentionedMember = await command.Guild.GetMemberAsync(userID);
|
||||
member = (user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id));
|
||||
|
||||
if (member == null)
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Could not find that user in this server."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Invalid ID/Mention. (Could not find user on this server)"
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
continue;
|
||||
Description = "Could not find that user in this server."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await command.Channel.AddOverwriteAsync(mentionedMember, Permissions.AccessChannels, Permissions.None);
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
await command.Channel.AddOverwriteAsync(member, Permissions.AccessChannels);
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Added " + mentionedMember.Mention + " to ticket."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
Description = "Added " + member.Mention + " to ticket."
|
||||
});
|
||||
|
||||
// Log it if the log channel exists
|
||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = mentionedMember.Mention + " was added to " + command.Channel.Mention +
|
||||
Description = member.Mention + " was added to " + command.Channel.Mention +
|
||||
" by " + command.Member.Mention + "."
|
||||
};
|
||||
await logChannel.SendMessageAsync(logMessage);
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Could not add <@" + parsedArg + "> to ticket, unknown error occured."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
}
|
||||
}
|
||||
Description = "Could not add " + member.Mention + " to ticket, unknown error occured."
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,76 +1,53 @@
|
|||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DSharpPlus.Entities;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
{
|
||||
public class AddMessageCommand : BaseCommandModule
|
||||
{
|
||||
[Command("addmessage")]
|
||||
[Description("Adds a new message for the 'say' command.")]
|
||||
public async Task OnExecute(CommandContext command, string identifier, [RemainingText] string message)
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "addmessage"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You do not have permission to use this command."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the addmessage command but did not have permission.");
|
||||
return;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class AddMessageCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("addmessage", "Adds a new message for the 'say' command.")]
|
||||
public async Task OnExecute(InteractionContext command,
|
||||
[Option("Identifier", "The identifier word used in the /say command.")] string identifier,
|
||||
[Option("Message", "The message the /say command will return.")] string message)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "No message specified."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Database.TryGetMessage(identifier.ToLower(), out Database.Message _))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "There is already a message with that identifier."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Database.AddMessage(identifier, command.Member.Id, message))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Message added."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
}, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: Failed adding the message to the database."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,96 +1,67 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
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;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
ulong userID;
|
||||
string[] parsedArgs = Utilities.ParseIDs(commandArgs);
|
||||
|
||||
if (!parsedArgs.Any())
|
||||
public class AddStaffCommand : ApplicationCommandModule
|
||||
{
|
||||
userID = command.Member.Id;
|
||||
}
|
||||
else if (!ulong.TryParse(parsedArgs[0], out userID))
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("addstaff", "Adds a new staff member.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("User", "User to add to staff.")] DiscordUser user)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Invalid ID/Mention. (Could not convert to numerical)"
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordMember member;
|
||||
DiscordMember staffMember = null;
|
||||
try
|
||||
{
|
||||
member = await command.Guild.GetMemberAsync(userID);
|
||||
staffMember = user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id);
|
||||
|
||||
if (staffMember == null)
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Could not find that user in this server."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Invalid ID/Mention. (Could not find user on this server)"
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
Description = "Could not find that user in this server."
|
||||
}, true);
|
||||
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);
|
||||
await using MySqlConnection c = Database.GetConnection();
|
||||
MySqlCommand cmd = Database.IsStaff(staffMember.Id) ? new MySqlCommand(@"UPDATE staff SET name = @name WHERE user_id = @user_id", c) : new MySqlCommand(@"INSERT INTO staff (user_id, name) VALUES (@user_id, @name);", c);
|
||||
|
||||
c.Open();
|
||||
cmd.Parameters.AddWithValue("@user_id", userID);
|
||||
cmd.Parameters.AddWithValue("@name", member.DisplayName);
|
||||
cmd.Parameters.AddWithValue("@user_id", staffMember.Id);
|
||||
cmd.Parameters.AddWithValue("@name", staffMember.DisplayName);
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Dispose();
|
||||
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = member.Mention + " was added to staff."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
Description = staffMember.Mention + " was added to staff."
|
||||
});
|
||||
|
||||
// Log it if the log channel exists
|
||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = member.Mention + " was added to staff.\n",
|
||||
};
|
||||
await logChannel.SendMessageAsync(logMessage);
|
||||
}
|
||||
}
|
||||
Description = staffMember.Mention + " was added to staff.\n"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
200
SupportChild/Commands/AdminCommands.cs
Normal file
200
SupportChild/Commands/AdminCommands.cs
Normal file
|
@ -0,0 +1,200 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.Interactivity;
|
||||
using DSharpPlus.Interactivity.Extensions;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
[SlashCommandGroup("admin", "Administrative commands.")]
|
||||
public class AdminCommands : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("listinvalid", "List tickets which channels have been deleted. Use /admin unsetticket <id> to remove them.")]
|
||||
public async Task ListInvalid(InteractionContext command)
|
||||
{
|
||||
if (!Database.TryGetOpenTickets(out List<Database.Ticket> openTickets))
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Could not get any open tickets from database."
|
||||
}, true);
|
||||
}
|
||||
|
||||
// Get all channels in all guilds the bot is part of
|
||||
List<DiscordChannel> allChannels = new List<DiscordChannel>();
|
||||
foreach (KeyValuePair<ulong, DiscordGuild> guild in SupportChild.discordClient.Guilds)
|
||||
{
|
||||
try
|
||||
{
|
||||
allChannels.AddRange(await guild.Value.GetChannelsAsync());
|
||||
}
|
||||
catch (Exception) { /*ignored*/ }
|
||||
}
|
||||
|
||||
// Check which tickets channels no longer exist
|
||||
List<string> listItems = new List<string>();
|
||||
foreach (Database.Ticket ticket in openTickets)
|
||||
{
|
||||
if (allChannels.All(channel => channel.Id != ticket.channelID))
|
||||
{
|
||||
listItems.Add("ID: **" + ticket.id.ToString("00000") + ":** <#" + ticket.channelID + ">\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (listItems.Count == 0)
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "All tickets are valid!"
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||
{
|
||||
embeds.Add(new DiscordEmbedBuilder
|
||||
{
|
||||
Title = "Invalid tickets:",
|
||||
Color = DiscordColor.Red,
|
||||
Description = message
|
||||
});
|
||||
}
|
||||
|
||||
// Add the footers
|
||||
for (int i = 0; i < embeds.Count; i++)
|
||||
{
|
||||
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||
{
|
||||
Text = $"Page {i + 1} / {embeds.Count}"
|
||||
};
|
||||
}
|
||||
|
||||
List<Page> listPages = new List<Page>();
|
||||
foreach (DiscordEmbedBuilder embed in embeds)
|
||||
{
|
||||
listPages.Add(new Page("", embed));
|
||||
}
|
||||
|
||||
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||
}
|
||||
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("setticket", "Turns a channel into a ticket WARNING: Anyone will be able to delete the channel using /close.")]
|
||||
public async Task SetTicket(InteractionContext command, [Option("User", "(Optional) The owner of the ticket.")] DiscordUser user = null)
|
||||
{
|
||||
// Check if ticket exists in the database
|
||||
if (Database.IsOpenTicket(command.Channel.Id))
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "This channel is already a ticket."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordUser ticketUser = (user == null ? command.User : user);
|
||||
|
||||
long id = Database.NewTicket(ticketUser.Id, 0, command.Channel.Id);
|
||||
string ticketID = id.ToString("00000");
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Channel has been designated ticket " + ticketID + "."
|
||||
});
|
||||
|
||||
// Log it if the log channel exists
|
||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = command.Channel.Mention + " has been designated ticket " + ticketID + " by " + command.Member.Mention + "."
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("unsetticket", "Deletes a ticket from the ticket system without deleting the channel.")]
|
||||
public async Task UnsetTicket(InteractionContext command, [Option("TicketID", "(Optional) Ticket to unset. Uses the channel you are in by default.")] long ticketID = 0)
|
||||
{
|
||||
Database.Ticket ticket;
|
||||
|
||||
if (ticketID == 0)
|
||||
{
|
||||
// Check if ticket exists in the database
|
||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out ticket))
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "This channel is not a ticket!"
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if ticket exists in the database
|
||||
if (!Database.TryGetOpenTicketByID((uint)ticketID, out ticket))
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "There is no ticket with this ticket ID."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (Database.DeleteOpenTicket(ticket.id))
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Channel has been undesignated as a ticket."
|
||||
});
|
||||
|
||||
// Log it if the log channel exists
|
||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = command.Channel.Mention + " has been undesignated as a ticket by " + command.Member.Mention + "."
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: Failed removing ticket from database."
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
|
||||
[SlashCommand("reload", "Reloads the bot config.")]
|
||||
public async Task Reload(InteractionContext command)
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Reloading bot application..."
|
||||
});
|
||||
Logger.Log("Reloading bot...");
|
||||
SupportChild.Reload();
|
||||
}
|
||||
}
|
|
@ -1,135 +1,102 @@
|
|||
using System.Linq;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class AssignCommand : ApplicationCommandModule
|
||||
{
|
||||
public class AssignCommand : BaseCommandModule
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("assign", "Assigns a staff member to this ticket.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) User to assign to this ticket.")] DiscordUser user = null)
|
||||
{
|
||||
[Command("assign")]
|
||||
[Description("Assigns a staff member to a ticket.")]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
DiscordMember member = null;
|
||||
try
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "assign"))
|
||||
member = user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id);
|
||||
|
||||
if (member == null)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(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.");
|
||||
Description = "Could not find that user in this server."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Could not find that user in this server."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if ticket exists in the database
|
||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "This channel is not a ticket."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
ulong staffID;
|
||||
string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);
|
||||
|
||||
if (!parsedMessage.Any())
|
||||
if (!Database.IsStaff(member.Id))
|
||||
{
|
||||
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) { }
|
||||
|
||||
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
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: User is not registered as staff."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Database.AssignStaff(ticket, staffID))
|
||||
if (!Database.AssignStaff(ticket, member.Id))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: Failed to assign " + staffMember.Mention + " to ticket."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
Description = "Error: Failed to assign " + member.Mention + " to ticket."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordEmbed feedback = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Assigned " + staffMember.Mention + " to ticket."
|
||||
};
|
||||
await command.RespondAsync(feedback);
|
||||
Description = "Assigned " + member.Mention + " to ticket."
|
||||
});
|
||||
|
||||
if (Config.assignmentNotifications)
|
||||
{
|
||||
try
|
||||
{
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
await member.SendMessageAsync(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
|
||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = staffMember.Mention + " was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
||||
};
|
||||
await logChannel.SendMessageAsync(logMessage);
|
||||
}
|
||||
Description = member.Mention + " was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,99 +1,54 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class BlacklistCommand : ApplicationCommandModule
|
||||
{
|
||||
public class BlacklistCommand : BaseCommandModule
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("blacklist", "Blacklists a user from opening tickets.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("User", "User to blacklist.")] DiscordUser user)
|
||||
{
|
||||
[Command("blacklist")]
|
||||
[Description("Blacklists a user from opening tickets.")]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
try
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "blacklist"))
|
||||
if (!Database.Blacklist(user.Id, command.User.Id))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(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.");
|
||||
Description = user.Mention + " is already blacklisted."
|
||||
}, true);
|
||||
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) { }
|
||||
|
||||
if (blacklistedUser == null)
|
||||
{
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: Could not find user."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!Database.Blacklist(blacklistedUser.Id, command.User.Id))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = blacklistedUser.Mention + " is already blacklisted."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
continue;
|
||||
}
|
||||
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Blacklisted " + blacklistedUser.Mention + "."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
Description = "Blacklisted " + user.Mention + "."
|
||||
}, true);
|
||||
|
||||
// Log it if the log channel exists
|
||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = blacklistedUser.Mention + " was blacklisted from opening tickets by " + command.Member.Mention + "."
|
||||
};
|
||||
await logChannel.SendMessageAsync(logMessage);
|
||||
Description = user.Mention + " was blacklisted from opening tickets by " + command.Member.Mention + "."
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error occured while blacklisting " + blacklistedUser.Mention + "."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
Description = "Error occured while blacklisting " + user.Mention + "."
|
||||
}, true);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,84 +2,94 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class CloseCommand : ApplicationCommandModule
|
||||
{
|
||||
public class CloseCommand : BaseCommandModule
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("close", "Closes a ticket.")]
|
||||
public async Task OnExecute(InteractionContext command)
|
||||
{
|
||||
[Command("close")]
|
||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
// Check if ticket exists in the database
|
||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket _))
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "close"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(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.");
|
||||
Description = "This channel is not a ticket."
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
ulong channelID = command.Channel.Id;
|
||||
string channelName = command.Channel.Name;
|
||||
DiscordInteractionResponseBuilder confirmation = new DiscordInteractionResponseBuilder()
|
||||
.AddEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Cyan,
|
||||
Description = "Are you sure you wish to close this ticket? You cannot re-open it again later."
|
||||
})
|
||||
.AddComponents(new DiscordButtonComponent(ButtonStyle.Danger, "supportboi_closeconfirm", "Confirm"));
|
||||
|
||||
|
||||
await command.CreateResponseAsync(confirmation);
|
||||
}
|
||||
|
||||
public static async Task OnConfirmed(DiscordInteraction interaction)
|
||||
{
|
||||
await interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate);
|
||||
ulong channelID = interaction.Channel.Id;
|
||||
string channelName = interaction.Channel.Name;
|
||||
|
||||
// Check if ticket exists in the database
|
||||
if (!Database.TryGetOpenTicket(channelID, out Database.Ticket ticket))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(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);
|
||||
await Transcriber.ExecuteAsync(interaction.Channel.Id, ticket.id);
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception e)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
Logger.Error("Exception occured when trying to save transcript while closing ticket: " + e);
|
||||
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "ERROR: Could not save transcript file. Aborting..."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
throw;
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
// Log it if the log channel exists
|
||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||
DiscordChannel logChannel = interaction.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",
|
||||
Description = "Ticket " + ticket.id.ToString("00000") + " closed by " + interaction.User.Mention + ".\n",
|
||||
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + channelName }
|
||||
};
|
||||
|
||||
using (FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
|
||||
DiscordMessageBuilder message = new DiscordMessageBuilder();
|
||||
message.WithEmbed(embed);
|
||||
message.WithFiles(new Dictionary<string, Stream>() { { Transcriber.GetFilename(ticket.id), file } });
|
||||
message.WithFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||
|
||||
await logChannel.SendMessageAsync(message);
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.closingNotifications)
|
||||
{
|
||||
|
@ -92,27 +102,33 @@ namespace SupportChild.Commands
|
|||
|
||||
try
|
||||
{
|
||||
DiscordMember staffMember = await command.Guild.GetMemberAsync(ticket.creatorID);
|
||||
DiscordMember staffMember = await interaction.Guild.GetMemberAsync(ticket.creatorID);
|
||||
await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
|
||||
|
||||
using (FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
DiscordMessageBuilder message = new DiscordMessageBuilder();
|
||||
message.WithEmbed(embed);
|
||||
message.WithFiles(new Dictionary<string, Stream>() { { Transcriber.GetFilename(ticket.id), file } });
|
||||
message.WithFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||
|
||||
await staffMember.SendMessageAsync(message);
|
||||
}
|
||||
}
|
||||
catch (NotFoundException) { }
|
||||
catch (UnauthorizedException) { }
|
||||
}
|
||||
|
||||
Database.ArchiveTicket(ticket);
|
||||
|
||||
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Channel will be deleted in 3 seconds..."
|
||||
}));
|
||||
|
||||
|
||||
await Task.Delay(3000);
|
||||
|
||||
// Delete the channel and database entry
|
||||
await command.Channel.DeleteAsync("Ticket closed.");
|
||||
await interaction.Channel.DeleteAsync("Ticket closed.");
|
||||
|
||||
Database.DeleteOpenTicket(ticket.id);
|
||||
}
|
||||
}
|
||||
}
|
81
SupportChild/Commands/CreateButtonPanelCommand.cs
Normal file
81
SupportChild/Commands/CreateButtonPanelCommand.cs
Normal file
|
@ -0,0 +1,81 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class CreateButtonPanelCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("createbuttonpanel", "Creates a series of buttons which users can use to open new tickets in specific categories.")]
|
||||
public async Task OnExecute(InteractionContext command)
|
||||
{
|
||||
DiscordMessageBuilder builder = new DiscordMessageBuilder().WithContent(" ");
|
||||
List<Database.Category> verifiedCategories = await Utilities.GetVerifiedChannels();
|
||||
|
||||
if (verifiedCategories.Count == 0)
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: No registered categories found."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList();
|
||||
|
||||
int nrOfButtons = 0;
|
||||
for (int nrOfButtonRows = 0; nrOfButtonRows < 5 && nrOfButtons < verifiedCategories.Count; nrOfButtonRows++)
|
||||
{
|
||||
List<DiscordButtonComponent> buttonRow = new List<DiscordButtonComponent>();
|
||||
|
||||
for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < verifiedCategories.Count; nrOfButtons++)
|
||||
{
|
||||
buttonRow.Add(new DiscordButtonComponent(ButtonStyle.Primary, "supportboi_newticketbutton " + verifiedCategories[nrOfButtons].id, verifiedCategories[nrOfButtons].name));
|
||||
}
|
||||
builder.AddComponents(buttonRow);
|
||||
}
|
||||
|
||||
await command.Channel.SendMessageAsync(builder);
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Successfully created message, make sure to run this command again if you add new categories to the bot."
|
||||
}, true);
|
||||
}
|
||||
|
||||
public static async Task OnButtonUsed(DiscordInteraction interaction)
|
||||
{
|
||||
await interaction.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral());
|
||||
|
||||
if (!ulong.TryParse(interaction.Data.CustomId.Replace("supportboi_newticketbutton ", ""), out ulong categoryID) || categoryID == 0)
|
||||
{
|
||||
Logger.Warn("Invalid ID: " + interaction.Data.CustomId.Replace("supportboi_newticketbutton ", ""));
|
||||
return;
|
||||
}
|
||||
|
||||
(bool success, string message) = await NewCommand.OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID);
|
||||
|
||||
if (success)
|
||||
{
|
||||
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = message
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = message
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
79
SupportChild/Commands/CreateSelectionBoxPanelCommand.cs
Normal file
79
SupportChild/Commands/CreateSelectionBoxPanelCommand.cs
Normal file
|
@ -0,0 +1,79 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class CreateSelectionBoxPanelCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("createselectionboxpanel", "Creates a selection box which users can use to open new tickets in specific categories.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("Message", "(Optional) The message to show in the selection box.")] string message = null)
|
||||
{
|
||||
DiscordMessageBuilder builder = new DiscordMessageBuilder()
|
||||
.WithContent(" ")
|
||||
.AddComponents(await GetSelectComponents(command, message ?? "Open new ticket..."));
|
||||
|
||||
await command.Channel.SendMessageAsync(builder);
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Successfully created message, make sure to run this command again if you add new categories to the bot."
|
||||
}, true);
|
||||
}
|
||||
|
||||
public static async Task<List<DiscordSelectComponent>> GetSelectComponents(InteractionContext command, string placeholder)
|
||||
{
|
||||
List<Database.Category> verifiedCategories = await Utilities.GetVerifiedChannels();
|
||||
|
||||
if (verifiedCategories.Count == 0) return new List<DiscordSelectComponent>();
|
||||
|
||||
verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList();
|
||||
List<DiscordSelectComponent> selectionComponents = new List<DiscordSelectComponent>();
|
||||
int selectionOptions = 0;
|
||||
for (int selectionBoxes = 0; selectionBoxes < 5 && selectionOptions < verifiedCategories.Count; selectionBoxes++)
|
||||
{
|
||||
List<DiscordSelectComponentOption> categoryOptions = new List<DiscordSelectComponentOption>();
|
||||
|
||||
for (; selectionOptions < 25 * (selectionBoxes + 1) && selectionOptions < verifiedCategories.Count; selectionOptions++)
|
||||
{
|
||||
categoryOptions.Add(new DiscordSelectComponentOption(verifiedCategories[selectionOptions].name, verifiedCategories[selectionOptions].id.ToString()));
|
||||
}
|
||||
selectionComponents.Add(new DiscordSelectComponent("supportboi_newticketselector" + selectionBoxes, placeholder, categoryOptions, false, 0, 1));
|
||||
}
|
||||
|
||||
return selectionComponents;
|
||||
}
|
||||
|
||||
public static async Task OnSelectionMenuUsed(DiscordInteraction interaction)
|
||||
{
|
||||
if (interaction.Data.Values == null || interaction.Data.Values.Length <= 0) return;
|
||||
|
||||
if (!ulong.TryParse(interaction.Data.Values[0], out ulong categoryID) || categoryID == 0) return;
|
||||
|
||||
await interaction.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral());
|
||||
|
||||
(bool success, string message) = await NewCommand.OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID);
|
||||
|
||||
if (success)
|
||||
{
|
||||
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = message
|
||||
}).AsEphemeral());
|
||||
}
|
||||
else
|
||||
{
|
||||
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = message
|
||||
}).AsEphemeral());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,76 +1,63 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.Interactivity;
|
||||
using DSharpPlus.Interactivity.Extensions;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class ListAssignedCommand : ApplicationCommandModule
|
||||
{
|
||||
public class ListAssignedCommand : BaseCommandModule
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("listassigned", "Lists tickets assigned to a user.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) User to list tickets for.")] DiscordUser user = null)
|
||||
{
|
||||
[Command("listassigned")]
|
||||
[Aliases("la")]
|
||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
DiscordUser listUser = user == null ? command.User : user;
|
||||
|
||||
if (!Database.TryGetAssignedTickets(listUser.Id, out List<Database.Ticket> assignedTickets))
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "listassigned"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(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);
|
||||
|
||||
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);
|
||||
Description = "User does not have any assigned tickets."
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> listItems = new List<string>();
|
||||
foreach (Database.Ticket ticket in assignedTickets)
|
||||
{
|
||||
listItems.Add("**" + ticket.FormattedCreatedTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
||||
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
||||
}
|
||||
|
||||
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
|
||||
foreach (string message in messages)
|
||||
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||
{
|
||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
||||
.WithTitle("Assigned tickets: ")
|
||||
.WithColor(DiscordColor.Green)
|
||||
.WithDescription(message);
|
||||
await command.RespondAsync(channelInfo);
|
||||
embeds.Add(new DiscordEmbedBuilder
|
||||
{
|
||||
Title = "Assigned tickets: ",
|
||||
Color = DiscordColor.Green,
|
||||
Description = message
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
// Add the footers
|
||||
for (int i = 0; i < embeds.Count; i++)
|
||||
{
|
||||
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||
{
|
||||
Text = $"Page {i + 1} / {embeds.Count}"
|
||||
};
|
||||
}
|
||||
|
||||
List<Page> listPages = new List<Page>();
|
||||
foreach (DiscordEmbedBuilder embed in embeds)
|
||||
{
|
||||
listPages.Add(new Page("", embed));
|
||||
}
|
||||
|
||||
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||
}
|
||||
}
|
|
@ -1,101 +1,99 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.Interactivity;
|
||||
using DSharpPlus.Interactivity.Extensions;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
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;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
ulong userID;
|
||||
string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);
|
||||
public class ListCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("list", "Lists tickets opened by a user.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) The user to get tickets by.")] DiscordUser user = null)
|
||||
{
|
||||
DiscordUser listUser = user == null ? command.User : user;
|
||||
|
||||
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<DiscordEmbedBuilder> openEmbeds = new List<DiscordEmbedBuilder>();
|
||||
if (Database.TryGetOpenTickets(listUser.Id, out List<Database.Ticket> openTickets))
|
||||
{
|
||||
List<string> listItems = new List<string>();
|
||||
foreach (Database.Ticket ticket in openTickets)
|
||||
{
|
||||
listItems.Add("**" + ticket.FormattedCreatedTime() + ":** <#" + ticket.channelID + ">\n");
|
||||
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + ">\n");
|
||||
}
|
||||
|
||||
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
|
||||
foreach (string message in messages)
|
||||
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||
{
|
||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
||||
.WithTitle("Open tickets: ")
|
||||
.WithColor(DiscordColor.Green)
|
||||
.WithDescription(message);
|
||||
await command.RespondAsync(channelInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
openEmbeds.Add(new DiscordEmbedBuilder
|
||||
{
|
||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
||||
.WithColor(DiscordColor.Green)
|
||||
.WithDescription("User does not have any open tickets.");
|
||||
await command.RespondAsync(channelInfo);
|
||||
Color = DiscordColor.Green,
|
||||
Description = message
|
||||
});
|
||||
}
|
||||
|
||||
if (Database.TryGetClosedTickets(userID, out List<Database.Ticket> closedTickets))
|
||||
// Add the titles
|
||||
for (int i = 0; i < openEmbeds.Count; i++)
|
||||
{
|
||||
openEmbeds[i].Title = $"Open tickets ({i + 1}/{openEmbeds.Count})";
|
||||
}
|
||||
}
|
||||
|
||||
List<DiscordEmbedBuilder> closedEmbeds = new List<DiscordEmbedBuilder>();
|
||||
if (Database.TryGetClosedTickets(listUser.Id, out List<Database.Ticket> closedTickets))
|
||||
{
|
||||
List<string> listItems = new List<string>();
|
||||
foreach (Database.Ticket ticket in closedTickets)
|
||||
{
|
||||
listItems.Add("**" + ticket.FormattedCreatedTime() + ":** Ticket " + ticket.id.ToString("00000") + "\n");
|
||||
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** Ticket " + ticket.id.ToString("00000") + "\n");
|
||||
}
|
||||
|
||||
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
|
||||
foreach (string message in messages)
|
||||
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||
{
|
||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
||||
.WithTitle("Closed tickets: ")
|
||||
.WithColor(DiscordColor.Red)
|
||||
.WithDescription(message);
|
||||
await command.RespondAsync(channelInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
closedEmbeds.Add(new DiscordEmbedBuilder
|
||||
{
|
||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
||||
.WithColor(DiscordColor.Red)
|
||||
.WithDescription("User does not have any closed tickets.");
|
||||
await command.RespondAsync(channelInfo);
|
||||
Color = DiscordColor.Red,
|
||||
Description = message
|
||||
});
|
||||
}
|
||||
|
||||
// Add the titles
|
||||
for (int i = 0; i < closedEmbeds.Count; i++)
|
||||
{
|
||||
closedEmbeds[i].Title = $"Closed tickets ({i + 1}/{closedEmbeds.Count})";
|
||||
}
|
||||
}
|
||||
|
||||
// Merge the embed lists and add the footers
|
||||
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||
embeds.AddRange(openEmbeds);
|
||||
embeds.AddRange(closedEmbeds);
|
||||
for (int i = 0; i < embeds.Count; i++)
|
||||
{
|
||||
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||
{
|
||||
Text = $"Page {i + 1} / {embeds.Count}"
|
||||
};
|
||||
}
|
||||
|
||||
if (embeds.Count == 0)
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Cyan,
|
||||
Description = "User does not have any open or closed tickets."
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
List<Page> listPages = new List<Page>();
|
||||
foreach (DiscordEmbedBuilder embed in embeds)
|
||||
{
|
||||
listPages.Add(new Page("", embed));
|
||||
}
|
||||
|
||||
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
{
|
||||
public class ListOldestCommand : BaseCommandModule
|
||||
{
|
||||
[Command("listoldest")]
|
||||
[Aliases("lo")]
|
||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "listoldest"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You do not have permission to use this command."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the listoldest command but did not have permission.");
|
||||
return;
|
||||
}
|
||||
|
||||
int listLimit = 20;
|
||||
if (!string.IsNullOrEmpty(command.RawArgumentString?.Trim() ?? ""))
|
||||
{
|
||||
if (!int.TryParse(command.RawArgumentString?.Trim(), out listLimit) || listLimit < 5 || listLimit > 100)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Invalid list amount. (Must be integer between 5 and 100)"
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Database.TryGetOldestTickets(command.Member.Id, out List<Database.Ticket> openTickets, listLimit))
|
||||
{
|
||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
||||
.WithColor(DiscordColor.Red)
|
||||
.WithDescription("Could not fetch any open tickets.");
|
||||
await command.RespondAsync(channelInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> listItems = new List<string>();
|
||||
foreach (Database.Ticket ticket in openTickets)
|
||||
{
|
||||
listItems.Add("**" + ticket.FormattedCreatedTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
||||
}
|
||||
|
||||
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
|
||||
foreach (string message in messages)
|
||||
{
|
||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
||||
.WithTitle("The " + openTickets.Count + " oldest open tickets: ")
|
||||
.WithColor(DiscordColor.Green)
|
||||
.WithDescription(message?.Trim());
|
||||
await command.RespondAsync(channelInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
SupportChild/Commands/ListOpen.cs
Normal file
60
SupportChild/Commands/ListOpen.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.Interactivity;
|
||||
using DSharpPlus.Interactivity.Extensions;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class ListOpen : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("listopen", "Lists all open tickets, oldest first.")]
|
||||
public async Task OnExecute(InteractionContext command)
|
||||
{
|
||||
if (!Database.TryGetOpenTickets(out List<Database.Ticket> openTickets))
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Could not fetch any open tickets."
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> listItems = new List<string>();
|
||||
foreach (Database.Ticket ticket in openTickets)
|
||||
{
|
||||
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
||||
}
|
||||
|
||||
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||
{
|
||||
embeds.Add(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = message
|
||||
});
|
||||
}
|
||||
|
||||
// Add the footers
|
||||
for (int i = 0; i < embeds.Count; i++)
|
||||
{
|
||||
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||
{
|
||||
Text = $"Page {i + 1} / {embeds.Count}"
|
||||
};
|
||||
}
|
||||
|
||||
List<Page> listPages = new List<Page>();
|
||||
foreach (DiscordEmbedBuilder embed in embeds)
|
||||
{
|
||||
listPages.Add(new Page("", embed));
|
||||
}
|
||||
|
||||
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||
}
|
||||
}
|
|
@ -1,55 +1,61 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.Interactivity;
|
||||
using DSharpPlus.Interactivity.Extensions;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
{
|
||||
public class ListUnassignedCommand : BaseCommandModule
|
||||
{
|
||||
[Command("listunassigned")]
|
||||
[Aliases("lu")]
|
||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "listunassigned"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You do not have permission to use this command."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the listunassigned command but did not have permission.");
|
||||
return;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class ListUnassignedCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("listunassigned", "Lists unassigned tickets.")]
|
||||
public async Task OnExecute(InteractionContext command)
|
||||
{
|
||||
if (!Database.TryGetAssignedTickets(0, out List<Database.Ticket> unassignedTickets))
|
||||
{
|
||||
DiscordEmbed response = new DiscordEmbedBuilder()
|
||||
.WithColor(DiscordColor.Green)
|
||||
.WithDescription("There are no unassigned tickets.");
|
||||
await command.RespondAsync(response);
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "There are no unassigned tickets."
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> listItems = new List<string>();
|
||||
foreach (Database.Ticket ticket in unassignedTickets)
|
||||
{
|
||||
listItems.Add("**" + ticket.FormattedCreatedTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
||||
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
|
||||
}
|
||||
|
||||
LinkedList<string> messages = Utilities.ParseListIntoMessages(listItems);
|
||||
foreach (string message in messages)
|
||||
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();
|
||||
foreach (string message in Utilities.ParseListIntoMessages(listItems))
|
||||
{
|
||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
||||
.WithTitle("Unassigned tickets: ")
|
||||
.WithColor(DiscordColor.Green)
|
||||
.WithDescription(message?.Trim());
|
||||
await command.RespondAsync(channelInfo);
|
||||
}
|
||||
}
|
||||
embeds.Add(new DiscordEmbedBuilder
|
||||
{
|
||||
Title = "Unassigned tickets: ",
|
||||
Color = DiscordColor.Green,
|
||||
Description = message
|
||||
});
|
||||
}
|
||||
|
||||
// Add the footers
|
||||
for (int i = 0; i < embeds.Count; i++)
|
||||
{
|
||||
embeds[i].Footer = new DiscordEmbedBuilder.EmbedFooter
|
||||
{
|
||||
Text = $"Page {i + 1} / {embeds.Count}"
|
||||
};
|
||||
}
|
||||
|
||||
List<Page> listPages = new List<Page>();
|
||||
foreach (DiscordEmbedBuilder embed in embeds)
|
||||
{
|
||||
listPages.Add(new Page("", embed));
|
||||
}
|
||||
|
||||
await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages);
|
||||
}
|
||||
}
|
|
@ -2,103 +2,82 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
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;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class MoveCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("move", "Moves a ticket to another category.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("Category", "The category to move the ticket to. Only has to be the beginning of the name.")] string category)
|
||||
{
|
||||
// Check if ticket exists in the database
|
||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket _))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "This channel is not a ticket."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(command.RawArgumentString))
|
||||
if (string.IsNullOrEmpty(category))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: No category provided."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
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));
|
||||
DiscordChannel categoryChannel = categories.FirstOrDefault(x => x.Name.StartsWith(category.Trim(), StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (category == null)
|
||||
if (categoryChannel == null)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: Could not find a category by that name."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.Channel.Id == category.Id)
|
||||
if (command.Channel.Id == categoryChannel.Id)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: The ticket is already in that category."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await command.Channel.ModifyAsync(modifiedAttributes => modifiedAttributes.Parent = category);
|
||||
await command.Channel.ModifyAsync(modifiedAttributes => modifiedAttributes.Parent = categoryChannel);
|
||||
}
|
||||
catch (UnauthorizedException)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: Not authorized to move this ticket to that category."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordEmbed feedback = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Ticket was moved to " + category.Mention
|
||||
};
|
||||
await command.RespondAsync(feedback);
|
||||
}
|
||||
Description = "Ticket was moved to " + categoryChannel.Mention
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,85 +1,199 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class NewCommand : ApplicationCommandModule
|
||||
{
|
||||
public class NewCommand : BaseCommandModule
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("new", "Opens a new ticket.")]
|
||||
public async Task OnExecute(InteractionContext command)
|
||||
{
|
||||
[Command("new")]
|
||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
List<Database.Category> verifiedCategories = await Utilities.GetVerifiedChannels();
|
||||
switch (verifiedCategories.Count)
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "new"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
case 0:
|
||||
await command.CreateResponseAsync(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.");
|
||||
Description = "Error: No registered categories found."
|
||||
}, true);
|
||||
return;
|
||||
case 1:
|
||||
await command.DeferAsync(true);
|
||||
(bool success, string message) = await OpenNewTicket(command.User.Id, command.Channel.Id, verifiedCategories[0].id);
|
||||
|
||||
if (success)
|
||||
{
|
||||
await command.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = message
|
||||
}).AsEphemeral());
|
||||
}
|
||||
else
|
||||
{
|
||||
await command.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = message
|
||||
}).AsEphemeral());
|
||||
}
|
||||
return;
|
||||
default:
|
||||
if (Config.newCommandUsesSelector)
|
||||
{
|
||||
await CreateSelector(command, verifiedCategories);
|
||||
}
|
||||
else
|
||||
{
|
||||
await CreateButtons(command, verifiedCategories);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task CreateButtons(InteractionContext command, List<Database.Category> verifiedCategories)
|
||||
{
|
||||
DiscordInteractionResponseBuilder builder = new DiscordInteractionResponseBuilder().WithContent(" ");
|
||||
int nrOfButtons = 0;
|
||||
for (int nrOfButtonRows = 0; nrOfButtonRows < 5 && nrOfButtons < verifiedCategories.Count; nrOfButtonRows++)
|
||||
{
|
||||
List<DiscordButtonComponent> buttonRow = new List<DiscordButtonComponent>();
|
||||
|
||||
for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < verifiedCategories.Count; nrOfButtons++)
|
||||
{
|
||||
buttonRow.Add(new DiscordButtonComponent(ButtonStyle.Primary, "supportboi_newcommandbutton " + verifiedCategories[nrOfButtons].id, verifiedCategories[nrOfButtons].name));
|
||||
}
|
||||
builder.AddComponents(buttonRow);
|
||||
}
|
||||
|
||||
await command.CreateResponseAsync(builder.AsEphemeral());
|
||||
}
|
||||
|
||||
public static async Task CreateSelector(InteractionContext command, List<Database.Category> verifiedCategories)
|
||||
{
|
||||
verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList();
|
||||
List<DiscordSelectComponent> selectionComponents = new List<DiscordSelectComponent>();
|
||||
int selectionOptions = 0;
|
||||
for (int selectionBoxes = 0; selectionBoxes < 5 && selectionOptions < verifiedCategories.Count; selectionBoxes++)
|
||||
{
|
||||
List<DiscordSelectComponentOption> categoryOptions = new List<DiscordSelectComponentOption>();
|
||||
|
||||
for (; selectionOptions < 25 * (selectionBoxes + 1) && selectionOptions < verifiedCategories.Count; selectionOptions++)
|
||||
{
|
||||
categoryOptions.Add(new DiscordSelectComponentOption(verifiedCategories[selectionOptions].name, verifiedCategories[selectionOptions].id.ToString()));
|
||||
}
|
||||
selectionComponents.Add(new DiscordSelectComponent("supportboi_newcommandselector" + selectionBoxes, "Open new ticket...", categoryOptions, false, 0, 1));
|
||||
}
|
||||
|
||||
await command.CreateResponseAsync(new DiscordInteractionResponseBuilder().AddComponents(selectionComponents).AsEphemeral());
|
||||
}
|
||||
|
||||
public static async Task OnCategorySelection(DiscordInteraction interaction)
|
||||
{
|
||||
string stringID;
|
||||
switch (interaction.Data.ComponentType)
|
||||
{
|
||||
case ComponentType.Button:
|
||||
stringID = interaction.Data.CustomId.Replace("supportboi_newcommandbutton ", "");
|
||||
break;
|
||||
case ComponentType.Select:
|
||||
if (interaction.Data.Values == null || interaction.Data.Values.Length <= 0) return;
|
||||
stringID = interaction.Data.Values[0];
|
||||
break;
|
||||
|
||||
case ComponentType.ActionRow:
|
||||
case ComponentType.FormInput:
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ulong.TryParse(stringID, out ulong categoryID) || categoryID == 0) return;
|
||||
|
||||
await interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate, new DiscordInteractionResponseBuilder().AsEphemeral());
|
||||
|
||||
(bool success, string message) = await OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID);
|
||||
|
||||
if (success)
|
||||
{
|
||||
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = message
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = message
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<(bool, string)> OpenNewTicket(ulong userID, ulong commandChannelID, ulong categoryID)
|
||||
{
|
||||
// Check if user is blacklisted
|
||||
if (Database.IsBlacklisted(command.User.Id))
|
||||
if (Database.IsBlacklisted(userID))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You are banned from opening tickets."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
return (false, "You are banned from opening tickets.");
|
||||
}
|
||||
|
||||
if (Database.IsOpenTicket(command.Channel.Id))
|
||||
if (Database.IsOpenTicket(commandChannelID))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You cannot use this command in a ticket channel."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
return (false, "You cannot use this command in a ticket channel.");
|
||||
}
|
||||
|
||||
DiscordChannel category = command.Guild.GetChannel(Config.ticketCategory);
|
||||
DiscordChannel ticketChannel;
|
||||
if (!Database.IsStaff(userID) && Database.TryGetOpenTickets(userID, out List<Database.Ticket> ownTickets) && ownTickets.Count >= Config.ticketLimit)
|
||||
{
|
||||
return (false, "You have reached the limit for maximum open tickets.");
|
||||
}
|
||||
|
||||
DiscordChannel category = null;
|
||||
try
|
||||
{
|
||||
category = await SupportChild.discordClient.GetChannelAsync(categoryID);
|
||||
}
|
||||
catch (Exception) { /*ignored*/ }
|
||||
|
||||
if (category == null)
|
||||
{
|
||||
return (false, "Error: Could not find the category to place the ticket in.");
|
||||
}
|
||||
|
||||
DiscordMember member = null;
|
||||
try
|
||||
{
|
||||
member = await category.Guild.GetMemberAsync(userID);
|
||||
}
|
||||
catch (Exception) { /*ignored*/ }
|
||||
|
||||
if (member == null)
|
||||
{
|
||||
return (false, "Error: Could not find you on the Discord server.");
|
||||
}
|
||||
|
||||
DiscordChannel ticketChannel = null;
|
||||
|
||||
try
|
||||
{
|
||||
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;
|
||||
ticketChannel = await category.Guild.CreateChannelAsync("ticket", ChannelType.Text, category);
|
||||
}
|
||||
catch (Exception) { /* ignored */ }
|
||||
|
||||
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;
|
||||
return (false, "Error occured while creating ticket, " + member.Mention +
|
||||
"!\nIs the channel limit reached in the server or ticket category?");
|
||||
}
|
||||
|
||||
ulong staffID = 0;
|
||||
|
@ -88,63 +202,75 @@ namespace SupportChild.Commands
|
|||
staffID = Database.GetRandomActiveStaff(0)?.userID ?? 0;
|
||||
}
|
||||
|
||||
long id = Database.NewTicket(command.Member.Id, staffID, ticketChannel.Id);
|
||||
long id = Database.NewTicket(member.Id, staffID, ticketChannel.Id);
|
||||
string ticketID = id.ToString("00000");
|
||||
await ticketChannel.ModifyAsync(modifiedAttributes => modifiedAttributes.Name = "ticket-" + ticketID);
|
||||
await ticketChannel.AddOverwriteAsync(command.Member, Permissions.AccessChannels, Permissions.None);
|
||||
|
||||
await ticketChannel.SendMessageAsync("Hello, " + command.Member.Mention + "!\n" + Config.welcomeMessage);
|
||||
try
|
||||
{
|
||||
await ticketChannel.ModifyAsync(modifiedAttributes => modifiedAttributes.Name = "ticket-" + ticketID);
|
||||
}
|
||||
catch (DiscordException e)
|
||||
{
|
||||
Logger.Error("Exception occurred trying to modify channel: " + e);
|
||||
Logger.Error("JsomMessage: " + e.JsonMessage);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await ticketChannel.AddOverwriteAsync(member, Permissions.AccessChannels);
|
||||
}
|
||||
catch (DiscordException e)
|
||||
{
|
||||
Logger.Error("Exception occurred trying to add channel permissions: " + e);
|
||||
Logger.Error("JsomMessage: " + e.JsonMessage);
|
||||
}
|
||||
|
||||
await ticketChannel.SendMessageAsync("Hello, " + member.Mention + "!\n" + Config.welcomeMessage);
|
||||
|
||||
// Refreshes the channel as changes were made to it above
|
||||
ticketChannel = command.Guild.GetChannel(ticketChannel.Id);
|
||||
ticketChannel = await SupportChild.discordClient.GetChannelAsync(ticketChannel.Id);
|
||||
|
||||
if (staffID != 0)
|
||||
{
|
||||
DiscordEmbed assignmentMessage = new DiscordEmbedBuilder
|
||||
await ticketChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Ticket was randomly assigned to <@" + staffID + ">."
|
||||
};
|
||||
await ticketChannel.SendMessageAsync(assignmentMessage);
|
||||
});
|
||||
|
||||
if (Config.assignmentNotifications)
|
||||
{
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
try
|
||||
{
|
||||
DiscordMember staffMember = await category.Guild.GetMemberAsync(staffID);
|
||||
await staffMember.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "You have been randomly assigned to a newly opened support ticket: " +
|
||||
ticketChannel.Mention
|
||||
};
|
||||
|
||||
try
|
||||
});
|
||||
}
|
||||
catch (DiscordException e)
|
||||
{
|
||||
DiscordMember staffMember = await command.Guild.GetMemberAsync(staffID);
|
||||
await staffMember.SendMessageAsync(message);
|
||||
}
|
||||
catch (NotFoundException) {}
|
||||
catch (UnauthorizedException) {}
|
||||
Logger.Error("Exception occurred assign random staff member: " + e);
|
||||
Logger.Error("JsomMessage: " + e.JsonMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
DiscordChannel logChannel = category.Guild.GetChannel(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Ticket " + ticketChannel.Mention + " opened by " + command.Member.Mention + ".\n",
|
||||
Description = "Ticket " + ticketChannel.Mention + " opened by " + member.Mention + ".\n",
|
||||
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "Ticket " + ticketID }
|
||||
};
|
||||
await logChannel.SendMessageAsync(logMessage);
|
||||
}
|
||||
}
|
||||
|
||||
return (true, "Ticket opened, " + member.Mention + "!\n" + ticketChannel.Mention);
|
||||
}
|
||||
}
|
|
@ -2,47 +2,33 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.Exceptions;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
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;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class RandomAssignCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("rassign", "Randomly assigns a staff member to a ticket.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("Role", "(Optional) Limit the random assignment to a specific role.")] DiscordRole role = null)
|
||||
{
|
||||
// Check if ticket exists in the database
|
||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "This channel is not a ticket."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
Description = "Error: This channel is not a ticket."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get a random staff member who is verified to have the correct role if applicable
|
||||
DiscordMember staffMember = await GetRandomVerifiedStaffMember(command, ticket);
|
||||
DiscordMember staffMember = await GetRandomVerifiedStaffMember(command, role, ticket);
|
||||
if (staffMember == null)
|
||||
{
|
||||
return;
|
||||
|
@ -51,34 +37,31 @@ namespace SupportChild.Commands
|
|||
// Attempt to assign the staff member to the ticket
|
||||
if (!Database.AssignStaff(ticket, staffMember.Id))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: Failed to assign " + staffMember.Mention + " to ticket."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Respond that the command was successful
|
||||
DiscordEmbed feedback = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(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
|
||||
await staffMember.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "You have been randomly assigned to a support ticket: " + command.Channel.Mention
|
||||
};
|
||||
await staffMember.SendMessageAsync(message);
|
||||
});
|
||||
}
|
||||
catch (UnauthorizedException) { }
|
||||
}
|
||||
|
@ -87,48 +70,25 @@ namespace SupportChild.Commands
|
|||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = staffMember.Mention + " was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
||||
};
|
||||
await logChannel.SendMessageAsync(logMessage);
|
||||
Description = staffMember.Mention + " was randomly assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<DiscordMember> GetRandomVerifiedStaffMember(CommandContext command, Database.Ticket ticket)
|
||||
private static async Task<DiscordMember> GetRandomVerifiedStaffMember(InteractionContext command, DiscordRole targetRole, Database.Ticket ticket)
|
||||
{
|
||||
if (command.RawArguments.Any()) // An argument was provided, check if this can be parsed into a role
|
||||
if (targetRole != null) // A role was provided
|
||||
{
|
||||
ulong roleID = 0;
|
||||
|
||||
// Try to parse either discord mention or ID
|
||||
string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);
|
||||
if (!ulong.TryParse(parsedMessage[0], out roleID))
|
||||
{
|
||||
// Try to find role by name
|
||||
roleID = Utilities.GetRoleByName(command.Guild, command.RawArgumentString)?.Id ?? 0;
|
||||
}
|
||||
|
||||
// Check if a role was found
|
||||
if (roleID == 0)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Could not find a role by that name/ID."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if role rassign should override staff's active status
|
||||
List<Database.StaffMember> staffMembers = Config.randomAssignRoleOverride
|
||||
? Database.GetAllStaff(ticket.assignedStaffID)
|
||||
: Database.GetActiveStaff(ticket.assignedStaffID);
|
||||
? Database.GetAllStaff(ticket.assignedStaffID, ticket.creatorID)
|
||||
: Database.GetActiveStaff(ticket.assignedStaffID, ticket.creatorID);
|
||||
|
||||
// Randomize the list before checking for roles in order to reduce number of API calls
|
||||
staffMembers = Utilities.RandomizeList(staffMembers);
|
||||
staffMembers.Shuffle();
|
||||
|
||||
// Get the first staff member that has the role
|
||||
foreach (Database.StaffMember sm in staffMembers)
|
||||
|
@ -136,7 +96,7 @@ namespace SupportChild.Commands
|
|||
try
|
||||
{
|
||||
DiscordMember verifiedMember = await command.Guild.GetMemberAsync(sm.userID);
|
||||
if (verifiedMember?.Roles?.Any(role => role.Id == roleID) ?? false)
|
||||
if (verifiedMember?.Roles?.Any(role => role.Id == targetRole.Id) ?? false)
|
||||
{
|
||||
return verifiedMember;
|
||||
}
|
||||
|
@ -149,15 +109,14 @@ namespace SupportChild.Commands
|
|||
}
|
||||
else // No role was specified, any active staff will be picked
|
||||
{
|
||||
Database.StaffMember staffEntry = Database.GetRandomActiveStaff(ticket.assignedStaffID);
|
||||
Database.StaffMember staffEntry = Database.GetRandomActiveStaff(ticket.assignedStaffID, ticket.creatorID);
|
||||
if (staffEntry == null)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: There are no other staff members to choose from."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -170,13 +129,11 @@ namespace SupportChild.Commands
|
|||
}
|
||||
|
||||
// Send a more generic error if we get to this point and still haven't found the staff member
|
||||
DiscordEmbed err = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: Could not find an applicable staff member."
|
||||
};
|
||||
await command.RespondAsync(err);
|
||||
}, true);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
{
|
||||
public class ReloadCommand : BaseCommandModule
|
||||
{
|
||||
[Command("reload")]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "reload"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You do not have permission to use this command."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the reload command but did not have permission.");
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Reloading bot application..."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
Console.WriteLine("Reloading bot...");
|
||||
SupportChild.instance.Reload();
|
||||
}
|
||||
}
|
||||
}
|
41
SupportChild/Commands/RemoveCategoryCommand.cs
Normal file
41
SupportChild/Commands/RemoveCategoryCommand.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using System.Threading.Tasks;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class RemoveCategoryCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("removecategory", "Removes the ability for users to open tickets in a specific category.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("Category", "The category to remove.")] DiscordChannel channel)
|
||||
{
|
||||
if (!Database.TryGetCategory(channel.Id, out Database.Category _))
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "That category is not registered."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Database.RemoveCategory(channel.Id))
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Category removed."
|
||||
}, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: Failed removing the category from the database."
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,66 +1,41 @@
|
|||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DSharpPlus.Entities;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
{
|
||||
public class RemoveMessageCommand : BaseCommandModule
|
||||
{
|
||||
[Command("removemessage")]
|
||||
[Description("Removes a message from the 'say' command.")]
|
||||
public async Task OnExecute(CommandContext command, string identifier)
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "removemessage"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You do not have permission to use this command."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the removemessage command but did not have permission.");
|
||||
return;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class RemoveMessageCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("removemessage", "Removes a message from the 'say' command.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("Identifier", "The identifier word used in the /say command.")] string identifier)
|
||||
{
|
||||
if (!Database.TryGetMessage(identifier.ToLower(), out Database.Message _))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "There is no message with that identifier."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Database.RemoveMessage(identifier))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Message removed."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
}, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: Failed removing the message from the database."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
}
|
||||
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,104 +1,49 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
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;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
ulong userID;
|
||||
string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);
|
||||
|
||||
if (!parsedMessage.Any())
|
||||
public class RemoveStaffCommand : ApplicationCommandModule
|
||||
{
|
||||
userID = command.Member.Id;
|
||||
}
|
||||
else if (!ulong.TryParse(parsedMessage[0], out userID))
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("removestaff", "Removes a staff member.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("User", "User to remove from staff.")] DiscordUser user)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
if (!Database.IsStaff(user.Id))
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Invalid ID/Mention. (Could not convert to numerical)"
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await command.Client.GetUserAsync(userID);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Invalid ID/Mention. (Could not find user on Discord)"
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Database.IsStaff(userID))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "User is already not registered as staff."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
using (MySqlConnection c = Database.GetConnection())
|
||||
{
|
||||
await 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.Parameters.AddWithValue("@user_id", user.Id);
|
||||
deletion.Prepare();
|
||||
deletion.ExecuteNonQuery();
|
||||
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "User was removed from staff."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
}, true);
|
||||
|
||||
// Log it if the log channel exists
|
||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "User was removed from staff.\n",
|
||||
};
|
||||
await logChannel.SendMessageAsync(logMessage);
|
||||
}
|
||||
}
|
||||
Description = "User was removed from staff.\n"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,78 +1,29 @@
|
|||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
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;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
if (!Database.TryGetMessage(identifier.ToLower(), out Database.Message message))
|
||||
public class SayCommand : ApplicationCommandModule
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("say", "Prints a message with information from staff. Use without identifier to list all identifiers.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("Identifier", "(Optional) The identifier word to summon a message.")] string identifier = null)
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "There is no message with that identifier."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordEmbed reply = new DiscordEmbedBuilder
|
||||
// Print list of all messages if no identifier is provided
|
||||
if (identifier == null)
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = message.message
|
||||
};
|
||||
await command.RespondAsync(reply);
|
||||
}
|
||||
|
||||
[Command("say")]
|
||||
[Cooldown(1, 2.0, CooldownBucketType.Channel)]
|
||||
[Description("Prints a list of staff messages.")]
|
||||
public async Task OnExecute(CommandContext command)
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "say"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You do not have permission to use this command."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the say command but did not have permission.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
List<Database.Message> messages = Database.GetAllMessages();
|
||||
if (!messages.Any())
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder()
|
||||
.WithColor(DiscordColor.Red)
|
||||
.WithDescription("There are no messages registered.");
|
||||
await command.RespondAsync(error);
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "There are no messages registered."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -85,12 +36,32 @@ namespace SupportChild.Commands
|
|||
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);
|
||||
}
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Title = "Available messages: ",
|
||||
Color = DiscordColor.Green,
|
||||
Description = listMessage
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
// Print specific message
|
||||
else
|
||||
{
|
||||
if (!Database.TryGetMessage(identifier.ToLower(), out Database.Message message))
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "There is no message with that identifier."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Cyan,
|
||||
Description = message.message.Replace("\\n", "\n")
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,48 +1,30 @@
|
|||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
{
|
||||
public class SetSummaryCommand : BaseCommandModule
|
||||
{
|
||||
[Command("setsummary")]
|
||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "setsummary"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You do not have permission to use this command."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the setsummary command but did not have permission.");
|
||||
return;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class SetSummaryCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("setsummary", "Sets a ticket's summary for the summary command.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("Summary", "The ticket summary text.")] string summary)
|
||||
{
|
||||
ulong channelID = command.Channel.Id;
|
||||
// Check if ticket exists in the database
|
||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket _))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "This channel is not a ticket."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
string summary = command.Message.Content.Replace(Config.prefix + "setsummary", "").Trim();
|
||||
|
||||
using (MySqlConnection c = Database.GetConnection())
|
||||
{
|
||||
await using MySqlConnection c = Database.GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand update = new MySqlCommand(@"UPDATE tickets SET summary = @summary WHERE channel_id = @channel_id", c);
|
||||
update.Parameters.AddWithValue("@summary", summary);
|
||||
|
@ -51,13 +33,10 @@ namespace SupportChild.Commands
|
|||
update.ExecuteNonQuery();
|
||||
update.Dispose();
|
||||
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Summary set."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
{
|
||||
public class SetTicketCommand :BaseCommandModule
|
||||
{
|
||||
[Command("setticket")]
|
||||
[Description("Turns a channel into a ticket, warning: this will let anyone with write access delete the channel using the close command.")]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
{
|
||||
using (MySqlConnection c = Database.GetConnection())
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "setticket"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You do not have permission to use this command."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the setticket command but did not have permission.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if ticket exists in the database
|
||||
if (Database.IsOpenTicket(command.Channel.Id))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "This channel is already a ticket."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
}
|
||||
|
||||
ulong userID;
|
||||
string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);
|
||||
|
||||
if (!parsedMessage.Any())
|
||||
{
|
||||
userID = command.Member.Id;
|
||||
}
|
||||
else if (!ulong.TryParse(parsedMessage[0], out userID))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Invalid ID/Mention. (Could not convert to numerical)"
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordUser user = await command.Client.GetUserAsync(userID);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Invalid ID/Mention."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
}
|
||||
|
||||
long id = Database.NewTicket(userID, 0, command.Channel.Id);
|
||||
string ticketID = id.ToString("00000");
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Channel has been designated ticket " + ticketID + "."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
|
||||
// Log it if the log channel exists
|
||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = command.Channel.Mention + " has been designated ticket " + ticketID + " by " + command.Member.Mention + "."
|
||||
};
|
||||
await logChannel.SendMessageAsync(logMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,41 +1,26 @@
|
|||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
{
|
||||
public class StatusCommand : BaseCommandModule
|
||||
{
|
||||
[Command("status")]
|
||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "status"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You do not have permission to use this command."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the status command but did not have permission.");
|
||||
return;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class StatusCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("status", "Shows bot status and information.")]
|
||||
public async Task OnExecute(InteractionContext command)
|
||||
{
|
||||
long openTickets = Database.GetNumberOfTickets();
|
||||
long closedTickets = Database.GetNumberOfClosedTickets();
|
||||
|
||||
DiscordEmbed botInfo = new DiscordEmbedBuilder()
|
||||
.WithAuthor("EmotionChild/SupportChild @ GitHub", "https://github.com/EmotionChild/SupportChild", "https://cdn.emotionchild.com/Ellie.png")
|
||||
.WithAuthor("KarlofDuty/SupportBoi @ GitHub", "https://github.com/EmotionChild/SupportChild", "https://cdn.discordapp.com/attachments/765441543100170271/914327948667011132/Ellie_Concept_2_transparent_ver.png")
|
||||
.WithTitle("Bot information")
|
||||
.WithColor(DiscordColor.Cyan)
|
||||
.AddField("Version:", SupportChild.GetVersion(), false)
|
||||
.AddField("Version:", SupportChild.GetVersion())
|
||||
.AddField("Open tickets:", openTickets + "", true)
|
||||
.AddField("Closed tickets (1.1.0+ tickets only):", closedTickets + " ", true);
|
||||
await command.RespondAsync(botInfo);
|
||||
}
|
||||
.AddField("Closed tickets:", closedTickets + " ", true);
|
||||
await command.CreateResponseAsync(botInfo);
|
||||
}
|
||||
}
|
|
@ -1,51 +1,35 @@
|
|||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
{
|
||||
public class SummaryCommand : BaseCommandModule
|
||||
{
|
||||
[Command("summary")]
|
||||
[Cooldown(1, 5, CooldownBucketType.User)]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "summary"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You do not have permission to use this command."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the summary command but did not have permission.");
|
||||
return;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class SummaryCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("summary", "Lists tickets assigned to a user.")]
|
||||
public async Task OnExecute(InteractionContext command)
|
||||
{
|
||||
if (Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
||||
{
|
||||
DiscordEmbed channelInfo = new DiscordEmbedBuilder()
|
||||
.WithTitle("Channel information")
|
||||
.WithColor(DiscordColor.Cyan)
|
||||
.AddField("Ticket number:", ticket.id.ToString(), true)
|
||||
.AddField("Ticket number:", ticket.id.ToString("00000"), true)
|
||||
.AddField("Ticket creator:", $"<@{ticket.creatorID}>", true)
|
||||
.AddField("Assigned staff:", ticket.assignedStaffID == 0 ? "Unassigned." : $"<@{ticket.assignedStaffID}>", true)
|
||||
.AddField("Creation time:", ticket.createdTime.ToString(Config.timestampFormat), true)
|
||||
.AddField("Summary:", string.IsNullOrEmpty(ticket.summary) ? "No summary." : ticket.summary, false);
|
||||
await command.RespondAsync(channelInfo);
|
||||
.AddField("Creation time:", ticket.DiscordRelativeTime(), true)
|
||||
.AddField("Summary:", string.IsNullOrEmpty(ticket.summary) ? "No summary." : ticket.summary.Replace("\\n", "\n"));
|
||||
await command.CreateResponseAsync(channelInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "This channel is not a ticket."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,78 +1,44 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MySql.Data.MySqlClient;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
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;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
ulong staffID;
|
||||
string[] parsedMessage = Utilities.ParseIDs(command.RawArgumentString);
|
||||
|
||||
if (!parsedMessage.Any())
|
||||
public class ToggleActiveCommand : ApplicationCommandModule
|
||||
{
|
||||
staffID = command.Member.Id;
|
||||
}
|
||||
else if (!ulong.TryParse(parsedMessage[0], out staffID))
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("toggleactive", "Toggles active status for a staff member.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) Staff member to toggle activity for.")] DiscordUser user = null)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Invalid ID/Mention. (Could not convert to numerical)"
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
}
|
||||
DiscordUser staffUser = user == null ? command.User : user;
|
||||
|
||||
// Check if ticket exists in the database
|
||||
if (!Database.TryGetStaff(staffID, out Database.StaffMember staffMember))
|
||||
if (!Database.TryGetStaff(staffUser.Id, out Database.StaffMember staffMember))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You have not been registered as staff."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
Description = user == null ? "You have not been registered as staff." : "The user is not registered as staff."
|
||||
}, true);
|
||||
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();
|
||||
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
if (Database.SetStaffActive(staffUser.Id, !staffMember.active))
|
||||
{
|
||||
await command.CreateResponseAsync(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);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: Unable to update active status in database."
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,39 +2,22 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
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;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class TranscriptCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("transcript", "Creates a transcript of a ticket.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("Ticket", "(Optional) Ticket number to get transcript of.")] long ticketID = 0)
|
||||
{
|
||||
await command.DeferAsync(true);
|
||||
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 (ticketID == 0) // If there are no arguments use current channel
|
||||
{
|
||||
if (Database.TryGetOpenTicket(command.Channel.Id, out ticket))
|
||||
{
|
||||
|
@ -44,42 +27,28 @@ namespace SupportChild.Commands
|
|||
}
|
||||
catch (Exception)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "ERROR: Could not save transcript file. Aborting..."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(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)
|
||||
if (Database.TryGetOpenTicketByID((uint)ticketID, out ticket) && ticket?.creatorID == command.Member.Id)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -87,25 +56,23 @@ namespace SupportChild.Commands
|
|||
}
|
||||
catch (Exception)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(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)))
|
||||
else if (!Database.TryGetClosedTicket((uint)ticketID, out ticket) || (ticket?.creatorID != command.Member.Id && !Database.IsStaff(command.Member.Id)))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
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);
|
||||
Description = "Could not find a closed ticket with that number which you opened.\n(Use the /list command to see all your tickets)"
|
||||
}));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -114,59 +81,49 @@ namespace SupportChild.Commands
|
|||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
DiscordEmbed embed = new DiscordEmbedBuilder
|
||||
await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
|
||||
|
||||
DiscordMessageBuilder message = new DiscordMessageBuilder();
|
||||
message.WithEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
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 } });
|
||||
});
|
||||
message.WithFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||
|
||||
await logChannel.SendMessageAsync(message);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Send transcript privately
|
||||
DiscordEmbed directMessageEmbed = new DiscordEmbedBuilder
|
||||
// Send transcript in a direct message
|
||||
await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
|
||||
|
||||
DiscordMessageBuilder directMessage = new DiscordMessageBuilder();
|
||||
directMessage.WithEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
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 } });
|
||||
Description = "Transcript generated!\n"
|
||||
});
|
||||
directMessage.WithFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||
|
||||
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
|
||||
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(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);
|
||||
}
|
||||
}
|
||||
Description = "Not allowed to send direct message to you, please check your privacy settings.\n"
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Transcript sent!\n"
|
||||
}));
|
||||
}
|
||||
}
|
|
@ -1,71 +1,52 @@
|
|||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
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;
|
||||
}
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class UnassignCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("unassign", "Unassigns a staff member from a ticket.")]
|
||||
public async Task OnExecute(InteractionContext command)
|
||||
{
|
||||
// Check if ticket exists in the database
|
||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "This channel is not a ticket."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Database.UnassignStaff(ticket))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: Failed to unassign staff from ticket."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
Description = "Error: Failed to unassign staff member from ticket."
|
||||
}, true);
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Unassigned staff from ticket."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
Description = "Unassigned staff member from ticket."
|
||||
});
|
||||
|
||||
// Log it if the log channel exists
|
||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Staff was unassigned from " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
||||
};
|
||||
await logChannel.SendMessageAsync(logMessage);
|
||||
}
|
||||
Description = "Staff member was unassigned from " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,99 +1,54 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
namespace SupportChild.Commands;
|
||||
|
||||
public class UnblacklistCommand : ApplicationCommandModule
|
||||
{
|
||||
public class UnblacklistCommand : BaseCommandModule
|
||||
[SlashRequireGuild]
|
||||
[SlashCommand("unblacklist", "Unblacklists a user from opening tickets.")]
|
||||
public async Task OnExecute(InteractionContext command, [Option("User", "User to remove from blacklist.")] DiscordUser user)
|
||||
{
|
||||
[Command("unblacklist")]
|
||||
[Description("Un-blacklists a user from opening tickets.")]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
try
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "unblacklist"))
|
||||
if (!Database.Unblacklist(user.Id))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(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.");
|
||||
Description = user.Mention + " is not blacklisted."
|
||||
}, true);
|
||||
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) { }
|
||||
|
||||
if (blacklistedUser == null)
|
||||
{
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error: Could not find user."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!Database.Unblacklist(blacklistedUser.Id))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = blacklistedUser.Mention + " is not blacklisted."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
continue;
|
||||
}
|
||||
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Removed " + blacklistedUser.Mention + " from blacklist."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
Description = "Removed " + user.Mention + " from blacklist."
|
||||
}, true);
|
||||
|
||||
// Log it if the log channel exists
|
||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = blacklistedUser.Mention + " was unblacklisted from opening tickets by " + command.Member.Mention + "."
|
||||
};
|
||||
await logChannel.SendMessageAsync(logMessage);
|
||||
Description = user.Mention + " was unblacklisted from opening tickets by " + command.Member.Mention + "."
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Error occured while removing " + blacklistedUser.Mention + " from blacklist."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
Description = "Error occured while removing " + user.Mention + " from blacklist."
|
||||
}, true);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace SupportChild.Commands
|
||||
{
|
||||
public class UnsetTicketCommand : BaseCommandModule
|
||||
{
|
||||
[Command("unsetticket")]
|
||||
[Description(
|
||||
"Deletes a channel from the ticket system without deleting the channel.")]
|
||||
public async Task OnExecute(CommandContext command, [RemainingText] string commandArgs)
|
||||
{
|
||||
using (MySqlConnection c = Database.GetConnection())
|
||||
{
|
||||
// Check if the user has permission to use this command.
|
||||
if (!Config.HasPermission(command.Member, "unsetticket"))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "You do not have permission to use this command."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
command.Client.Logger.Log(LogLevel.Information, "User tried to use the unsetticket command but did not have permission.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if ticket exists in the database
|
||||
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "This channel is not a ticket."
|
||||
};
|
||||
await command.RespondAsync(error);
|
||||
return;
|
||||
}
|
||||
|
||||
c.Open();
|
||||
MySqlCommand deletion = new MySqlCommand(@"DELETE FROM tickets WHERE channel_id=@channel_id", c);
|
||||
deletion.Parameters.AddWithValue("@channel_id", command.Channel.Id);
|
||||
deletion.Prepare();
|
||||
deletion.ExecuteNonQuery();
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Channel has been undesignated as a ticket."
|
||||
};
|
||||
await command.RespondAsync(message);
|
||||
|
||||
// Log it if the log channel exists
|
||||
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = command.Channel.Mention + " has been undesignated as a ticket by " + command.Member.Mention + "."
|
||||
};
|
||||
await logChannel.SendMessageAsync(logMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,29 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SupportChild.Properties;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace SupportChild
|
||||
{
|
||||
namespace SupportChild;
|
||||
|
||||
internal static class Config
|
||||
{
|
||||
internal static string token = "";
|
||||
internal static string prefix = "";
|
||||
internal static ulong logChannel;
|
||||
internal static ulong ticketCategory;
|
||||
internal static ulong reactionMessage;
|
||||
internal static string welcomeMessage = "";
|
||||
internal static string logLevel = "Information";
|
||||
internal static string timestampFormat = "yyyy-MMM-dd HH:mm";
|
||||
internal static LogLevel logLevel = LogLevel.Information;
|
||||
internal static TimestampFormat timestampFormat = TimestampFormat.RelativeTime;
|
||||
internal static bool randomAssignment = false;
|
||||
internal static bool randomAssignRoleOverride = false;
|
||||
internal static string presenceType = "Playing";
|
||||
internal static string presenceText = "";
|
||||
internal static bool newCommandUsesSelector = false;
|
||||
internal static int ticketLimit = 5;
|
||||
|
||||
internal static bool ticketUpdatedNotifications = false;
|
||||
internal static double ticketUpdatedNotificationDelay = 0.0;
|
||||
|
@ -32,43 +30,10 @@ namespace SupportChild
|
|||
|
||||
internal static string hostName = "127.0.0.1";
|
||||
internal static int port = 3306;
|
||||
internal static string database = "supportbot";
|
||||
internal static string username = "supportbot";
|
||||
internal static string database = "supportchild";
|
||||
internal static string username = "supportchild";
|
||||
internal static string password = "";
|
||||
|
||||
private static readonly Dictionary<string, ulong[]> permissions = new Dictionary<string, ulong[]>
|
||||
{
|
||||
// Public commands
|
||||
{ "close", new ulong[]{ } },
|
||||
{ "list", new ulong[]{ } },
|
||||
{ "new", new ulong[]{ } },
|
||||
{ "say", new ulong[]{ } },
|
||||
{ "status", new ulong[]{ } },
|
||||
{ "summary", new ulong[]{ } },
|
||||
{ "transcript", new ulong[]{ } },
|
||||
// Moderator commands
|
||||
{ "add", new ulong[]{ } },
|
||||
{ "addmessage", new ulong[]{ } },
|
||||
{ "assign", new ulong[]{ } },
|
||||
{ "blacklist", new ulong[]{ } },
|
||||
{ "listassigned", new ulong[]{ } },
|
||||
{ "listoldest", new ulong[]{ } },
|
||||
{ "listunassigned", new ulong[]{ } },
|
||||
{ "move", new ulong[]{ } },
|
||||
{ "rassign", new ulong[]{ } },
|
||||
{ "removemessage", new ulong[]{ } },
|
||||
{ "setsummary", new ulong[]{ } },
|
||||
{ "toggleactive", new ulong[]{ } },
|
||||
{ "unassign", new ulong[]{ } },
|
||||
{ "unblacklist", new ulong[]{ } },
|
||||
// Admin commands
|
||||
{ "addstaff", new ulong[]{ } },
|
||||
{ "reload", new ulong[]{ } },
|
||||
{ "removestaff", new ulong[]{ } },
|
||||
{ "setticket", new ulong[]{ } },
|
||||
{ "unsetticket", new ulong[]{ } },
|
||||
};
|
||||
|
||||
public static void LoadConfig()
|
||||
{
|
||||
// Writes default config to file if it does not already exist
|
||||
|
@ -82,25 +47,38 @@ namespace SupportChild
|
|||
|
||||
// Converts the FileStream into a YAML object
|
||||
IDeserializer deserializer = new DeserializerBuilder().Build();
|
||||
object yamlObject = deserializer.Deserialize(new StreamReader(stream));
|
||||
object yamlObject = deserializer.Deserialize(new StreamReader(stream)) ?? "";
|
||||
|
||||
// Converts the YAML object into a JSON object as the YAML ones do not support traversal or selection of nodes by name
|
||||
ISerializer serializer = new SerializerBuilder().JsonCompatible().Build();
|
||||
JObject json = JObject.Parse(serializer.Serialize(yamlObject));
|
||||
|
||||
// Sets up the bot
|
||||
token = json.SelectToken("bot.token").Value<string>() ?? "";
|
||||
prefix = json.SelectToken("bot.prefix").Value<string>() ?? "";
|
||||
logChannel = json.SelectToken("bot.log-channel").Value<ulong>();
|
||||
ticketCategory = json.SelectToken("bot.ticket-category")?.Value<ulong>() ?? 0;
|
||||
reactionMessage = json.SelectToken("bot.reaction-message")?.Value<ulong>() ?? 0;
|
||||
welcomeMessage = json.SelectToken("bot.welcome-message").Value<string>() ?? "";
|
||||
logLevel = json.SelectToken("bot.console-log-level").Value<string>() ?? "";
|
||||
timestampFormat = json.SelectToken("bot.timestamp-format").Value<string>() ?? "yyyy-MM-dd HH:mm";
|
||||
token = json.SelectToken("bot.token")?.Value<string>() ?? "";
|
||||
logChannel = json.SelectToken("bot.log-channel")?.Value<ulong>() ?? 0;
|
||||
welcomeMessage = json.SelectToken("bot.welcome-message")?.Value<string>() ?? "";
|
||||
string stringLogLevel = json.SelectToken("bot.console-log-level")?.Value<string>() ?? "";
|
||||
|
||||
if (!Enum.TryParse(stringLogLevel, true, out logLevel))
|
||||
{
|
||||
logLevel = LogLevel.Information;
|
||||
Logger.Warn("Log level '" + stringLogLevel + "' invalid, using 'Information' instead.");
|
||||
}
|
||||
|
||||
string stringTimestampFormat = json.SelectToken("bot.timestamp-format")?.Value<string>() ?? "RelativeTime";
|
||||
|
||||
if (!Enum.TryParse(stringTimestampFormat, true, out timestampFormat))
|
||||
{
|
||||
timestampFormat = TimestampFormat.RelativeTime;
|
||||
Logger.Warn("Timestamp '" + stringTimestampFormat + "' invalid, using 'RelativeTime' instead.");
|
||||
}
|
||||
|
||||
randomAssignment = json.SelectToken("bot.random-assignment")?.Value<bool>() ?? false;
|
||||
randomAssignRoleOverride = json.SelectToken("bot.random-assign-role-override")?.Value<bool>() ?? false;
|
||||
presenceType = json.SelectToken("bot.presence-type")?.Value<string>() ?? "Playing";
|
||||
presenceText = json.SelectToken("bot.presence-text")?.Value<string>() ?? "";
|
||||
newCommandUsesSelector = json.SelectToken("bot.new-command-uses-selector")?.Value<bool>() ?? false;
|
||||
ticketLimit = json.SelectToken("bot.ticket-limit")?.Value<int>() ?? 5;
|
||||
|
||||
ticketUpdatedNotifications = json.SelectToken("notifications.ticket-updated")?.Value<bool>() ?? false;
|
||||
ticketUpdatedNotificationDelay = json.SelectToken("notifications.ticket-updated-delay")?.Value<double>() ?? 0.0;
|
||||
|
@ -113,31 +91,5 @@ namespace SupportChild
|
|||
database = json.SelectToken("database.name")?.Value<string>() ?? "supportchild";
|
||||
username = json.SelectToken("database.user")?.Value<string>() ?? "supportchild";
|
||||
password = json.SelectToken("database.password")?.Value<string>() ?? "";
|
||||
|
||||
timestampFormat = timestampFormat.Trim();
|
||||
|
||||
foreach (KeyValuePair<string, ulong[]> node in permissions.ToList())
|
||||
{
|
||||
try
|
||||
{
|
||||
permissions[node.Key] = json.SelectToken("permissions." + node.Key).Value<JArray>().Values<ulong>().ToArray();
|
||||
}
|
||||
catch (ArgumentNullException)
|
||||
{
|
||||
Console.WriteLine("Permission node '" + node.Key + "' was not found in the config, using default value: []");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a user has a specific permission.
|
||||
/// </summary>
|
||||
/// <param name="member">The Discord user to check.</param>
|
||||
/// <param name="permission">The permission name to check.</param>
|
||||
/// <returns></returns>
|
||||
public static bool HasPermission(DiscordMember member, string permission)
|
||||
{
|
||||
return member.Roles.Any(role => permissions[permission].Contains(role.Id)) || permissions[permission].Contains(member.Guild.Id);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,16 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using DSharpPlus;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace SupportChild
|
||||
{
|
||||
namespace SupportChild;
|
||||
|
||||
public static class Database
|
||||
{
|
||||
private static string connectionString = "";
|
||||
|
||||
private static Random random = new Random();
|
||||
private static readonly Random random = new Random();
|
||||
|
||||
public static void SetConnectionString(string host, int port, string database, string username, string password)
|
||||
{
|
||||
|
@ -19,51 +20,50 @@ namespace SupportChild
|
|||
";userid=" + username +
|
||||
";password=" + password;
|
||||
}
|
||||
|
||||
public static MySqlConnection GetConnection()
|
||||
{
|
||||
return new MySqlConnection(connectionString);
|
||||
}
|
||||
|
||||
public static long GetNumberOfTickets()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
MySqlCommand countTickets = new MySqlCommand("SELECT COUNT(*) FROM tickets", c);
|
||||
using MySqlConnection c = GetConnection();
|
||||
using MySqlCommand countTickets = new MySqlCommand("SELECT COUNT(*) FROM tickets", c);
|
||||
c.Open();
|
||||
return (long)countTickets.ExecuteScalar();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Error occured when attempting to count number of open tickets: " + e);
|
||||
Logger.Error("Error occured when attempting to count number of open tickets: " + e);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static long GetNumberOfClosedTickets()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
MySqlCommand countTickets = new MySqlCommand("SELECT COUNT(*) FROM ticket_history", c);
|
||||
using MySqlConnection c = GetConnection();
|
||||
using MySqlCommand countTickets = new MySqlCommand("SELECT COUNT(*) FROM ticket_history", c);
|
||||
c.Open();
|
||||
return (long)countTickets.ExecuteScalar();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Error occured when attempting to count number of open tickets: " + e);
|
||||
Logger.Error("Error occured when attempting to count number of open tickets: " + e);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void SetupTables()
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
MySqlCommand createTickets = new MySqlCommand(
|
||||
using MySqlConnection c = GetConnection();
|
||||
using MySqlCommand createTickets = new MySqlCommand(
|
||||
"CREATE TABLE IF NOT EXISTS tickets(" +
|
||||
"id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT," +
|
||||
"created_time DATETIME NOT NULL," +
|
||||
|
@ -73,7 +73,7 @@ namespace SupportChild
|
|||
"channel_id BIGINT UNSIGNED NOT NULL UNIQUE," +
|
||||
"INDEX(created_time, assigned_staff_id, channel_id))",
|
||||
c);
|
||||
MySqlCommand createTicketHistory = new MySqlCommand(
|
||||
using MySqlCommand createTicketHistory = new MySqlCommand(
|
||||
"CREATE TABLE IF NOT EXISTS ticket_history(" +
|
||||
"id INT UNSIGNED NOT NULL PRIMARY KEY," +
|
||||
"created_time DATETIME NOT NULL," +
|
||||
|
@ -84,39 +84,44 @@ namespace SupportChild
|
|||
"channel_id BIGINT UNSIGNED NOT NULL UNIQUE," +
|
||||
"INDEX(created_time, closed_time, channel_id))",
|
||||
c);
|
||||
MySqlCommand createBlacklisted = new MySqlCommand(
|
||||
using MySqlCommand createBlacklisted = new MySqlCommand(
|
||||
"CREATE TABLE IF NOT EXISTS blacklisted_users(" +
|
||||
"user_id BIGINT UNSIGNED NOT NULL PRIMARY KEY," +
|
||||
"time DATETIME NOT NULL," +
|
||||
"moderator_id BIGINT UNSIGNED NOT NULL," +
|
||||
"INDEX(user_id, time))",
|
||||
c);
|
||||
MySqlCommand createStaffList = new MySqlCommand(
|
||||
using MySqlCommand createStaffList = new MySqlCommand(
|
||||
"CREATE TABLE IF NOT EXISTS staff(" +
|
||||
"user_id BIGINT UNSIGNED NOT NULL PRIMARY KEY," +
|
||||
"name VARCHAR(256) NOT NULL," +
|
||||
"active BOOLEAN NOT NULL DEFAULT true)",
|
||||
c);
|
||||
MySqlCommand createMessages = new MySqlCommand(
|
||||
using MySqlCommand createMessages = new MySqlCommand(
|
||||
"CREATE TABLE IF NOT EXISTS messages(" +
|
||||
"identifier VARCHAR(256) NOT NULL PRIMARY KEY," +
|
||||
"user_id BIGINT UNSIGNED NOT NULL," +
|
||||
"message VARCHAR(5000) NOT NULL)",
|
||||
c);
|
||||
using MySqlCommand createCategories = new MySqlCommand(
|
||||
"CREATE TABLE IF NOT EXISTS categories(" +
|
||||
"name VARCHAR(256) NOT NULL UNIQUE," +
|
||||
"category_id BIGINT UNSIGNED NOT NULL PRIMARY KEY)",
|
||||
c);
|
||||
c.Open();
|
||||
createTickets.ExecuteNonQuery();
|
||||
createBlacklisted.ExecuteNonQuery();
|
||||
createTicketHistory.ExecuteNonQuery();
|
||||
createStaffList.ExecuteNonQuery();
|
||||
createMessages.ExecuteNonQuery();
|
||||
createCategories.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsOpenTicket(ulong channelID)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM tickets WHERE channel_id=@channel_id", c);
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM tickets WHERE channel_id=@channel_id", c);
|
||||
selection.Parameters.AddWithValue("@channel_id", channelID);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
@ -127,15 +132,14 @@ namespace SupportChild
|
|||
return false;
|
||||
}
|
||||
results.Close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryGetOpenTicket(ulong channelID, out Ticket ticket)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM tickets WHERE channel_id=@channel_id", c);
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM tickets WHERE channel_id=@channel_id", c);
|
||||
selection.Parameters.AddWithValue("@channel_id", channelID);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
@ -151,13 +155,12 @@ namespace SupportChild
|
|||
results.Close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetOpenTicketByID(uint id, out Ticket ticket)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM tickets WHERE id=@id", c);
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM tickets WHERE id=@id", c);
|
||||
selection.Parameters.AddWithValue("@id", id);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
@ -166,19 +169,20 @@ namespace SupportChild
|
|||
if (results.Read())
|
||||
{
|
||||
ticket = new Ticket(results);
|
||||
results.Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
results.Close();
|
||||
ticket = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetClosedTicket(uint id, out Ticket ticket)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM ticket_history WHERE id=@id", c);
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM ticket_history WHERE id=@id", c);
|
||||
selection.Parameters.AddWithValue("@id", id);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
@ -187,20 +191,21 @@ namespace SupportChild
|
|||
if (results.Read())
|
||||
{
|
||||
ticket = new Ticket(results);
|
||||
results.Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
ticket = null;
|
||||
results.Close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetOpenTickets(ulong userID, out List<Ticket> tickets)
|
||||
{
|
||||
tickets = null;
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM tickets WHERE creator_id=@creator_id", c);
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM tickets WHERE creator_id=@creator_id", c);
|
||||
selection.Parameters.AddWithValue("@creator_id", userID);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
@ -218,16 +223,13 @@ namespace SupportChild
|
|||
results.Close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public static bool TryGetOldestTickets(ulong userID, out List<Ticket> tickets, int listLimit)
|
||||
|
||||
public static bool TryGetOpenTickets(out List<Ticket> tickets)
|
||||
{
|
||||
tickets = null;
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM tickets ORDER BY created_time ASC LIMIT @limit", c);
|
||||
selection.Parameters.AddWithValue("@creator_id", userID);
|
||||
selection.Parameters.AddWithValue("@limit", listLimit);
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM tickets ORDER BY channel_id ASC", c);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
||||
|
@ -244,14 +246,13 @@ namespace SupportChild
|
|||
results.Close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetClosedTickets(ulong userID, out List<Ticket> tickets)
|
||||
{
|
||||
tickets = null;
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM ticket_history WHERE creator_id=@creator_id", c);
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM ticket_history WHERE creator_id=@creator_id", c);
|
||||
selection.Parameters.AddWithValue("@creator_id", userID);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
@ -269,14 +270,13 @@ namespace SupportChild
|
|||
results.Close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetAssignedTickets(ulong staffID, out List<Ticket> tickets)
|
||||
{
|
||||
tickets = null;
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM tickets WHERE assigned_staff_id=@assigned_staff_id", c);
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM tickets WHERE assigned_staff_id=@assigned_staff_id", c);
|
||||
selection.Parameters.AddWithValue("@assigned_staff_id", staffID);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
@ -294,15 +294,12 @@ namespace SupportChild
|
|||
results.Close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static long NewTicket(ulong memberID, ulong staffID, ulong ticketID)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand cmd = new MySqlCommand(
|
||||
@"INSERT INTO tickets (created_time, creator_id, assigned_staff_id, summary, channel_id) VALUES (UTC_TIMESTAMP(), @creator_id, @assigned_staff_id, @summary, @channel_id);",
|
||||
c);
|
||||
using MySqlCommand cmd = new MySqlCommand(@"INSERT INTO tickets (created_time, creator_id, assigned_staff_id, summary, channel_id) VALUES (UTC_TIMESTAMP(), @creator_id, @assigned_staff_id, @summary, @channel_id);", c);
|
||||
cmd.Parameters.AddWithValue("@creator_id", memberID);
|
||||
cmd.Parameters.AddWithValue("@assigned_staff_id", staffID);
|
||||
cmd.Parameters.AddWithValue("@summary", "");
|
||||
|
@ -310,16 +307,14 @@ namespace SupportChild
|
|||
cmd.ExecuteNonQuery();
|
||||
return cmd.LastInsertedId;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ArchiveTicket(Ticket ticket)
|
||||
{
|
||||
// Check if ticket already exists in the archive
|
||||
if (TryGetClosedTicket(ticket.id, out Ticket _))
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
MySqlCommand deleteTicket = new MySqlCommand(@"DELETE FROM ticket_history WHERE id=@id OR channel_id=@channel_id", c);
|
||||
using MySqlConnection c = GetConnection();
|
||||
using MySqlCommand deleteTicket = new MySqlCommand(@"DELETE FROM ticket_history WHERE id=@id OR channel_id=@channel_id", c);
|
||||
deleteTicket.Parameters.AddWithValue("@id", ticket.id);
|
||||
deleteTicket.Parameters.AddWithValue("@channel_id", ticket.channelID);
|
||||
|
||||
|
@ -327,44 +322,45 @@ namespace SupportChild
|
|||
deleteTicket.Prepare();
|
||||
deleteTicket.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
// Create an entry in the ticket history database
|
||||
MySqlCommand archiveTicket = new MySqlCommand(@"INSERT INTO ticket_history (id, created_time, closed_time, creator_id, assigned_staff_id, summary, channel_id) VALUES (@id, @created_time, UTC_TIMESTAMP(), @creator_id, @assigned_staff_id, @summary, @channel_id);", c);
|
||||
using MySqlConnection conn = GetConnection();
|
||||
using MySqlCommand archiveTicket = new MySqlCommand(@"INSERT INTO ticket_history (id, created_time, closed_time, creator_id, assigned_staff_id, summary, channel_id) VALUES (@id, @created_time, UTC_TIMESTAMP(), @creator_id, @assigned_staff_id, @summary, @channel_id);", conn);
|
||||
archiveTicket.Parameters.AddWithValue("@id", ticket.id);
|
||||
archiveTicket.Parameters.AddWithValue("@created_time", ticket.createdTime);
|
||||
archiveTicket.Parameters.AddWithValue("@created_time", ticket.channelID.GetSnowflakeTime());
|
||||
archiveTicket.Parameters.AddWithValue("@creator_id", ticket.creatorID);
|
||||
archiveTicket.Parameters.AddWithValue("@assigned_staff_id", ticket.assignedStaffID);
|
||||
archiveTicket.Parameters.AddWithValue("@summary", ticket.summary);
|
||||
archiveTicket.Parameters.AddWithValue("@channel_id", ticket.channelID);
|
||||
|
||||
c.Open();
|
||||
conn.Open();
|
||||
archiveTicket.Prepare();
|
||||
archiveTicket.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteOpenTicket(uint ticketID)
|
||||
public static bool DeleteOpenTicket(uint ticketID)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
try
|
||||
{
|
||||
MySqlCommand deletion = new MySqlCommand(@"DELETE FROM tickets WHERE id=@id", c);
|
||||
using MySqlConnection c = GetConnection();
|
||||
using MySqlCommand deletion = new MySqlCommand(@"DELETE FROM tickets WHERE id=@id", c);
|
||||
deletion.Parameters.AddWithValue("@id", ticketID);
|
||||
|
||||
c.Open();
|
||||
deletion.Prepare();
|
||||
deletion.ExecuteNonQuery();
|
||||
return deletion.ExecuteNonQuery() > 0;
|
||||
}
|
||||
catch (MySqlException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsBlacklisted(ulong userID)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM blacklisted_users WHERE user_id=@user_id", c);
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM blacklisted_users WHERE user_id=@user_id", c);
|
||||
selection.Parameters.AddWithValue("@user_id", userID);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
@ -375,18 +371,17 @@ namespace SupportChild
|
|||
return true;
|
||||
}
|
||||
results.Close();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool Blacklist(ulong blacklistedID, ulong staffID)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand cmd = new MySqlCommand(@"INSERT INTO blacklisted_users (user_id,time,moderator_id) VALUES (@user_id, UTC_TIMESTAMP(), @moderator_id);", c);
|
||||
using MySqlCommand cmd = new MySqlCommand(@"INSERT INTO blacklisted_users (user_id,time,moderator_id) VALUES (@user_id, UTC_TIMESTAMP(), @moderator_id);", c);
|
||||
cmd.Parameters.AddWithValue("@user_id", blacklistedID);
|
||||
cmd.Parameters.AddWithValue("@moderator_id", staffID);
|
||||
cmd.Prepare();
|
||||
|
@ -397,15 +392,14 @@ namespace SupportChild
|
|||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Unblacklist(ulong blacklistedID)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand cmd = new MySqlCommand(@"DELETE FROM blacklisted_users WHERE user_id=@user_id", c);
|
||||
using MySqlCommand cmd = new MySqlCommand(@"DELETE FROM blacklisted_users WHERE user_id=@user_id", c);
|
||||
cmd.Parameters.AddWithValue("@user_id", blacklistedID);
|
||||
cmd.Prepare();
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
|
@ -414,17 +408,15 @@ namespace SupportChild
|
|||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public static bool AssignStaff(Ticket ticket, ulong staffID)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand update = new MySqlCommand(@"UPDATE tickets SET assigned_staff_id = @assigned_staff_id WHERE id = @id", c);
|
||||
using MySqlCommand update = new MySqlCommand(@"UPDATE tickets SET assigned_staff_id = @assigned_staff_id WHERE id = @id", c);
|
||||
update.Parameters.AddWithValue("@assigned_staff_id", staffID);
|
||||
update.Parameters.AddWithValue("@id", ticket.id);
|
||||
update.Prepare();
|
||||
|
@ -434,31 +426,57 @@ namespace SupportChild
|
|||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public static bool UnassignStaff(Ticket ticket)
|
||||
{
|
||||
return AssignStaff(ticket, 0);
|
||||
}
|
||||
public static StaffMember GetRandomActiveStaff(ulong currentStaffID)
|
||||
{
|
||||
List<StaffMember> staffMembers = GetActiveStaff(currentStaffID);
|
||||
if (!staffMembers.Any())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return staffMembers[random.Next(staffMembers.Count)];
|
||||
}
|
||||
|
||||
public static List<StaffMember> GetActiveStaff(ulong currentStaffID = 0)
|
||||
public static bool SetStaffActive(ulong staffID, bool active)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
try
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM staff WHERE active = true AND user_id != @user_id", c);
|
||||
selection.Parameters.AddWithValue("@user_id", currentStaffID);
|
||||
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", active);
|
||||
update.Prepare();
|
||||
return update.ExecuteNonQuery() > 0;
|
||||
}
|
||||
catch (MySqlException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static StaffMember GetRandomActiveStaff(params ulong[] ignoredUserIDs)
|
||||
{
|
||||
List<StaffMember> staffMembers = GetActiveStaff(ignoredUserIDs);
|
||||
return staffMembers.Any() ? staffMembers[random.Next(staffMembers.Count)] : null;
|
||||
}
|
||||
|
||||
public static List<StaffMember> GetActiveStaff(params ulong[] ignoredUserIDs)
|
||||
{
|
||||
bool first = true;
|
||||
string filterString = "";
|
||||
foreach (ulong userID in ignoredUserIDs)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
filterString += "AND user_id != " + userID;
|
||||
}
|
||||
else
|
||||
{
|
||||
filterString += "&& user_id != " + userID;
|
||||
}
|
||||
}
|
||||
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM staff WHERE active = true " + filterString, c);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
||||
|
@ -477,15 +495,29 @@ namespace SupportChild
|
|||
|
||||
return staffMembers;
|
||||
}
|
||||
|
||||
public static List<StaffMember> GetAllStaff(params ulong[] ignoredUserIDs)
|
||||
{
|
||||
bool first = true;
|
||||
string filterString = "";
|
||||
foreach (ulong userID in ignoredUserIDs)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
filterString += "WHERE user_id != " + userID;
|
||||
}
|
||||
else
|
||||
{
|
||||
filterString += "&& user_id != " + userID;
|
||||
}
|
||||
|
||||
public static List<StaffMember> GetAllStaff(ulong currentStaffID = 0)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM staff WHERE user_id != @user_id", c);
|
||||
selection.Parameters.AddWithValue("@user_id", currentStaffID);
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM staff " + filterString, c);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
||||
|
@ -504,14 +536,12 @@ namespace SupportChild
|
|||
|
||||
return staffMembers;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsStaff(ulong staffID)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM staff WHERE user_id=@user_id", c);
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM staff WHERE user_id=@user_id", c);
|
||||
selection.Parameters.AddWithValue("@user_id", staffID);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
@ -524,13 +554,12 @@ namespace SupportChild
|
|||
results.Close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetStaff(ulong staffID, out StaffMember staffMember)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM staff WHERE user_id=@user_id", c);
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM staff WHERE user_id=@user_id", c);
|
||||
selection.Parameters.AddWithValue("@user_id", staffID);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
@ -545,14 +574,12 @@ namespace SupportChild
|
|||
results.Close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Message> GetAllMessages()
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM messages", c);
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM messages", c);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
||||
|
@ -571,14 +598,12 @@ namespace SupportChild
|
|||
|
||||
return messages;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetMessage(string identifier, out Message message)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand selection = new MySqlCommand(@"SELECT * FROM messages WHERE identifier=@identifier", c);
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM messages WHERE identifier=@identifier", c);
|
||||
selection.Parameters.AddWithValue("@identifier", identifier);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
@ -593,16 +618,14 @@ namespace SupportChild
|
|||
results.Close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool AddMessage(string identifier, ulong userID, string message)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand cmd = new MySqlCommand(@"INSERT INTO messages (identifier,user_id,message) VALUES (@identifier, @user_id, @message);", c);
|
||||
using MySqlCommand cmd = new MySqlCommand(@"INSERT INTO messages (identifier,user_id,message) VALUES (@identifier, @user_id, @message);", c);
|
||||
cmd.Parameters.AddWithValue("@identifier", identifier);
|
||||
cmd.Parameters.AddWithValue("@user_id", userID);
|
||||
cmd.Parameters.AddWithValue("@message", message);
|
||||
|
@ -614,16 +637,14 @@ namespace SupportChild
|
|||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool RemoveMessage(string identifier)
|
||||
{
|
||||
using (MySqlConnection c = GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
MySqlCommand cmd = new MySqlCommand(@"DELETE FROM messages WHERE identifier=@identifier", c);
|
||||
using MySqlCommand cmd = new MySqlCommand(@"DELETE FROM messages WHERE identifier=@identifier", c);
|
||||
cmd.Parameters.AddWithValue("@identifier", identifier);
|
||||
cmd.Prepare();
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
|
@ -632,14 +653,110 @@ namespace SupportChild
|
|||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Category> GetAllCategories()
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM categories", c);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
||||
// Check if messages exist in the database
|
||||
if (!results.Read())
|
||||
{
|
||||
return new List<Category>();
|
||||
}
|
||||
|
||||
List<Category> categories = new List<Category> { new Category(results) };
|
||||
while (results.Read())
|
||||
{
|
||||
categories.Add(new Category(results));
|
||||
}
|
||||
results.Close();
|
||||
|
||||
return categories;
|
||||
}
|
||||
|
||||
public static bool TryGetCategory(ulong categoryID, out Category message)
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM categories WHERE category_id=@category_id", c);
|
||||
selection.Parameters.AddWithValue("@category_id", categoryID);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
||||
// Check if ticket exists in the database
|
||||
if (!results.Read())
|
||||
{
|
||||
message = null;
|
||||
return false;
|
||||
}
|
||||
message = new Category(results);
|
||||
results.Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryGetCategory(string name, out Category message)
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
using MySqlCommand selection = new MySqlCommand(@"SELECT * FROM categories WHERE name=@name", c);
|
||||
selection.Parameters.AddWithValue("@name", name);
|
||||
selection.Prepare();
|
||||
MySqlDataReader results = selection.ExecuteReader();
|
||||
|
||||
// Check if ticket exists in the database
|
||||
if (!results.Read())
|
||||
{
|
||||
message = null;
|
||||
return false;
|
||||
}
|
||||
message = new Category(results);
|
||||
results.Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool AddCategory(string name, ulong categoryID)
|
||||
{
|
||||
try
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
using MySqlCommand cmd = new MySqlCommand(@"INSERT INTO categories (name,category_id) VALUES (@name, @category_id);", c);
|
||||
cmd.Parameters.AddWithValue("@name", name);
|
||||
cmd.Parameters.AddWithValue("@category_id", categoryID);
|
||||
cmd.Prepare();
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}
|
||||
catch (MySqlException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool RemoveCategory(ulong categoryID)
|
||||
{
|
||||
try
|
||||
{
|
||||
using MySqlConnection c = GetConnection();
|
||||
c.Open();
|
||||
using MySqlCommand cmd = new MySqlCommand(@"DELETE FROM categories WHERE category_id=@category_id", c);
|
||||
cmd.Parameters.AddWithValue("@category_id", categoryID);
|
||||
cmd.Prepare();
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}
|
||||
catch (MySqlException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class Ticket
|
||||
{
|
||||
public uint id;
|
||||
public DateTime createdTime;
|
||||
public ulong creatorID;
|
||||
public ulong assignedStaffID;
|
||||
public string summary;
|
||||
|
@ -647,17 +764,16 @@ namespace SupportChild
|
|||
|
||||
public Ticket(MySqlDataReader reader)
|
||||
{
|
||||
this.id = reader.GetUInt32("id");
|
||||
this.createdTime = reader.GetDateTime("created_time");
|
||||
this.creatorID = reader.GetUInt64("creator_id");
|
||||
this.assignedStaffID = reader.GetUInt64("assigned_staff_id");
|
||||
this.summary = reader.GetString("summary");
|
||||
this.channelID = reader.GetUInt64("channel_id");
|
||||
id = reader.GetUInt32("id");
|
||||
creatorID = reader.GetUInt64("creator_id");
|
||||
assignedStaffID = reader.GetUInt64("assigned_staff_id");
|
||||
summary = reader.GetString("summary");
|
||||
channelID = reader.GetUInt64("channel_id");
|
||||
}
|
||||
|
||||
public string FormattedCreatedTime()
|
||||
public string DiscordRelativeTime()
|
||||
{
|
||||
return this.createdTime.ToString(Config.timestampFormat);
|
||||
return Formatter.Timestamp(channelID.GetSnowflakeTime(), Config.timestampFormat);
|
||||
}
|
||||
}
|
||||
public class StaffMember
|
||||
|
@ -668,9 +784,9 @@ namespace SupportChild
|
|||
|
||||
public StaffMember(MySqlDataReader reader)
|
||||
{
|
||||
this.userID = reader.GetUInt64("user_id");
|
||||
this.name = reader.GetString("name");
|
||||
this.active = reader.GetBoolean("active");
|
||||
userID = reader.GetUInt64("user_id");
|
||||
name = reader.GetString("name");
|
||||
active = reader.GetBoolean("active");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -682,10 +798,21 @@ namespace SupportChild
|
|||
|
||||
public Message(MySqlDataReader reader)
|
||||
{
|
||||
this.identifier = reader.GetString("identifier");
|
||||
this.userID = reader.GetUInt64("user_id");
|
||||
this.message = reader.GetString("message");
|
||||
}
|
||||
identifier = reader.GetString("identifier");
|
||||
userID = reader.GetUInt64("user_id");
|
||||
message = reader.GetString("message");
|
||||
}
|
||||
}
|
||||
|
||||
public class Category
|
||||
{
|
||||
public string name;
|
||||
public ulong id;
|
||||
|
||||
public Category(MySqlDataReader reader)
|
||||
{
|
||||
name = reader.GetString("name");
|
||||
id = reader.GetUInt64("category_id");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,64 +2,59 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using DSharpPlus.CommandsNext.Exceptions;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.EventArgs;
|
||||
using DSharpPlus.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
using DSharpPlus.SlashCommands.EventArgs;
|
||||
using SupportChild.Commands;
|
||||
|
||||
namespace SupportChild
|
||||
{
|
||||
internal class EventHandler
|
||||
{
|
||||
private DiscordClient discordClient;
|
||||
namespace SupportChild;
|
||||
|
||||
//DateTime for the end of the cooldown
|
||||
private static Dictionary<ulong, DateTime> reactionTicketCooldowns = new Dictionary<ulong, DateTime>();
|
||||
|
||||
public EventHandler(DiscordClient client)
|
||||
internal static class EventHandler
|
||||
{
|
||||
this.discordClient = client;
|
||||
}
|
||||
|
||||
internal Task OnReady(DiscordClient client, ReadyEventArgs e)
|
||||
internal static Task OnReady(DiscordClient client, ReadyEventArgs e)
|
||||
{
|
||||
discordClient.Logger.Log(LogLevel.Information, "Client is ready to process events.");
|
||||
Logger.Log("Client is ready to process events.");
|
||||
|
||||
// Checking activity type
|
||||
if (!Enum.TryParse(Config.presenceType, true, out ActivityType activityType))
|
||||
{
|
||||
Console.WriteLine("Presence type '" + Config.presenceType + "' invalid, using 'Playing' instead.");
|
||||
Logger.Log("Presence type '" + Config.presenceType + "' invalid, using 'Playing' instead.");
|
||||
activityType = ActivityType.Playing;
|
||||
}
|
||||
|
||||
this.discordClient.UpdateStatusAsync(new DiscordActivity(Config.presenceText, activityType), UserStatus.Online);
|
||||
client.UpdateStatusAsync(new DiscordActivity(Config.presenceText, activityType), UserStatus.Online);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
internal Task OnGuildAvailable(DiscordClient client, GuildCreateEventArgs e)
|
||||
internal static Task OnGuildAvailable(DiscordClient _, GuildCreateEventArgs e)
|
||||
{
|
||||
discordClient.Logger.Log(LogLevel.Information, $"Guild available: {e.Guild.Name}");
|
||||
Logger.Log("Guild available: " + e.Guild.Name);
|
||||
|
||||
IReadOnlyDictionary<ulong, DiscordRole> roles = e.Guild.Roles;
|
||||
|
||||
foreach ((ulong roleID, DiscordRole role) in roles)
|
||||
{
|
||||
discordClient.Logger.Log(LogLevel.Information, role.Name.PadRight(40, '.') + roleID);
|
||||
Logger.Log(role.Name.PadRight(40, '.') + roleID);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
internal Task OnClientError(DiscordClient client, ClientErrorEventArgs e)
|
||||
internal static Task OnClientError(DiscordClient _, ClientErrorEventArgs e)
|
||||
{
|
||||
discordClient.Logger.Log(LogLevel.Error, $"Exception occured: {e.Exception.GetType()}: {e.Exception}");
|
||||
|
||||
Logger.Error("Client exception occured:\n" + e.Exception);
|
||||
switch (e.Exception)
|
||||
{
|
||||
case BadRequestException ex:
|
||||
Logger.Error("JSON Message: " + ex.JsonMessage);
|
||||
break;
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
internal async Task OnMessageCreated(DiscordClient client, MessageCreateEventArgs e)
|
||||
internal static async Task OnMessageCreated(DiscordClient client, MessageCreateEventArgs e)
|
||||
{
|
||||
if (e.Author.IsBot)
|
||||
{
|
||||
|
@ -78,141 +73,54 @@ namespace SupportChild
|
|||
{
|
||||
try
|
||||
{
|
||||
DiscordEmbed message = new DiscordEmbedBuilder
|
||||
DiscordMember staffMember = await e.Guild.GetMemberAsync(ticket.assignedStaffID);
|
||||
await staffMember.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "A ticket you are assigned to has been updated: " + e.Channel.Mention
|
||||
};
|
||||
|
||||
DiscordMember staffMember = await e.Guild.GetMemberAsync(ticket.assignedStaffID);
|
||||
await staffMember.SendMessageAsync(message);
|
||||
});
|
||||
}
|
||||
catch (NotFoundException) { }
|
||||
catch (UnauthorizedException) { }
|
||||
}
|
||||
}
|
||||
|
||||
internal Task OnCommandError(CommandsNextExtension commandSystem, CommandErrorEventArgs e)
|
||||
internal static async Task OnCommandError(SlashCommandsExtension commandSystem, SlashCommandErrorEventArgs e)
|
||||
{
|
||||
switch (e.Exception)
|
||||
{
|
||||
case CommandNotFoundException _:
|
||||
return Task.CompletedTask;
|
||||
case ChecksFailedException _:
|
||||
case SlashExecutionChecksFailedException checksFailedException:
|
||||
{
|
||||
foreach (CheckBaseAttribute attr in ((ChecksFailedException)e.Exception).FailedChecks)
|
||||
foreach (SlashCheckBaseAttribute attr in checksFailedException.FailedChecks)
|
||||
{
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
await e.Context.Channel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = this.ParseFailedCheck(attr)
|
||||
};
|
||||
e.Context?.Channel?.SendMessageAsync(error);
|
||||
Description = ParseFailedCheck(attr)
|
||||
});
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
}
|
||||
|
||||
case BadRequestException ex:
|
||||
Logger.Error("Command exception occured:\n" + e.Exception);
|
||||
Logger.Error("JSON Message: " + ex.JsonMessage);
|
||||
return;
|
||||
|
||||
default:
|
||||
{
|
||||
discordClient.Logger.Log(LogLevel.Error, $"Exception occured: {e.Exception.GetType()}: {e.Exception}");
|
||||
DiscordEmbed error = new DiscordEmbedBuilder
|
||||
Logger.Error("Exception occured: " + e.Exception.GetType() + ": " + e.Exception);
|
||||
await e.Context.Channel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Internal error occured, please report this to the developer."
|
||||
};
|
||||
e.Context?.Channel?.SendMessageAsync(error);
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task OnReactionAdded(DiscordClient client, MessageReactionAddEventArgs e)
|
||||
{
|
||||
if (e.Message.Id != Config.reactionMessage) return;
|
||||
|
||||
DiscordGuild guild = e.Message.Channel.Guild;
|
||||
DiscordMember member = await guild.GetMemberAsync(e.User.Id);
|
||||
|
||||
if (!Config.HasPermission(member, "new") || Database.IsBlacklisted(member.Id)) return;
|
||||
if (reactionTicketCooldowns.ContainsKey(member.Id))
|
||||
{
|
||||
if (reactionTicketCooldowns[member.Id] > DateTime.Now) return; // cooldown has not expired
|
||||
else reactionTicketCooldowns.Remove(member.Id); // cooldown exists but has expired, delete it
|
||||
}
|
||||
|
||||
|
||||
DiscordChannel category = guild.GetChannel(Config.ticketCategory);
|
||||
DiscordChannel ticketChannel = await guild.CreateChannelAsync("ticket", ChannelType.Text, category);
|
||||
|
||||
if (ticketChannel == null) return;
|
||||
|
||||
ulong staffID = 0;
|
||||
if (Config.randomAssignment)
|
||||
{
|
||||
staffID = Database.GetRandomActiveStaff(0)?.userID ?? 0;
|
||||
}
|
||||
|
||||
long id = Database.NewTicket(member.Id, staffID, ticketChannel.Id);
|
||||
reactionTicketCooldowns.Add(member.Id, DateTime.Now.AddSeconds(10)); // add a cooldown which expires in 10 seconds
|
||||
string ticketID = id.ToString("00000");
|
||||
|
||||
await ticketChannel.ModifyAsync(model => model.Name = "ticket-" + ticketID);
|
||||
await ticketChannel.AddOverwriteAsync(member, Permissions.AccessChannels, Permissions.None);
|
||||
await ticketChannel.SendMessageAsync("Hello, " + member.Mention + "!\n" + Config.welcomeMessage);
|
||||
|
||||
// Remove user's reaction
|
||||
await e.Message.DeleteReactionAsync(e.Emoji, e.User);
|
||||
|
||||
// Refreshes the channel as changes were made to it above
|
||||
ticketChannel = await SupportChild.GetClient().GetChannelAsync(ticketChannel.Id);
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
DiscordMember staffMember = await guild.GetMemberAsync(staffID);
|
||||
await staffMember.SendMessageAsync(message);
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
}
|
||||
catch (UnauthorizedException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Log it if the log channel exists
|
||||
DiscordChannel logChannel = guild.GetChannel(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
DiscordEmbed logMessage = new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "Ticket " + ticketChannel.Mention + " opened by " + member.Mention + ".\n",
|
||||
Footer = new DiscordEmbedBuilder.EmbedFooter {Text = "Ticket " + ticketID}
|
||||
};
|
||||
await logChannel.SendMessageAsync(logMessage);
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task OnMemberAdded(DiscordClient client, GuildMemberAddEventArgs e)
|
||||
internal static async Task OnMemberAdded(DiscordClient client, GuildMemberAddEventArgs e)
|
||||
{
|
||||
if (!Database.TryGetOpenTickets(e.Member.Id, out List<Database.Ticket> ownTickets))
|
||||
{
|
||||
|
@ -226,18 +134,18 @@ namespace SupportChild
|
|||
DiscordChannel channel = await client.GetChannelAsync(ticket.channelID);
|
||||
if (channel?.GuildId == e.Guild.Id)
|
||||
{
|
||||
await channel.AddOverwriteAsync(e.Member, Permissions.AccessChannels, Permissions.None);
|
||||
DiscordEmbed message = new DiscordEmbedBuilder()
|
||||
.WithColor(DiscordColor.Green)
|
||||
.WithDescription("User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has rejoined the server, and has been re-added to the ticket.");
|
||||
await channel.SendMessageAsync(message);
|
||||
await channel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Green,
|
||||
Description = "User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has rejoined the server, and has been re-added to the ticket."
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
catch (Exception) { /* ignored */ }
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task OnMemberRemoved(DiscordClient client, GuildMemberRemoveEventArgs e)
|
||||
internal static async Task OnMemberRemoved(DiscordClient client, GuildMemberRemoveEventArgs e)
|
||||
{
|
||||
if (Database.TryGetOpenTickets(e.Member.Id, out List<Database.Ticket> ownTickets))
|
||||
{
|
||||
|
@ -248,13 +156,14 @@ namespace SupportChild
|
|||
DiscordChannel channel = await client.GetChannelAsync(ticket.channelID);
|
||||
if (channel?.GuildId == e.Guild.Id)
|
||||
{
|
||||
DiscordEmbed message = new DiscordEmbedBuilder()
|
||||
.WithColor(DiscordColor.Red)
|
||||
.WithDescription("User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server.");
|
||||
await channel.SendMessageAsync(message);
|
||||
await channel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server."
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
catch (Exception) { /* ignored */ }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,7 +172,6 @@ namespace SupportChild
|
|||
DiscordChannel logChannel = await client.GetChannelAsync(Config.logChannel);
|
||||
if (logChannel != null)
|
||||
{
|
||||
|
||||
foreach (Database.Ticket ticket in assignedTickets)
|
||||
{
|
||||
try
|
||||
|
@ -271,37 +179,97 @@ namespace SupportChild
|
|||
DiscordChannel channel = await client.GetChannelAsync(ticket.channelID);
|
||||
if (channel?.GuildId == e.Guild.Id)
|
||||
{
|
||||
DiscordEmbed message = new DiscordEmbedBuilder()
|
||||
.WithColor(DiscordColor.Red)
|
||||
.WithDescription("Assigned staff member '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server: <#" + channel.Id + ">");
|
||||
await logChannel.SendMessageAsync(message);
|
||||
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
||||
{
|
||||
Color = DiscordColor.Red,
|
||||
Description = "Assigned staff member '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server: <#" + channel.Id + ">"
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
catch (Exception) { /* ignored */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string ParseFailedCheck(CheckBaseAttribute attr)
|
||||
internal static async Task OnComponentInteractionCreated(DiscordClient client, ComponentInteractionCreateEventArgs e)
|
||||
{
|
||||
switch (attr)
|
||||
try
|
||||
{
|
||||
case CooldownAttribute _:
|
||||
return "You cannot use do that so often!";
|
||||
case RequireOwnerAttribute _:
|
||||
return "Only the server owner can use that command!";
|
||||
case RequirePermissionsAttribute _:
|
||||
return "You don't have permission to do that!";
|
||||
case RequireRolesAttribute _:
|
||||
return "You do not have a required role!";
|
||||
case RequireUserPermissionsAttribute _:
|
||||
return "You don't have permission to do that!";
|
||||
case RequireNsfwAttribute _:
|
||||
return "This command can only be used in an NSFW channel!";
|
||||
switch (e.Interaction.Data.ComponentType)
|
||||
{
|
||||
case ComponentType.Button:
|
||||
switch (e.Id)
|
||||
{
|
||||
case "supportchild_closeconfirm":
|
||||
await CloseCommand.OnConfirmed(e.Interaction);
|
||||
return;
|
||||
case { } when e.Id.StartsWith("supportchild_newcommandbutton"):
|
||||
await NewCommand.OnCategorySelection(e.Interaction);
|
||||
return;
|
||||
case { } when e.Id.StartsWith("supportchild_newticketbutton"):
|
||||
await CreateButtonPanelCommand.OnButtonUsed(e.Interaction);
|
||||
return;
|
||||
case "right":
|
||||
return;
|
||||
case "left":
|
||||
return;
|
||||
case "rightskip":
|
||||
return;
|
||||
case "leftskip":
|
||||
return;
|
||||
case "stop":
|
||||
return;
|
||||
default:
|
||||
return "Unknown Discord API error occured, please try again later.";
|
||||
Logger.Warn("Unknown button press received! '" + e.Id + "'");
|
||||
return;
|
||||
}
|
||||
case ComponentType.Select:
|
||||
switch (e.Id)
|
||||
{
|
||||
case { } when e.Id.StartsWith("supportchild_newcommandselector"):
|
||||
await NewCommand.OnCategorySelection(e.Interaction);
|
||||
return;
|
||||
case { } when e.Id.StartsWith("supportchild_newticketselector"):
|
||||
await CreateSelectionBoxPanelCommand.OnSelectionMenuUsed(e.Interaction);
|
||||
return;
|
||||
default:
|
||||
Logger.Warn("Unknown selection box option received! '" + e.Id + "'");
|
||||
return;
|
||||
}
|
||||
case ComponentType.ActionRow:
|
||||
Logger.Warn("Unknown action row received! '" + e.Id + "'");
|
||||
return;
|
||||
case ComponentType.FormInput:
|
||||
Logger.Warn("Unknown form input received! '" + e.Id + "'");
|
||||
return;
|
||||
default:
|
||||
Logger.Warn("Unknown interaction type received! '" + e.Interaction.Data.ComponentType + "'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (DiscordException ex)
|
||||
{
|
||||
Logger.Error("Interaction Exception occurred: " + ex);
|
||||
Logger.Error("JsomMessage: " + ex.JsonMessage);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error("Interaction Exception occured: " + ex.GetType() + ": " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static string ParseFailedCheck(SlashCheckBaseAttribute attr)
|
||||
{
|
||||
return attr switch
|
||||
{
|
||||
SlashRequireDirectMessageAttribute => "This command can only be used in direct messages!",
|
||||
SlashRequireOwnerAttribute => "Only the server owner can use that command!",
|
||||
SlashRequirePermissionsAttribute => "You don't have permission to do that!",
|
||||
SlashRequireBotPermissionsAttribute => "The bot doesn't have the required permissions to do that!",
|
||||
SlashRequireUserPermissionsAttribute => "You don't have permission to do that!",
|
||||
SlashRequireGuildAttribute => "This command has to be used in a Discord server!",
|
||||
_ => "Unknown Discord API error occured, please try again later."
|
||||
};
|
||||
}
|
||||
}
|
68
SupportChild/Logger.cs
Normal file
68
SupportChild/Logger.cs
Normal file
|
@ -0,0 +1,68 @@
|
|||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace SupportChild;
|
||||
|
||||
public static class Logger
|
||||
{
|
||||
public static void Debug(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
SupportChild.discordClient.Logger.Log(LogLevel.Debug, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
Console.WriteLine("[DEBUG] " + message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Log(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
SupportChild.discordClient.Logger.Log(LogLevel.Information, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
Console.WriteLine("[INFO] " + message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Warn(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
SupportChild.discordClient.Logger.Log(LogLevel.Warning, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
Console.WriteLine("[WARNING] " + message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Error(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
SupportChild.discordClient.Logger.Log(LogLevel.Error, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
Console.WriteLine("[ERROR] " + message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Fatal(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
SupportChild.discordClient.Logger.Log(LogLevel.Critical, new EventId(420, Assembly.GetEntryAssembly()?.GetName().Name), message);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
Console.WriteLine("[CRITICAL] " + message);
|
||||
}
|
||||
}
|
||||
}
|
18
SupportChild/Properties/Resources.Designer.cs
generated
18
SupportChild/Properties/Resources.Designer.cs
generated
|
@ -1,7 +1,6 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
|
@ -12,13 +11,6 @@ namespace SupportChild.Properties {
|
|||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
|
@ -32,9 +24,6 @@ namespace SupportChild.Properties {
|
|||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
|
@ -46,10 +35,6 @@ namespace SupportChild.Properties {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
|
@ -60,9 +45,6 @@ namespace SupportChild.Properties {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
internal static byte[] default_config {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("default_config", resourceCulture);
|
||||
|
|
|
@ -3,161 +3,148 @@ using System.IO;
|
|||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.Interactivity;
|
||||
using DSharpPlus.Interactivity.Enums;
|
||||
using DSharpPlus.Interactivity.Extensions;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SupportChild.Commands;
|
||||
|
||||
namespace SupportChild
|
||||
{
|
||||
internal class SupportChild
|
||||
{
|
||||
internal static SupportChild instance;
|
||||
namespace SupportChild;
|
||||
|
||||
private DiscordClient discordClient = null;
|
||||
private CommandsNextExtension commands = null;
|
||||
private EventHandler eventHandler;
|
||||
|
||||
static void Main(string[] args)
|
||||
internal static class SupportChild
|
||||
{
|
||||
new SupportChild().MainAsync().GetAwaiter().GetResult();
|
||||
// Sets up a dummy client to use for logging
|
||||
public static DiscordClient discordClient = new DiscordClient(new DiscordConfiguration { Token = "DUMMY_TOKEN", TokenType = TokenType.Bot, MinimumLogLevel = LogLevel.Debug });
|
||||
private static SlashCommandsExtension commands = null;
|
||||
|
||||
private static void Main()
|
||||
{
|
||||
MainAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
private async Task MainAsync()
|
||||
private static async Task MainAsync()
|
||||
{
|
||||
instance = this;
|
||||
|
||||
Console.WriteLine("Starting SupportChild version " + GetVersion() + "...");
|
||||
Logger.Log("Starting " + Assembly.GetEntryAssembly()?.GetName().Name + " version " + GetVersion() + "...");
|
||||
try
|
||||
{
|
||||
this.Reload();
|
||||
Reload();
|
||||
|
||||
// Block this task until the program is closed.
|
||||
await Task.Delay(-1);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Fatal error:");
|
||||
Console.WriteLine(e);
|
||||
Logger.Fatal("Fatal error:\n" + e);
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
|
||||
public static DiscordClient GetClient()
|
||||
{
|
||||
return instance.discordClient;
|
||||
}
|
||||
|
||||
public static string GetVersion()
|
||||
{
|
||||
Version version = Assembly.GetEntryAssembly()?.GetName().Version;
|
||||
return version?.Major + "." + version?.Minor + "." + version?.Build + (version?.Revision == 0 ? "" : "-" + (char)(64 + version?.Revision ?? 0));
|
||||
}
|
||||
|
||||
public async void Reload()
|
||||
public static async void Reload()
|
||||
{
|
||||
if (this.discordClient != null)
|
||||
if (discordClient != null)
|
||||
{
|
||||
await this.discordClient.DisconnectAsync();
|
||||
this.discordClient.Dispose();
|
||||
Console.WriteLine("Discord client disconnected.");
|
||||
await discordClient.DisconnectAsync();
|
||||
discordClient.Dispose();
|
||||
Logger.Log("Discord client disconnected.");
|
||||
}
|
||||
|
||||
Console.WriteLine("Loading config \"" + Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "config.yml\"");
|
||||
Logger.Log("Loading config \"" + Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "config.yml\"");
|
||||
Config.LoadConfig();
|
||||
|
||||
// Check if token is unset
|
||||
if (Config.token == "<add-token-here>" || Config.token == "")
|
||||
if (Config.token is "<add-token-here>" or "")
|
||||
{
|
||||
Console.WriteLine("You need to set your bot token in the config and start the bot again.");
|
||||
Logger.Fatal("You need to set your bot token in the config and start the bot again.");
|
||||
throw new ArgumentException("Invalid Discord bot token");
|
||||
}
|
||||
|
||||
// Database connection and setup
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Connecting to database... (" + Config.hostName + ":" + Config.port + ")");
|
||||
Logger.Log("Connecting to database... (" + Config.hostName + ":" + Config.port + ")");
|
||||
Database.SetConnectionString(Config.hostName, Config.port, Config.database, Config.username, Config.password);
|
||||
Database.SetupTables();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Could not set up database tables, please confirm connection settings, status of the server and permissions of MySQL user. Error: " + e);
|
||||
Logger.Fatal("Could not set up database tables, please confirm connection settings, status of the server and permissions of MySQL user. Error: " + e);
|
||||
throw;
|
||||
}
|
||||
|
||||
Console.WriteLine("Setting up Discord client...");
|
||||
|
||||
// Checking log level
|
||||
if (!Enum.TryParse(Config.logLevel, true, out LogLevel logLevel))
|
||||
{
|
||||
Console.WriteLine("Log level '" + Config.logLevel + "' invalid, using 'Information' instead.");
|
||||
logLevel = LogLevel.Information;
|
||||
}
|
||||
Logger.Log("Setting up Discord client...");
|
||||
|
||||
// Setting up client configuration
|
||||
DiscordConfiguration cfg = new DiscordConfiguration
|
||||
{
|
||||
Token = Config.token,
|
||||
TokenType = TokenType.Bot,
|
||||
MinimumLogLevel = logLevel,
|
||||
MinimumLogLevel = Config.logLevel,
|
||||
AutoReconnect = true,
|
||||
Intents = DiscordIntents.All
|
||||
};
|
||||
|
||||
this.discordClient = new DiscordClient(cfg);
|
||||
discordClient = new DiscordClient(cfg);
|
||||
|
||||
this.eventHandler = new EventHandler(this.discordClient);
|
||||
Logger.Log("Hooking events...");
|
||||
discordClient.Ready += EventHandler.OnReady;
|
||||
discordClient.GuildAvailable += EventHandler.OnGuildAvailable;
|
||||
discordClient.ClientErrored += EventHandler.OnClientError;
|
||||
discordClient.MessageCreated += EventHandler.OnMessageCreated;
|
||||
discordClient.GuildMemberAdded += EventHandler.OnMemberAdded;
|
||||
discordClient.GuildMemberRemoved += EventHandler.OnMemberRemoved;
|
||||
discordClient.ComponentInteractionCreated += EventHandler.OnComponentInteractionCreated;
|
||||
|
||||
Console.WriteLine("Hooking events...");
|
||||
this.discordClient.Ready += this.eventHandler.OnReady;
|
||||
this.discordClient.GuildAvailable += this.eventHandler.OnGuildAvailable;
|
||||
this.discordClient.ClientErrored += this.eventHandler.OnClientError;
|
||||
this.discordClient.MessageCreated += this.eventHandler.OnMessageCreated;
|
||||
this.discordClient.GuildMemberAdded += this.eventHandler.OnMemberAdded;
|
||||
this.discordClient.GuildMemberRemoved += this.eventHandler.OnMemberRemoved;
|
||||
if (Config.reactionMessage != 0)
|
||||
discordClient.UseInteractivity(new InteractivityConfiguration
|
||||
{
|
||||
this.discordClient.MessageReactionAdded += this.eventHandler.OnReactionAdded;
|
||||
}
|
||||
|
||||
Console.WriteLine("Registering commands...");
|
||||
commands = discordClient.UseCommandsNext(new CommandsNextConfiguration
|
||||
{
|
||||
StringPrefixes = new []{ Config.prefix }
|
||||
AckPaginationButtons = true,
|
||||
PaginationBehaviour = PaginationBehaviour.Ignore,
|
||||
PaginationDeletion = PaginationDeletion.DeleteMessage,
|
||||
Timeout = TimeSpan.FromMinutes(15)
|
||||
});
|
||||
|
||||
this.commands.RegisterCommands<AddCommand>();
|
||||
this.commands.RegisterCommands<AddMessageCommand>();
|
||||
this.commands.RegisterCommands<AddStaffCommand>();
|
||||
this.commands.RegisterCommands<AssignCommand>();
|
||||
this.commands.RegisterCommands<BlacklistCommand>();
|
||||
this.commands.RegisterCommands<CloseCommand>();
|
||||
this.commands.RegisterCommands<ListAssignedCommand>();
|
||||
this.commands.RegisterCommands<ListCommand>();
|
||||
this.commands.RegisterCommands<ListOldestCommand>();
|
||||
this.commands.RegisterCommands<ListUnassignedCommand>();
|
||||
this.commands.RegisterCommands<MoveCommand>();
|
||||
this.commands.RegisterCommands<NewCommand>();
|
||||
this.commands.RegisterCommands<RandomAssignCommand>();
|
||||
this.commands.RegisterCommands<ReloadCommand>();
|
||||
this.commands.RegisterCommands<RemoveMessageCommand>();
|
||||
this.commands.RegisterCommands<RemoveStaffCommand>();
|
||||
this.commands.RegisterCommands<SayCommand>();
|
||||
this.commands.RegisterCommands<SetSummaryCommand>();
|
||||
this.commands.RegisterCommands<SetTicketCommand>();
|
||||
this.commands.RegisterCommands<StatusCommand>();
|
||||
this.commands.RegisterCommands<SummaryCommand>();
|
||||
this.commands.RegisterCommands<ToggleActiveCommand>();
|
||||
this.commands.RegisterCommands<TranscriptCommand>();
|
||||
this.commands.RegisterCommands<UnassignCommand>();
|
||||
this.commands.RegisterCommands<UnblacklistCommand>();
|
||||
this.commands.RegisterCommands<UnsetTicketCommand>();
|
||||
Logger.Log("Registering commands...");
|
||||
commands = discordClient.UseSlashCommands();
|
||||
|
||||
Console.WriteLine("Hooking command events...");
|
||||
this.commands.CommandErrored += this.eventHandler.OnCommandError;
|
||||
commands.RegisterCommands<AddCategoryCommand>();
|
||||
commands.RegisterCommands<AddCommand>();
|
||||
commands.RegisterCommands<AddMessageCommand>();
|
||||
commands.RegisterCommands<AddStaffCommand>();
|
||||
commands.RegisterCommands<AssignCommand>();
|
||||
commands.RegisterCommands<BlacklistCommand>();
|
||||
commands.RegisterCommands<CloseCommand>();
|
||||
commands.RegisterCommands<CreateButtonPanelCommand>();
|
||||
commands.RegisterCommands<CreateSelectionBoxPanelCommand>();
|
||||
commands.RegisterCommands<ListAssignedCommand>();
|
||||
commands.RegisterCommands<ListCommand>();
|
||||
commands.RegisterCommands<ListOpen>();
|
||||
commands.RegisterCommands<ListUnassignedCommand>();
|
||||
commands.RegisterCommands<MoveCommand>();
|
||||
commands.RegisterCommands<NewCommand>();
|
||||
commands.RegisterCommands<RandomAssignCommand>();
|
||||
commands.RegisterCommands<RemoveCategoryCommand>();
|
||||
commands.RegisterCommands<RemoveMessageCommand>();
|
||||
commands.RegisterCommands<RemoveStaffCommand>();
|
||||
commands.RegisterCommands<SayCommand>();
|
||||
commands.RegisterCommands<SetSummaryCommand>();
|
||||
commands.RegisterCommands<StatusCommand>();
|
||||
commands.RegisterCommands<SummaryCommand>();
|
||||
commands.RegisterCommands<ToggleActiveCommand>();
|
||||
commands.RegisterCommands<TranscriptCommand>();
|
||||
commands.RegisterCommands<UnassignCommand>();
|
||||
commands.RegisterCommands<UnblacklistCommand>();
|
||||
commands.RegisterCommands<AdminCommands>();
|
||||
|
||||
Console.WriteLine("Connecting to Discord...");
|
||||
await this.discordClient.ConnectAsync();
|
||||
}
|
||||
Logger.Log("Hooking command events...");
|
||||
commands.SlashCommandErrored += EventHandler.OnCommandError;
|
||||
|
||||
Logger.Log("Connecting to Discord...");
|
||||
await discordClient.ConnectAsync();
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
<ApplicationIcon>ellie_icon.ico</ApplicationIcon>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
|
||||
<Version>1.2.0</Version>
|
||||
|
||||
<StartupObject>SupportChild.SupportChild</StartupObject>
|
||||
<Authors>EmotionChild</Authors>
|
||||
<Product />
|
||||
|
@ -13,34 +13,33 @@
|
|||
<RepositoryUrl>https://github.com/EmotionChild/SupportChild</RepositoryUrl>
|
||||
<RepositoryType>Git</RepositoryType>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
<PackageIconUrl>https://cdn.emotionchild.com/Ellie.png</PackageIconUrl>
|
||||
<Description>A Discord support bot build for the Ellie's Home Discord server</Description>
|
||||
<AssemblyVersion>2.6.1.1</AssemblyVersion>
|
||||
<FileVersion>2.6.1.1</FileVersion>
|
||||
<PackageIconUrl>https://cdn.discordapp.com/attachments/765441543100170271/914327948667011132/Ellie_Concept_2_transparent_ver.png</PackageIconUrl>
|
||||
<Description>A Discord support ticket bot built for the Ellie's home server</Description>
|
||||
<NeutralLanguage>en</NeutralLanguage>
|
||||
<PackageVersion>1.2.0</PackageVersion>
|
||||
<Version>3.0.0.1</Version>
|
||||
<PackageVersion>1.3.0</PackageVersion>
|
||||
<AssemblyVersion>3.0.0.1</AssemblyVersion>
|
||||
<FileVersion>3.0.0.1</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DebugType>full</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DSharpPlus" Version="4.2.0" />
|
||||
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.2.0" />
|
||||
<PackageReference Include="DSharpPlus.Interactivity" Version="4.2.0" />
|
||||
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.2.0" />
|
||||
<PackageReference Include="Gress" Version="2.0.1" />
|
||||
<PackageReference Include="JsonExtensions" Version="1.2.0" />
|
||||
<PackageReference Include="MiniRazor.CodeGen" Version="2.2.1" />
|
||||
<PackageReference Include="MySql.Data" Version="8.0.29" />
|
||||
<PackageReference Include="MySql.Data" Version="8.0.30" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="Polly" Version="7.2.3" />
|
||||
<PackageReference Include="Superpower" Version="3.0.0" />
|
||||
<PackageReference Include="Tyrrrz.Extensions" Version="1.6.5" />
|
||||
<PackageReference Include="YamlDotNet" Version="11.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<PackageReference Include="WebMarkupMin.Core" Version="2.9.0" />
|
||||
<PackageReference Include="YamlDotNet" Version="12.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -50,13 +49,6 @@
|
|||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="lib\" />
|
||||
</ItemGroup>
|
||||
|
@ -67,4 +59,12 @@
|
|||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -3,50 +3,42 @@ using System.Threading.Tasks;
|
|||
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Discord.Data;
|
||||
using DiscordChatExporter.Core.Exceptions;
|
||||
using DiscordChatExporter.Core.Exporting;
|
||||
using DiscordChatExporter.Core.Exporting.Filtering;
|
||||
using DiscordChatExporter.Core.Exporting.Partitioning;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
|
||||
namespace SupportChild
|
||||
{
|
||||
namespace SupportChild;
|
||||
|
||||
internal static class Transcriber
|
||||
{
|
||||
internal static async Task ExecuteAsync(ulong channelID, uint ticketID)
|
||||
{
|
||||
DiscordClient discordClient = new DiscordClient(new AuthToken(AuthTokenKind.Bot, Config.token));
|
||||
ChannelExporter Exporter = new ChannelExporter(discordClient);
|
||||
DiscordClient discordClient = new DiscordClient(Config.token);
|
||||
ChannelExporter exporter = new ChannelExporter(discordClient);
|
||||
|
||||
if (!Directory.Exists("./transcripts"))
|
||||
{
|
||||
Directory.CreateDirectory("./transcripts");
|
||||
}
|
||||
|
||||
string dateFormat = "yyyy-MMM-dd HH:mm";
|
||||
|
||||
// Configure settings
|
||||
if (Config.timestampFormat != "")
|
||||
dateFormat = Config.timestampFormat;
|
||||
|
||||
Channel channel = await discordClient.GetChannelAsync(new Snowflake(channelID));
|
||||
Guild guild = await discordClient.GetGuildAsync(channel.GuildId);
|
||||
|
||||
ExportRequest request = new ExportRequest(
|
||||
guild: guild,
|
||||
channel: channel,
|
||||
outputPath: GetPath(ticketID),
|
||||
format: ExportFormat.HtmlDark,
|
||||
after: null,
|
||||
before: null,
|
||||
partitionLimit: PartitionLimit.Null,
|
||||
messageFilter: MessageFilter.Null,
|
||||
shouldDownloadMedia: false,
|
||||
shouldReuseMedia: false,
|
||||
dateFormat: dateFormat
|
||||
Guild: guild,
|
||||
Channel: channel,
|
||||
OutputPath: GetPath(ticketID),
|
||||
Format: ExportFormat.HtmlDark,
|
||||
After: null,
|
||||
Before: null,
|
||||
PartitionLimit: PartitionLimit.Null,
|
||||
MessageFilter: MessageFilter.Null,
|
||||
ShouldDownloadMedia: false,
|
||||
ShouldReuseMedia: false,
|
||||
DateFormat: "yyyy-MMM-dd HH:mm"
|
||||
);
|
||||
|
||||
await Exporter.ExportChannelAsync(request);
|
||||
await exporter.ExportChannelAsync(request);
|
||||
}
|
||||
|
||||
internal static string GetPath(uint ticketNumber)
|
||||
|
@ -59,4 +51,3 @@ namespace SupportChild
|
|||
return "ticket-" + ticketNumber.ToString("00000") + ".html";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,38 +1,23 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.Entities;
|
||||
|
||||
namespace SupportChild
|
||||
{
|
||||
namespace SupportChild;
|
||||
|
||||
public static class Utilities
|
||||
{
|
||||
public static List<T> RandomizeList<T>(List<T> list)
|
||||
private static readonly Random rng = new Random();
|
||||
|
||||
public static void Shuffle<T>(this IList<T> list)
|
||||
{
|
||||
RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
|
||||
int n = list.Count;
|
||||
while (n > 1)
|
||||
{
|
||||
byte[] box = new byte[1];
|
||||
do provider.GetBytes(box);
|
||||
while (!(box[0] < n * (Byte.MaxValue / n)));
|
||||
int k = (box[0] % n);
|
||||
n--;
|
||||
T value = list[k];
|
||||
list[k] = list[n];
|
||||
list[n] = value;
|
||||
int k = rng.Next(n + 1);
|
||||
(list[k], list[n]) = (list[n], list[k]);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static string[] ParseIDs(string args)
|
||||
{
|
||||
if (string.IsNullOrEmpty(args))
|
||||
{
|
||||
return new string[0];
|
||||
}
|
||||
return args.Trim().Replace("<@!", "").Replace("<@", "").Replace(">", "").Split();
|
||||
}
|
||||
|
||||
public static LinkedList<string> ParseListIntoMessages(List<string> listItems)
|
||||
|
@ -54,18 +39,27 @@ namespace SupportChild
|
|||
return messages;
|
||||
}
|
||||
|
||||
public static DiscordRole GetRoleByName(DiscordGuild guild, string Name)
|
||||
public static async Task<List<Database.Category>> GetVerifiedChannels()
|
||||
{
|
||||
Name = Name.Trim().ToLower();
|
||||
foreach (DiscordRole role in guild.Roles.Values)
|
||||
List<Database.Category> verifiedCategories = new List<Database.Category>();
|
||||
foreach (Database.Category category in Database.GetAllCategories())
|
||||
{
|
||||
if (role.Name.ToLower().StartsWith(Name))
|
||||
DiscordChannel channel = null;
|
||||
try
|
||||
{
|
||||
return role;
|
||||
}
|
||||
channel = await SupportChild.discordClient.GetChannelAsync(category.id);
|
||||
}
|
||||
catch (Exception) { /*ignored*/ }
|
||||
|
||||
return null;
|
||||
if (channel != null)
|
||||
{
|
||||
verifiedCategories.Add(category);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Warn("Category '" + category.name + "' (" + category.id + ") no longer exists! Ignoring...");
|
||||
}
|
||||
}
|
||||
return verifiedCategories;
|
||||
}
|
||||
}
|
|
@ -1,31 +1,30 @@
|
|||
bot:
|
||||
# Bot token.
|
||||
token: "<add-token-here>"
|
||||
# Command prefix.
|
||||
prefix: "-"
|
||||
# Channel where ticket logs are posted (recommended)
|
||||
log-channel: 000000000000000000
|
||||
# Category where the ticket will be created, it will have the same permissions of that ticket plus read permissions for the user opening the ticket (recommended)
|
||||
ticket-category: 000000000000000000
|
||||
# A message which will open new tickets when users react to it (optional)
|
||||
reaction-message: 000000000000000000
|
||||
# Message posted when a ticket is opened.
|
||||
welcome-message: "Please describe your issue below, and include all information needed for us to help you."
|
||||
welcome-message: "Please describe your issue below, and include all information needed for us to take action."
|
||||
# Decides what messages are shown in console
|
||||
# Possible values are: Critical, Error, Warning, Information, Debug.
|
||||
console-log-level: "Information"
|
||||
# Format for timestamps in transcripts and google sheets if used
|
||||
timestamp-format: "yyyy-MM-dd HH:mm"
|
||||
# One of the following: LongDate, LongDateTime, LongTime, RelativeTime, ShortDate, ShortDateTime, ShortTime
|
||||
# More info: https://dsharpplus.github.io/api/DSharpPlus.TimestampFormat.html
|
||||
timestamp-format: "RelativeTime"
|
||||
# Whether or not staff members should be randomly assigned tickets when they are made. Individual staff members can opt out using the toggleactive command.
|
||||
random-assignment: true
|
||||
# If set to true the rasssign command will include staff members set as inactive if a specific role is specified in the command.
|
||||
# This can be useful if you have admins set as inactive to not automatically recieve tickets and then have moderators elevate tickets when needed.
|
||||
# This can be useful if you have admins set as inactive to not automatically receive tickets and then have moderators elevate tickets when needed.
|
||||
random-assign-role-override: true
|
||||
# Sets the type of activity for the bot to display in its presence status
|
||||
# Possible values are: Playing, Streaming, ListeningTo, Watching, Competing
|
||||
presence-type: "ListeningTo"
|
||||
# Sets the activity text shown in the bot's status
|
||||
presence-text: "-new"
|
||||
presence-text: "/new"
|
||||
# Set to true if you want the /new command to show a selection box instead of a series of buttons
|
||||
new-command-uses-selector: false
|
||||
# Number of tickets a single user can have open at a time, staff members are excluded from this
|
||||
ticket-limit: 5
|
||||
|
||||
notifications:
|
||||
# Notifies the assigned staff member when a new message is posted in a ticket if the ticket has been silent for a configurable amount of time
|
||||
|
@ -47,38 +46,3 @@ database:
|
|||
# Username and password for authentication
|
||||
user: ""
|
||||
password: ""
|
||||
|
||||
# Set up which roles are allowed to use different commands.
|
||||
# Example:
|
||||
# new: [ 000000000000000000, 111111111111111111 ]
|
||||
# They are grouped into suggested command groups below for first time setup.
|
||||
permissions:
|
||||
# Public commands
|
||||
close: []
|
||||
list: []
|
||||
new: []
|
||||
say: []
|
||||
status: []
|
||||
summary: []
|
||||
transcript: []
|
||||
# Moderator commands
|
||||
add: []
|
||||
addmessage: []
|
||||
assign: []
|
||||
blacklist: []
|
||||
listassigned: []
|
||||
listoldest: []
|
||||
listunassigned: []
|
||||
move: []
|
||||
rassign: []
|
||||
removemessage: []
|
||||
setsummary: []
|
||||
toggleactive: []
|
||||
unassign: []
|
||||
unblacklist: []
|
||||
# Admin commands
|
||||
addstaff: []
|
||||
reload: []
|
||||
removestaff: []
|
||||
setticket: []
|
||||
unsetticket: []
|
Binary file not shown.
Loading…
Reference in a new issue