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