commit 2051dab54600ea40cd20ccdfa3dc870202d468a7
Author: ctucx <c@ctu.cx>
Date: Wed, 15 Jan 2020 12:18:58 +0100
Author: ctucx <c@ctu.cx>
Date: Wed, 15 Jan 2020 12:18:58 +0100
init
9 files changed, 104 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore @@ -0,0 +1,2 @@ +ctucxbot +secret.key
diff --git a/cmd/uptime.nim b/cmd/uptime.nim @@ -0,0 +1,8 @@ +import asyncdispatch, telebot, strutils, osproc + +proc uptimeCmd(bot: Telebot, command: Command) {.async.} = + let uptime = execProcess("uptime", options={poUsePath}) + var message = newMessage(command.message.chat.id, "``" & uptime & "``") + message.replyToMessageId = command.message.messageId + message.parseMode = "markdown" + discard bot.send(message)+ \ No newline at end of file
diff --git a/cmd/yesorno.nim b/cmd/yesorno.nim @@ -0,0 +1,24 @@ +import asyncdispatch, telebot, strutils, random + +#init rng +randomize() + +proc yesornoCmd(bot: Telebot, command: Command) {.async.} = + let random = rand(-8..8) + let maybe = ["maybe", "dunno", "perhabs", "…", "idk", "I have no idea", "mrew", "mew", "meow", "use TOR, use Signal"] + + var answer = "" + + if random < 0: + answer = "no" + elif random > 0: + answer = "yes" + else: + let num = rand(maybe.len) - 1 + + answer = maybe[num] + + var message = newMessage(command.message.chat.id, answer) + message.replyToMessageId = command.message.messageId + message.parseMode = "markdown" + discard bot.send(message)+ \ No newline at end of file
diff --git a/ctucxbot.nim b/ctucxbot.nim @@ -0,0 +1,48 @@ +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 @@ -0,0 +1,14 @@ +# Package + +version = "0.1.0" +author = "ctucx" +description = "ctucxbot now written in nimlang" +license = "MIT" +srcDir = "src" +bin = @["ctucxbot"] + + + +# Dependencies + +requires "nim >= 1.0.4"
diff --git a/data/pics/egg.jpg b/data/pics/egg.jpg Binary files differ.
diff --git a/data/pics/penis.jpg b/data/pics/penis.jpg Binary files differ.
diff --git a/data/pics/sarcasm_sign.webp b/data/pics/sarcasm_sign.webp Binary files differ.
diff --git a/src/ctucxbot.nim b/src/ctucxbot.nim @@ -0,0 +1,5 @@ +# This is just an example to get you started. A typical binary package +# uses this file as the main entry point of the application. + +when isMainModule: + echo("Hello, World!")