def start_register_2(update, context): try: if update.message.forward_from_chat.type != 'channel': raise ValidationError('Only Channels allowed') context.user_data['chnlid'] = update.message.forward_from_chat.id context.user_data['chnltitle'] = update.message.forward_from_chat.title if update.message.forward_from_chat.username is None: raise ValidationError( "We are accepting only public channels as of now") context.user_data[ 'chnlusnme'] = '@' + update.message.forward_from_chat.username '''banned = get_ban() if context.user_data['chnlid'] in banned[0] or context.user_data['chnlusnme'].lower() in banned[1]: update.message.reply_text('Oops! Your channel has been banned') return cancel(update, context)''' mem_count = context.bot.get_chat_members_count( context.user_data['chnlusnme']) min_subs_required = get_groupinfo_db(context.user_data['grpid']).get( 'minimum subs required', 0) if mem_count < min_subs_required and not ( update.effective_user.id in get_admins_list(context) or update.effective_user.id in MY_ID): raise ValidationError( f'Minimum Subs required for this promogroup -> {min_subs_required}' ) context.user_data['memcount'] = mem_count update.message.reply_text('Send the description,') return DESCR except ValidationError as v: update.message.reply_text(f'{v}', reply_markup=cancel_markup)
def get_unshared(update, context): if update.message.chat.type != 'supergroup': update.message.reply_text('This command only works in supergroup') elif update.effective_user.id not in get_admins_list(context): update.message.reply_text('Only admins can do that') elif update.message.chat_id not in get_grps_list(context): update.message.reply_text('This group is not registered with us') else: grpid = update.message.chat_id chnlid = get_groupinfo_db(grpid).get('channel id') unshared_list = check_unshared_db(chnlid=chnlid, grpid=grpid) if unshared_list: unshared_str = '#unshared List ::\n\n' for j in unshared_list: unshared_str += f"[{j.get('name')}](https://t.me/{j.get('name')[1:]}/)" if len(unshared_str) > 20: context.bot.send_message( text=unshared_str, chat_id=update.message.chat.id, reply_to_message_id=update.message.message_id, parse_mode='Markdown', disable_web_page_preview=True) return context.bot.send_message(text='OOPS! No one shared the list yet', chat_id=update.message.chat.id, reply_to_message_id=update.message.message_id, parse_mode='Markdown')
def group_commands(update, context): admininfo = get_admin_db(update.effective_user.id) grps = admininfo.get('groups') if not grps or not grps[0]: update.message.reply_text("You haven't added any groups yet") return ConversationHandler.END elif search('.*Edit', update.message.text): context.user_data['edit'] = True # kbgrpmenu = [[]] >>>> kbgrpmenu = [[]] # reserved for future releases >>>> '''else: context.user_data['edit'] = False kbgrpmenu = [[KeyboardButton('All Groups')]] context.user_data['channel'] = admininfo.get('channel id') context.user_data['channel_username'] = admininfo.get('channel username') context.user_data['premium_1'] = admininfo.get('premium_1', []) context.user_data['premium_2'] = admininfo.get('premium_2', []) context.user_data['premium_3'] = admininfo.get('premium_3', [])''' context.user_data['groups'] = [] context.user_data['adminid'] = update.effective_user.id context.user_data['group_dict'] = {} for grp in grps: if not context.user_data['edit']: continue context.user_data['groups'].append(grp) context.user_data['group_dict'].update({grp: get_groupinfo_db(grp)}) kbgrpmenu.append([KeyboardButton(str(grp)+' | '+str(context.user_data['group_dict'][grp].get('name')))]) # reserved for future releases >>>> '''if len(kbgrpmenu) < 2: update.message.reply_text('Lists have been scheduled/posted in all groups' '\nWait till it finishes') return cancel(update, context)''' kbgrpmenu.append([KeyboardButton('/cancel')]) kbgrpmenu_markup = ReplyKeyboardMarkup(kbgrpmenu, resize_keyboard = True, one_time_keyboard = True) context.bot.send_message(chat_id = update.message.chat_id, text = 'Select a Group', reply_markup = kbgrpmenu_markup) return SELECT_GROUP
def start_all_ck(update, context): if update.message.chat.type == 'supergroup': update.message.reply_text( f'{context.bot.link}?start={update.message.chat.id}') return -1 elif context.args and context.args[0]: try: context.user_data['grpid'] = int(context.args[0]) grpinfo = get_groupinfo_db(context.user_data['grpid']) context.user_data['grpname'] = grpinfo.get('name') context.user_data['promochnid'] = grpinfo.get('channel id') except: update.message.reply_text('Invalid Link') return cancel(update, context) my_chnls = get_chnl_db(chanid=context.user_data['promochnid'], adminid=update.message.chat.id) chnl_btn = [] for chnl in my_chnls: chnl_btn.append([ InlineKeyboardButton(f"{chnl['name']}", callback_data=f"c_{chnl['_id']}") ]) chnl_btn.append( [InlineKeyboardButton("Add New Channel", callback_data="new")]) update.message.reply_text("Select an option,", reply_markup=InlineKeyboardMarkup(chnl_btn)) return CHANNEL else: if update.effective_user.id in get_admins_list(context): update.effective_message.reply_text( f"Hey there, {update.effective_user.first_name}", reply_markup=kb_admins_markup) else: update.effective_message.reply_text( f"Hey there, {update.effective_user.first_name}", reply_markup=kbmenu_default_markup)
def valid_open_regstr(grps: list): for grp in grps: if get_groupinfo_db(grp)['status'] in (STATUS.LIST_PUBLISHED, STATUS.REGISTRATION_OPEN): return False return True
def valid_del_list(grps: list): for grp in grps: if get_groupinfo_db(grp)['status'] in (STATUS.LIST_DELETED, STATUS.NEW, STATUS.REGISTRATION_OPEN): return False return True
def valid_create_list(grps: list): for grp in grps: if get_groupinfo_db(grp)['status'] in (STATUS.NEW): return False return True
def create_list(update: Update, context): try: admin_info = get_admin_db(update.effective_user.id) for grp in admin_info['groups']: ''' grp -> Group ID grp_info -> Group Dict ''' grp_info = get_groupinfo_db(grp) if grp_info: header = grp_info['header'] footer = grp_info['footer'] chnls = reg_channels_db(adminid=update.effective_user.id, groupid=grp) chnl_list = [] for chnl in chnls: chnl_list.append(chnl) if not chnl_list: context.bot.send_message( text= f"No Channels registered for the group {grp_info['name']}", chat_id=admin_info['_id']) continue chnl_list.sort(key=lambda x: x.get('members count'), reverse=True) ################################# ''' List Creation Logic ''' ''' quotient = No of Lists ''' f = True num = MIN_CHNLS_PER_LIST // 2 quotient = 1 remain = 0 total = len(chnl_list) if total > MIN_CHNLS_PER_LIST: while f: quotient = total // num remain = total % num if quotient >= remain: f = False else: num += 1 else: num = total num2 = num + 1 n = 0 emoticon_1 = choice(list_emojis) for g in range(quotient): post = f'*' + e_m(str(header)) + '*\n' + e_m( 10 * '━━') + '\n\n' if not remain: num2 = num else: remain -= 1 to_send = {} for _ in range(num2): to_send.update({ chnl_list[n].get('_id'): chnl_list[n].get('name') }) post += f"{emoticon_1}[{chnl_list[n].get('name')[1:]}]({chnl_list[n].get('invitelink')})" \ f"\n\t\t\t\t\t\t*{chnl_list[n].get('description')}*\n\n" n += 1 if admin_info.get('premium_1', []): post += f"\n\t[{admin_info['premium_1']['text']}]({admin_info['premium_1']['url']})" if admin_info.get('premium_2', []): post += f"\t|\t[{admin_info['premium_2']['text']}]({admin_info['premium_2']['url']})" if admin_info.get('premium_3', []): post += f"\t|\t[{admin_info['premium_3']['text']}]({admin_info['premium_3']['url']})" grpname = context.bot.get_chat(chat_id=grp).title post += f"\n{e_m(10*'━━')}\n[{footer['text']}]({footer['url']})" kb = [[ InlineKeyboardButton(text=grpname, callback_data='prbt_1') ], [ InlineKeyboardButton(text='Created by this bot', url=context.bot.link) ]] list_link = context.bot.send_message( text=post, chat_id=admin_info['channel id'], parse_mode='Markdown', reply_markup=InlineKeyboardMarkup(kb), disable_web_page_preview=True) if str(type(list_link)).endswith("Promise'>"): list_link = list_link.result() context.user_data['list_link'] = list_link.link list_id = get_next_list_num_db()['Total Lists Created'] insert_list_db(list_id=list_id, grpname=grp_info['name'], text=post) to_chnl = f"List {g + 1}\n" \ f"\t\t⏩ `@PromoAssistant_bot {list_id}`\n\n\t" to_chnl += '\n\t'.join(e_m(v) for v in to_send.values()) context.bot.send_message(chat_id=admin_info['channel id'], text=to_chnl, parse_mode='Markdown') failed = 'Auto-Posting failed in these Channels::\nShare the list manually\n\n' for chnl in to_send.keys(): try: shared = context.bot.send_message( text=post, chat_id=chnl, disable_web_page_preview=True, parse_mode='Markdown') if str(type(shared)).endswith("Promise'>"): shared = shared.result() # Private chnls will have None as link context.bot.send_message( text=f"#shared|{to_send[chnl]}|{shared.link}", chat_id=grp, disable_notification=True, disable_web_page_preview=True) update_shared_db( chnlid=chnl, forwarded_from=admin_info['channel id'], time=shared.date, msgid=shared.message_id) sleep(0.1) # Cooldown, prevents flooding except: failed += f"{to_send[chnl]}\n" sleep(0.2) # Cooldown, prevents flooding if len(failed) > 60: context.bot.send_message(text=failed, chat_id=grp) context.bot.send_message(text=pub_pin_tx.replace( '||', context.user_data['list_link']), chat_id=grp, disable_web_page_preview=True) log_this( f" List created for the admin {admin_info['_id']}\n{admin_info['channel username']}" ) if not admin_info['groups']: context.bot.send_message( text="You don't have any groups registered", chat_id=update.effective_user.id) except Exception as e: context.bot.send_message( chat_id=update.effective_user.id, text=f"Error occurred during list creation, \n\n{e}", reply_markup=kbmenu_markup)