Compare commits

...

2 Commits

  1. 3
      .gitignore
  2. 116
      dreamer.py

3
.gitignore vendored

@ -115,3 +115,6 @@ settings.py
tmp.png
secrets.py
frames/
tmp.jpg
tmp.png
garden.mp4

@ -12,6 +12,7 @@ import json
import base64
import time
import re
import pytz
from PIL import Image
from datetime import datetime, timezone, timedelta
from io import BytesIO
@ -24,7 +25,10 @@ JASON = 172033414
TANNER = 79316791
TANNERBOT_MICROSCOPY = -1001886549266
TIMEZONE_TANNER = pytz.timezone('America/Edmonton')
scope_subject = ''
scope_zoom = ''
client = TelegramClient('data/dreamer.session', secrets.TG_API_ID, secrets.TG_API_HASH)
@ -63,7 +67,7 @@ def dreamer(prompt, steps=30, seed=1234, height=512, width=512):
return None
async def message_handler(event):
global scope_subject
global scope_subject, scope_zoom
text = event.raw_text
chat = event.chat_id
@ -84,6 +88,9 @@ async def message_handler(event):
reply = ''
reply_file = None
if event.message.is_reply and 'plz type it' in text.lower():
text = '!transcribe'
if text.startswith('! '):
text = text[2:]
elif text.startswith('!'):
@ -99,8 +106,87 @@ async def message_handler(event):
command = command.lower()
#!chat
if command in ['chat', 'yarr', 'hwhat']:
await client.send_read_acknowledge(event.chat, event.message, clear_mentions=True)
return
#!transacribe
if command == 'transcribe':
logging.info('Chat: {:<14} | ID: {:<6} | User: {} {} | Command: {} | Data: {}'.format(chat, event.id, name, sender.id, command, data or 'None'))
if not reply and not event.message.is_reply:
reply = '> reply to the voice message you want transcribed'
await event.reply(reply, link_preview=False)
if not reply:
reply_message = await event.get_reply_message()
try:
if 'audio' in reply_message.media.document.mime_type:
audio = BytesIO()
await client.download_media(reply_message, file=audio)
audio.seek(0)
else:
raise
except:
reply = '> reply to a voice message'
await event.reply(reply, link_preview=False)
if not reply:
try:
url = secrets.WHISPER_API
res = requests.post(url, files={'audio': audio.getvalue()}, timeout=30)
res.raise_for_status()
res = res.json()
logging.info('Whisper response: %s', str(res))
reply = '> audio transcription: "{}"'.format(res['text'].strip())
await event.reply(reply, link_preview=False)
except:
reply = '> error'
await event.reply(reply, link_preview=False)
#!garden
if command == 'garden':
logging.info('Chat: {:<14} | ID: {:<6} | User: {} {} | Command: {} | Data: {}'.format(chat, event.id, name, sender.id, command, data or 'None'))
headers = {'Authorization': 'Basic YWRtaW46NXFoaDM0ZHFqMzRx'}
try:
res = requests.get('http://cameras.dns.t0.vc/image/G-1?&w=9999', headers=headers, timeout=4)
res.raise_for_status()
with open('tmp.jpg', 'wb') as f:
f.write(res.content)
start = datetime(2023, 3, 5, 19, 0, tzinfo=TIMEZONE_TANNER)
delta = datetime.now(pytz.utc) - start
reply = '> secret garden #3 day {}'.format(delta.days + 1)
reply += '\n> iceberg lettuce'
await event.reply(reply, file='tmp.jpg', link_preview=False)
except:
reply = '> error'
await event.reply(reply, link_preview=False)
#!gardenvid
if command == 'gardenvid':
logging.info('Chat: {:<14} | ID: {:<6} | User: {} {} | Command: {} | Data: {}'.format(chat, event.id, name, sender.id, command, data or 'None'))
reply_file = await client.upload_file('garden.mp4')
start = datetime(2023, 3, 5, 19, 0, tzinfo=TIMEZONE_TANNER)
delta = datetime.now(pytz.utc) - start
reply = '> secret garden #3 day {}'.format(delta.days + 1)
reply += '\n> iceberg lettuce'
await event.reply(reply, file=reply_file, link_preview=False)
#!setscope
if command == 'setscope' and data:
logging.info('Chat: {:<14} | ID: {:<6} | User: {} {} | Command: {} | Data: {}'.format(chat, event.id, name, sender.id, command, data or 'None'))
if not reply and sender.id != TANNER:
reply = '> do !scope to look under the microscope'
await event.reply(reply)
@ -108,10 +194,20 @@ async def message_handler(event):
if not reply:
scope_subject = data
for zoom in ['4x', '10x', '40x']:
if zoom in scope_subject:
scope_zoom = zoom
scope_subject = scope_subject.replace(zoom, '')
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)
file_name = 'frames/' + now.strftime('image%S.jpg')
frame = Image.open(file_name)
if scope_zoom:
label = Image.open(scope_zoom + '_label.png')
frame.paste(label, (0,0), label)
frame.save('tmp.jpg')
reply_msg = await event.reply(reply, file='tmp.jpg', link_preview=False)
await reply_msg.forward_to(TANNERBOT_MICROSCOPY)
@ -122,9 +218,15 @@ async def message_handler(event):
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)
if scope_subject:
reply = '> ' + scope_subject
file_name = 'frames/' + now.strftime('image%S.jpg')
frame = Image.open(file_name)
if scope_zoom:
label = Image.open(scope_zoom + '_label.png')
frame.paste(label, (0,0), label)
frame.save('tmp.jpg')
reply_msg = await event.reply(reply, file='tmp.jpg', link_preview=False)
#!dream
@ -153,7 +255,7 @@ async def message_handler(event):
if not reply and not to_send:
reply = '> usage: !dream [prompt] [options]'
reply += '\n> or reply to a someone with !dream'
reply += '\n> or reply to someone with !dream'
reply += '\n> default options:'
reply += '\n> steps:30 (20-40)'
reply += '\n> height:512 (512-1024)'

Loading…
Cancel
Save