1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import asyncdispatch, strformat, telebot
const COMMANDS = [
# command arguments description
[ "daysuntilcongress", "", "prints the number of days till congress." ],
[ "help", "[[command]]", "prints the description of the given command." ],
[ "stats", "", "print some stats…dunno?" ],
[ "uptime", "", "prints the uptime of this bot." ],
[ "yesorno", "", "helps with decisions." ],
]
proc helpCommand* (bot: Telebot, command: Command): Future[bool] {.async.} =
var answer = ""
if command.params.len() > 0:
let command = command.params
answer = fmt"Could not find Command ›/{command}‹"
for index in 0..( COMMANDS.len() - 1 ):
let entry = COMMANDS[ index ]
if entry[ 0 ] == command:
let arguments = entry[ 1 ]
let description = entry[ 2 ]
answer = fmt"/{command} {arguments}{'\n'} {description}"
break
else:
answer = "This Bot reacts to messages…\n"
answer &= "…starting with ›/‹ (see below),\n"
answer &= "…containing ›penis‹,\n"
answer &= "…containing ›/s‹ somewhere.\n"
answer &= "Available Commands:"
for index in 0..( COMMANDS.len() - 1 ):
let entry = COMMANDS[ index ]
let command = entry[ 0 ]
let arguments = entry[ 1 ]
let description = entry[ 2 ]
answer &= fmt"{'\n'}/{command} {arguments} – {description}"
discard await bot.sendMessage(command.message.chat.id, answer, replyToMessageId = command.message.messageId, parseMode = "markdown")