diff --git a/.gitignore b/.gitignore index 52cbac9..1e41f9e 100644 --- a/.gitignore +++ b/.gitignore @@ -117,3 +117,4 @@ secrets.py frames/ tmp.jpg tmp.png +garden.mp4 diff --git a/dreamer.py b/dreamer.py index 006ab30..0f53293 100644 --- a/dreamer.py +++ b/dreamer.py @@ -88,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('!'): @@ -103,8 +106,53 @@ 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) @@ -121,9 +169,24 @@ async def message_handler(event): 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) @@ -192,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)'