merged production and dev containers
This commit is contained in:
@@ -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