-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
131 lines (112 loc) · 3 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const Discord = require('discord.js');
const Sequelize = require('sequelize');
/**
* Intents and token setup and assignment
*/
const botIntents = new Discord.IntentsBitField();
botIntents.add(
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.DirectMessages,
Discord.GatewayIntentBits.MessageContent
);
const client = new Discord.Client({ intents: botIntents });
const { token } = require('./token.json');
/**
* Command & event collections mapped to client for easy access in handlers
*/
client.commands = new Discord.Collection();
client.commandArray = [];
client.events = new Discord.Collection();
client.cooldowns = new Set();
/**
* This section creates a DB using sequelize and sqlite, we also setup
* the data model to be used in the DB and both are attached to the client for easy access.
*/
client.dbRefresh = function (client) {
if (client.sequelize) {
client.sequelize.close();
}
client.sequelize = new Sequelize('database', 'user', 'password', {
host: 'localhost',
dialect: 'sqlite',
logging: false,
storage: './database/database.sqlite',
});
client.Tags = client.sequelize.define('tags', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: {
type: Sequelize.STRING,
unique: true,
allowNull: false,
},
dexNumber: {
type: Sequelize.INTEGER,
defaultValue: 0,
allowNull: false,
},
dexEntry: {
type: Sequelize.TEXT,
allowNull: false
},
type1: {
type: Sequelize.STRING,
allowNull: false,
},
type2: {
type: Sequelize.STRING,
defaultValue: null,
},
height: {
type: Sequelize.FLOAT,
defaultValue: 0,
},
weight: {
type: Sequelize.FLOAT,
defaultValue: 0,
},
hp: {
type: Sequelize.INTEGER,
defaultValue: 0,
},
atk: {
type: Sequelize.INTEGER,
defaultValue: 0,
},
def: {
type: Sequelize.INTEGER,
defaultValue: 0,
},
specialAtk: {
type: Sequelize.INTEGER,
defaultValue: 0,
},
specialDef: {
type: Sequelize.INTEGER,
defaultValue: 0,
},
speed: {
type: Sequelize.INTEGER,
defaultValue: 0,
},
doodle: {
type: Sequelize.STRING,
defaultValue: null,
},
});
console.log('Syncing DB');
client.Tags.sync();
console.log('Sync finished');
}
client.dbRefresh(client);
/**
* Loads the handlers and passess the client to them
*/
['command_handler', 'event_handler'].forEach(handler => {
require(`./handlers/${handler}`)(client)
});
client.login(token);