-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
59 lines (48 loc) · 1.81 KB
/
bot.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
"use strict";
const azureStorage = require('azure-storage');
const commando = require('discord.js-commando');
const path = require('path');
const sqlite = require('sqlite');
const express = require('express');
const port = process.env.PORT || 3000;
const Secrets = require('./config/Secrets');
const Authenticator = require('./network/Authenticator');
const PingHandler = require('./network/PingHandler');
const TableStorageProvider = require('./providers/TableStorageProvider');
const client = new commando.CommandoClient({
owner: [
'559861066251894847', '106647509031452672', // joeflint
'559793784771051531', // daleclai
]
});
client.registry
.registerDefaultTypes()
.registerDefaultGroups()
.registerDefaultCommands({ eval_: false })
.registerGroup('calendar', 'Calendar')
.registerGroup('config', 'Configuration')
.registerTypesIn(path.join(__dirname, 'types'))
.registerCommands([
require('./commands/config/Auth'),
require('./commands/calendar/CreateEvent'),
require('./commands/calendar/Out'),
]);
/**
* @returns {Promise<commando.SettingProvider>}
*/
async function selectProvider() {
let tableServiceConnectionString = await Secrets.tableServiceConnectionString();
if (tableServiceConnectionString) {
return new TableStorageProvider(azureStorage.createTableService(tableServiceConnectionString));
} else {
let db = await sqlite.open(path.join(__dirname, 'settings.sqlite3'));
return new commando.SQLiteProvider(db);
}
}
client.setProvider(selectProvider()).catch(console.error);
Secrets.discordToken().then((token) => client.login(token));
let app = express();
Authenticator.outlook.setupCallbackHandler(app, client);
PingHandler(app);
app.listen(port);
console.log('Server running at http://localhost:%d', port);