Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit f29dc04

Browse files
converted all commands to .ts, updated it with class, final copy (until database is completed
1 parent 7b7312d commit f29dc04

File tree

4 files changed

+226
-124
lines changed

4 files changed

+226
-124
lines changed

src/commands/main/log.ts

Lines changed: 117 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,159 @@
1-
/*import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
2-
import mysql from "mysql";
3-
const allowedroleID = "" // do this later when I have perms
4-
const logchannel = ""
1+
import { SlashCommandBuilder, EmbedBuilder, ChatInputCommandInteraction } from "discord.js";
2+
import mysql from "mysql";
3+
import { KOGBot } from "index.ts";
4+
import { SlashCommand } from "main.d.ts"; //
5+
6+
const allowedroleID = ""; // Set this later when I have perms
7+
const logchannel = ""; // log channel
58
const connection = mysql.createConnection({
6-
// credientials to be added soon
9+
// goes here
710
});
811

9-
module.exports = {
10-
data: new SlashCommandBuilder()
11-
.setName("log")
12-
.setDescription("Logs offical events for KOG."),
12+
class LogEventCommand implements SlashCommand {
13+
name = "log";
14+
description = "Logs official events for KOG.";
15+
subcommands = [];
16+
parameters = [];
17+
dev = true;
18+
kogBot: KOGBot;
19+
20+
constructor(kogBot: KOGBot) {
21+
this.kogBot = kogBot;
22+
}
1323

14-
async execute(interaction) {
24+
async execute(interaction: ChatInputCommandInteraction): Promise<void> {
1525
try {
16-
if (!interaction.member.role.cache.has(allowedroleID)) {
26+
// Check for required role
27+
if (!interaction.member?.roles.cache.has(allowedroleID)) {
1728
const noperms = new EmbedBuilder()
18-
.setColor("#E73A3A")
19-
.setTitle("Error")
20-
.setDescription("You don't have the required role to use this command.")
21-
.setTimestamp()
29+
.setColor("#E73A3A")
30+
.setTitle("Error")
31+
.setDescription("You don't have the required role to use this command.")
32+
.setTimestamp();
2233

23-
await interaction.reply({ embeds: [noperms], ephemeral: true})
24-
34+
await interaction.reply({ embeds: [noperms], ephemeral: true });
35+
return;
2536
}
2637

38+
2739
const logStart = new EmbedBuilder()
28-
.setColor("#9033FF")
29-
.setTitle("Logging")
30-
.setDescription("To log an event, please follow the following format:\n\n<@1344176447551574078>,<@1138235120424325160>,<@110877167897853952>,<@573540579682811906> and so on.\n\nNames must be seperated by commas and must be mentions. Otherwise you'll be asked to re do it.\n\nYou have 2 minutes to submit attendees, before this times out.\n\nTo cancel, please type **cancel**.")
31-
.setTimestamp()
40+
.setColor("#9033FF")
41+
.setTitle("Logging")
42+
.setDescription("To log an event, please follow the format:\n\n<@user1>,<@user2>,<@user3>...\n\nNames must be separated by commas and must be mentions.") // put peoples names here
43+
.setTimestamp();
3244

33-
await interaction.reply({ embeds: [logStart], ephemeral: true})
45+
await interaction.reply({ embeds: [logStart], ephemeral: true });
3446

35-
const filter = (message) => message.author.id === interaction.user.id && message.channel.id === interaction.channel.id;
47+
const filter = (message: any) => message.author.id === interaction.user.id && message.channel.id === interaction.channel.id;
3648
const input = await interaction.channel.awaitMessages({ filter, max: 1, time: 60000, errors: ['time'] });
37-
const response = userInput.first().content;
38-
49+
const response = input.first()?.content;
50+
3951
const mentionRegexthing = /^<@\d+>(?:,\s?<@\d+>)*$/;
40-
41-
if (!mentionRegexthing.test(response)) {
42-
return interaction.followUp("Invalid format. Please make sure the names are separated by commas and each name is a mention. Run the command again and use the correct format.");
43-
}
4452

45-
if (error instanceof Error && error.message === 'time') {
46-
return interaction.reply(`<@${interaction.user.id}> you took too long to follow up, please try again.`);
53+
if (!mentionRegexthing.test(response!)) {
54+
return interaction.followUp("Invalid format. Please make sure the names are separated by commas and each name is a mention. Run the command again with the correct format.");
4755
}
48-
if (response.toLowerCase() === 'cancel') {
56+
57+
if (response?.toLowerCase() === 'cancel') {
4958
return interaction.reply(`<@${interaction.user.id}> canceled the event log.`);
5059
}
51-
52-
const mentions = response.split(',').map(id => id.trim().replace('<@', '').replace('>', ''));
53-
const userIds = []
60+
61+
if (response instanceof Error && response.message === 'time') {
62+
return interaction.reply(`<@${interaction.user.id}> you took too long to follow up, please try again.`);
63+
}
64+
65+
const mentions = response.split(',').map((id: string) => id.trim().replace('<@', '').replace('>', ''));
66+
const userIds: string[] = [];
5467

5568
for (const mention of mentions) {
56-
const userId = mention.slice(2, -1)
57-
if (userId)
58-
userIds.push(userId)
69+
const userId = mention.slice(2, -1);
70+
if (userId) userIds.push(userId);
5971
}
6072

6173
if (userIds.length === 0) {
6274
return interaction.reply("No users mentioned. Please try again.");
6375
}
76+
77+
// Log the event in the log channel
6478
const timestamp = Math.floor(Date.now() / 1000);
6579
const logEmbed = new EmbedBuilder()
66-
.setColor("#9033FF")
67-
.setTitle("Log Event")
68-
.setDescription(`A new event was logged.\n\nHost: ${interaction.user.id}\n\nTime: <t:${timestamp}:F>\n\nAttendees: ${mentions.map(id => `<@${id}>`).join(', ')}\n\nSquadron Rally: False`) // set to false until we integrate with squads??
69-
.setTimestamp()
80+
.setColor("#9033FF")
81+
.setTitle("Log Event")
82+
.setDescription(`A new event was logged.\n\nHost: ${interaction.user.id}\n\nTime: <t:${timestamp}:F>\n\nAttendees: ${mentions.map(id => `<@${id}>`).join(', ')}\n\nSquadron Rally: False`)
83+
.setTimestamp();
84+
85+
const logChannel = await interaction.client.channels.fetch(logchannel);
86+
if (logChannel) {
87+
await logChannel.send({ embeds: [logEmbed] });
88+
}
89+
90+
91+
for (const userId of userIds) {
92+
connection.query(// 'SELECT COUNT(*) AS eventCount FROM events WHERE userId = ?' this is not final (async will do db)
93+
, [userId], async (err, results) => {
94+
if (err) {
95+
console.error(err);
96+
return interaction.followUp("There was an error querying the database.");
97+
}
7098

71-
await logchannel.send({embeds: [logStart], ephemeral: false})
99+
const eventCount = results[0]?.eventCount || 0;
72100

73-
// database stuff will go here: example
101+
102+
74103

75-
if ("We have updated the DB") {
76-
const DB = new EmbedBuilder()
77-
.setColor("#9033FF")
78-
.setTitle("Log Event")
79-
.setDescription(`Database updated, event has been logged succesfully.`)
80-
.setTimestamp()
104+
if (eventCount === 5) {
105+
const promotionEmbed = new EmbedBuilder()
106+
.setColor("#FFBF00")
107+
.setTitle("Promotion Needed")
108+
.setDescription(`<@${userId}> has reached 5 events! This user needs promoting.`)
109+
.setTimestamp();
110+
} else if (eventCount >= 10) {
111+
const promotionEmbed = new EmbedBuilder()
112+
.setColor("#FFD700")
113+
.setTitle("Promotion Needed")
114+
.setDescription(`<@${userId}> has reached 10 events! Consider promoting them.`)
115+
.setTimestamp();
116+
}
81117

82-
await logchannel.send({embeds: [DB], ephemeral: false})
118+
/
119+
if (promotionEmbed) {
120+
await logChannel.send({ embeds: [promotionEmbed] });
121+
}
122+
});
83123
}
84-
else {
124+
125+
// database updating goes here
126+
127+
128+
if () { // database logging
129+
const dbEmbed = new EmbedBuilder()
130+
.setColor("#9033FF")
131+
.setTitle("Log Event")
132+
.setDescription("Database updated, event has been logged successfully.")
133+
.setTimestamp();
134+
135+
await logChannel.send({ embeds: [dbEmbed] });
136+
} else {
85137
const errorEmbed = new EmbedBuilder()
86-
.setColor("#E73A3A")
87-
.setTitle("Error")
88-
.setDescription("An error occurred while updating the DB. The database has not been updated and the log has failed\nContact <@1344176447551574078> or <@1138235120424325160>")
89-
90-
await logchannel.send({embeds: [errorEmbed], ephemeral: false})
91-
}
138+
.setColor("#E73A3A")
139+
.setTitle("Error")
140+
.setDescription("An error occurred while updating the DB. The database has not been updated, and the log has failed.\nContact the admin for support.")
141+
.setTimestamp();
92142

143+
await logChannel.send({ embeds: [errorEmbed] });
144+
}
93145

94146
} catch (error) {
95-
console.log(error)
147+
console.log(error);
96148
const errorEmbed = new EmbedBuilder()
97149
.setColor("#E73A3A")
98150
.setTitle("Error")
99151
.setDescription("An error occurred while executing this command.")
100-
101-
await interaction.reply({embeds: [errorEmbed], ephemeral: true})
102-
}
103-
152+
.setTimestamp();
153+
154+
await interaction.reply({ embeds: [errorEmbed], ephemeral: true });
104155
}
105156
}
106-
*/
157+
}
158+
159+
export default LogEventCommand;

src/commands/main/mydata.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
/* import { config } from "../../config.toml";
2-
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
3-
import mysql from "mysql";
4-
1+
import { SlashCommandBuilder, EmbedBuilder, ChatInputCommandInteraction } from "discord.js";
2+
import mysql from "mysql";
3+
import { KOGBot } from "index.ts";
4+
import { SlashCommand } from "main.d.ts";
55

66
const connection = mysql.createConnection({
7-
credientials to be added soon
7+
// cool connections goes here
88
});
99

10-
module.exports = {
11-
data: new SlashCommandBuilder()
12-
.setName("mydata")
13-
.setDescription("Returns data on yourself from DB."),
10+
class GetDataCommand implements SlashCommand {
11+
name = "mydata";
12+
description = "Returns data on yourself from DB.";
13+
subcommands = [];
14+
parameters = [];
15+
dev = true; // dev for now
16+
kogBot: KOGBot;
17+
18+
constructor(kogBot: KOGBot) {
19+
this.kogBot = kogBot;
20+
}
1421

15-
async execute(interaction) {
22+
async execute(interaction: ChatInputCommandInteraction): Promise<void> {
1623
try {
1724
const user = interaction.user;
1825
const userId = interaction.user.id; // Needed for DB
1926

20-
2127
connection.query('SELECT * FROM KOGDB WHERE userid = ?', [userId], async (err, results) => {
2228
if (err) {
2329
console.error(err);
@@ -30,21 +36,20 @@ module.exports = {
3036
}
3137

3238
if (results.length > 0) {
33-
34-
retrieve information here (later)
39+
40+
const { eventsAttended, eventsHosted } = results[0];
3541

3642
const embed = new EmbedBuilder()
3743
.setColor("#9033FF")
3844
.setTitle(`Information Retrieved on ${user.username}`)
3945
.addFields(
40-
{ name: "Events Attended", value: eventsAttended },
41-
{ name: "Events Hosted", value: eventsHosted }
46+
{ name: "Events Attended", value: eventsAttended.toString() },
47+
{ name: "Events Hosted", value: eventsHosted.toString() }
4248
);
4349

4450
await interaction.reply({ embeds: [embed] });
4551

4652
} else {
47-
no data found
4853
const embedFail = new EmbedBuilder()
4954
.setColor("#E73A3A")
5055
.setTitle("No Data Found")
@@ -57,12 +62,12 @@ module.exports = {
5762
} catch (error) {
5863
console.error(error);
5964
const embedError = new EmbedBuilder()
60-
.setColor(config.EmbedColorError)
65+
.setColor("#E73A3A")
6166
.setTitle("Error")
6267
.setDescription("An error occurred while trying to retrieve your data.");
6368
await interaction.reply({ embeds: [embedError] });
6469
}
6570
}
66-
};
71+
}
6772

68-
*/
73+
export default GetDataCommand;

src/commands/misc/kill.ts

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,44 @@
1-
/*const { SlashCommandBuilder, EmbedBuilder } = import("discord.js"); // async is a stinky and made me use import require on top all im saying
2-
const config = ("../../config.toml")
3-
4-
module.exports = {
5-
data: new SlashCommandBuilder()
6-
.setName('kill')
7-
.setDescription("Kill a user (in messages)."),
8-
.addUserOption(option =>
9-
option.setName('user')
10-
.setDescription('The user to kill.')
11-
.setRequired(true)
12-
)
13-
},
14-
async execute(interaction) {
15-
16-
const user = interaction.getUser();
17-
const embed = new EmbedBuilder()
18-
.setColor("#9033FF")
19-
.setTitle('Killed')
20-
.setDescription(`I have killed the stinky of <@{user.id}>`);
21-
await interaction.reply({ embeds: [embed] });
1+
import { SlashCommandBuilder, EmbedBuilder, ChatInputCommandInteraction, SlashCommand } from "discord.js";
2+
import { KOGBot } from "index.ts";
3+
4+
class KillCommand implements SlashCommand {
5+
name = 'kill';
6+
description = 'Kill a user (in messages).';
7+
subcommands = [];
8+
parameters = [];
9+
dev = true;
10+
kogBot: KOGBot;
11+
12+
constructor(kogBot: KOGBot) {
13+
this.kogBot = kogBot;
2214
}
23-
};
24-
*/
15+
16+
async execute(interaction: ChatInputCommandInteraction): Promise<void> {
17+
try {
18+
19+
const user = interaction.options.getUser('user');
20+
if (!user) {
21+
return interaction.reply("No user was mentioned. Please mention a user to kill.");
22+
}
23+
24+
const embed = new EmbedBuilder()
25+
.setColor("#9033FF")
26+
.setTitle('Killed')
27+
.setDescription(`I have killed the stinky of <@${user.id}>`);
28+
29+
await interaction.reply({ embeds: [embed] });
30+
} catch (error) {
31+
console.error("Error in executing kill command:", error);
32+
33+
const errorEmbed = new EmbedBuilder()
34+
.setColor("#E73A3A")
35+
.setTitle("Error")
36+
.setDescription("An error occurred while executing the kill command.")
37+
.setTimestamp();
38+
39+
await interaction.reply({ embeds: [errorEmbed], ephemeral: true });
40+
}
41+
}
42+
}
43+
44+
export default KillCommand;

0 commit comments

Comments
 (0)