diff --git a/kibicara/config.py b/kibicara/config.py index 76ce55d..e75dc28 100644 --- a/kibicara/config.py +++ b/kibicara/config.py @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: 0BSD -""" Configuration file and command line argument parser. +"""Configuration file and command line argument parser. Gives a dictionary named `config` with configuration parsed either from `/etc/kibicara.conf` or from a file given by command line argument `-f`. @@ -38,7 +38,7 @@ config = { 'root_url': 'http://localhost:8000', # url of backend 'cors_allow_origin': 'http://127.0.0.1:4200', } -""" Default configuration. +"""Default configuration. The default configuration gets overwritten by a configuration file if one exists. """ diff --git a/kibicara/email.py b/kibicara/email.py index 65b5822..66de70c 100644 --- a/kibicara/email.py +++ b/kibicara/email.py @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: 0BSD -""" E-Mail handling. """ +"""E-Mail handling.""" from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText diff --git a/kibicara/kibicara.py b/kibicara/kibicara.py index d31e923..fd882e5 100644 --- a/kibicara/kibicara.py +++ b/kibicara/kibicara.py @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: 0BSD -""" Entrypoint of Kibicara. """ +"""Entrypoint of Kibicara.""" from asyncio import run as asyncio_run from logging import DEBUG, INFO, WARNING, basicConfig, getLogger diff --git a/kibicara/model.py b/kibicara/model.py index b3fe386..c39ec5c 100644 --- a/kibicara/model.py +++ b/kibicara/model.py @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: 0BSD -""" ORM Models for core. """ +"""ORM Models for core.""" from databases import Database from ormantic import Boolean, ForeignKey, Integer, Model, Text diff --git a/kibicara/platformapi.py b/kibicara/platformapi.py index 6bd8b65..fba3136 100644 --- a/kibicara/platformapi.py +++ b/kibicara/platformapi.py @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: 0BSD -""" API classes for implementing bots for platforms. """ +"""API classes for implementing bots for platforms.""" from asyncio import Queue, create_task from enum import Enum, auto @@ -24,10 +24,6 @@ class Message: message = Message('Message sent from platform xyz', xyz_message_id=123) ``` - Args: - text (str): The message text - **kwargs (object, optional): Other platform-specific data. - Attributes: text (str): The message text **kwargs (object, optional): Other platform-specific data. @@ -71,9 +67,6 @@ class Censor: # XXX send message.text to platform xyz ``` - Args: - hood (Hood): A Hood Model object - Attributes: hood (Hood): A Hood Model object """ @@ -90,12 +83,12 @@ class Censor: self.status = BotStatus.INSTANTIATED def start(self): - """ Start the bot. """ + """Start the bot.""" if self.__task is None: self.__task = create_task(self.__run()) def stop(self): - """ Stop the bot. """ + """Stop the bot.""" if self.__task is not None: self.__task.cancel() @@ -120,7 +113,7 @@ class Censor: @classmethod async def destroy_hood(cls, hood): - """Removes all its database entries. + """Remove all of its database entries. Note: Override this in the derived bot class. """ @@ -176,10 +169,6 @@ class Spawner: spawner = Spawner(XYZ, XYZPlatform) ``` - Args: - ORMClass (ORM Model subclass): A Bot Model object - BotClass (Censor subclass): A Bot Class object - Attributes: ORMClass (ORM Model subclass): A Hood Model object BotClass (Censor subclass): A Bot Class object diff --git a/kibicara/platforms/email/bot.py b/kibicara/platforms/email/bot.py index 5e84e62..3553bcc 100644 --- a/kibicara/platforms/email/bot.py +++ b/kibicara/platforms/email/bot.py @@ -32,7 +32,7 @@ class EmailBot(Censor): await subscriber.delete() async def run(self): - """ Loop which waits for new messages and sends emails to all subscribers. """ + """Loop which waits for new messages and sends emails to all subscribers.""" while True: message = await self.receive() logger.debug( diff --git a/kibicara/platforms/email/model.py b/kibicara/platforms/email/model.py index 0f98a69..ce52b06 100644 --- a/kibicara/platforms/email/model.py +++ b/kibicara/platforms/email/model.py @@ -11,7 +11,7 @@ from kibicara.model import Hood, Mapping class Email(Model): - """ This table is used to track the names. It also stores the token secret. """ + """This table is used to track the names. It also stores the token secret.""" id: Integer(primary_key=True) = None hood: ForeignKey(Hood) @@ -23,7 +23,7 @@ class Email(Model): class EmailSubscribers(Model): - """ This table stores all subscribers, who want to receive messages via email. """ + """This table stores all subscribers, who want to receive messages via email.""" id: Integer(primary_key=True) = None hood: ForeignKey(Hood) diff --git a/kibicara/platforms/email/webapi.py b/kibicara/platforms/email/webapi.py index 4a91c9d..739f728 100644 --- a/kibicara/platforms/email/webapi.py +++ b/kibicara/platforms/email/webapi.py @@ -41,20 +41,21 @@ class BodyEmailPublic(BaseModel): class BodyMessage(BaseModel): - """ This model shows which values are supplied by the MDA listener script. """ + """This model shows which values are supplied by the MDA listener script.""" text: str secret: str class BodySubscriber(BaseModel): - """ This model holds the email address of a fresh subscriber. """ + """This model holds the email address of a fresh subscriber.""" email: str async def get_email(email_id: int, hood=Depends(get_hood)): """Get Email row by hood. + You can specify an email_id to nail it down, but it works without as well. :param hood: Hood the Email bot belongs to. @@ -168,6 +169,7 @@ async def email_read(email=Depends(get_email)): ) async def email_delete(email=Depends(get_email)): """Delete an Email bot. + Stops and deletes the Email bot. :param hood: Hood the Email bot belongs to. diff --git a/kibicara/webapi/__init__.py b/kibicara/webapi/__init__.py index 18c5d2c..0572d69 100644 --- a/kibicara/webapi/__init__.py +++ b/kibicara/webapi/__init__.py @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: 0BSD -""" Routing definitions for the REST API. +"""Routing definitions for the REST API. A platform bot shall add its API router in this `__init__.py` file to get included into the main application. diff --git a/kibicara/webapi/admin.py b/kibicara/webapi/admin.py index e534f0f..ae57eb0 100644 --- a/kibicara/webapi/admin.py +++ b/kibicara/webapi/admin.py @@ -5,7 +5,7 @@ # # SPDX-License-Identifier: 0BSD -""" REST API endpoints for hood admins. """ +"""REST API endpoints for hood admins.""" from datetime import datetime, timedelta from logging import getLogger @@ -230,7 +230,7 @@ async def admin_confirm_reset(reset_token: str, values: BodyPassword): operation_id='get_hoods_admin', ) async def admin_hood_read_all(admin=Depends(get_admin)): - """ Get a list of all hoods of a given admin. """ + """Get a list of all hoods of a given admin.""" return ( await AdminHoodRelation.objects.select_related('hood').filter(admin=admin).all() ) @@ -242,7 +242,7 @@ async def admin_hood_read_all(admin=Depends(get_admin)): operation_id='get_admin', ) async def admin_read(admin=Depends(get_admin)): - """ Get a list of all hoods of a given admin. """ + """Get a list of all hoods of a given admin.""" admin = await Admin.objects.filter(email=admin.email).all() if len(admin) != 1: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) diff --git a/kibicara/webapi/hoods/__init__.py b/kibicara/webapi/hoods/__init__.py index a839979..20fb7ee 100644 --- a/kibicara/webapi/hoods/__init__.py +++ b/kibicara/webapi/hoods/__init__.py @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: 0BSD -""" REST API Endpoints for managing hoods. """ +"""REST API Endpoints for managing hoods.""" from sqlite3 import IntegrityError @@ -54,7 +54,7 @@ router = APIRouter() tags=['hoods'], ) async def hood_read_all(): - """ Get all existing hoods. """ + """Get all existing hoods.""" return await Hood.objects.all() @@ -92,7 +92,7 @@ async def hood_create(values: BodyHood, response: Response, admin=Depends(get_ad tags=['hoods'], ) async def hood_read(hood=Depends(get_hood_unauthorized)): - """ Get hood with id **hood_id**. """ + """Get hood with id **hood_id**.""" return hood @@ -119,6 +119,6 @@ async def hood_update(values: BodyHood, hood=Depends(get_hood)): tags=['hoods'], ) async def hood_delete(hood=Depends(get_hood)): - """ Deletes hood with id **hood_id**. """ + """Deletes hood with id **hood_id**.""" await delete_hood(hood) return Response(status_code=status.HTTP_204_NO_CONTENT) diff --git a/kibicara/webapi/hoods/badwords.py b/kibicara/webapi/hoods/badwords.py index 15f1677..cf314ae 100644 --- a/kibicara/webapi/hoods/badwords.py +++ b/kibicara/webapi/hoods/badwords.py @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: 0BSD -""" REST API endpoints for managing badwords. +"""REST API endpoints for managing badwords. Provides API endpoints for adding, removing and reading regular expressions that block a received message to be dropped by a censor. This provides a message filter customizable @@ -43,7 +43,7 @@ router = APIRouter() operation_id='get_badwords', ) async def badword_read_all(hood=Depends(get_hood)): - """ Get all badwords of hood with id **hood_id**. """ + """Get all badwords of hood with id **hood_id**.""" return await BadWord.objects.filter(hood=hood).all() @@ -77,7 +77,7 @@ async def badword_create( operation_id='get_badword', ) async def badword_read(badword=Depends(get_badword)): - """ Reads badword with id **badword_id** for hood with id **hood_id**. """ + """Reads badword with id **badword_id** for hood with id **hood_id**.""" return badword @@ -101,6 +101,6 @@ async def badword_update(values: BodyBadWord, badword=Depends(get_badword)): operation_id='delete_badword', ) async def badword_delete(badword=Depends(get_badword)): - """ Deletes badword with id **badword_id** for hood with id **hood_id**. """ + """Deletes badword with id **badword_id** for hood with id **hood_id**.""" await badword.delete() return Response(status_code=status.HTTP_204_NO_CONTENT) diff --git a/kibicara/webapi/hoods/triggers.py b/kibicara/webapi/hoods/triggers.py index 283e159..82deb71 100644 --- a/kibicara/webapi/hoods/triggers.py +++ b/kibicara/webapi/hoods/triggers.py @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: 0BSD -""" REST API endpoints for managing triggers. +"""REST API endpoints for managing triggers. Provides API endpoints for adding, removing and reading regular expressions that allow a message to be passed through by a censor. A published message must match one of these @@ -44,7 +44,7 @@ router = APIRouter() operation_id='get_triggers', ) async def trigger_read_all(hood=Depends(get_hood)): - """ Get all triggers of hood with id **hood_id**. """ + """Get all triggers of hood with id **hood_id**.""" return await Trigger.objects.filter(hood=hood).all() @@ -78,7 +78,7 @@ async def trigger_create( operation_id='get_trigger', ) async def trigger_read(trigger=Depends(get_trigger)): - """ Reads trigger with id **trigger_id** for hood with id **hood_id**. """ + """Reads trigger with id **trigger_id** for hood with id **hood_id**.""" return trigger @@ -102,6 +102,6 @@ async def trigger_update(values: BodyTrigger, trigger=Depends(get_trigger)): operation_id='delete_trigger', ) async def trigger_delete(trigger=Depends(get_trigger)): - """ Deletes trigger with id **trigger_id** for hood with id **hood_id**. """ + """Deletes trigger with id **trigger_id** for hood with id **hood_id**.""" await trigger.delete() return Response(status_code=status.HTTP_204_NO_CONTENT)