generated from bot-base/telegram-bot-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
41 changed files
with
398 additions
and
502 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
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
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,34 @@ | ||
import { Composer } from "grammy" | ||
import { getMarkdownTable, Row } from "markdown-table-ts" | ||
import type { Context } from "#root/bot/context.js" | ||
import { logHandle } from "#root/bot/helpers/logging.js" | ||
import { kFormatter } from "#root/bot/helpers/numbers.js" | ||
import { | ||
countAllBalanceRecords, | ||
getBalanceChangeTypeName, | ||
getUserBalanceRecords, | ||
} from "#root/bot/models/balance.js" | ||
import { formatDateTimeCompact } from "#root/bot/helpers/time.js" | ||
|
||
const composer = new Composer<Context>() | ||
const feature = composer.chatType("private") | ||
|
||
feature.command("balance", logHandle("command-balance"), async ctx => { | ||
const count = await countAllBalanceRecords() | ||
const records = await getUserBalanceRecords(ctx.dbuser.id, count) | ||
const body: Row[] = records.map(v => [ | ||
kFormatter(v.amount), | ||
getBalanceChangeTypeName(v.type), | ||
v.createdAt ? formatDateTimeCompact(v.createdAt) : "", | ||
]) | ||
const md = `${ctx.t("line.count", { count })} | ||
\`\`\`\n${getMarkdownTable({ | ||
table: { | ||
head: ["$CUBE", "Type", "Date"], | ||
body, | ||
}, | ||
})}\n\`\`\`` | ||
await ctx.replyWithMarkdown(md) | ||
}) | ||
|
||
export { composer as balanceFeature } |
Oops, something went wrong.