ai621_new/handlers/info.py

53 lines
2.3 KiB
Python

from telethon import events
from telethon.utils import get_display_name
from telethon.events import StopPropagation
import logging
import httpx
from config import *
log = logging.getLogger('info')
@events.register(events.NewMessage(pattern='^/info', incoming=True, func=lambda e: e.is_private))
async def info(ev):
try:
async with httpx.AsyncClient() as client:
res = await client.get("https://stablehorde.net/api/v2/find_user", headers={'apikey': api_horde})
data = res.json()
except:
await ev.respond('There was an issue retrieving details. Try later')
else:
await ev.respond(f"""<strong>{data['username']}'s <a href="https://stablehorde.net/">stable horde</a></strong>\nKudos: {data['kudos']}\nOnline workers: {data['worker_count']}\nTotal images: {data['contributions']['fulfillments']}\nTotal megapixelsteps: {data['contributions']['megapixelsteps']}""", parse_mode='html')
@events.register(events.NewMessage(pattern='^/kudos', incoming=True, func=lambda e: e.is_private))
async def kudos(ev):
apikey = conn.execute('SELECT key FROM user WHERE id = ? AND key IS NOT NULL', (ev.input_sender.user_id,)).fetchone()
try:
async with httpx.AsyncClient() as client:
res = await client.get("https://stablehorde.net/api/v2/find_user", headers={'apikey': default_horde_key if not apikey else apikey[0]})
data = res.json()
except:
await ev.respond('There was an issue retrieving details. Try later')
raise
else:
await ev.respond(f"""Hello {data['username']}, you have {data['kudos']} kudos.\nA higher amount of kudos will lead to faster generations!""" + ('\n\n⚠️ You are using the bot as a guest: register on <a href="https://stablehorde.net">Stable Horde</a> and donate GPU time to have higher priority' if not apikey else ''), parse_mode='html')
@events.register(events.NewMessage(pattern='^/models', incoming=True, func=lambda e: e.is_private))
async def models(ev):
try:
async with httpx.AsyncClient() as client:
res = await client.get("https://stablehorde.net/api/v2/status/models")
data = res.json()
except:
await ev.respond('There was an issue retrieving details. Try later')
raise
else:
ret = "Available models (number of workers):"
for mod in data:
if mod['name'] not in enabled_models: continue
ret += f"\n- {mod['name']} ({mod['count']})"
await ev.respond(ret, parse_mode='html')
handler = [info,kudos,models]