forked from hemisemidemipresent/cyberquincy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
173 lines (149 loc) · 5.81 KB
/
server.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
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
const { Client, GatewayIntentBits, InteractionType, ChatInputCommandInteraction } = require('discord.js');
function main() {
pingHeroku();
globalRequirements();
consoleBootup();
googleSheetsInitialization();
configureAliases();
// commandCenter = configureCommands();
slashCommandCenter = setupSlashCommandCenter();
generateCommandListeners(slashCommandCenter);
login();
}
function pingHeroku() {
let isTesting = require('./1/config.json')['testing'];
if (isTesting) return;
const express = require('express');
// this part is to keep the project going
const app = express();
// app.use(express.static('public'));
app.get('/', (request, response) => {
let d = new Date(Date.now());
d.toString();
response.sendStatus(200);
});
app.listen(process.env.PORT || 3000);
}
function globalRequirements() {
global.colours = require('./jsons/colors.json');
global.Towers = require('./helpers/towers.js');
global.Heroes = require('./helpers/heroes.js')
global.AliasRepository = require('./alias-repository.js');
global.Discord = require('discord.js');
global.client = new Client({
intents: [GatewayIntentBits.Guilds]
});
global.prefix = require('./1/config.json')['prefix'];
global.Cooldowns = require('./helpers/cooldowns.js');
global.CommandParser = require('./parser/command-parser.js');
global.UserCommandError = require('./exceptions/user-command-error.js');
global.DeveloperCommandError = require('./exceptions/developer-command-error.js');
//global.Xp = require('./helpers/xp.js');
//global.DiscordUsers = require('./helpers/discord-users.js');
//global.xpEnabled = true;
}
function consoleBootup() {
client.once('ready', () => {
client.user.setPresence({
activity: {
name: `${prefix}help`
},
status: 'online'
});
console.log('<Program Directive> Discord Bot Client is ready');
const botposting = require('./1/config.json')['botposting'];
if (!botposting) {
global.statcord = undefined;
return;
}
const Statcord = require('statcord.js');
let statcordKey = require('./1/config.json')['statcord'];
if (!statcordKey || statcordKey === 'no') {
console.log('[INFO] statcord is not configured');
return;
}
const statcord = new Statcord.Client({
client,
key: statcordKey
});
statcord.autopost();
statcord.on('autopost-start', () => {
// Emitted when statcord autopost starts
console.log('[POST] started autopost');
});
statcord.on('post', (status) => {
// status = false if the post was successful
// status = "Error message" or status = Error if there was an error
if (!status) {
//console.log('[POST] successful Statcord post');
} else console.error(status);
});
statcord.autopost().catch((error) => {
console.log(error.name);
console.error('[ERROR] Something is wrong with statcord autopost');
});
// Make available globally
global.statcord = statcord;
});
}
async function googleSheetsInitialization() {
let btd6index = require('./1/config.json')['btd6index'];
if (!btd6index) return;
const GoogleSheetsHelper = require('./helpers/google-sheets.js');
// Load the BTD6 Index
global.Btd6Index = await GoogleSheetsHelper.load(GoogleSheetsHelper.BTD6_INDEX_KEY);
console.log('<INITIATE> Btd6 Index has been loaded');
}
function configureAliases() {
const AliasRepository = require('./alias-repository.js');
global.Aliases = new AliasRepository();
Aliases.asyncAliasFiles();
}
// function configureCommands() {
// commandCenter = require('./command_center');
// commandCenter.configureCommands(client);
// return commandCenter;
// }
function setupSlashCommandCenter() {
slashCommandCenter = require('./slash_command_center');
slashCommandCenter.configureCommands(client);
slashCommandCenter.extendStructure(ChatInputCommandInteraction);
return slashCommandCenter;
}
function generateCommandListeners(slashCommandCenter) {
global.Guilds = require('./helpers/guilds.js');
client.on('guildCreate', async (guild) => {
try {
return await Guilds.enterGuild(guild);
} catch (e) {
return; // probably Missing Permissions
}
});
// q! commands - no longer exist as of August 2022 due to Discord making bots changes to slash commands
// and this bot doesnt have a valid reason to be using message content so we do not have this intent
// * https://support-dev.discord.com/hc/en-us/articles/4404772028055-Message-Content-Privileged-Intent-FAQ
// client.on('messageCreate', async (message) => {
// commandCenter.handleCommand(message);
// });
// slash commands
client.on('interactionCreate', async (interaction) => {
if (interaction.type === InteractionType.ApplicationCommand) slashCommandCenter.handleCommand(interaction);
if (interaction.isButton()) slashCommandCenter.handleButton(interaction);
if (interaction.type === InteractionType.ApplicationCommandAutocomplete)
slashCommandCenter.handleAutocomplete(interaction);
if (interaction.isSelectMenu()) slashCommandCenter.handleSelectMenu(interaction);
});
}
function login() {
const { ActivityType } = require('discord.js');
configHelper = require('./helpers/config');
const activeToken = configHelper.activeToken();
client.login(activeToken).then(() => {
client.user?.setActivity('/help', { type: ActivityType.Listening });
});
}
try {
main();
} catch (e) {
console.log(e);
}