ctucx.git: ctucxbot

[nimlang] A telegram bot

commit b479ace35d57cf60d85abf5bc9588cda971516c9
parent b5c56ca7bc3ca7fb497bf34d331f2801983c58d7
Author: Milan Pässler <me@pbb.lc>
Date: Fri, 24 Jan 2020 23:05:16 +0100

fix sarcasm reaction
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/cmd/sarcasm.nim b/src/cmd/sarcasm.nim
@@ -0,0 +1,4 @@
+proc sarcasmCommand(bot: Telebot, command: Command) {.async.} =
+  var response = newSticker(command.message.chat.id, "file://" & getCurrentDir() & "/data/pics/sarcasm_sign.webp")
+  response.replyToMessageId = command.message.messageId
+  discard await bot.send(response)
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, debuginfo, help, stats, unixtime, utc, uptime, yesorno, whoami, invitelinks]
+include cmd/[animalpics, daysuntilcongress, debuginfo, help, stats, unixtime, utc, uptime, yesorno, whoami, invitelinks, sarcasm]
 
 proc ctrlcHandler() {.noconv.} =
   quit()

@@ -42,14 +42,8 @@ proc updateHandler(bot: Telebot, update: Update) {.async.} =
 
       let penisCount = text.normalize.count("penis")
 
-      #react to sarcasm to make it more obvious
-      if text.contains(re"(^|[\s(])/s\b"):
-        var response = newSticker(message.chat.id, "file://" & getCurrentDir() & "/data/pics/sarcasm_sign.webp")
-        response.replyToMessageId = message.messageId
-        discard await bot.send(response)
-
       # if much penis send a pic
-      elif penisCount > 4:
+      if penisCount > 4:
         discard statsHandler(message, true)
 
         var response = newPhoto(message.chat.id, "file://" & getCurrentDir() & "/data/pics/penis.jpg")

@@ -104,6 +98,7 @@ if getEnv("API_KEY") != "":
   bot.onCommand("yesorno", yesornoCommand)
   bot.onCommand("whoami", whoamiCommand)
   bot.onCommand("invitelinks", invitelinksCommand)
+  bot.onCommand("s", sarcasmCommand)
   bot.poll(timeout=300)
 
 else: