Add !garden and scope scale bar

master
Tanner Collin 1 year ago
parent 8c5a53317b
commit ab12ba8ec5
  1. 2
      .gitignore
  2. 51
      dreamer.py

2
.gitignore vendored

@ -115,3 +115,5 @@ settings.py
tmp.png tmp.png
secrets.py secrets.py
frames/ frames/
tmp.jpg
tmp.png

@ -12,6 +12,7 @@ import json
import base64 import base64
import time import time
import re import re
import pytz
from PIL import Image from PIL import Image
from datetime import datetime, timezone, timedelta from datetime import datetime, timezone, timedelta
from io import BytesIO from io import BytesIO
@ -24,7 +25,10 @@ JASON = 172033414
TANNER = 79316791 TANNER = 79316791
TANNERBOT_MICROSCOPY = -1001886549266 TANNERBOT_MICROSCOPY = -1001886549266
TIMEZONE_TANNER = pytz.timezone('America/Edmonton')
scope_subject = '' scope_subject = ''
scope_zoom = ''
client = TelegramClient('data/dreamer.session', secrets.TG_API_ID, secrets.TG_API_HASH) 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 return None
async def message_handler(event): async def message_handler(event):
global scope_subject global scope_subject, scope_zoom
text = event.raw_text text = event.raw_text
chat = event.chat_id chat = event.chat_id
@ -99,6 +103,25 @@ async def message_handler(event):
command = command.lower() command = command.lower()
#!garden
if command == 'garden':
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)
#!setscope #!setscope
if command == 'setscope' and data: if command == 'setscope' and data:
if not reply and sender.id != TANNER: if not reply and sender.id != TANNER:
@ -108,10 +131,20 @@ async def message_handler(event):
if not reply: if not reply:
scope_subject = data 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) now = datetime.now(tz=timezone.utc) - timedelta(seconds=1)
reply = '> ' + scope_subject reply = '> ' + scope_subject
reply_file = 'frames/' + now.strftime('image%S.jpg') file_name = 'frames/' + now.strftime('image%S.jpg')
reply_msg = await event.reply(reply, file=reply_file, link_preview=False) 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) await reply_msg.forward_to(TANNERBOT_MICROSCOPY)
@ -122,9 +155,15 @@ async def message_handler(event):
if not reply: if not reply:
now = datetime.now(tz=timezone.utc) - timedelta(seconds=1) now = datetime.now(tz=timezone.utc) - timedelta(seconds=1)
reply = '> ' + scope_subject if scope_subject:
reply_file = 'frames/' + now.strftime('image%S.jpg') reply = '> ' + scope_subject
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)
#!dream #!dream

Loading…
Cancel
Save