[bot] working version

This commit is contained in:
41666 2019-04-14 13:00:27 -05:00
parent d4112c4252
commit aeac74ae98
No known key found for this signature in database
GPG key ID: BC51D07640DC10AF
8 changed files with 351 additions and 0 deletions

View 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>

View 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)

View 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)

View 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)