Extends the 'hey/hi/hello/sup' functionality with a new `!toggle-hey` prefix command that enables/disables the bot from responding.
// ** DEV ** Customise values here
const messageContent = `Hey 👋 <@!${context.params.event.author.id}>!`
const toggleCommand = '!toggle-hey'
const key = 'hey-command'
// Request value stuff
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const event = context.params.event
const { channel_id, content } = event
// Make it active by default by storing the deactive state
const isDeactive = await lib.utils.kv['@0.1.16'].get({ key })
const isActive = !isDeactive
// Is this the toggle command?
if (content.startsWith(toggleCommand)) {
let message = null
if (isActive) {
await lib.utils.kv['@0.1.16'].set({ key, value: true })
message = "'Hey' command is now inactive"
}
else {
await lib.utils.kv['@0.1.16'].clear({ key })
message = "'Hey' command is now active"
}
await lib.discord.channels['@0.0.6'].messages.create({
channel_id, content: message,
message_reference: {
message_id: context.params.event.id
}
});
}
// Only respond to messages containing the word "hi", "hey", "hello", or "sup"
else if (isActive && context.params.event.content.match(/\bhi\b|\bhey\b|\bhello\b|\bsup\b/i))
await lib.discord.channels['@0.0.6'].messages.create({
channel_id,
content: messageContent,
message_reference: {
message_id: context.params.event.id
}
});