added cli for handling the alive flag
This commit is contained in:
@@ -2,13 +2,14 @@ FROM python:latest
|
||||
RUN apt update && apt install -y bash
|
||||
|
||||
RUN python3 -m pip install --upgrade pip
|
||||
|
||||
RUN mkdir -p /kwaylon/src
|
||||
WORKDIR /kwaylon
|
||||
COPY ./requirements.txt ./requirements.txt
|
||||
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip python3 -m pip install -r ./requirements.txt
|
||||
|
||||
RUN python3 -m nltk.downloader words punkt averaged_perceptron_tagger
|
||||
|
||||
RUN mkdir -p /kwaylon/src
|
||||
COPY ./src /kwaylon/src
|
||||
COPY pyproject.toml /kwaylon
|
||||
WORKDIR /kwaylon
|
||||
RUN python3 -m pip install -e /kwaylon
|
||||
|
||||
@@ -20,4 +20,4 @@ dependencies = [
|
||||
requires-python = ">=3.9"
|
||||
|
||||
[project.scripts]
|
||||
kwaylon = "kwaylon:main"
|
||||
kwaylon = "kwaylon:cli"
|
||||
|
||||
@@ -2,6 +2,7 @@ import asyncio
|
||||
import logging
|
||||
import os
|
||||
|
||||
import click
|
||||
from dotenv import load_dotenv
|
||||
from rich.console import Console
|
||||
from rich.highlighter import NullHighlighter
|
||||
@@ -30,21 +31,30 @@ def init_logging(log_level: int = logging.INFO):
|
||||
datefmt=dt_fmt,
|
||||
handlers=[rich_handler]
|
||||
)
|
||||
logging.getLogger('discord').setLevel(logging.WARNING)
|
||||
logging.getLogger('urllib3').setLevel(logging.INFO)
|
||||
|
||||
|
||||
def main(token_var: str = 'DISCORD_TOKEN'):
|
||||
init_logging(logging.DEBUG)
|
||||
load_dotenv()
|
||||
def main(token_var: str = 'DISCORD_TOKEN', alive_flag: bool = False):
|
||||
loop = asyncio.new_event_loop()
|
||||
loop.create_task(
|
||||
Kwaylon.create_and_start(
|
||||
os.getenv(token_var),
|
||||
logging.DEBUG
|
||||
logging.DEBUG,
|
||||
alive_flag
|
||||
)
|
||||
)
|
||||
logging.getLogger('discord').setLevel(logging.WARNING)
|
||||
logging.getLogger('urllib3').setLevel(logging.INFO)
|
||||
try:
|
||||
loop.run_forever()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.option('-a', '--alive', required=False, default=False, is_flag=True)
|
||||
def cli(alive: bool):
|
||||
load_dotenv()
|
||||
init_logging(logging.DEBUG)
|
||||
logging.debug(f'Starting from [bold red]Kwaylon CLI[/]')
|
||||
main(token_var='DISCORD_TOKEN', alive_flag=alive)
|
||||
|
||||
@@ -19,6 +19,8 @@ _log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Kwaylon(Client):
|
||||
im_alive_flag: bool
|
||||
|
||||
def __init__(self, limit: int = 5000, days: int = 30, db_path: Path = None, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.jokes = list(jokes.collect_jokes())
|
||||
@@ -35,15 +37,19 @@ class Kwaylon(Client):
|
||||
self.robotics_facility: TextChannel = await self.fetch_channel(ROBOTICS_FACILITY_ID)
|
||||
self.robotics_facility_dev: TextChannel = await self.fetch_channel(DEV_ROBOTICS_FACILITY_ID)
|
||||
self.kaylon_emoji: Emoji = utils.get(self.emojis, name='kaylon')
|
||||
# await alive(self.robotics_facility)
|
||||
_log.info(
|
||||
'[bold bright_green]Done[/][bright_black], laying in wait...[/]')
|
||||
|
||||
if self.im_alive_flag:
|
||||
# await alive(self.robotics_facility)
|
||||
await alive(self.robotics_facility_dev)
|
||||
|
||||
_log.info('[bold bright_green]Done[/][bright_black], laying in wait...[/]')
|
||||
|
||||
@classmethod
|
||||
async def create_and_start(cls, token: str, log_level: int = logging.INFO):
|
||||
async def create_and_start(cls, token: str, log_level: int = logging.INFO, alive: bool = False):
|
||||
intents = Intents.default()
|
||||
intents.message_content = True
|
||||
client = cls(intents=intents)
|
||||
client.im_alive_flag = alive
|
||||
|
||||
@client.event
|
||||
async def on_ready():
|
||||
|
||||
Reference in New Issue
Block a user