-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
91 lines (73 loc) · 2.66 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const { REST, Routes, Collection, Client, GatewayIntentBits } = require('discord.js');
require('dotenv').config();
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.MessageContent] });
const fs = require('node:fs');
const path = require('node:path');
const Sequelize = require('sequelize')
const express = require('express');
// const { data } = require('./Commands/settings');
const app = express()
const datatable = {};
const sequelize = new Sequelize('database', 'user', 'password', {
host: 'localhost',
dialect: 'sqlite',
logging: false,
storage: 'database.sqlite',
});
module.exports = sequelize;
const commandsPath = path.join(__dirname, 'Commands');
const eventsPath = path.join(__dirname, 'Events');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
client.commands = new Collection();
const commands = [];
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
client.on('messageCreate', message => {
const prefix = "!"
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(" ");
if (args[0].toLowerCase() === "get") {
const player = args[1]
const playerData = datatable[player]
if (playerData) {
message.reply("Player " + player + " has " + playerData.money + " money");
} else {
message.reply("Player " + player + " does not exist in the data");
}
}
});
app.get("/update", function (req, res) {
const player = req.query.player
const money = req.query.money
if (player && money) {
if (!datatable[player]) {
datatable[player] = {}
}
datatable[player].money = money
console.log(`Update ${player} with ${money} money`)
res.send(`Update ${player} with ${money} money`)
} else {
res.status(400).send('Missing player or money data.')
}
})
app.listen(3000, () => {
console.log(`Express is on Port 3000`)
})
async function startApp() {
try {
await client.login(process.env.TOKEN);
} catch (error) {
console.log(`Failed to login | ${error}`);
process.exit(1);
}
}
startApp();
module.exports = { client };