from telethon import TelegramClient, connection import logging, asyncio, sqlite3 from telethon.tl.types import MessageActionChatJoinedByLink from telethon.tl.types import MessageActionChatAddUser from telethon.tl.types import ReplyInlineMarkup from telethon.tl.types import KeyboardButtonRow from telethon.tl.types import KeyboardButton from telethon import events from telethon.tl.custom import Button from asyncio import sleep, Future from telethon.tl.types import PeerUser, PeerChannel logging.basicConfig(level=logging.INFO) api_id = YOUR_API_ID api_hash = 'YOUR_API_HASH' db = sqlite3.connect('votes') client = TelegramClient('bot', api_id, api_hash).start() verifications = {} client.max_id = 0 @client.on(events.NewMessage(incoming=True, chats=[PeerUser(user_id=184151234),PeerUser(user_id=52493088)], func=lambda e: e.is_private)) async def handler(ev): msg = await client.send_message(PeerChannel(channel_id=1340677057), ev.message, buttons=[[Button.inline("๐Ÿ‘", f"like"),Button.inline("๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ", b"gold")]]) client.max_id = msg.id @client.on(events.callbackquery.CallbackQuery) async def get_vote(ev): print(ev) #print(ev.from_id, 'voted for', ev.data) if ev.data == b"gold": await ev.answer('Grazie per la tua preferenza! Il tuo oro รจ stato registrato.\nThanks! The gold has been received owo', alert=True) db.execute('DELETE FROM votes WHERE is_golden = 1 AND user_id = ?', (ev.original_update.user_id,)) db.execute('INSERT INTO votes(user_id, is_golden, msg_id) VALUES (?,?,?)', (ev.original_update.user_id, 1, ev.original_update.msg_id)) elif ev.data == b"like": await ev.answer('Grazie per il like!\nThanks for the like!', alert=False) db.execute('INSERT INTO votes(user_id, is_golden, msg_id) VALUES (?,?,?) ON CONFLICT DO NOTHING', (ev.original_update.user_id, 0, ev.original_update.msg_id)) db.commit() client.flood_sleep_threshold = 24*60*60 client.run_until_disconnected()