From 8b9ea0f5937c96a6a549a11a5d2ae53d44e7e041 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Fri, 3 Mar 2023 19:33:41 +0000 Subject: [PATCH] Add !scope command --- .gitignore | 1 + dreamer.py | 36 ++++++++++++++++++++++++++++++++++++ frames/.gitkeep | 0 3 files changed, 37 insertions(+) create mode 100644 frames/.gitkeep diff --git a/.gitignore b/.gitignore index b7d9569..bc9d02a 100644 --- a/.gitignore +++ b/.gitignore @@ -114,3 +114,4 @@ settings.py *.session-journal tmp.png secrets.py +frames/ diff --git a/dreamer.py b/dreamer.py index 3fdc81e..0e65591 100644 --- a/dreamer.py +++ b/dreamer.py @@ -5,12 +5,15 @@ logging.basicConfig( format='[%(asctime)s] %(levelname)s %(module)s/%(funcName)s - %(message)s', level=logging.DEBUG if DEBUG else logging.INFO) +import asyncio import requests import random import json import base64 import time import re +from PIL import Image +from datetime import datetime, timezone, timedelta from io import BytesIO from telethon import TelegramClient, events @@ -18,6 +21,10 @@ import secrets PROTOSPACE = -1001298858490 JASON = 172033414 +TANNER = 79316791 +TANNERBOT_MICROSCOPY = -1001886549266 + +scope_subject = '' client = TelegramClient('data/dreamer.session', secrets.TG_API_ID, secrets.TG_API_HASH) @@ -56,6 +63,8 @@ def dreamer(prompt, steps=30, seed=1234, height=512, width=512): return None async def message_handler(event): + global scope_subject + text = event.raw_text chat = event.chat_id @@ -90,6 +99,33 @@ async def message_handler(event): command = command.lower() + #!setscope + if command == 'setscope' and data: + if not reply and sender.id != TANNER: + reply = '> do !scope to look under the microscope' + await event.reply(reply) + + if not reply: + scope_subject = data + + now = datetime.now(tz=timezone.utc) - timedelta(seconds=1) + reply = '> ' + scope_subject + reply_file = 'frames/' + now.strftime('image%S.jpg') + reply_msg = await event.reply(reply, file=reply_file, link_preview=False) + + await reply_msg.forward_to(TANNERBOT_MICROSCOPY) + + #!scope + if command == 'scope': + logging.info('Chat: {:<14} | ID: {:<6} | User: {} {} | Command: {} | Data: {}'.format(chat, event.id, name, sender.id, command, data or 'None')) + + if not reply: + + now = datetime.now(tz=timezone.utc) - timedelta(seconds=1) + reply = '> ' + scope_subject + reply_file = 'frames/' + now.strftime('image%S.jpg') + reply_msg = await event.reply(reply, file=reply_file, link_preview=False) + #!dream if command == 'dream': diff --git a/frames/.gitkeep b/frames/.gitkeep new file mode 100644 index 0000000..e69de29