def broadcast(bot: Bot, update: Update): to_send = update.effective_message.text.split(None, 1) if len(to_send) >= 2: chats = sql.get_all_chats() or [] users = get_all_users() failed = 0 failed_user = 0 for chat in chats: try: bot.sendMessage(int(chat.chat_id), to_send[1]) sleep(0.1) except TelegramError: failed += 1 LOGGER.warning("%S, grup adına yayın gönderilemedi %s", str(chat.chat_id), str(chat.chat_name)) for user in users: try: bot.sendMessage(int(user.user_id), to_send[1]) sleep(0.1) except TelegramError: failed_user += 1 LOGGER.warning("Adresine yayın gönderilemedi %s", str(user.user_id)) update.effective_message.reply_text( f"Yayın tamamlandı. {failed} gruplar büyük olasılıkla tekmelendikleri için mesajı alamadılar. {failed_user} büyük olasılıkla engellendiği için ileti alınamadı" )
def broadcast(bot: Bot, update: Update): to_send = update.effective_message.text.split(None, 1) if len(to_send) >= 2: chats = sql.get_all_chats() or [] users = get_all_users() failed = 0 failed_user = 0 for chat in chats: try: bot.sendMessage(int(chat.chat_id), to_send[1]) sleep(0.1) except TelegramError: failed += 1 LOGGER.warning("Couldn't send broadcast to %s, group name %s", str(chat.chat_id), str(chat.chat_name)) for user in users: try: bot.sendMessage(int(user.user_id), to_send[1]) sleep(0.1) except TelegramError: failed_user += 1 LOGGER.warning("Couldn't send broadcast to %s", str(user.user_id)) update.effective_message.reply_text( f"Broadcast complete. {failed} groups failed to receive the message, probably due to being kicked. {failed_user} failed to receive message, probably due to being blocked" )
def broadcast(update: Update, context: CallbackContext): to_send = update.effective_message.text.split(None, 1) if len(to_send) >= 2: err = [] errors = 'List of errors\n0. Error Name' P = 1 update.effective_message.reply_text( "Broadcast is in Progress my ser....") to_group = False to_user = False if to_send[0] == '/broadcastgroups': to_group = True if to_send[0] == '/broadcastusers': to_user = True else: to_group = to_user = True chats = sql.get_all_chats() or [] users = get_all_users() failed = 0 failed_user = 0 if to_group: for chat in chats: try: context.bot.sendMessage(int(chat.chat_id), to_send[1], parse_mode="MARKDOWN", disable_web_page_preview=True) sleep(0.1) except Exception as e: if e not in err: err.append(e) failed += 1 if to_user: for user in users: try: context.bot.sendMessage(int(user.user_id), to_send[1], parse_mode="MARKDOWN", disable_web_page_preview=True) sleep(0.1) except Exception as e: if e not in err: err.append(e) failed_user += 1 for el in err: errors += "{}. {}\n".format(P, el) P += 1 update.effective_message.reply_text( f"Broadcast complete.\nGroups failed: {failed}.\nUsers failed: {failed_user}." ) with BytesIO(str.encode(errors)) as output: output.name = "errors.txt" update.effective_message.reply_document( document=output, filename="errors.txt", caption= "Here is the list of reasons lead to failure of broadcast.")
def userss(update: Update, context: CallbackContext): users = get_all_users() userfile = "" P = 1 for user in users: try: userfile += "{}\n".format(int(user.user_id)) P += 1 except: pass with BytesIO(str.encode(userfile)) as output: output.name = "users_list.txt" update.effective_message.reply_document( document=output, filename="users_list.txt", caption="Here is the list of All {} users in my database.".format( P))
def broadcast(update: Update, context: CallbackContext): to_send = update.effective_message.text.split(None, 1) if len(to_send) >= 2: to_group = False to_user = False if to_send[0] == "/broadcastgroups": to_group = True if to_send[0] == "/broadcastusers": to_user = True else: to_group = to_user = True chats = sql.get_all_chats() or [] users = get_all_users() failed = 0 failed_user = 0 if to_group: for chat in chats: try: context.bot.sendMessage( int(chat.chat_id), to_send[1], parse_mode="MARKDOWN", disable_web_page_preview=True, ) sleep(0.1) except TelegramError: failed += 1 if to_user: for user in users: try: context.bot.sendMessage( int(user.user_id), to_send[1], parse_mode="MARKDOWN", disable_web_page_preview=True, ) sleep(0.1) except TelegramError: failed_user += 1 update.effective_message.reply_text( f"Broadcast complete.\nGroups failed: {failed}.\nUsers failed: {failed_user}.", )
def broadcast(update: Update, context: CallbackContext): to_send = update.effective_message.text.split(None, 1) if len(to_send) >= 2: to_group = False to_user = False if to_send[0] == '/broadcastgroups': to_group = True if to_send[0] == '/broadcastusers': to_user = True else: to_group = to_user = True chats = sql.get_all_chats() or [] users = get_all_users() failed = 0 failed_user = 0 if to_group: for chat in chats: try: context.bot.sendMessage( int(chat.chat_id), to_send[1], parse_mode="MARKDOWN", disable_web_page_preview=True) sleep(0.1) except TelegramError: failed += 1 if to_user: for user in users: try: context.bot.sendMessage( int(user.user_id), to_send[1], parse_mode="MARKDOWN", disable_web_page_preview=True) sleep(0.1) except TelegramError: failed_user += 1 update.effective_message.reply_text( f"Yayım tamamlndı.\nUğursuz olan qruplar: {failed}.\nUğursuz olan istifadəçilər: {failed_user}." )
def broadcast(update: Update, context: CallbackContext): msg = update.effective_message option = msg.text.split(None, 1)[0] to_group = False to_user = False if option == "/broadcastgroups": to_group = True elif option == "/broadcastusers": to_user = True else: to_group = to_user = True failed_group = 0 failed_user = 0 successful_group = 0 successful_user = 0 if to_group: for group in sql.get_all_chats(): try: msg.reply_to_message.copy(int(group.chat_id)) successful_group += 1 sleep(0.1) except TelegramError: failed_group += 1 if to_user: for user in sql.get_all_users(): try: msg.reply_to_message.copy(int(user.user_id)) successful_user += 1 sleep(0.1) except TelegramError: failed_user += 1 msg.reply_text( text=("Broadcast complete.\n" f"Groups success/fail: {successful_group}/{failed_group}.\n" f"Users success/failed: {successful_user}/{failed_user}."))
def broadcast(update: Update, context: CallbackContext): to_send = update.effective_message.text.split(None, 1) if len(to_send) >= 2: to_group = to_user = False if to_send[0] == '/broadcastgroup': to_group = True if to_send[0] == '/broadcastuser': to_user = True else: to_group = to_user = True chats = sql.get_all_chats() or [] users = get_all_users() failed = 0 failed_user = 0 if to_group: for chat in chats: try: context.bot.sendMessage(int(chat.chat_id), to_send[1]) sleep(0.1) except TelegramError: failed += 1 LOGGER.warning( "Couldn't send broadcast to %s, group name %s", str(chat.chat_id), str(chat.chat_name)) if to_user: for user in users: try: context.bot.sendMessage(int(user.user_id), to_send[1]) sleep(0.1) except TelegramError: failed_user += 1 LOGGER.warning("Couldn't send broadcast to %s", str(user.user_id)) update.effective_message.reply_text( f"Broadcast complete. {failed} groups failed to receive the message, probably due to being kicked. {failed_user} failed to receive message, probably due to being blocked" )