mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 18:29:08 +00:00
[bot] working version
This commit is contained in:
parent
d4112c4252
commit
aeac74ae98
8 changed files with 351 additions and 0 deletions
12
packages/roleypoly-bot/commands/_types.js.flow
Normal file
12
packages/roleypoly-bot/commands/_types.js.flow
Normal file
|
@ -0,0 +1,12 @@
|
|||
// @flow
|
||||
import type { Message } from 'eris'
|
||||
import type Bot from '../Bot'
|
||||
|
||||
export type Command = {
|
||||
regex: RegExp,
|
||||
usage: string,
|
||||
description: string,
|
||||
handler: (bot: Bot, message: Message, matches: string[]) => Promise<string | void> | string | void
|
||||
}
|
||||
|
||||
export type CommandSet = Set<Command>
|
30
packages/roleypoly-bot/commands/dm.js
Normal file
30
packages/roleypoly-bot/commands/dm.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
// @flow
|
||||
import type { Command } from './_types'
|
||||
import { withTyping } from '../utils'
|
||||
import type Bot from '../Bot'
|
||||
import type { Message } from 'eris'
|
||||
|
||||
const cmds: Command[] = [
|
||||
{
|
||||
regex: /^\blog ?in|auth\b/,
|
||||
usage: 'login',
|
||||
description: 'responds with a login token and link',
|
||||
|
||||
handler: withTyping(async (bot: Bot, msg: Message) => {
|
||||
const chall = await bot.rpc.issueAuthChallenge(msg.author.id)
|
||||
return chall
|
||||
})
|
||||
},
|
||||
{
|
||||
regex: /^\blog ?out\b/,
|
||||
usage: 'logout',
|
||||
description: 'removes all sessions',
|
||||
|
||||
handler: withTyping(async (bot: Bot, msg: Message) => {
|
||||
await bot.rpc.removeUserSessions(msg.author.id)
|
||||
return `I've logged you out!`
|
||||
})
|
||||
}
|
||||
]
|
||||
|
||||
export default new Set<Command>(cmds)
|
30
packages/roleypoly-bot/commands/root.js
Normal file
30
packages/roleypoly-bot/commands/root.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
// @flow
|
||||
import type { Command } from './_types'
|
||||
import type Bot from '../Bot'
|
||||
import type { Message } from 'eris'
|
||||
import { withTyping } from '../utils'
|
||||
|
||||
const cmds: Command[] = [
|
||||
{
|
||||
regex: /^remove sessions for/,
|
||||
usage: 'remove sessions for <mention>',
|
||||
description: 'removes all sessions for a given user.',
|
||||
|
||||
handler: withTyping(async (bot: Bot, msg: Message) => {
|
||||
const u = msg.mentions[0]
|
||||
await bot.rpc.removeUserSessions(u.id)
|
||||
return `${u.mention} should no longer be logged in on any device.`
|
||||
})
|
||||
},
|
||||
{
|
||||
regex: /^always error/,
|
||||
usage: 'always error',
|
||||
description: 'creates an error',
|
||||
|
||||
handler: () => {
|
||||
throw new Error('not an error, this is actually a success.')
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
export default new Set<Command>(cmds)
|
18
packages/roleypoly-bot/commands/text.js
Normal file
18
packages/roleypoly-bot/commands/text.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
// @flow
|
||||
import type { Command } from './_types'
|
||||
import type Bot from '../Bot'
|
||||
import type { Message } from 'eris'
|
||||
|
||||
const cmds: Command[] = [
|
||||
{
|
||||
regex: /^hi/,
|
||||
usage: 'hi',
|
||||
description: 'says hello',
|
||||
|
||||
handler: (bot: Bot, msg: Message) => {
|
||||
msg.channel.createMessage('Hi there!')
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
export default new Set<Command>(cmds)
|
Loading…
Add table
Add a link
Reference in a new issue