def connected(bot, update, chat, user_id, need_admin=True): user = update.effective_user if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id): conn_id = sql.get_connected_chat(user_id).chat_id getstatusadmin = bot.get_chat_member( conn_id, update.effective_message.from_user.id) isadmin = getstatusadmin.status in ('administrator', 'creator') ismember = getstatusadmin.status in ('member') isallow = sql.allow_connect_to_chat(conn_id) if (isadmin) or (isallow and ismember) or (user.id in SUDO_USERS): if need_admin is True: if getstatusadmin.status in ( 'administrator', 'creator') or user_id in SUDO_USERS: return conn_id else: send_message( update.effective_message, languages.tl( update.effective_message, "Anda harus menjadi admin dalam grup yang terhubung!" )) else: return conn_id else: send_message( update.effective_message, languages.tl( update.effective_message, "Grup mengubah koneksi hak atau Anda bukan admin lagi.\nSaya putuskan koneksi Anda." )) disconnect_chat(update, bot) else: return False
def connected(bot, update, chat, user_id, need_admin=True): chat = update.effective_chat # type: Optional[Chat] if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id): conn_id = sql.get_connected_chat(user_id).chat_id if (bot.get_chat_member( conn_id, user_id).status in ('administrator', 'creator') or (sql.allow_connect_to_chat(connect_chat) is True) and bot.get_chat_member( user_id, update.effective_message.from_user.id).status in ('member')) or (user_id in SUDO_USERS): if need_admin: if bot.get_chat_member( conn_id, update.effective_message.from_user.id).status in ( 'administrator', 'creator') or user_id in SUDO_USERS: return conn_id update.effective_message.reply_text( tld(chat.id, "connection_err_no_admin")) return else: return conn_id else: update.effective_message.reply_text( tld(chat.id, "connection_err_unknown")) disconnect_chat(bot, update) return else: return False
def connected(bot, update, chat, user_id, need_admin=True): if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id): conn_id = sql.get_connected_chat(user_id).chat_id if (bot.get_chat_member( conn_id, user_id).status in ('administrator', 'creator') or (sql.allow_connect_to_chat(connect_chat) == True) and bot.get_chat_member( user_id, update.effective_message.from_user.id).status in ('member')) or (user_id in SUDO_USERS): if need_admin: if bot.get_chat_member( conn_id, update.effective_message.from_user.id).status in ( 'administrator', 'creator') or user_id in SUDO_USERS: return conn_id else: update.effective_message.reply_text( "You need to be a admin in a connected group!") exit(1) else: return conn_id else: update.effective_message.reply_text( "Group changed rights connection or you are not admin anymore.\nI'll disconnect you." ) disconnect_chat(bot, update) exit(1) else: return False
def keyboard(bot, update): chat = update.effective_chat user = update.effective_user conn_id = con_sql.get_connected_chat(user.id) if conn_id and not conn_id is False: btn1 = "/disconnect - {}".format(tld(chat.id, "keyboard_disconnect")) btn2 = "" btn3 = "" else: if con_sql.get_history(user.id): history = con_sql.get_history(user.id) try: chat_name1 = dispatcher.bot.getChat(history.chat_id1).title except Exception: chat_name1 = "" try: chat_name2 = dispatcher.bot.getChat(history.chat_id2).title except Exception: chat_name2 = "" try: chat_name3 = dispatcher.bot.getChat(history.chat_id3).title except Exception: chat_name3 = "" if chat_name1: btn1 = "/connect {} - {}".format(history.chat_id1, chat_name1) else: btn1 = "/connect - {}".format(tld(chat.id, "keyboard_connect")) if chat_name2: btn2 = "/connect {} - {}".format(history.chat_id2, chat_name2) else: btn2 = "" if chat_name3: btn3 = "/connect {} - {}".format(history.chat_id3, chat_name3) else: btn3 = "" #TODO: Remove except garbage update.effective_message.reply_text( tld(chat.id, "keyboard_updated"), reply_markup=ReplyKeyboardMarkup([[ KeyboardButton("/help"), KeyboardButton("/notes - {}".format(tld(chat.id, "keyboard_notes"))) ], [KeyboardButton(btn1)], [KeyboardButton(btn2)], [KeyboardButton(btn3)]]))
def keyboard(bot, update): user = update.effective_user # type: Optional[User] conn_id = con_sql.get_connected_chat(user.id) if conn_id and not conn_id == False: btn1 = "/disconnect - Disconnect from chat" btn2 = "" btn3 = "" else: if con_sql.get_history(user.id): history = con_sql.get_history(user.id) try: chat_name1 = dispatcher.bot.getChat(history.chat_id1).title except: chat_name1 = "" try: chat_name2 = dispatcher.bot.getChat(history.chat_id2).title except: chat_name2 = "" try: chat_name3 = dispatcher.bot.getChat(history.chat_id3).title except: chat_name3 = "" if chat_name1: btn1 = "/connect {} - {}".format(history.chat_id1, chat_name1) else: btn1 = "/connect - Connect to the chat" if chat_name2: btn2 = "/connect {} - {}".format(history.chat_id2, chat_name2) else: btn2 = "" if chat_name3: btn3 = "/connect {} - {}".format(history.chat_id3, chat_name3) else: btn3 = "" # TODO: Remove except garbage update.effective_message.reply_text("Keyboard Updated", reply_markup=ReplyKeyboardMarkup([[ KeyboardButton("/help - Bot Help"), KeyboardButton("/notes - Notes")], [KeyboardButton(btn1)], [KeyboardButton(btn2)], [KeyboardButton(btn3)]]))