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

Commit a2d93ac

Browse files
added more code to mydata
1 parent 3b571c2 commit a2d93ac

File tree

1 file changed

+52
-29
lines changed

1 file changed

+52
-29
lines changed

src/commands/main/mydata.ts

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,68 @@
1+
/* import { config } from "../../config.toml";
2+
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
3+
import mysql from "mysql";
14
2-
/*import {config} from "../../config.toml"
3-
import {SlashCommandBuilder, EmbedBuilder} from "discord.js"
45
6+
const connection = mysql.createConnection({
7+
credientials to be added soon
8+
});
59
610
module.exports = {
711
data: new SlashCommandBuilder()
8-
.setName("mydata")
9-
.setDescription("Returns data on yourself from DB."),
12+
.setName("mydata")
13+
.setDescription("Returns data on yourself from DB."),
1014
1115
async execute(interaction) {
1216
try {
1317
const user = interaction.user;
14-
const userId = interaction.user.id; // needed for DB methinks
15-
16-
if ("") { // if there is datta in the user found in DB (attended an event and logged)
17-
const embed = new EmbedBuilder()
18-
.setColor(config.EmbedColor)
19-
.setTitle(`Information Retrieved on ${user}`)
20-
.addFields(
21-
{ name: "Events Attended", value: "DB Stuff Here" },
22-
{ name: "Events Hosted", value: "Events Hosted" },
23-
// add a field for squads? (are they gonna last though?)
24-
)
25-
await interaction.reply({ embed: embed})
26-
}
27-
else { // if theres no information on the user (they havent attended an event and not been logged)
28-
const embedFail = new EmbedBuilder()
29-
.setColor(config.EmbedColorFail)
30-
.setTitle("No Data Found")
31-
.setDescription("You need to be logged for an event before you can retrieve your data.")
32-
await interaction.reply({ embed: embedFail})
33-
}
18+
const userId = interaction.user.id; // Needed for DB
19+
20+
// Query the DB to fetch data related to the user
21+
connection.query('SELECT * FROM KOGDB WHERE userid = ?', [userId], async (err, results) => {
22+
if (err) {
23+
console.error(err);
24+
const embedError = new EmbedBuilder()
25+
.setColor(config.EmbedColorError)
26+
.setTitle("Database Error")
27+
.setDescription("An error occurred while trying to retrieve your data.");
28+
await interaction.reply({ embeds: [embedError] });
29+
return;
30+
}
31+
32+
if (results.length > 0) {
33+
34+
retrieve information here (later)
35+
36+
const embed = new EmbedBuilder()
37+
.setColor(config.EmbedColor)
38+
.setTitle(`Information Retrieved on ${user.username}`)
39+
.addFields(
40+
{ name: "Events Attended", value: eventsAttended },
41+
{ name: "Events Hosted", value: eventsHosted }
42+
);
43+
44+
await interaction.reply({ embeds: [embed] });
45+
46+
} else {
47+
no data found
48+
const embedFail = new EmbedBuilder()
49+
.setColor(config.EmbedColorFail)
50+
.setTitle("No Data Found")
51+
.setDescription("You need to be logged for an event before you can retrieve your data.");
52+
53+
await interaction.reply({ embeds: [embedFail] });
54+
}
55+
});
56+
3457
} catch (error) {
3558
console.error(error);
3659
const embedError = new EmbedBuilder()
37-
.setColor(config.EmbedColorError)
38-
.setTitle("Error")
39-
.setDescription("An error occurred while trying to retrieve your data.")
40-
await interaction.reply({ embed: embedError})
60+
.setColor(config.EmbedColorError)
61+
.setTitle("Error")
62+
.setDescription("An error occurred while trying to retrieve your data.");
63+
await interaction.reply({ embeds: [embedError] });
4164
}
4265
}
43-
}
66+
};
4467
4568
*/

0 commit comments

Comments
 (0)