ai621_new/handlers/welcome.py

30 lines
1.7 KiB
Python

from telethon import events
from telethon.utils import get_display_name
from telethon.events import StopPropagation
from telethon.tl.custom import Button
import logging
from config import *
log = logging.getLogger('welcome')
@events.register(events.NewMessage(pattern='^/start', incoming=True, func=lambda e: e.is_private))
async def welcome(ev):
exists = conn.execute('SELECT 1 FROM user WHERE id = ?', (ev.input_sender.user_id,))
if not exists.fetchone():
conn.execute('INSERT INTO user(id, first_name, last_name, lang_code) VALUES (?,?,?,?)',
(ev.input_sender.user_id, ev.sender.first_name, ev.sender.last_name, ev.sender.lang_code))
log.info(f'{(ev.input_sender.user_id, get_display_name(ev.sender))}: hello')
await ev.respond(f'Hello, and welcome to ai621. The guidelines are simple:\n1. No prompts that could result in abusive images or underage characters\nThis bot is powered by <strong>Stable Horde</strong>.', buttons=[[Button.url('👥 Group (NSFW)', 'https://t.me/ai621chat'),], [Button.url('📣 News & Best images (NSFW)', 'https://t.me/ai621gen'),],[Button.url('🔗 Join the Horde', 'https://stablehorde.net'),],[Button.inline('🆕 New prompt', 'new_prompt')]], parse_mode='html')
@events.register(events.callbackquery.CallbackQuery())
@events.register(events.NewMessage(incoming=True, func=lambda e: e.is_private))
async def precheck(ev):
exists = conn.execute('SELECT 1 FROM user WHERE id = ?', (ev.input_sender.user_id,))
if not exists.fetchone():
log.info(f'{(ev.input_sender.user_id, get_display_name(ev.sender))}: invite start')
await ev.client.send_message(ev.input_sender, 'Your profile is incomplete. Please use /start again.')
raise StopPropagation
handler = [welcome, precheck]