-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
92b00cc
commit ed64a11
Showing
4 changed files
with
54 additions
and
38 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
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,15 @@ | ||
const { commands } = require('./commands'); | ||
const { createClient } = require('./utils/client'); | ||
const { getPrefix } = require('./utils/getprefix'); | ||
const settings = require('./settings.json'); | ||
const cluster = require('cluster'); | ||
const { startBot } = require('./start'); | ||
if (cluster.isMaster) { | ||
cluster.fork(); | ||
|
||
const client = createClient(); | ||
cluster.on('exit', function(worker, code, signal) { | ||
console.log("Bot restarting!") | ||
|
||
// Event handler for when a message is received | ||
client.on('messageCreate', (message) => { | ||
cluster.fork(); | ||
}); | ||
} | ||
|
||
// Ignore messages from bots | ||
if (message.author.bot) return; | ||
|
||
// Ignore messages outside of the designated channel | ||
if (message.channel.id != settings.channel) return; | ||
|
||
// Get the preferred prefix of the user, but default to the bot prefix | ||
getPrefix(message.author.id).then((preferred_prefix) => { | ||
|
||
// Only act on commands starting with the prefix | ||
if (!message.content.startsWith(preferred_prefix)) return; | ||
|
||
// Convert message to lowercase array and go through all the registered commands | ||
const args = message.content.substring(preferred_prefix.length).toLowerCase().split(' '); | ||
commands.forEach((command) => { | ||
// If the message matches any of the aliases, execute the corresponding function | ||
if (command.aliases.includes(args[0])) { | ||
command.func(message, args[1], args[2], args[3]) | ||
} | ||
}) | ||
}) | ||
}); | ||
|
||
// Log in the bot using the token | ||
client.login(settings.token); | ||
if (cluster.isWorker) { | ||
startBot(); | ||
} |
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,6 +1,8 @@ | ||
{ | ||
"dependencies": { | ||
"canvas": "^2.11.2", | ||
"cluster": "^0.7.7", | ||
"discord.js": "^14.9.0", | ||
"sqlite3": "^5.1.6" | ||
} | ||
} | ||
} |
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,38 @@ | ||
const { commands } = require('./commands'); | ||
const { createClient } = require('./utils/client'); | ||
const { getPrefix } = require('./utils/getprefix'); | ||
const settings = require('./settings.json'); | ||
|
||
function startBot() { | ||
const client = createClient(); | ||
|
||
// Event handler for when a message is received | ||
client.on('messageCreate', (message) => { | ||
|
||
// Ignore messages from bots | ||
if (message.author.bot) return; | ||
|
||
// Ignore messages outside of the designated channel | ||
if (message.channel.id != settings.channel) return; | ||
|
||
// Get the preferred prefix of the user, but default to the bot prefix | ||
getPrefix(message.author.id).then((preferred_prefix) => { | ||
|
||
// Only act on commands starting with the prefix | ||
if (!message.content.startsWith(preferred_prefix)) return; | ||
|
||
// Convert message to lowercase array and go through all the registered commands | ||
const args = message.content.substring(preferred_prefix.length).toLowerCase().split(' '); | ||
commands.forEach((command) => { | ||
// If the message matches any of the aliases, execute the corresponding function | ||
if (command.aliases.includes(args[0])) { | ||
command.func(message, args[1], args[2], args[3]) | ||
} | ||
}) | ||
}) | ||
}); | ||
|
||
// Log in the bot using the token | ||
client.login(settings.token); | ||
} | ||
exports.startBot = startBot; |