commit 05183127c03a75200f99e6d8c6585e008539bc31
parent 8b9e8db64ea944a4cf5a49cb5496b63a43d09f2a
Author: ctucx <c@ctu.cx>
Date: Wed, 15 Jan 2020 22:53:18 +0100
parent 8b9e8db64ea944a4cf5a49cb5496b63a43d09f2a
Author: ctucx <c@ctu.cx>
Date: Wed, 15 Jan 2020 22:53:18 +0100
add command: /fox, rename some command procs
7 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/src/cmd/animalpics.nim b/src/cmd/animalpics.nim @@ -0,0 +1,13 @@ +import asyncdispatch, telebot, strutils, os, times, httpClient + +proc foxCommand(bot: Telebot, command: Command) {.async.} = + var httpClient = newHttpClient() + + let tmpFile = getCurrentDir() & "/data/tmp/" & $(toUnix(getTime())) & ".image" + + httpClient.downloadFile("https://foxrudor.de", tmpFile) + + var message = newPhoto(command.message.chat.id, "file://" & tmpFile) + message.replyToMessageId = command.message.messageId + discard bot.send(message) + removeFile(tmpFile)+ \ No newline at end of file
diff --git a/src/cmd/daysuntilcongress.nim b/src/cmd/daysuntilcongress.nim @@ -1,6 +1,6 @@ import asyncdispatch, strformat, strutils, times, telebot -proc daysUntilCongressCmd(bot: Telebot, command: Command) {.async.} = +proc daysUntilCongressCommand(bot: Telebot, command: Command) {.async.} = let difference = parse("2020-12-26", "yyyy-MM-dd") - now() let days = difference.inDays() let answer = fmt"{days}"
diff --git a/src/cmd/stats.nim b/src/cmd/stats.nim @@ -1,6 +1,6 @@ import asyncdispatch, telebot, strutils, options, os, json -proc statsCmd(bot: Telebot, command: Command) {.async.} = +proc statsCommand(bot: Telebot, command: Command) {.async.} = let filePath = getCurrentDir() & "/data/stats/" & $(command.message.chat.id) & ".json" var text = ""
diff --git a/src/cmd/uptime.nim b/src/cmd/uptime.nim @@ -1,6 +1,6 @@ import asyncdispatch, telebot, strutils, osproc -proc uptimeCmd(bot: Telebot, command: Command) {.async.} = +proc uptimeCommand(bot: Telebot, command: Command) {.async.} = let uptime = execProcess("uptime", options={poUsePath}) var message = newMessage(command.message.chat.id, "``" & uptime & "``") message.replyToMessageId = command.message.messageId
diff --git a/src/cmd/yesorno.nim b/src/cmd/yesorno.nim @@ -3,7 +3,7 @@ import asyncdispatch, telebot, strutils, random #init rng randomize() -proc yesornoCmd(bot: Telebot, command: Command) {.async.} = +proc yesornoCommand(bot: Telebot, command: Command) {.async.} = let random = rand(-8..8) let maybe = ["maybe", "dunno", "perhabs", "…", "idk", "I have no idea", "mrew", "mew", "meow", "use TOR, use Signal"]
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/[daysuntilcongress, help, stats, uptime, yesorno] +include cmd/[animalpics, daysuntilcongress, help, stats, uptime, yesorno] const API_KEY = slurp("secret.key") @@ -51,9 +51,10 @@ proc updateHandler(bot: Telebot, update: Update) {.async.} = let bot = newTeleBot(API_KEY) bot.onUpdate(updateHandler) -bot.onCommand("daysuntilcongress", daysUntilCongressCmd) +bot.onCommand("daysuntilcongress", daysUntilCongressCommand) +bot.onCommand("fox", foxCommand) bot.onCommand("help", helpCommand) -bot.onCommand("stats", statsCmd) -bot.onCommand("uptime", uptimeCmd) -bot.onCommand("yesorno", yesornoCmd) +bot.onCommand("stats", statsCommand) +bot.onCommand("uptime", uptimeCommand) +bot.onCommand("yesorno", yesornoCommand) bot.poll(timeout=300)