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 import asyncdispatch, telebot, posix, os 
include updateHandler
import cmd/[animalpics, daysuntilcongress, debuginfo, ds100, help, httpstatuscode, sarcasm, stats, unixtime, utc, uptime, whoami, yesorno]

proc CtrlCHook() {.noconv.} =
  echo "Ctrl+C fired! \nStopping bot now!"
  quit()

proc main =  # for gcsafe
  setControlCHook(CtrlCHook)

  onSignal(SIGTERM):
    echo "Got SIGTERM! \nStopping bot now!"
    quit()

  if getEnv("DATA_PATH") == "":
    echo "DATA_PATH not set."
    quit()

  if getEnv("ASSETS_PATH") == "":
    echo "ASSETS_PATH not set."
    quit()

  if getEnv("API_KEY") != "":
    let bot = newTeleBot(getEnv("API_KEY"))

    bot.onUpdate(updateHandler)
    bot.onCommand("daysuntilcongress",    daysUntilCongressCommand)
    bot.onCommand("fox",                  animalCommand(fox, false))
    bot.onCommand("penguin",              animalCommand(penguin, false))
    bot.onCommand("dog",                  animalCommand(dog, false))
    bot.onCommand("doggo",                animalCommand(dog, false))
    bot.onCommand("cat",                  animalCommand(cat, false))
    bot.onCommand("catgif",               animalCommand(cat, true))
    bot.onCommand("flauschehorn",         animalCommand(flauschehorn, false))
    bot.onCommand("debuginfo",            debuginfoCommand)
    bot.onCommand("help",                 helpCommand)
    bot.onCommand("stats",                statsCommand)
    bot.onCommand("unixtime",             unixtimeCommand)
    bot.onCommand("utc",                  utcCommand)
    bot.onCommand("uptime",               uptimeCommand)
    bot.onCommand("yesorno",              yesornoCommand)
    bot.onCommand("whoami",               whoamiCommand)
    bot.onCommand("s",                    sarcasmCommand)
    bot.onCommand("httpstatuscode",       httpstatuscodeCommand)
    bot.onCommand("ds100",                ds100Command)
    bot.poll(timeout=300)

  else:
    echo "No API_KEY given!"

main()