From f314e966dbe052dbcfcc1446521514ea74b12745 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Thu, 26 Dec 2019 11:10:15 +0530 Subject: [PATCH] Add readme and revoke commands --- src/hqtoxbot.nim | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/hqtoxbot.nim b/src/hqtoxbot.nim index ce503a1..bfc500e 100644 --- a/src/hqtoxbot.nim +++ b/src/hqtoxbot.nim @@ -3,6 +3,7 @@ import toxcore import std/asyncdispatch, std/base64, std/json, std/httpclient, std/os, std/strutils const + readmeText = readFile "README.md" spaceApiUrl = "http://spaceapi.hq.c3d2.de:3000/spaceapi.json" saveFileName = "hqtoxbot.save" adminIds = [ @@ -11,8 +12,11 @@ const ] proc bootstrap(bot: Tox) = - const servers = [ ("tox.neuland.technology", - "15E9C309CFCB79FDDF0EBA057DABB49FE15F3803B1BFF06536AE2E5BA5E4690E".toPublicKey)] + const servers = [ + ( "tox.neuland.technology", + "15E9C309CFCB79FDDF0EBA057DABB49FE15F3803B1BFF06536AE2E5BA5E4690E".toPublicKey + ) + ] for host, key in servers.items: bot.bootstrap(host, key) @@ -40,6 +44,8 @@ type Command = enum help, invite, lock, + readme, + revoke, unlock, proc setup(bot: Tox) = @@ -57,6 +63,9 @@ proc setup(bot: Tox) = if status != TOX_CONNECTION_NONE: bot.invite(f, conference) + bot.onFriendReadReceipt do (f: friend; id; MessageId): + discard """TODO some commands should be defered until a read receipt is acquired. Maybe just revoke.""" + bot.onFriendMessage do (f: Friend; msg: string; kind: MessageType): proc reply(msg: string) = discard bot.send(f, msg) @@ -90,6 +99,10 @@ proc setup(bot: Tox) = of lock: reply("""Lock the HQ door. """ & """If the door is already open his command is not effective.""") + of readme: + reply """Return bot README""" + of revoke: + reply """Remove yourself from the bot roster.""" of unlock: reply """Unlock the HQ door.""" @@ -116,6 +129,13 @@ proc setup(bot: Tox) = else: reply(fut.read.status) + of readme: + reply readmeText + + of revoke: + reply """Tchuss""" + discard bot.delete(f) + of unlock: bot.typing(f, true) let fut = schalterClient.post("http://schalter.hq.c3d2.de/door/unlock")