Skip to content

Commit

Permalink
feat: add /cancel command
Browse files Browse the repository at this point in the history
  • Loading branch information
roziscoding committed Aug 14, 2022
1 parent c0d9ebd commit 3c13d16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Bot, Context, session, SessionFlavor } from 'grammy'
import { start } from './commands'
import { cancel } from './commands/cancel'
import { AppConfig } from './config'
import { WizardFlavor, wizards } from './util/wizard'
import setInfo from './wizards/set-info'
Expand Down Expand Up @@ -29,6 +30,7 @@ export async function getBot(config: AppConfig) {

bot.use(...wizards([setInfo]))

bot.command(cancel.name, cancel.fn)
bot.command(start.name, start.fn)

return bot
Expand Down
16 changes: 16 additions & 0 deletions src/commands/cancel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { AppContext } from '../bot'

export const cancel = {
name: 'cancel',
helpText: 'Cancela a operação atual',
fn: (ctx: AppContext) => {
if (ctx.session.wizard?.id === 'setInfo') {
ctx.session.city = ''
ctx.session.name = ''
ctx.session.pixKey = ''
}
ctx.wizard.exit()
delete ctx.session.query
return ctx.reply('Ok, deixa pra lá')
}
}

0 comments on commit 3c13d16

Please sign in to comment.