-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfb2472
commit 2b51ec7
Showing
21 changed files
with
135 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { safeHtml, stripIndents } from 'common-tags' | ||
import { format } from 'util' | ||
import { Command } from '../domain/Command' | ||
|
||
export const getInfo: Command = { | ||
name: 'getinfo', | ||
helpText: 'Exibe todas as informações que eu tenho sobre você', | ||
fn: async (ctx) => { | ||
const message = format( | ||
'Aqui estão todas as informações que eu tenho sobre você:\n\n```\n%s```', | ||
stripIndents(safeHtml)` | ||
<b>Chave PIX</b>: ${ctx.session.pixKey} | ||
<b>Cidade</b>: ${ctx.session.city} | ||
<b>Nome</b>: ${ctx.session.name} | ||
` | ||
) | ||
|
||
return ctx.reply(message, { parse_mode: 'HTML' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as commands from '.' | ||
import { Command } from '../domain/Command' | ||
|
||
const help: Command = { | ||
name: 'help', | ||
fn: async (ctx) => { | ||
const message = [ | ||
'Aqui está a lista dos comandos mais importantes:\n', | ||
...Object.values(commands) | ||
.filter((command) => !!command.helpText) | ||
.map((command) => `/${command.name}: ${command.helpText}`) | ||
].join('\n') | ||
|
||
return ctx.reply(message) | ||
} | ||
} | ||
|
||
export default help |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export * from './cancel' | ||
export * from './getInfo' | ||
export * from './help' | ||
export * from './privacy' | ||
export * from './repo' | ||
export * from './set-info' | ||
export * from './start' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { format } from 'util' | ||
import { Command } from '../domain/Command' | ||
import { PRIVACY_POLICY_URL, PRIVACY_TEXT } from '../util/strings' | ||
|
||
export const privacy: Command = { | ||
name: 'privacy', | ||
helpText: 'Envia o link da política de privacidade do bot', | ||
fn: async (ctx) => { | ||
const message = format(PRIVACY_TEXT, PRIVACY_POLICY_URL) | ||
|
||
return ctx.reply(message, { parse_mode: 'MarkdownV2' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { format } from 'util' | ||
import { Command } from '../domain/Command' | ||
import { REPO_URL } from '../util/strings' | ||
|
||
export const repo: Command = { | ||
name: 'repo', | ||
helpText: 'Envia o link do repositório do bot', | ||
fn: async (ctx) => { | ||
const message = format('Para obter meu código fonte, acesse meu [repositório no GitHub](%s)', REPO_URL) | ||
|
||
return ctx.reply(message, { parse_mode: 'MarkdownV2' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { AppContext } from '../bot' | ||
import { Command } from '../domain/Command' | ||
|
||
export const setInfo = { | ||
export const setInfo: Command = { | ||
name: 'setinfo', | ||
helpText: 'Define suas informações', | ||
fn: async (ctx: AppContext) => { | ||
fn: async (ctx) => { | ||
return ctx.conversation.enter('setInfo') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Command } from '../domain/Command' | ||
|
||
export const stop: Command = { | ||
name: 'stop', | ||
helpText: 'Apaga todos os dados que eu tenho armazenados sobre você', | ||
fn: async (ctx) => { | ||
return ctx.conversation.enter('stop') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Conversation, createConversation } from '@grammyjs/conversations' | ||
import { InlineKeyboard } from 'grammy' | ||
import { AppContext } from '../bot' | ||
|
||
const stop = async (converstion: Conversation<AppContext>, ctx: AppContext) => { | ||
await ctx.reply('Deseja realmente apagar todos os seus dados?', { | ||
reply_markup: new InlineKeyboard().text('Sim', 'y').text('Não', 'n') | ||
}) | ||
|
||
const [confirmation, newContext] = await converstion | ||
.waitFor('callback_query:data') | ||
.then(async (ctx) => { | ||
await ctx.editMessageReplyMarkup({}) | ||
return ctx | ||
}) | ||
.then((ctx) => { | ||
return [ctx.callbackQuery.data === 'y', ctx] as const | ||
}) | ||
|
||
if (!confirmation) { | ||
return ctx.reply('Beleza, não vou apagar nada então.') | ||
} | ||
|
||
newContext.session.name = '' | ||
newContext.session.pixKey = '' | ||
newContext.session.city = '' | ||
delete newContext.session.query | ||
|
||
return ctx.reply('Pronto. Excluí todos os dados que eu tinha sobre você') | ||
} | ||
|
||
export default createConversation(stop) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,7 @@ | ||
import { Message, Params, Telegram } from 'typegram' | ||
import { UserRepository } from '../repositories/users' | ||
import { Markup, sendMessage } from '../util/telegram/sendMessage' | ||
import { Awaitable } from '../util/types/Awaitable' | ||
import { Response } from './Response' | ||
import { User } from './User' | ||
|
||
export type Context = { | ||
user: User | ||
repository: UserRepository | ||
message: Message.TextMessage | ||
match: RegExpMatchArray | null | ||
command: Command | ||
sendMessage: ( | ||
text: string, | ||
markdown?: boolean, | ||
markup?: Markup, | ||
extra?: Partial<Params<'sendMessage', any>[0]> | ||
) => ReturnType<typeof sendMessage> | ||
} | ||
import { AppContext } from '../bot' | ||
|
||
export type Command = { | ||
name: string | ||
regex: RegExp | ||
helpText?: string | ||
fn: (ctx: Context) => Awaitable<Response<keyof Telegram> | null> | ||
fn: (ctx: AppContext) => any | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as math from 'mathjs' | ||
|
||
export async function evaluateQuery(query: string): Promise<number> { | ||
return math.round(math.evaluate(query), 2) | ||
} |