-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·240 lines (202 loc) · 7.64 KB
/
app.js
File metadata and controls
executable file
·240 lines (202 loc) · 7.64 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
const Discord = require('discord.js');
// configs
const config = require('./config.json');
const permission = require('./permission.json');
// class
const AlanaDB = require('./src/AlanaDB');
const AlanaController = require('./src/AlanaController');
const AlanaCommand = require('./src/AlanaCommand');
const AlanaTTS = require('./src/AlanaTTS');
const AlanaSTT = require('./src/AlanaSTT');
// module
const AlanaRequest = require('./src/AlanaRequest');
const AlanaParser = require('./src/AlanaParser');
const AlanaConfig = require('./src/AlanaConfig');
const AlanaDialog = require('./src/AlanaDialog');
const AlanaGame = require('./src/AlanaGame');
const AlanaGuildManager = require('./src/AlanaGuildManager');
const AlanaGameManager = require('./src/AlanaGameManager');
let database = new AlanaDB();
let tts = new AlanaTTS();
let stt = new AlanaSTT();
const client = new Discord.Client({ partials: ['MESSAGE', 'REACTION'] });
client.on('ready', () => {
console.log('Starting!');
client.user.setActivity(`Listening to : ${config.prefix.game}`);
const chan = client.channels.resolve(config.rulesChannel);
const emoji = chan.guild.emojis.cache.find(d => d.name === 'play');
chan.messages.fetchPinned().then(msgs => msgs.forEach(msg => msg.react(emoji)));
});
// config command
let createConfigCommand = new AlanaCommand(
AlanaConfig.createConfig,
{},
() => `\`${config.prefix.dev}config create <JSON>\n\``,
function () {
return this.generalHelp() + 'Create a configuration. Configuration pecify the bots to use in the request.\nE.g:\n `'+ config.prefix.dev +'config create {JSON TEMPLATE}`\n';
}
);
let deleteConfigCommand = new AlanaCommand(
AlanaConfig.deleteConfig,
{},
() => `\`${config.prefix.dev}config delete <configuration name>\n\``,
function () {
return this.generalHelp() + 'Delete a configuration, and all the dialog using it. bot to use in the request.\nE.g:\n `'+ config.prefix.dev +'config delete test_config`\n';
}
);
let getConfigCommand = new AlanaCommand(
AlanaConfig.getConfig,
{},
() => `\`${config.prefix.dev}config get <name>\n\``,
function () {
return this.generalHelp() + 'Print the JSON of the config named <name>. Useful to copy it.\nE.g:'+config.prefix.dev+'config get config1\n';
}
);
let templateConfigCommand = new AlanaCommand(
AlanaConfig.printTemplate,
{},
() => `\`${config.prefix.dev}config template\n\``,
function () {
return this.generalHelp() + 'Print a template of configuration\n';
}
);
let listConfigCommand = new AlanaCommand(
AlanaConfig.listConfig,
{},
() => `\`${config.prefix.dev}config list\n\``,
function () {
return this.generalHelp() + 'List all the configuration\n';
}
);
let configCommand = new AlanaCommand(
() => console.log("INFO: Config command called"),
{'create': createConfigCommand, 'delete': deleteConfigCommand, 'template': templateConfigCommand, 'list': listConfigCommand, 'get': getConfigCommand},
function() {
return `\`${config.prefix.dev}config <subcomand>\`\n${this.listSubCommand().join(', ')}\n`;
}
);
// dialog command
let listDialogCommand = new AlanaCommand(
AlanaDialog.listDialog,
{},
() => `\`${config.prefix.dev}dialog list\n\``,
function () { // redundant
return this.generalHelp() + 'List all the dialog\n';
}
);
let startDialogCommand = new AlanaCommand(
AlanaDialog.startDialog,
{},
() => `\`${config.prefix.dev}dialog start <prefix> <config name>\n\``,
function () {
return this.generalHelp() + 'Start a dialog using a specific configuration. To talk to Alana, start your message with your <prefix>.\nE.g:\n `'+ config.prefix.dev +'dialog start ! config_test`\n`!hello Alana`\n';
}
);
let endDialogCommand = new AlanaCommand(
AlanaDialog.endDialog,
{},
() => `\`${config.prefix.dev}dialog end <prefix>\n\``,
function () {
return this.generalHelp() + 'End a dialog (specify it by using the <prefix>).\nE.g:\n `'+ config.prefix.dev +'dialog end !`\n';
}
);
let talkDialogCommand = new AlanaCommand(
AlanaDialog.talkToggleDialog,
{},
() => `\`${config.prefix.dev}dialog talk <prefix>\n\``,
function () {
return this.generalHelp() + "Toggle the talk function. If it's true and the user is in a vocalChannel, the chatbot will join the user in the channel and read the next message with text to speech. If toggled to false, the bot will leave the channel.\n";
}
);
let listenDialogCommand = new AlanaCommand(
AlanaDialog.listenToggleDialog,
{},
() => `\`${config.prefix.dev}dialog listen <prefix>\n\``,
function () {
return this.generalHelp() + "Toggle the listen function. If it's true and the user is in a vocalChannel, the chatbot will join the user in the channel and listen to the user. If toggled to false, the bot will leave the channel.\n";
}
);
let dialogCommand = new AlanaCommand(
() => console.log("INFO: Dialog command called"),
{'start': startDialogCommand, end: endDialogCommand, list: listDialogCommand, 'talk': talkDialogCommand, 'listen': listenDialogCommand},
function() {
return `\`${config.prefix.dev}dialog <subcomand>\`\n${this.listSubCommand().join(', ')}\n`;
}
);
// dev command
let devPrefixCmd = new AlanaCommand(
() => console.log("INFO: Dev prefix called"),
{'dialog': dialogCommand, 'config': configCommand},
function(){
return `Dev Command prefix: ${config.prefix.dev}\n${this.listSubCommand().map(d => `\`${d}\``).join(', ')}\n`;
},
'',
permission.level.admins
);
//game commands
let startGameCommand = new AlanaCommand(
AlanaGame.startGameClassic,
{},
() => `\`${config.prefix.game}start_game\n\``,
function () {
return this.generalHelp() + "Start a normal game using fixed dialog.";
}
);
let startGameGPT2Command = new AlanaCommand(
AlanaGame.startGameGPT2,
{},
() => `\`${config.prefix.game}start_game_gpt2\n\``,
function () {
return this.generalHelp() + "Start a normal game using gpt2 dialog. There could only be one gpt2 game at a time, go it may be already used when you try. Please try another time. There's a timeout of 5 mins without activity on this type of dialog.";
}
);
let startGameGuidedCommand = new AlanaCommand(
AlanaGame.startGameGuided,
{},
() => `\`${config.prefix.game}start_game_guided\n\``,
function () {
return this.generalHelp() + "Start a normal game using guided dialog. Every possible option will be disclaused to you when the game master will give you description.";
}
);
let endGameCommand = new AlanaCommand(
AlanaGame.endGame,
{},
() => `\`${config.prefix.game}end_game\n\``,
function () {
return this.generalHelp() + "Terminate any type of game. It will also close the channel you're in.";
}
);
// game command
let gamePrefixCmd = new AlanaCommand(
() => console.log("INFO: Game prefix called"),
{
'start_game': startGameCommand,
'start_game_gpt2': startGameGPT2Command,
'start_game_guided': startGameGuidedCommand,
'end_game': endGameCommand
},
function(){
return `Game Command prefix: ${config.prefix.game}\n${this.listSubCommand().map(d => `\`${d}\``).join(', ')}\n`;
},
);
let cmdMessage = new AlanaCommand(
AlanaRequest.answer,
{[config.prefix.dev]: devPrefixCmd, [config.prefix.game]: gamePrefixCmd},
'',
'',
permission.level.blacklist,
AlanaParser.prefixParser
);
let reactionPlay = new AlanaCommand(
AlanaGuildManager.createChannel,
{},
'',
'',
permission.level.blacklist
);
let reactionCmd = {'play': reactionPlay};
let controller = new AlanaController(client, cmdMessage, reactionCmd, {}, database, tts, stt);
const interval = setInterval(() => {
AlanaGameManager.clearOldGPT2OrVoice(database, client, tts);
}, config.timeout);
client.login(config.token).then(() => console.log("We're in!")).catch((err) => console.log(err));