diff --git a/kibicara/config.py b/kibicara/config.py index d6f1e6f..4208a56 100644 --- a/kibicara/config.py +++ b/kibicara/config.py @@ -47,7 +47,10 @@ if argv[0].endswith('kibicara'): help='path to config file', ) parser.add_argument( - '-v', '--verbose', action="count", help="Raise verbosity level", + '-v', + '--verbose', + action="count", + help="Raise verbosity level", ) args = parser.parse_args() diff --git a/kibicara/email.py b/kibicara/email.py index 9a7a677..0179b6c 100644 --- a/kibicara/email.py +++ b/kibicara/email.py @@ -16,7 +16,7 @@ logger = getLogger(__name__) def send_email(to, subject, sender='kibicara', body=''): - """ E-Mail sender. + """E-Mail sender. Sends an E-Mail to a specified recipient with a body diff --git a/kibicara/kibicara.py b/kibicara/kibicara.py index 7ab9584..e219d45 100644 --- a/kibicara/kibicara.py +++ b/kibicara/kibicara.py @@ -22,7 +22,7 @@ logger = getLogger(__name__) class Main: - """ Entrypoint for Kibicara. + """Entrypoint for Kibicara. Initializes the platform bots and starts the hypercorn webserver serving the Kibicara application and the specified frontend on port 8000. diff --git a/kibicara/platformapi.py b/kibicara/platformapi.py index eb36c20..c65b46f 100644 --- a/kibicara/platformapi.py +++ b/kibicara/platformapi.py @@ -44,7 +44,7 @@ class BotStatus(Enum): class Censor: - """ The superclass for a platform bot. + """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 @@ -111,14 +111,14 @@ class Censor: self.status = BotStatus.STOPPED async def run(self): - """ Entry point for a bot. + """Entry point for a bot. Note: Override this in the derived bot class. """ pass async def publish(self, message): - """ Distribute a message to the bots in a hood. + """Distribute a message to the bots in a hood. Args: message (Message): Message to distribute @@ -131,7 +131,7 @@ class Censor: return True async def receive(self): - """ Receive a message. + """Receive a message. Returns (Message): Received message """ @@ -151,7 +151,7 @@ class Censor: class Spawner: - """ Spawns a bot with a specific bot model. + """Spawns a bot with a specific bot model. Examples: ``` @@ -183,8 +183,7 @@ class Spawner: @classmethod async def init_all(cls): - """ Instantiate and start a bot for every row in the corresponding ORM model. - """ + """Instantiate and start a bot for every row in the corresponding ORM model.""" for spawner in cls.__instances: await spawner._init() @@ -193,7 +192,7 @@ class Spawner: self.start(item) def start(self, item): - """ Instantiate and start a bot with the provided ORM object. + """Instantiate and start a bot with the provided ORM object. Example: ``` @@ -209,7 +208,7 @@ class Spawner: bot.start() def stop(self, item): - """ Stop and delete a bot. + """Stop and delete a bot. Args: item (ORM Model object): ORM object corresponding to bot. @@ -219,7 +218,7 @@ class Spawner: bot.stop() def get(self, item): - """ Get a running bot. + """Get a running bot. Args: item (ORM Model object): ORM object corresponding to bot. diff --git a/kibicara/platforms/email/bot.py b/kibicara/platforms/email/bot.py index 30f76b4..afc275c 100644 --- a/kibicara/platforms/email/bot.py +++ b/kibicara/platforms/email/bot.py @@ -41,7 +41,9 @@ class EmailBot(Censor): try: logger.debug('Trying to send: \n%s' % body) email.send_email( - subscriber.email, "Kibicara " + self.hood.name, body=body, + subscriber.email, + "Kibicara " + self.hood.name, + body=body, ) except (ConnectionRefusedError, SMTPException): logger.exception("Sending email to subscriber failed.") diff --git a/kibicara/platforms/email/webapi.py b/kibicara/platforms/email/webapi.py index 305613c..06a4a71 100644 --- a/kibicara/platforms/email/webapi.py +++ b/kibicara/platforms/email/webapi.py @@ -51,7 +51,7 @@ class BodySubscriber(BaseModel): async def get_email(email_id: int, hood=Depends(get_hood)): - """ Get Email row by 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. @@ -102,7 +102,7 @@ async def email_read_all(hood=Depends(get_hood)): operation_id='create_email', ) async def email_create(values: BodyEmail, response: Response, hood=Depends(get_hood)): - """ Create an Email bot. Call this when creating a hood. + """Create an Email bot. Call this when creating a hood. :param hood: Hood row of the hood the Email bot is supposed to belong to. :return: Email row of the new email bot. @@ -164,7 +164,7 @@ async def email_read(email=Depends(get_email)): '/{email_id}', status_code=status.HTTP_204_NO_CONTENT, operation_id='delete_email' ) async def email_delete(email=Depends(get_email)): - """ Delete an Email bot. + """Delete an Email bot. Stops and deletes the Email bot. :param hood: Hood the Email bot belongs to. @@ -181,7 +181,7 @@ async def email_delete(email=Depends(get_email)): async def email_subscribe( subscriber: BodySubscriber, hood=Depends(get_hood_unauthorized) ): - """ Send a confirmation mail to subscribe to messages via email. + """Send a confirmation mail to subscribe to messages via email. :param subscriber: Subscriber object, holds the email address. :param hood: Hood the Email bot belongs to. @@ -218,7 +218,7 @@ async def email_subscribe( response_model=BaseModel, ) async def email_subscribe_confirm(token, hood=Depends(get_hood_unauthorized)): - """ Confirm a new subscriber and add them to the database. + """Confirm a new subscriber and add them to the database. :param token: encrypted JSON token, holds the email of the subscriber. :param hood: Hood the Email bot belongs to. @@ -241,7 +241,7 @@ async def email_subscribe_confirm(token, hood=Depends(get_hood_unauthorized)): operation_id='unsubscribe', ) async def email_unsubscribe(token, hood=Depends(get_hood_unauthorized)): - """ Remove a subscriber from the database when they click on an unsubscribe link. + """Remove a subscriber from the database when they click on an unsubscribe link. :param token: encrypted JSON token, holds subscriber email + hood.id. :param hood: Hood the Email bot belongs to. @@ -284,7 +284,7 @@ async def subscribers_read(subscriber=Depends(get_subscriber)): async def email_message_create( message: BodyMessage, hood=Depends(get_hood_unauthorized) ): - """ Receive a message from the MDA and pass it to the censor. + """Receive a message from the MDA and pass it to the censor. :param message: BodyMessage object, holds the message. :param hood: Hood the Email bot belongs to. diff --git a/kibicara/webapi/admin.py b/kibicara/webapi/admin.py index d329101..7486449 100644 --- a/kibicara/webapi/admin.py +++ b/kibicara/webapi/admin.py @@ -85,7 +85,7 @@ router = APIRouter() operation_id='register', ) async def admin_register(values: BodyAdmin): - """ Sends an email with a confirmation link. + """Sends an email with a confirmation link. - **email**: E-Mail Address of new hood admin - **password**: Password of new hood admin @@ -104,7 +104,9 @@ async def admin_register(values: BodyAdmin): body = f'{config["frontend_url"]}/confirm?token={register_token}' logger.debug(body) email.send_email( - to=values.email, subject='Confirm Account', body=body, + to=values.email, + subject='Confirm Account', + body=body, ) except (ConnectionRefusedError, SMTPException): logger.exception('Email sending failed') @@ -113,10 +115,12 @@ async def admin_register(values: BodyAdmin): @router.post( - '/confirm/{register_token}', response_model=BodyAccessToken, operation_id='confirm', + '/confirm/{register_token}', + response_model=BodyAccessToken, + operation_id='confirm', ) async def admin_confirm(register_token: str): - """ Registration confirmation and account creation. + """Registration confirmation and account creation. - **register_token**: Registration token received in email from /register """ @@ -130,10 +134,12 @@ async def admin_confirm(register_token: str): @router.post( - '/login/', response_model=BodyAccessToken, operation_id='login', + '/login/', + response_model=BodyAccessToken, + operation_id='login', ) async def admin_login(form_data: OAuth2PasswordRequestForm = Depends()): - """ Get an access token. + """Get an access token. - **username**: Email of a registered hood admin - **password**: Password of a registered hood admin diff --git a/kibicara/webapi/hoods/__init__.py b/kibicara/webapi/hoods/__init__.py index 22452f6..c12c3d0 100644 --- a/kibicara/webapi/hoods/__init__.py +++ b/kibicara/webapi/hoods/__init__.py @@ -62,7 +62,7 @@ async def hood_read_all(): tags=['hoods'], ) async def hood_create(values: BodyHood, response: Response, admin=Depends(get_admin)): - """ Creates a hood. + """Creates a hood. - **name**: Name of the hood - **landingpage**: Markdown formatted description of the hood @@ -95,7 +95,7 @@ async def hood_read(hood=Depends(get_hood_unauthorized)): tags=['hoods'], ) async def hood_update(values: BodyHood, hood=Depends(get_hood)): - """ Updates hood with id **hood_id**. + """Updates hood with id **hood_id**. - **name**: New name of the hood - **landingpage**: New Markdown formatted description of the hood diff --git a/kibicara/webapi/hoods/badwords.py b/kibicara/webapi/hoods/badwords.py index d7bc539..197abe0 100644 --- a/kibicara/webapi/hoods/badwords.py +++ b/kibicara/webapi/hoods/badwords.py @@ -52,7 +52,7 @@ async def badword_read_all(hood=Depends(get_hood)): async def badword_create( values: BodyBadWord, response: Response, hood=Depends(get_hood) ): - """ Creates a new badword for hood with id **hood_id**. + """Creates a new badword for hood with id **hood_id**. - **pattern**: Regular expression which is used to match a badword. """ @@ -83,7 +83,7 @@ async def badword_read(badword=Depends(get_badword)): operation_id='update_badword', ) async def badword_update(values: BodyBadWord, badword=Depends(get_badword)): - """ Updates badword with id **badword_id** for hood with id **hood_id**. + """Updates badword with id **badword_id** for hood with id **hood_id**. - **pattern**: Regular expression which is used to match a badword """ diff --git a/kibicara/webapi/hoods/triggers.py b/kibicara/webapi/hoods/triggers.py index cdd71b0..4ae0c28 100644 --- a/kibicara/webapi/hoods/triggers.py +++ b/kibicara/webapi/hoods/triggers.py @@ -53,7 +53,7 @@ async def trigger_read_all(hood=Depends(get_hood)): async def trigger_create( values: BodyTrigger, response: Response, hood=Depends(get_hood) ): - """ Creates a new trigger for hood with id **hood_id**. + """Creates a new trigger for hood with id **hood_id**. - **pattern**: Regular expression which is used to match a trigger. """ @@ -84,7 +84,7 @@ async def trigger_read(trigger=Depends(get_trigger)): operation_id='update_trigger', ) async def trigger_update(values: BodyTrigger, trigger=Depends(get_trigger)): - """ Updates trigger with id **trigger_id** for hood with id **hood_id**. + """Updates trigger with id **trigger_id** for hood with id **hood_id**. - **pattern**: Regular expression which is used to match a trigger """