def _load_and_save_participants_from_destination_group(self): fn.print_title('\nLOAD & SAVE PARTICIPANTS from DESTINATION_GROUP.') fn.stdout_text(' "%s" ...' % self._destination_group.username) participants = self._client.get_participants(self._destination_group, aggressive=True) fn.print_success(' %d members.' % len(participants)) i = 0 for u in participants: if u.bot is False: self._db.save_invite(u) i += 1 fn.stdout_warning('\r %d saved.' % i) fn.stdout_text(' not include any bot.') sys.stdout.flush() print()
def start(self): if len(self._source_groups) and self._destination_group: fn.print_text('\n------ ------ ------ ------') fn.print_warning('CLIENT "%s":' % self._client_name) fn.print_title( 'START INVITING, from %d source_group(s) to 1 destination_group' % len(self._source_groups)) fn.print_text('------ ------ ------ ------\n') self._load_and_save_participants_from_destination_group() # Start working... for source_group in self._source_groups: fn.print_title('\nIMPORTING PARTICIPANTS from SOURCE_GROUP.') fn.print_text(' #%d / %s' % (source_group.id, source_group.username)) fn.stdout_warning(' %s ...' % source_group.title) participants = self._client.get_participants(source_group, aggressive=True) fn.print_success(' %d members.' % len(participants)) for user in participants: if user.bot is False: if len( self._get_user_display_name(user) ) > conf.filter_user_display_name_too_much_words_limit: # avoid spam, who has a very long name pass elif type( user.status) in conf.filter_user_status_types: # Not UserStatusOffline self._pend_user(user) elif (isinstance(user.status, UserStatusOffline) and self._is_user_status_offline_passed( user.status.was_online)): # UserStatusOffline self._pend_user(user) if len(self._pending_users) > random.randint( conf.rd_pending_users_amount_min, conf.rd_pending_users_amount_max): self._do_batch_invite() return
def _do_batch_invite(self): fn.print_warning('\n INVITE %d users:' % len(self._pending_users)) # call the roll for user in self._pending_users: fn.print_text(' #.%d > %s' % (user.id, self._get_user_console_name(user))) # batch invite fn.stdout_warning(' BATCH INVITE...') updates = self._client( InviteToChannelRequest(self._destination_group, self._pending_users)) if len(updates.users): fn.print_success( ' %d/%d DONE' % (len(updates.users) - 1, len(self._pending_users))) # save invite to database for user in updates.users: if user.id != self._me.id: fn.print_success( ' #.%d > %s' % (user.id, self._get_user_console_name(user))) self._db.save_invite(user) # clear pool self._pending_users = [] # CPU sleep sleeping_secs = random.randint(conf.rd_sleep_min, conf.rd_sleep_max) fn.print_info(' ... waiting %d secs ...' % sleeping_secs) time.sleep(sleeping_secs) else: print() for user in self._pending_users: self._do_one_invite(user) pass