def set_source_groups(self, group_keys): """Set `source_groups` for this client Confirm the groups is exist. Args: group_keys: list Returns: int, number of groups """ self._source_groups = [] fn.print_title('\nsetting "%s" source groups:' % self._client_name) for group_key in group_keys: print(' "%s" ...' % group_key) try: group = self._client.get_entity(group_key) fn.print_success(' %s' % group.title) self._source_groups.append(group) except telethon.errors.rpcerrorlist.InviteHashInvalidError as e: fn.stdout_error(' [InviteHashInvalidError] ') fn.print_warning(e) except ValueError as e: fn.stdout_error(' [ValueError] ') fn.print_warning(e) return len(self._source_groups)
def set_destination_group(self, key): """Set `destination_group` for this client Confirm the group is exist, and joined, and have the right to add a member. Args: group_keys: list Returns: int, number of groups """ fn.print_title('\nsetting "%s" destination group:' % self._client_name) fn.stdout_text(' "%s" ...' % key) # error when session user is banned try: group = self._client.get_entity(key) print(group) # Join if not IN. if group.left: self._client(JoinChannelRequest(group)) fn.print_warning(' JOINED') else: fn.print_success(' IN') # Democracy if group.democracy: # All members can add members # fn.print_success(' %s' % group.title) self._destination_group = group return True else: # Only admins can add members if (group.admin_rights is not None and group.admin_rights.invite_users): #fn.print_success(' %s' % group.title) self._destination_group = group return True else: fn.stdout_error(' Have NO admin right to add a member.') fn.print_warning(' destination group invalid.') return False except ValueError as e: fn.print_error(' ERROR') fn.print_error(' [ValueError] %s' % e) fn.print_warning(' Please make sure "%s" is NOT banned' % self._client_name)
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