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