-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathbot.js
More file actions
executable file
·87 lines (74 loc) · 2.21 KB
/
bot.js
File metadata and controls
executable file
·87 lines (74 loc) · 2.21 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
// Utility libraries used throughout the app
global._ = require("underscore");
global.S = require("underscore.string");
global.moment = require("moment");
const { existsSync, readFileSync, readdirSync } = require("fs");
require("popyt");
//import { decode, encode } from "html-entities";
// Reload the last existing state of the config file, otherwise revert to the default
global.config = {};
if (existsSync("configState.json")) {
config = JSON.parse(readFileSync("configState.json", "utf-8"));
console.log("Loaded config file from configState.json");
} else {
config = JSON.parse(readFileSync("config.json", "utf-8"));
console.log("Loaded config file from config.json");
}
global.models = require('./models/index');
// @FIXME - YouTube connectivity
/*
if (config.apiKeys.youtube !== undefined) {
console.log("[YOUTUBE]", "Authenticating with youtube...");
var oauth = YouTube.authenticate({
type: "key",
key: config.apiKeys.youtube.api_key,
});
console.log("[YOUTUBE]", "Authenticated! " + JSON.stringify(oauth, null, 2));
}
*/
/**
* Custom functions accessible to commands
*/
/*
const getActiveDJs = function (maxIdleMins, startPosition, callback) {
var activeUsers = [];
if (startPosition === undefined) {
startPosition = 0;
}
Promise.map(_.rest(bot.getDJs(), startPosition), function (dj) {
return models.User.find({
where: { site_id: dj.id, site: config.site },
}).then(function (dbUser) {
if (dbUser !== null && dbUser.site_id !== bot.getSelf().id) {
if (secondsSince(dbUser.last_active) <= maxIdleMins * 60) {
activeUsers.push(dbUser);
}
}
});
}).then(function () {
callback(activeUsers);
});
};
*/
const Bot = require("ttapi");
global.bot = new Bot(config.auth.authKey, config.auth.userId);
bot.commands = [];
bot.user = {};
//bot.debug = config.verboseLogging;
global.roomState = {
mentions: { lastRunAll : 0, lastRunUsers: [] },
snags: 0,
};
require("./globals.js")();
try {
readdirSync("./functions").forEach(function (file) {
if (file.indexOf(".js") > -1) {
require(`./functions/${file}`)();
}
});
} catch (e) {
console.error("Unable to load function: ", e.stack);
}
loadEvents();
loadCommands();
loadExtensions();