-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
110 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
const { Events } = require('discord.js'); | ||
|
||
|
||
async function registerBotOnReady(client) { | ||
await client.core.refreshBotInfo(true); | ||
await client.core.updateServerSortOrder(); | ||
} | ||
|
||
module.exports = { | ||
name: Events.ClientReady, | ||
once: false, | ||
async execute(client) { | ||
await registerBotOnReady(client); | ||
const core = client.core; | ||
await core.refreshBotInfo(true); | ||
await core.updateServerSortOrder(); | ||
global.logger.info(`Logged in as ${client.user.tag}!`); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,4 @@ module.exports = { | |
return false; | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,27 @@ | ||
const botMethods = require('./botMethods'); | ||
const botController = require('./botController'); | ||
const _ = require('lodash'); | ||
|
||
module.exports = { | ||
...botMethods, | ||
...botController, | ||
|
||
function rejectInvocation(method) { | ||
this.logger.warn('CALLING CLIENT METHODS BEFORE LOGIN'); | ||
console.trace(method); | ||
return {}; | ||
} | ||
|
||
function requireClientLogin(modulePath) { | ||
const moduleObj = require(modulePath); | ||
return _.mapValues(moduleObj, (method) => { | ||
return function(...args) { | ||
if (this.client && this.client.isReady()) { | ||
return method.apply(this, args); | ||
} else { | ||
return rejectInvocation(method); | ||
} | ||
}; | ||
}); | ||
} | ||
|
||
module.exports = { | ||
...require('./methods'), | ||
...require('./controller'), | ||
...requireClientLogin('./afterAuth') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module.exports = { | ||
async updatePowerState(powerOn, discordBotInst = null) { | ||
this.logger.debug('Changing Discord Bot Power State: ', discordBot); | ||
const discordBot = discordBotInst || await this.discordBot.get(); | ||
await this.emitCompiled([ | ||
'nav/user/buttons/botPowerButton.pug', | ||
'nav/user/userBoxInfo.pug', | ||
'nav/servers/addServer.pug' | ||
], { | ||
discordBot, | ||
state: await this.state.update({ discord_state: powerOn }) | ||
}); | ||
}, | ||
|
||
async getInviteLink() { | ||
const discordBot = await this.discordBot.get(); | ||
const inviteLink = discordBot.bot_invite_link; | ||
return inviteLink; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,8 @@ | ||
const discord = require('./discord'); | ||
const websocket = require('./websocket'); | ||
const server = require('./server'); | ||
const rendering = require('./rendering'); | ||
|
||
|
||
function bindMethods(methods, cls) { | ||
for (let [name, method] of Object.entries(methods)) { | ||
cls[name] = method; | ||
} | ||
} | ||
const _ = require('lodash'); | ||
|
||
module.exports = (core) => { | ||
bindMethods(discord, core); | ||
bindMethods(websocket, core); | ||
bindMethods(server, core); | ||
bindMethods(rendering, core); | ||
_.mixin(core, require('./websocket')); | ||
_.mixin(core, require('./server')); | ||
_.mixin(core, require('./rendering')); | ||
_.mixin(core, require('./discord')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
const serverBarRendering = require('./serverBarRendering'); | ||
const templateCompiler = require('./templateCompiler'); | ||
|
||
module.exports = { | ||
...serverBarRendering, | ||
...templateCompiler, | ||
} | ||
...require('./serverBarRendering'), | ||
...require('./templateCompiler') | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
const processTerminator = require('./processTerminator.js'); | ||
|
||
module.exports = { | ||
...processTerminator, | ||
} | ||
...require('./processTerminator.js') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,19 @@ | ||
const { createHttpTerminator } = require('http-terminator'); | ||
const logger = global.logger; | ||
|
||
|
||
module.exports = { | ||
generateTerminator() { | ||
const serverTerminator = createHttpTerminator({ server: this.server }) | ||
const logger = this.logger; | ||
|
||
async function cleanup() { | ||
logger.info('IN CLEANUP'); | ||
try { | ||
await serverTerminator.terminate(); | ||
} catch (error) { | ||
logger.error('Failed to terminate server:', error); | ||
} | ||
} | ||
|
||
async function uncaught(signal, e) { | ||
logger.error(`Uncaught exception encountered\n...CHECK LOGS.`, signal, e); | ||
console.trace(signal, e); | ||
} | ||
|
||
async function shutdownServer(signal, e) { | ||
logger.silly(`Received ${signal}\n${e}\n...Shutting down gracefully.`); | ||
await cleanup(); | ||
process.exit(); | ||
async uncaughtShutdown(signal, e) { | ||
logger.error(`Uncaught exception encountered\n...CHECK LOGS.`, signal, e); | ||
console.trace(signal, e); | ||
}, | ||
async shutdownServer(signal, e) { | ||
logger.silly(`Received ${signal}\n${e}\n...Shutting down gracefully.`); | ||
try { | ||
const serverTerminator = createHttpTerminator({ server: this.server }).terminate(); | ||
} catch (error) { | ||
logger.error('Failed to terminate server:', error); | ||
} | ||
|
||
// SETTING EVENT HANDLERS FOR ON SHUTDOWN | ||
process.on('SIGINT', (e) => shutdownServer('SIGNINT', e)); | ||
process.on('SIGTERM', (e) => shutdownServer('SIGTERM', e)); | ||
process.on('uncaughtException', (e) => uncaught('uncaughtException', e)); | ||
|
||
return shutdownServer; | ||
process.exit(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
const connections = require('./connections'); | ||
|
||
module.exports = { | ||
...connections, | ||
} | ||
...require('./connections'), | ||
}; | ||
|