Skip to content

Instantly share code, notes, and snippets.

@Kylmakalle
Created October 1, 2017 21:53
Show Gist options
  • Save Kylmakalle/650f2245bbf131a2663e986b83ca4d24 to your computer and use it in GitHub Desktop.
Save Kylmakalle/650f2245bbf131a2663e986b83ca4d24 to your computer and use it in GitHub Desktop.
Telegram is bugged as hell, really
import telebot
from telebot.types import InlineKeyboardButton, InlineKeyboardMarkup
bot = telebot.TeleBot('123456789:wedcvbhjmlkjhbnjkhfdjkhfd')
ANTISPAMBOT = bot.get_me()
KNOWN_USERS = []
@bot.message_handler(content_types=['new_chat_members'])
def new_chat_members_handler(msg):
for new_member in msg.new_chat_members:
if new_member.id != ANTISPAMBOT.id:
if new_member.id not in KNOWN_USERS:
markup = InlineKeyboardMarkup(row_width=2)
markup.row(InlineKeyboardButton('TAP ME', callback_data='id={}OK'.format(new_member.id))
bot.send_message(msg.chat.id, 'Tap button below', parse_mode='HTML', reply_markup=markup)
RSTRICT = bot.restrict_chat_member(msg.chat.id, new_member.id, can_send_messages=False,
can_send_media_messages=False, can_send_other_messages=False,
can_add_web_page_previews=False)
print('RESTRICTED', RSTRICT)
@bot.callback_query_handler(func=lambda call: True)
def callback_buttons(call):
if call.message and call.data:
join_answer = re.search('id=([0-9]*)OK', call.data)
if join_answer:
if join_answer.group(1) == str(call.from_user.id):
unrestrict = bot.restrict_chat_member(call.message.chat.id, call.from_user.id, can_send_messages=True,
can_send_media_messages=True, can_send_other_messages=True,
can_add_web_page_previews=True)
print('UNRESTRICTED', unrestrict)
KNOWN_USERS.append(call.from_user.id)
if join_answer.group(2) == 'OK':
bot.edit_message_text(
'Привет, <a href="tg://user?id={}">{}</a>! Добро пожаловать в <b>{}</b>'.format(
call.from_user.id,
call.from_user.first_name,
call.chat.title),
call.message.chat.id, call.message.message_id, parse_mode='HTML')
bot.answer_callback_query(call.id)
else:
bot.answer_callback_query(call.id, 'It\'s not your button!', show_alert=True)
bot.polling(none_stop=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment