Add Bot class

- Use rewrite-2 callbacks modified for async
- Utility function for running singular controller
- Update TestBot to work with new system
This commit is contained in:
Joscha 2017-09-04 19:56:17 +00:00
parent b8bb75a897
commit 053573e3cb
6 changed files with 227 additions and 73 deletions

View file

@ -1,41 +1,48 @@
import asyncio
import yaboli
from yaboli.utils import *
#class TestBot(Bot):
class TestBot(yaboli.Controller):
class TestBot(yaboli.Bot):
def __init__(self, nick):
super().__init__(nick=nick)
self.register_callback("tree", self.command_tree, specific=False)
async def on_send(self, message):
if message.content == "!spawnevil":
bot = TestBot("TestSpawn")
task, reason = await bot.connect("test")
second = await self.room.send("We have " + ("a" if task else "no") + " task. Reason: " + reason, message.message_id)
if task:
await bot.stop()
await self.room.send("Stopped." if task.done() else "Still running (!)", second.message_id)
#async def on_send(self, message):
#if message.content == "!spawnevil":
#bot = TestBot("TestSpawn")
#task, reason = await bot.connect("test")
#second = await self.room.send("We have " + ("a" if task else "no") + " task. Reason: " + reason, message.message_id)
#if task:
#await bot.stop()
#await self.room.send("Stopped." if task.done() else "Still running (!)", second.message_id)
await self.room.send("All's over now.", message.message_id)
#await self.room.send("All's over now.", message.message_id)
elif message.content == "!tree":
messages = [message]
#elif message.content == "!tree":
#messages = [message]
#newmessages = []
#for i in range(2):
#for m in messages:
#for j in range(2):
#newm = await self.room.send(f"{m.content}.{j}", m.message_id)
#newmessages.append(newm)
#messages = newmessages
#newmessages = []
async def command_tree(self, message, args):
messages = [message]
newmessages = []
for i in range(2):
for m in messages:
for j in range(2):
newm = await self.room.send(f"{message.content}.{j}", m.message_id)
newmessages.append(newm)
messages = newmessages
newmessages = []
for i in range(2):
for m in messages:
for j in range(2):
newm = await self.room.send(f"{m.content}.{j}", m.message_id)
newmessages.append(newm)
messages = newmessages
newmessages = []
async def run_bot():
bot = TestBot("TestSummoner")
task, reason = await bot.connect("test")
if task:
await task
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(run_bot())
bot = TestBot("TestSummoner")
run_controller(bot, "test")