-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
99 lines (82 loc) · 2 KB
/
main.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
'use strict';
const config = require('./config.json');
const path = require('path').join;
const {mkdirSync} = require('fs-extra');
const {Sequelize, DataTypes} = require('sequelize');
const voxClient = require('voxclient').Client;
const { Client, GatewayIntentBits } = require('discord.js');
const discordEvents = require('./modules/discordEvents');
const discordInteractions = require('./modules/discordCommands');
// Ctrl+Cでexitするようにする。
process.once('SIGINT', () => process.exit(0));
// exit
process.once('exit', () => {
console.log('end');
});
// クライアントインスタンスの作成
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
client.db = new Sequelize({
dialect: 'sqlite',
storage: path(__dirname, 'db.sqlite'),
});
client.VoiceCache = client.db.define('VoiceCache', {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
content: {
type: DataTypes.STRING,
allowNull: false,
},
speaker: {
type: DataTypes.INTEGER,
allowNull: false,
},
counter: {
type: DataTypes.INTEGER,
}
});
client.UserData = client.db.define('UserData', {
userid: {
type: DataTypes.INTEGER,
primaryKey: true
},
speaker: {
type: DataTypes.INTEGER,
},
});
client.CommandsData = client.db.define('BotData', {
name: {
type: DataTypes.STRING,
primaryKey: true,
},
hash: {
type: DataTypes.STRING,
allowNull: false,
}
});
client.db.sync();
client.tempdir=path(__dirname, 'tmp')
client.queue = [];
try{
mkdirSync(client.tempdir);
}
catch(e){
if(e.code!='EEXIST'){
console.error(e);
process.exit(1);
}
}
client.voicevox = new voxClient(config.voicevox.address);
client.query = [];
// client.player = createAudioPlayer();
discordInteractions(client);
(async () => {
await Promise.all([
discordEvents(client),
discordInteractions(client),
]);
// discordにログインする。
await client.login(config.Discord.token);
})();