commit d2c5ade2771b8e570fca55fec8f7bfd12adf2df0
parent 7387b66befe41a14f3878a1a03ce1c1022a4c3b7
Author: ctucx <c@ctu.cx>
Date: Thu, 16 Jan 2020 11:22:39 +0100
parent 7387b66befe41a14f3878a1a03ce1c1022a4c3b7
Author: ctucx <c@ctu.cx>
Date: Thu, 16 Jan 2020 11:22:39 +0100
new commands: /whoami and /unixtime
4 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/cmd/unixtime.nim b/src/cmd/unixtime.nim @@ -0,0 +1,7 @@ +import asyncdispatch, telebot, strutils, times + +proc unixtimeCommand(bot: Telebot, command: Command) {.async.} = + var message = newMessage(command.message.chat.id, "```" & $(toUnix(getTime())) & "```") + message.replyToMessageId = command.message.messageId + message.parseMode = "markdown" + discard bot.send(message)+ \ No newline at end of file
diff --git a/src/cmd/uptime.nim b/src/cmd/uptime.nim @@ -2,7 +2,7 @@ import asyncdispatch, telebot, strutils, osproc proc uptimeCommand(bot: Telebot, command: Command) {.async.} = let uptime = execProcess("uptime", options={poUsePath}) - var message = newMessage(command.message.chat.id, "``" & uptime & "``") + var message = newMessage(command.message.chat.id, "```" & uptime & "```") message.replyToMessageId = command.message.messageId message.parseMode = "markdown" discard bot.send(message) \ No newline at end of file
diff --git a/src/cmd/whoami.nim b/src/cmd/whoami.nim @@ -0,0 +1,14 @@ +import asyncdispatch, telebot, strutils, options + +proc whoamiCommand(bot: Telebot, command: Command) {.async.} = + var text = "who are you?" + + let user = command.message.fromUser.get + + if user.username.isSome(): + text = "you are @" & user.username.get & ", nice to meet you!" + + var message = newMessage(command.message.chat.id, text) + message.replyToMessageId = command.message.messageId + message.parseMode = "markdown" + discard bot.send(message)+ \ No newline at end of file
diff --git a/src/ctucxbot.nim b/src/ctucxbot.nim @@ -1,5 +1,5 @@ import asyncdispatch, telebot, options, strutils, random, os, re, unicode -include cmd/[animalpics, daysuntilcongress, help, stats, uptime, yesorno] +include cmd/[animalpics, daysuntilcongress, help, stats, unixtime, uptime, yesorno, whoami] const API_KEY = slurp("secret.key") @@ -64,6 +64,8 @@ bot.onCommand("cat", animalCommand(cat, false)) bot.onCommand("catgif", animalCommand(cat, true)) bot.onCommand("help", helpCommand) bot.onCommand("stats", statsCommand) +bot.onCommand("unixtime", unixtimeCommand) bot.onCommand("uptime", uptimeCommand) bot.onCommand("yesorno", yesornoCommand) +bot.onCommand("whoami", whoamiCommand) bot.poll(timeout=300)