commit 53ee52d5b3d82c6d97dce4ad24505790fdc50c56
parent f51601b0655f3d1b92a20f96c4837b620c3cfa5c
Author: Sebastian Walz <sivizius@ohai.su>
Date: Wed, 15 Jan 2020 17:11:45 +0100
parent f51601b0655f3d1b92a20f96c4837b620c3cfa5c
Author: Sebastian Walz <sivizius@ohai.su>
Date: Wed, 15 Jan 2020 17:11:45 +0100
daysuntilcongress added. some var→let. if less complex.
2 files changed, 32 insertions(+), 24 deletions(-)
diff --git a/src/cmd/daysuntilcongress.nim b/src/cmd/daysuntilcongress.nim @@ -0,0 +1,10 @@ +import asyncdispatch, strformat, strutils, times, telebot + +proc daysUntilCongressCmd(bot: Telebot, command: Command) {.async.} = + let difference = parse("2020-12-26", "yyyy-MM-dd") - now() + let days = difference.inDays() + let answer = fmt"{days}" + var message = newMessage(command.message.chat.id, answer) + message.replyToMessageId = command.message.messageId + message.parseMode = "markdown" + discard bot.send(message)
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/[uptime, yesorno, stats] +include cmd/[daysuntilcongress, stats, uptime, yesorno] const API_KEY = slurp("secret.key") @@ -9,43 +9,41 @@ proc updateHandler(bot: Telebot, update: Update) {.async.} = discard statsHandler(message) if message.text.isSome: - var text = message.text.get + let text = message.text.get - var answers = [ - "Höhö! Penis!", + let answers = [ + "Höhö! Penis!", "Schwaaaaaanz!", "Gihihihi, Pimmel!", "Höhö, Döödel!", "Glied", - "8===D" + "8===D" ] - #react to sarcasm to make it more obvious + let penisCount = text.normalize.count("penis") + + #react to sarcasm to make it more obvious if text.contains(re"\/s"): var response = newSticker(message.chat.id, "file://" & getCurrentDir() & "/data/pics/sarcasm_sign.webp") response.replyToMessageId = message.messageId discard await bot.send(response) + elif penisCount > 4: + var response = newPhoto(message.chat.id, "file://" & getCurrentDir() & "/data/pics/penis.jpg") + response.replyToMessageId = message.messageId + discard await bot.send(response) - let penisCount = text.normalize.count("penis") - - if penisCount > 0: - if penisCount > 4: - var response = newPhoto(message.chat.id, "file://" & getCurrentDir() & "/data/pics/penis.jpg") - response.replyToMessageId = message.messageId - discard await bot.send(response) - - else: - var response = newMessage(message.chat.id, sample(answers)) - response.replyToMessageId = message.messageId - discard await bot.send(response) + elif penisCount > 0: + var response = newMessage(message.chat.id, sample(answers)) + response.replyToMessageId = message.messageId + discard await bot.send(response) - if text.normalize.contains("sinep"): + elif text.normalize.contains("sinep"): var response = newMessage(message.chat.id, reversed(sample(answers))) response.replyToMessageId = message.messageId - discard await bot.send(response) + discard await bot.send(response) - if text == "egg_irl": + elif text == "egg_irl": var response = newPhoto(message.chat.id, "file://" & getCurrentDir() & "/data/pics/egg.jpg") response.replyToMessageId = message.messageId discard await bot.send(response) @@ -53,7 +51,8 @@ proc updateHandler(bot: Telebot, update: Update) {.async.} = let bot = newTeleBot(API_KEY) bot.onUpdate(updateHandler) +bot.onCommand("daysuntilcongress", daysUntilCongressCmd) +bot.onCommand("stats", statsCmd) bot.onCommand("uptime", uptimeCmd) bot.onCommand("yesorno", yesornoCmd) -bot.onCommand("stats", statsCmd) -bot.poll(timeout=300)- \ No newline at end of file +bot.poll(timeout=300)