merged production and dev containers
This commit is contained in:
@@ -5,10 +5,13 @@ libblas-dev liblapack-dev \
|
||||
libffi-dev libnacl-dev \
|
||||
python3 python3-pip python3-dev
|
||||
|
||||
RUN mkdir -p /kwaylon/src
|
||||
WORKDIR /kwaylon
|
||||
COPY ./requirements.txt ./requirements.txt
|
||||
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip pip install -r ./requirements.txt
|
||||
|
||||
RUN python3 -m nltk.downloader words punkt averaged_perceptron_tagger
|
||||
|
||||
WORKDIR /usr/app
|
||||
CMD [ "./src/main.py" ]
|
||||
COPY ./src /kwaylon/src
|
||||
CMD [ "/kwaylon/src/main.py" ]
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
{
|
||||
"name": "Kwaylon",
|
||||
"build": {
|
||||
"dockerfile": "./Dockerfile",
|
||||
"context": "../"
|
||||
},
|
||||
"mounts": [
|
||||
"source=/etc/localtime,target=/etc/localtime,type=bind,consistency=cached",
|
||||
"source=/etc/timezone,target=/etc/timezone,type=bind,consistency=cached"
|
||||
],
|
||||
"dockerComposeFile": "../docker-compose.yml",
|
||||
"service": "kwaylon",
|
||||
"workspaceFolder": "/kwaylon",
|
||||
"shutdownAction": "stopCompose",
|
||||
// "build": {
|
||||
// "dockerfile": "./Dockerfile",
|
||||
// "context": "../"
|
||||
// },
|
||||
// "mounts": [
|
||||
// "source=/etc/localtime,target=/etc/localtime,type=bind",
|
||||
// "source=/etc/timezone,target=/etc/timezone,type=bind"
|
||||
// ],
|
||||
// "workspaceMount": "source=${localWorkspaceFolder}/src,target=/usr/app/src,type=bind",
|
||||
// "workspaceFolder": "/usr/app/src",
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/git:1": {},
|
||||
"ghcr.io/devcontainers/features/github-cli:1": {},
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ src/.env
|
||||
.ipynb_checkpoints
|
||||
discord.py
|
||||
*.db
|
||||
pics
|
||||
@@ -1,14 +1,20 @@
|
||||
version: '3.8'
|
||||
version: '3.3'
|
||||
services:
|
||||
kwaylon:
|
||||
container_name: kwaylon
|
||||
image: kwaylon:latest
|
||||
build: ./
|
||||
build:
|
||||
context: ./
|
||||
dockerfile: .devcontainer/Dockerfile
|
||||
# restart: unless-stopped
|
||||
network_mode: host
|
||||
tty: true
|
||||
stdin_open: true
|
||||
volumes:
|
||||
# give access to the system time as read-only
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- ./src:/usr/app/src
|
||||
- ./data:/usr/app/data
|
||||
- ./:/kwaylon
|
||||
# - ./src:/usr/app/src
|
||||
# - ./data:/usr/app/data
|
||||
# - ./pics:/discord_pics
|
||||
|
||||
@@ -2,7 +2,7 @@ import asyncio
|
||||
import logging
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
from typing import AsyncIterator, List
|
||||
|
||||
import pandas as pd
|
||||
from discord import (Client, Emoji, Guild, Message, RawReactionActionEvent,
|
||||
@@ -38,8 +38,6 @@ class Kwaylon(Client):
|
||||
# await alive(self.robotics_facility)
|
||||
_log.info('[bold bright_green]Done[/][bright_black], laying in wait...[/]')
|
||||
|
||||
await self.msg_gen(limit=10)
|
||||
|
||||
async def handle_message(self, message: Message):
|
||||
if message.author != self.user:
|
||||
await self.respond_to_joke(message)
|
||||
@@ -134,14 +132,15 @@ class Kwaylon(Client):
|
||||
channel = await guild.fetch_channel(row['channel_id'])
|
||||
return await channel.fetch_message(row['msg_id'])
|
||||
|
||||
async def msg_gen(self, **kwargs):
|
||||
_log.debug(f'Starting scan of {self.fd_guild.name}')
|
||||
async def msg_gen(self, **kwargs) -> AsyncIterator[Message]:
|
||||
# _log.debug(f'Starting scan of {self.fd_guild.name}')
|
||||
for channel in (await self.fd_guild.fetch_channels()):
|
||||
if isinstance(channel, TextChannel):
|
||||
_log.debug(f'[bold green]{channel.name}[/]')
|
||||
# _log.debug(f'[bold green]{channel.name}[/]')
|
||||
msg: Message
|
||||
async for msg in channel.history(**kwargs):
|
||||
_log.debug(f'[bold blue]{msg.author.display_name}[/] {msg.content[:200]}')
|
||||
yield msg
|
||||
# _log.debug(f'[bold blue]{msg.author.display_name}[/] {msg.content[:200]}')
|
||||
|
||||
|
||||
def log_info():
|
||||
|
||||
28
src/main.py
28
src/main.py
@@ -2,20 +2,44 @@
|
||||
|
||||
import logging
|
||||
import os
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from discord import Intents, Message
|
||||
from dotenv import load_dotenv
|
||||
from rich.console import Console
|
||||
from rich.highlighter import NullHighlighter
|
||||
from rich.logging import RichHandler
|
||||
|
||||
from kwaylon import Kwaylon
|
||||
|
||||
TZ = datetime.now().astimezone().tzinfo
|
||||
|
||||
async def save_pictures(client: Kwaylon, dest: Path):
|
||||
kwargs = dict(
|
||||
limit=10,
|
||||
after=datetime(year=2023, month=1, day=1, tzinfo=TZ),
|
||||
oldest_first=True
|
||||
)
|
||||
async for msg in client.msg_gen(**kwargs):
|
||||
if len(msg.attachments) > 0:
|
||||
for attachment in msg.attachments:
|
||||
if attachment.content_type == 'image/jpeg':
|
||||
filepath = Path(f'/kwaylon/pics/{msg.author.display_name.replace(".", "")}_{msg.created_at.strftime("%Y%m%d_%H%M%S.jpeg")}')
|
||||
if not filepath.exists():
|
||||
logging.debug(f'[bold blue]{msg.author.display_name}[/] {msg.clean_content[:200]}')
|
||||
logging.debug(f'Saving {filepath.name}')
|
||||
await attachment.save(filepath)
|
||||
else:
|
||||
logging.debug(f'Skipping {filepath.name}')
|
||||
|
||||
if __name__ == '__main__':
|
||||
rich_handler = RichHandler(
|
||||
console=Console(width=150),
|
||||
highlighter=NullHighlighter(),
|
||||
markup=True,
|
||||
rich_tracebacks=True,
|
||||
tracebacks_suppress=['pandas'],
|
||||
tracebacks_suppress=['pandas', 'discord'],
|
||||
)
|
||||
dt_fmt = '%Y-%m-%d %I:%M:%S %p'
|
||||
# https://docs.python.org/3/library/logging.html#logrecord-attributes
|
||||
@@ -36,6 +60,8 @@ if __name__ == '__main__':
|
||||
@client.event
|
||||
async def on_ready():
|
||||
await client.initialize()
|
||||
# https://discordpy.readthedocs.io/en/stable/api.html#discord.TextChannel.history
|
||||
# await save_pictures(client, Path('/kwaylon/pics'))
|
||||
|
||||
@client.event
|
||||
async def on_message(message: Message):
|
||||
|
||||
Reference in New Issue
Block a user