kaiowa

commit 8bfaf501f1a7928fb0ba4d3a99e9f48beeb9d89d

Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>

all: flesh out initial bot

 kaiowa/__main__.py | 12 ++++++++++++
 kaiowa/bot.py | 24 ++++++++++++++++++++++++
 kaiowa/config.py | 13 +++++++++++++
 setup.py | 18 ++++++++++++++++++


diff --git a/kaiowa/__main__.py b/kaiowa/__main__.py
new file mode 100644
index 0000000000000000000000000000000000000000..7542f375883da7614277c30289ed78a9099d504e
--- /dev/null
+++ b/kaiowa/__main__.py
@@ -0,0 +1,12 @@
+import asyncio
+from kaiowa.bot import bot
+
+loop = asyncio.get_event_loop()
+
+while True:
+    try:
+        loop.run_until_complete(bot.run())
+    except Exception as e:
+        print(e)
+
+    time.sleep(10)




diff --git a/kaiowa/bot.py b/kaiowa/bot.py
new file mode 100644
index 0000000000000000000000000000000000000000..f026bccc7c8e8c9cdd478c483d2fe0c99acd23d3
--- /dev/null
+++ b/kaiowa/bot.py
@@ -0,0 +1,24 @@
+import asyncio
+import json
+import logging
+import re
+
+from datetime import datetime
+
+from asif import Client, CommandSet, Message
+from asif.util import bold
+
+from kaiowa.config import config
+
+bot = Client(**config["kwargs"])
+cs = CommandSet(bot)
+
+primary = bot.get_channel(config["channel"])
+
+@bot.on_connected()
+async def on_connect():
+    await bot.join(config["channel"])
+
+@primary.on_message(re.compile("^.ping"))
+async def pong(m: Message):
+    await m.reply("pong", m.text[5:])




diff --git a/kaiowa/config.py b/kaiowa/config.py
new file mode 100644
index 0000000000000000000000000000000000000000..2bca6f7858bf3a9b0f4543efb61ccac3d84109c6
--- /dev/null
+++ b/kaiowa/config.py
@@ -0,0 +1,13 @@
+import json
+
+config = None
+_paths = ["./config.json", "/etc/kaiowa.json"]
+for path in _paths:
+    try:
+        with open(path) as f:
+            config = json.loads(f.read())
+    except:
+        pass
+
+assert config is not None
+




diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000000000000000000000000000000000000..ddc1b5c1542f8a4dad6200eedfe6c1fbc03c880d
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python3
+from distutils.core import setup
+
+setup(
+  name = 'kaiowa',
+  packages = [
+      'kaiowa'
+  ],
+  version = "0.0.0",
+  description = 'kaiowa bot',
+  author = 'eletrotupi',
+  author_email = 'porcellis@eletrotupi.com',
+  url = 'https://git.eletrotupi.com/kaiowa',
+  install_requires = [
+      'asif',
+  ],
+  license = 'MIT',
+)