diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2022-05-04 15:31:11 +0200 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2022-05-04 15:31:11 +0200 |
commit | fadd1eab07c9dfe317dfc31efa8ea254a78c3eeb (patch) | |
tree | 96f816efd151fd2b132add45a000bf0a7259e613 /labbot/bot.py | |
parent | 1ec64ccb178a4164ac204925c20c559d96508a9b (diff) | |
download | lab-bot-fadd1eab07c9dfe317dfc31efa8ea254a78c3eeb.tar.gz lab-bot-fadd1eab07c9dfe317dfc31efa8ea254a78c3eeb.zip |
improve typing, disable non-critical logging for aiohttp, […]
- correctly popped values from kwargs to pass over to gidgetlab
- add merge hook registration method to simplify future additions
- add new setups values to config
- add print option to config
Diffstat (limited to 'labbot/bot.py')
-rw-r--r-- | labbot/bot.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/labbot/bot.py b/labbot/bot.py index 1361656..9b5d70b 100644 --- a/labbot/bot.py +++ b/labbot/bot.py @@ -1,6 +1,6 @@ import os.path import sys -from gidgetlab.aiohttp import GitLabBot +from gidgetlab.aiohttp import GitLabBot # type: ignore from importlib import import_module import logging @@ -12,9 +12,10 @@ log = logging.getLogger(__name__) class Bot: def __init__(self, *args, **kwargs): - self.name = kwargs.get("name", "lab-bot") + self.name = kwargs.pop("name", "lab-bot") + self.access_token = kwargs.get("access_token") self.secret = kwargs.get("secret", "") - self.config = kwargs.get("config", labbot.config.read_instance_config(self.name)) + self.config = kwargs.pop("config", labbot.config.read_instance_config(self.name)) self.addons = self.config.get("addons", []) self.addon_paths = [] @@ -36,16 +37,19 @@ class Bot: sys.path.remove(path) - def load_addon(self, addon: str): + def load_addon(self, addon: str) -> None: try: import_module(f"{addon}").setup(self) log.info(f"Loaded {addon}") except ModuleNotFoundError: log.error(f"No addon named `{addon}`") - def register(self, func, *args, **kwargs): + def register(self, func, *args, **kwargs) -> None: return self.instance.router.register(*args, **kwargs)(func) - def run(self, *args, **kwargs): + def register_merge_hook(self, func, *args, **kwargs) -> None: + return self.instance.router.register("Merge Request Hook", *args, **kwargs)(func) + + def run(self, *args, **kwargs) -> None: log.info(f"Started {self.name}") self.instance.run(*args, **kwargs)
\ No newline at end of file |