-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from Sayrix/feat
Some Feature Updates
- Loading branch information
Showing
14 changed files
with
194 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {BaseCommand, ExtendedClient} from "../structure"; | ||
import {CommandInteraction, SlashCommandBuilder} from "discord.js"; | ||
|
||
/* | ||
Copyright © 2024 小兽兽/zhiyan114 (github.com/zhiyan114) | ||
File is licensed respectively under the terms of the Creative Commons Attribution 4.0 International | ||
or whichever license the project is using at the time https://github.com/Sayrix/Ticket-Bot/blob/main/LICENSE.md | ||
*/ | ||
|
||
export default class AddCommand extends BaseCommand { | ||
public static data: SlashCommandBuilder = <SlashCommandBuilder>new SlashCommandBuilder() | ||
.setName("cleardm") | ||
.setDescription("Clear all of your ticket history in your DM"); | ||
constructor(client: ExtendedClient) { | ||
super(client); | ||
} | ||
|
||
async execute(interaction: CommandInteraction) { | ||
interaction.deferReply({ ephemeral: true }); | ||
|
||
const dm = await interaction.user.createDM(); | ||
|
||
let messages = (await dm.messages.fetch({ limit: 100 })) | ||
.filter((message) => message.author.id === this.client.user?.id); | ||
while(messages.size > 0) { | ||
for(const message of messages) | ||
await message[1].delete(); | ||
if(messages.size < 100) | ||
break; | ||
messages = await dm.messages.fetch({ limit: 100 }); | ||
} | ||
await interaction.followUp({ content: "Cleared all of your DM history", ephemeral: true }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import AddCommand from "./add"; | ||
import MassAddCommand from "./massadd"; | ||
import ClaimCommand from "./claim"; | ||
import CloseCommand from "./close"; | ||
import RemoveCommand from "./remove"; | ||
import RenameCommand from "./rename"; | ||
import clearDM from "./clearDM"; | ||
|
||
export { | ||
AddCommand, | ||
MassAddCommand, | ||
ClaimCommand, | ||
CloseCommand, | ||
RemoveCommand, | ||
RenameCommand | ||
RenameCommand, | ||
clearDM | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import {BaseCommand, ExtendedClient} from "../structure"; | ||
import {CommandInteraction, SlashCommandBuilder, TextChannel} from "discord.js"; | ||
import {log} from "../utils/logs"; | ||
|
||
/* | ||
Copyright © 2023 小兽兽/zhiyan114 (github.com/zhiyan114) | ||
File is licensed respectively under the terms of the Apache License 2.0 | ||
or whichever license the project is using at the time https://github.com/Sayrix/Ticket-Bot/blob/main/LICENSE | ||
*/ | ||
|
||
|
||
// Use add command if possible, otherwise you're missing out on proper user validation... | ||
export default class MassAddCommand extends BaseCommand { | ||
public static data: SlashCommandBuilder = <SlashCommandBuilder>new SlashCommandBuilder() | ||
.setName("massadd") | ||
.setDescription("Add multiple users to the ticket. It's recommended to use the regular add command when possible.") | ||
.addStringOption((input) => input.setName("users").setDescription("Users to add. Use ',' as seperator.").setRequired(true)); | ||
constructor(client: ExtendedClient) { | ||
super(client); | ||
} | ||
|
||
async execute(interaction: CommandInteraction) { | ||
|
||
// In-case users will try things | ||
const users = await Promise.all((interaction.options.get("users", true).value as string) | ||
.replace(/\s/g, "") // Remove space incase user adds it as a seperator | ||
.split(",") // Get a list from it | ||
.filter((user) => user !== "") // anti seperator spams at the end lmao | ||
.map(async user => await this.client.users.fetch(user))); // Convert it to discord users objects | ||
|
||
// Additional checks | ||
if(users.length == 0) return await interaction.reply({ content: "You need to specify at least one user", ephemeral: true }); | ||
if(users.length > 25) return await interaction.reply({ content: "You can't add more than 25 users", ephemeral: true }); | ||
|
||
const ticket = await this.client.prisma.tickets.findUnique({ | ||
select: { | ||
id: true, | ||
invited: true, | ||
}, | ||
where: { | ||
channelid: interaction.channel?.id | ||
} | ||
}); | ||
|
||
if (!ticket) return interaction.reply({ content: "Ticket not found", ephemeral: true }).catch((e) => console.log(e)); | ||
|
||
const invited = JSON.parse(ticket.invited) as string[]; | ||
|
||
for(const user of users) { | ||
if (invited.includes(user.id)) | ||
continue; | ||
|
||
if (invited.length >= 25) | ||
break; | ||
|
||
invited.push(user.id); | ||
|
||
await (interaction.channel as TextChannel | null)?.permissionOverwrites | ||
.edit(user, { | ||
SendMessages: true, | ||
AddReactions: true, | ||
ReadMessageHistory: true, | ||
AttachFiles: true, | ||
ViewChannel: true, | ||
}); | ||
log( | ||
{ | ||
LogType: "userAdded", | ||
user: interaction.user, | ||
ticketId: ticket.id.toString(), | ||
ticketChannelId: interaction.channel?.id, | ||
target: user, | ||
}, | ||
this.client | ||
); | ||
} | ||
|
||
await this.client.prisma.tickets.update({ | ||
data: { | ||
invited: JSON.stringify(invited) | ||
}, | ||
where: { | ||
channelid: interaction.channel?.id | ||
} | ||
}); | ||
|
||
await interaction.reply({ content: "> Mass User Add Completed! Do note that not all users may be added if internal checks failed. It's advise you use the regular add command to guarantee the add status." }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters