Skip to content

Commit 0a62517

Browse files
guh
1 parent 1beb778 commit 0a62517

File tree

5 files changed

+119
-8
lines changed

5 files changed

+119
-8
lines changed

db.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"698221698838691920":{}}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"author": "",
1313
"license": "ISC",
1414
"dependencies": {
15+
"axios": "^1.7.3",
1516
"discord.js": "^14.15.3",
1617
"dotenv": "^16.4.5",
1718
"fs": "0.0.1-security"

pnpm-lock.yaml

+73
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"name": "ping",
3+
"name": "userid",
44
"description": "Replies with Pong!"
55
}
66
]

src/server.ts

+43-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Client, GatewayIntentBits, REST, Routes } from 'discord.js';
22
import dotenv from 'dotenv';
33
import fs from 'fs';
4+
import axios from 'axios';
45
dotenv.config();
56
const commands = JSON.parse(fs.readFileSync('src/commands.json', 'utf-8'));
67

@@ -22,7 +23,7 @@ async function registerCommands() {
2223
console.log('Started refreshing application (/) commands.');
2324

2425
await rest.put(
25-
Routes.applicationCommands(process.env.CLIENT_ID!),
26+
Routes.applicationGuildCommands(process.env.CLIENT_ID!, process.env.GUILD_ID!),
2627
{ body: commands },
2728
);
2829

@@ -31,16 +32,51 @@ async function registerCommands() {
3132
console.error(error);
3233
}
3334
}
34-
35+
function readUserIds() {
36+
if (fs.existsSync('userids.json')) {
37+
const data = fs.readFileSync('db.json', 'utf-8');
38+
return JSON.parse(data);
39+
} else {
40+
return {};
41+
}
42+
}
43+
async function apikey(name: string) {
44+
try {
45+
const response = await axios.post(
46+
'https://gpt.anyvm.tech/v1/admin/create',
47+
{ name },
48+
{
49+
headers: {
50+
Authorization: 'Bearer (key-noshow)'
51+
}
52+
}
53+
);
54+
console.log( response.data);
55+
return response.data;
56+
} catch (error) {
57+
console.error(error);
58+
}
59+
}
60+
function writeUserIds(userIds: any) {
61+
const data = JSON.stringify(userIds);
62+
fs.writeFileSync('db.json', data, 'utf-8');
63+
}
3564
client.once('ready', async () => {
36-
console.log('Bot is online!');
65+
console.log('online');
3766
await registerCommands();
3867
});
3968

4069
client.on('interactionCreate', async interaction => {
4170
if (!interaction.isChatInputCommand()) return;
42-
43-
if (interaction.commandName === 'ping') {
44-
await interaction.reply('Pong!');
71+
const userId = interaction.user.id;
72+
const userIds = readUserIds();
73+
74+
if (interaction.commandName === 'userid') {
75+
await interaction.deferReply({ ephemeral: true });
76+
77+
userIds[userId] = apikey(userId);
78+
writeUserIds(userIds);
79+
80+
await interaction.followUp({ content: userId, ephemeral: true });
4581
}
46-
});
82+
});

0 commit comments

Comments
 (0)