ctucx.git: ctucxbot

[nimlang] A telegram bot

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 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
import asyncdispatch, telebot, options, strutils, random, re, unicode, os 
import cmd/stats

randomize()

proc updateHandler* (bot: Telebot, update: Update): Future[bool] {.async.} =
  if not update.message.isNone:
    var message = update.message.get
    discard statsHandler(message, false)

    if message.text.isSome:
      let text = message.text.get

      let lewdAnswers = [
        "Höhö! Penis!",
        "Schwaaaaaanz!",
        "Gihihihi, Pimmel!",
        "Höhö, Döödel!",
        "Glied",
        "8===D",
      ]

      let meowAnswers = [
        "meow USER!",
        "Meow USER!",
        "Mew USER!",
        "mew USER!",
        "meow USER",
        "Meow USER",
        "Mew USER",
        "mew USER",
        "mreow USER!",
        "Mreow USER!",
        "Mrew USER!",
        "mrew USER!",
        "mreow USER",
        "Mreow USER",
        "Mrew USER",
        "mrew USER",
      ]

      let penisCount = text.normalize.count("penis")

      # if much penis send a pic
      if penisCount > 4:
        discard statsHandler(message, true)
        discard await bot.sendPhoto(message.chat.id, "file://" & getEnv("ASSETS_PATH") & "/pics/penis.jpg", replyToMessageId = message.messageId)

      #if not so much penis send a random lewd message
      elif penisCount > 0:
        discard statsHandler(message, true)
        discard await bot.sendMessage(message.chat.id, sample(lewdAnswers), replyToMessageId = message.messageId)

      #if sinep send a random dwel string
      elif text.normalize.contains("sinep"):
        discard await bot.sendMessage(message.chat.id, reversed(sample(lewdAnswers)), replyToMessageId = message.messageId)

      #if text is "egg_irl" send a real egg!
      elif text == "egg_irl":
        discard await bot.sendPhoto(message.chat.id, "file://" & getEnv("ASSETS_PATH") & "/pics/egg.jpg", replyToMessageId = message.messageId)

      #meow back at people with a 20% chance
      if (rand(100) < 20 or message.chat.kind == "private") and text.contains(re(r"^mr*(a+u+|e*[eo]o*w+)!*$", {reIgnoreCase})):
        discard await bot.sendMessage(message.chat.id, sample(meowAnswers).replace("USER", message.fromUser.get.firstName), replyToMessageId = message.messageId)