ctucx.git: ctucxbot

[nimlang] A telegram bot

commit ba7d3b64b417d13ffe38b2629f32df32836ce847
parent 2051dab54600ea40cd20ccdfa3dc870202d468a7
Author: ctucx <c@ctu.cx>
Date: Wed, 15 Jan 2020 12:39:02 +0100

now uses nimble
7 files changed, 52 insertions(+), 54 deletions(-)
M
.gitignore
|
2
+-
D
ctucxbot.nim
|
49
-------------------------------------------------
M
ctucxbot.nimble
|
2
++
A
nim.cfg
|
1
+
R
cmd/uptime.nim -> src/cmd/uptime.nim
|
0
R
cmd/yesorno.nim -> src/cmd/yesorno.nim
|
0
M
src/ctucxbot.nim
|
52
++++++++++++++++++++++++++++++++++++++++++++++++----
diff --git a/.gitignore b/.gitignore
@@ -1,2 +1,2 @@
 ctucxbot
-secret.key
+src/secret.key
diff --git a/ctucxbot.nim b/ctucxbot.nim
@@ -1,48 +0,0 @@
-import asyncdispatch, telebot, options, strutils, random, os
-include cmd/[uptime, yesorno]
-
-const API_KEY = slurp("secret.key")
-
-proc updateHandler(bot: Telebot, update: Update) {.async.} =
-  if not update.message.isNone:
-    var response = update.message.get
-    if response.text.isSome:
-      var text = response.text.get
-
-      var answers = [
-        "Höhö! Penis!", 
-        "Schwaaaaaanz!",
-        "Gihihihi, Pimmel!",
-        "Höhö, Döödel!",
-        "Glied",
-        "8===D" 
-      ]
-
-      let penisCount = text.normalize.count("penis")
-      
-      if penisCount > 0:
-        if penisCount > 4:
-          var message = newPhoto(response.chat.id, "file://" & getCurrentDir() & "/data/pics/penis.jpg")
-
-          message.replyToMessageId = response.messageId
-          discard await bot.send(message)
-
-        else:
-          var message = newMessage(response.chat.id, sample(answers))
-
-          message.replyToMessageId = response.messageId
-          discard await bot.send(message)
-
-      if text == "egg_irl":
-        var message = newPhoto(response.chat.id, "file://" & getCurrentDir() & "/data/pics/egg.jpg")
-
-        message.replyToMessageId = response.messageId
-        discard await bot.send(message)
-       
-
-let bot = newTeleBot(API_KEY)
-
-bot.onUpdate(updateHandler)
-bot.onCommand("uptime", uptimeCmd)
-bot.onCommand("yesorno", yesornoCmd)
-bot.poll(timeout=300)-
\ No newline at end of file
diff --git a/ctucxbot.nimble b/ctucxbot.nimble
@@ -12,3 +12,4 @@ bin           = @["ctucxbot"]
 # Dependencies
 
 requires "nim >= 1.0.4"
+requires "telebot >= 0.7.0"+
\ No newline at end of file
diff --git a/nim.cfg b/nim.cfg
@@ -0,0 +1 @@
+d:ssl
diff --git a/cmd/uptime.nim b/src/cmd/uptime.nim
diff --git a/cmd/yesorno.nim b/src/cmd/yesorno.nim
diff --git a/src/ctucxbot.nim b/src/ctucxbot.nim
@@ -1,5 +1,48 @@
-# This is just an example to get you started. A typical binary package
-# uses this file as the main entry point of the application.
+import asyncdispatch, telebot, options, strutils, random, os
+include cmd/[uptime, yesorno]
 
-when isMainModule:
-  echo("Hello, World!")
+const API_KEY = slurp("secret.key")
+
+proc updateHandler(bot: Telebot, update: Update) {.async.} =
+  if not update.message.isNone:
+    var response = update.message.get
+    if response.text.isSome:
+      var text = response.text.get
+
+      var answers = [
+        "Höhö! Penis!", 
+        "Schwaaaaaanz!",
+        "Gihihihi, Pimmel!",
+        "Höhö, Döödel!",
+        "Glied",
+        "8===D" 
+      ]
+
+      let penisCount = text.normalize.count("penis")
+      
+      if penisCount > 0:
+        if penisCount > 4:
+          var message = newPhoto(response.chat.id, "file://" & getCurrentDir() & "/data/pics/penis.jpg")
+
+          message.replyToMessageId = response.messageId
+          discard await bot.send(message)
+
+        else:
+          var message = newMessage(response.chat.id, sample(answers))
+
+          message.replyToMessageId = response.messageId
+          discard await bot.send(message)
+
+      if text == "egg_irl":
+        var message = newPhoto(response.chat.id, "file://" & getCurrentDir() & "/data/pics/egg.jpg")
+
+        message.replyToMessageId = response.messageId
+        discard await bot.send(message)
+       
+
+let bot = newTeleBot(API_KEY)
+
+bot.onUpdate(updateHandler)
+bot.onCommand("uptime", uptimeCmd)
+bot.onCommand("yesorno", yesornoCmd)
+bot.poll(timeout=300)+
\ No newline at end of file