Random Coffee alternative - random meetings for Telegram chats https://t.me/ranteabot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

42 lines
1.5 KiB

import telebot
import typing
import random
import string
def generate_id() -> str:
return ''.join(random.choice(string.digits + string.ascii_lowercase) for _ in range(8))
def isint(st: str) -> bool:
try:
int(st)
return True
except ValueError:
return False
def create_inline_button(text: str, callback_data: str) -> telebot.types.InlineKeyboardButton:
if callback_data.strip().startswith('https://') or callback_data.startswith('tg://'):
return telebot.types.InlineKeyboardButton(text, url=callback_data.strip())
if callback_data.strip().startswith('inline://'):
telebot.types.InlineKeyboardButton(text,
switch_inline_query_current_chat=callback_data.replace('inline://', ''))
if callback_data.strip().startswith('inline_other://'):
telebot.types.InlineKeyboardButton(text, switch_inline_query=callback_data.replace('inline_other://', ''))
return telebot.types.InlineKeyboardButton(text, callback_data=callback_data)
def create_keyboard(rows: typing.List[typing.List[str]]):
is_inline = not isinstance(rows[0][0], str)
markup = telebot.types.InlineKeyboardMarkup() if is_inline else telebot.types.ReplyKeyboardMarkup(
resize_keyboard=True)
for row in rows:
if is_inline:
markup.row(*(
create_inline_button(text, callback_data)
for text, callback_data in row
))
else:
markup.row(*(telebot.types.KeyboardButton(text) for text in row))
return markup