Add Client
Some functionality is yet to be tested.
This commit is contained in:
parent
17d4fb216e
commit
c3fa1bf396
3 changed files with 136 additions and 39 deletions
40
test.py
40
test.py
|
|
@ -4,7 +4,7 @@
|
|||
import asyncio
|
||||
import logging
|
||||
|
||||
from yaboli import Room
|
||||
import yaboli
|
||||
|
||||
FORMAT = "{asctime} [{levelname:<7}] <{name}> {funcName}(): {message}"
|
||||
DATE_FORMAT = "%F %T"
|
||||
|
|
@ -19,37 +19,17 @@ logger = logging.getLogger('yaboli')
|
|||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(handler)
|
||||
|
||||
class TestClient:
|
||||
def __init__(self):
|
||||
self.room = Room("test", target_nick="testbot")
|
||||
self.room.register_event("join", self.on_join)
|
||||
self.room.register_event("part", self.on_part)
|
||||
self.room.register_event("send", self.on_send)
|
||||
class TestClient(yaboli.Client):
|
||||
DEFAULT_NICK = "testbot"
|
||||
|
||||
self.stop = asyncio.Event()
|
||||
async def started(self):
|
||||
await self.join("test")
|
||||
|
||||
async def run(self):
|
||||
await self.room.connect()
|
||||
await self.stop.wait()
|
||||
|
||||
async def on_join(self, user):
|
||||
print()
|
||||
print(f"{user.nick} ({user.atmention}) joined.")
|
||||
if user.is_person:
|
||||
print("They're a person!")
|
||||
elif user.is_bot:
|
||||
print("They're just a bot")
|
||||
else:
|
||||
print("This should never happen")
|
||||
print()
|
||||
|
||||
async def on_part(self, user):
|
||||
print(f"{user.nick} left")
|
||||
|
||||
async def on_send(self, message):
|
||||
await message.reply(f"You said {message.content!r}.")
|
||||
msg1 = await message.room.send(f"{message.sender.atmention} said something.")
|
||||
await msg1.reply("Yes, they really did.")
|
||||
async def on_send(self, room, message):
|
||||
if message.content == "!test":
|
||||
await message.reply(f"You said {message.content!r}.")
|
||||
msg1 = await room.send(f"{message.sender.atmention} said something.")
|
||||
await msg1.reply("Yes, they really did.")
|
||||
|
||||
async def main():
|
||||
tc = TestClient()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue