Module kibicara.platforms.test.bot

Expand source code
# Copyright (C) 2020 by Thomas Lindner <tom@dl6tom.de>
# Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de>
#
# SPDX-License-Identifier: 0BSD

from kibicara.platforms.test.model import Test
from kibicara.platformapi import Censor, Spawner


class TestBot(Censor):
    def __init__(self, test):
        super().__init__(test.hood)
        self.messages = []

    async def run(self):
        while True:
            self.messages.append(await self.receive())


spawner = Spawner(Test, TestBot)

Classes

class TestBot (test)

The superclass for a platform bot.

The censor is the superclass for every platform bot. It distributes a message to all other bots from the same hood if it passes the message filter. It provides methods to start and stop the bot and an overwritable stub for a starting routine.

Examples

class XYZPlatform(Censor):
    def __init__(self, xyz_model):
        super().__init__(xyz_model.hood)
    ...
    async def run(self):
        await gather(self.poll(), self.push())
    ...
    async def poll(self):
        while True:
            # XXX get text message from platform xyz
            await self.publish(Message(text))
    ...
    async def push(self):
        while True:
            message = await self.receive()
            # XXX send message.text to platform xyz

Args

hood : Hood
A Hood Model object

Attributes

hood : Hood
A Hood Model object
Expand source code
class TestBot(Censor):
    def __init__(self, test):
        super().__init__(test.hood)
        self.messages = []

    async def run(self):
        while True:
            self.messages.append(await self.receive())

Ancestors

Inherited members