[misc] Reformat to fit new black guidelines
This commit is contained in:
parent
3dca6d07ba
commit
32dd8b9207
|
@ -47,7 +47,10 @@ if argv[0].endswith('kibicara'):
|
||||||
help='path to config file',
|
help='path to config file',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-v', '--verbose', action="count", help="Raise verbosity level",
|
'-v',
|
||||||
|
'--verbose',
|
||||||
|
action="count",
|
||||||
|
help="Raise verbosity level",
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def send_email(to, subject, sender='kibicara', body=''):
|
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
|
Sends an E-Mail to a specified recipient with a body
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Main:
|
class Main:
|
||||||
""" Entrypoint for Kibicara.
|
"""Entrypoint for Kibicara.
|
||||||
|
|
||||||
Initializes the platform bots and starts the hypercorn webserver serving the
|
Initializes the platform bots and starts the hypercorn webserver serving the
|
||||||
Kibicara application and the specified frontend on port 8000.
|
Kibicara application and the specified frontend on port 8000.
|
||||||
|
|
|
@ -44,7 +44,7 @@ class BotStatus(Enum):
|
||||||
|
|
||||||
|
|
||||||
class Censor:
|
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
|
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
|
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
|
self.status = BotStatus.STOPPED
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
""" Entry point for a bot.
|
"""Entry point for a bot.
|
||||||
|
|
||||||
Note: Override this in the derived bot class.
|
Note: Override this in the derived bot class.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def publish(self, message):
|
async def publish(self, message):
|
||||||
""" Distribute a message to the bots in a hood.
|
"""Distribute a message to the bots in a hood.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
message (Message): Message to distribute
|
message (Message): Message to distribute
|
||||||
|
@ -131,7 +131,7 @@ class Censor:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def receive(self):
|
async def receive(self):
|
||||||
""" Receive a message.
|
"""Receive a message.
|
||||||
|
|
||||||
Returns (Message): Received message
|
Returns (Message): Received message
|
||||||
"""
|
"""
|
||||||
|
@ -151,7 +151,7 @@ class Censor:
|
||||||
|
|
||||||
|
|
||||||
class Spawner:
|
class Spawner:
|
||||||
""" Spawns a bot with a specific bot model.
|
"""Spawns a bot with a specific bot model.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
```
|
```
|
||||||
|
@ -183,8 +183,7 @@ class Spawner:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def init_all(cls):
|
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:
|
for spawner in cls.__instances:
|
||||||
await spawner._init()
|
await spawner._init()
|
||||||
|
|
||||||
|
@ -193,7 +192,7 @@ class Spawner:
|
||||||
self.start(item)
|
self.start(item)
|
||||||
|
|
||||||
def start(self, 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:
|
Example:
|
||||||
```
|
```
|
||||||
|
@ -209,7 +208,7 @@ class Spawner:
|
||||||
bot.start()
|
bot.start()
|
||||||
|
|
||||||
def stop(self, item):
|
def stop(self, item):
|
||||||
""" Stop and delete a bot.
|
"""Stop and delete a bot.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
item (ORM Model object): ORM object corresponding to bot.
|
item (ORM Model object): ORM object corresponding to bot.
|
||||||
|
@ -219,7 +218,7 @@ class Spawner:
|
||||||
bot.stop()
|
bot.stop()
|
||||||
|
|
||||||
def get(self, item):
|
def get(self, item):
|
||||||
""" Get a running bot.
|
"""Get a running bot.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
item (ORM Model object): ORM object corresponding to bot.
|
item (ORM Model object): ORM object corresponding to bot.
|
||||||
|
|
|
@ -41,7 +41,9 @@ class EmailBot(Censor):
|
||||||
try:
|
try:
|
||||||
logger.debug('Trying to send: \n%s' % body)
|
logger.debug('Trying to send: \n%s' % body)
|
||||||
email.send_email(
|
email.send_email(
|
||||||
subscriber.email, "Kibicara " + self.hood.name, body=body,
|
subscriber.email,
|
||||||
|
"Kibicara " + self.hood.name,
|
||||||
|
body=body,
|
||||||
)
|
)
|
||||||
except (ConnectionRefusedError, SMTPException):
|
except (ConnectionRefusedError, SMTPException):
|
||||||
logger.exception("Sending email to subscriber failed.")
|
logger.exception("Sending email to subscriber failed.")
|
||||||
|
|
|
@ -51,7 +51,7 @@ class BodySubscriber(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
async def get_email(email_id: int, hood=Depends(get_hood)):
|
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.
|
You can specify an email_id to nail it down, but it works without as well.
|
||||||
|
|
||||||
:param hood: Hood the Email bot belongs to.
|
: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',
|
operation_id='create_email',
|
||||||
)
|
)
|
||||||
async def email_create(values: BodyEmail, response: Response, hood=Depends(get_hood)):
|
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.
|
:param hood: Hood row of the hood the Email bot is supposed to belong to.
|
||||||
:return: Email row of the new email bot.
|
: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'
|
'/{email_id}', status_code=status.HTTP_204_NO_CONTENT, operation_id='delete_email'
|
||||||
)
|
)
|
||||||
async def email_delete(email=Depends(get_email)):
|
async def email_delete(email=Depends(get_email)):
|
||||||
""" Delete an Email bot.
|
"""Delete an Email bot.
|
||||||
Stops and deletes the Email bot.
|
Stops and deletes the Email bot.
|
||||||
|
|
||||||
:param hood: Hood the Email bot belongs to.
|
:param hood: Hood the Email bot belongs to.
|
||||||
|
@ -181,7 +181,7 @@ async def email_delete(email=Depends(get_email)):
|
||||||
async def email_subscribe(
|
async def email_subscribe(
|
||||||
subscriber: BodySubscriber, hood=Depends(get_hood_unauthorized)
|
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 subscriber: Subscriber object, holds the email address.
|
||||||
:param hood: Hood the Email bot belongs to.
|
:param hood: Hood the Email bot belongs to.
|
||||||
|
@ -218,7 +218,7 @@ async def email_subscribe(
|
||||||
response_model=BaseModel,
|
response_model=BaseModel,
|
||||||
)
|
)
|
||||||
async def email_subscribe_confirm(token, hood=Depends(get_hood_unauthorized)):
|
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 token: encrypted JSON token, holds the email of the subscriber.
|
||||||
:param hood: Hood the Email bot belongs to.
|
: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',
|
operation_id='unsubscribe',
|
||||||
)
|
)
|
||||||
async def email_unsubscribe(token, hood=Depends(get_hood_unauthorized)):
|
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 token: encrypted JSON token, holds subscriber email + hood.id.
|
||||||
:param hood: Hood the Email bot belongs to.
|
: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(
|
async def email_message_create(
|
||||||
message: BodyMessage, hood=Depends(get_hood_unauthorized)
|
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 message: BodyMessage object, holds the message.
|
||||||
:param hood: Hood the Email bot belongs to.
|
:param hood: Hood the Email bot belongs to.
|
||||||
|
|
|
@ -85,7 +85,7 @@ router = APIRouter()
|
||||||
operation_id='register',
|
operation_id='register',
|
||||||
)
|
)
|
||||||
async def admin_register(values: BodyAdmin):
|
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
|
- **email**: E-Mail Address of new hood admin
|
||||||
- **password**: Password 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}'
|
body = f'{config["frontend_url"]}/confirm?token={register_token}'
|
||||||
logger.debug(body)
|
logger.debug(body)
|
||||||
email.send_email(
|
email.send_email(
|
||||||
to=values.email, subject='Confirm Account', body=body,
|
to=values.email,
|
||||||
|
subject='Confirm Account',
|
||||||
|
body=body,
|
||||||
)
|
)
|
||||||
except (ConnectionRefusedError, SMTPException):
|
except (ConnectionRefusedError, SMTPException):
|
||||||
logger.exception('Email sending failed')
|
logger.exception('Email sending failed')
|
||||||
|
@ -113,10 +115,12 @@ async def admin_register(values: BodyAdmin):
|
||||||
|
|
||||||
|
|
||||||
@router.post(
|
@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):
|
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
|
- **register_token**: Registration token received in email from /register
|
||||||
"""
|
"""
|
||||||
|
@ -130,10 +134,12 @@ async def admin_confirm(register_token: str):
|
||||||
|
|
||||||
|
|
||||||
@router.post(
|
@router.post(
|
||||||
'/login/', response_model=BodyAccessToken, operation_id='login',
|
'/login/',
|
||||||
|
response_model=BodyAccessToken,
|
||||||
|
operation_id='login',
|
||||||
)
|
)
|
||||||
async def admin_login(form_data: OAuth2PasswordRequestForm = Depends()):
|
async def admin_login(form_data: OAuth2PasswordRequestForm = Depends()):
|
||||||
""" Get an access token.
|
"""Get an access token.
|
||||||
|
|
||||||
- **username**: Email of a registered hood admin
|
- **username**: Email of a registered hood admin
|
||||||
- **password**: Password of a registered hood admin
|
- **password**: Password of a registered hood admin
|
||||||
|
|
|
@ -62,7 +62,7 @@ async def hood_read_all():
|
||||||
tags=['hoods'],
|
tags=['hoods'],
|
||||||
)
|
)
|
||||||
async def hood_create(values: BodyHood, response: Response, admin=Depends(get_admin)):
|
async def hood_create(values: BodyHood, response: Response, admin=Depends(get_admin)):
|
||||||
""" Creates a hood.
|
"""Creates a hood.
|
||||||
|
|
||||||
- **name**: Name of the hood
|
- **name**: Name of the hood
|
||||||
- **landingpage**: Markdown formatted description 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'],
|
tags=['hoods'],
|
||||||
)
|
)
|
||||||
async def hood_update(values: BodyHood, hood=Depends(get_hood)):
|
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
|
- **name**: New name of the hood
|
||||||
- **landingpage**: New Markdown formatted description of the hood
|
- **landingpage**: New Markdown formatted description of the hood
|
||||||
|
|
|
@ -52,7 +52,7 @@ async def badword_read_all(hood=Depends(get_hood)):
|
||||||
async def badword_create(
|
async def badword_create(
|
||||||
values: BodyBadWord, response: Response, hood=Depends(get_hood)
|
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.
|
- **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',
|
operation_id='update_badword',
|
||||||
)
|
)
|
||||||
async def badword_update(values: BodyBadWord, badword=Depends(get_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
|
- **pattern**: Regular expression which is used to match a badword
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -53,7 +53,7 @@ async def trigger_read_all(hood=Depends(get_hood)):
|
||||||
async def trigger_create(
|
async def trigger_create(
|
||||||
values: BodyTrigger, response: Response, hood=Depends(get_hood)
|
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.
|
- **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',
|
operation_id='update_trigger',
|
||||||
)
|
)
|
||||||
async def trigger_update(values: BodyTrigger, trigger=Depends(get_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
|
- **pattern**: Regular expression which is used to match a trigger
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue