-
Notifications
You must be signed in to change notification settings - Fork 0
Attachments Usage
Arthur Neuman edited this page Jul 6, 2020
·
2 revisions
The attachments system is used to keep environments usable in commands that are defined outside the scope.
For example, with a proper modular commands system, you normally would not have access to your database manager. However, if your database manager is added as an attachment, your commands will be able to reference it with the agent attached.
const {
TOKEN,
DATABASE_URL
} = process.env
const Eris = require('eris')
const Knex = require('knex')
const {
commands
} = require('./data/')
const knex = new Knex({
client: 'pg',
connection: DATABASE_URL
})
const agent = new Agent({
Eris,
token: TOKEN,
handlerData: {
commands
}
})
agent.attach('db', knex)
agent.connect()
const {
Command
} = require('cyclone-engine')
const data = {
name: 'points',
desc: 'See how many points you have',
action: ({ agent, msg }) => {
return agent.attachments.db('users')
.select('points')
.where({
id: msg.author.id
})
.limit(1)
.then((res) => {
if (res) return res.points
else return 'You aren\'t registered in the database'
})
}
}
module.exports = new Command(data)