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 _do_one_invite(self, user): fn.stdout_text(' INVITE user.#%d > %s...' % (user.id, self._get_user_console_name(user))) # Invite try: self._client( InviteToChannelRequest(self._destination_group, [user])) # save to database self._db.save_invite(user) # shows done fn.stdout_success(' DONE') # 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) except ValueError as e: fn.print_error('\n [ValueError] > ') fn.print_text(e) # 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) except telethon.errors.rpcerrorlist.UserPrivacyRestrictedError: fn.stdout_error(' error.#0: UserPrivacyRestrictedError') self._db.save_user_privacy_restricted(user) # 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) except telethon.errors.rpcerrorlist.ChatAdminRequiredError: fn.stdout_error(' error.#1: ChatAdminRequiredError') # 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) except telethon.errors.rpcerrorlist.ChatIdInvalidError: fn.stdout_error(' error.#2: ChatIdInvalidError') # 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) except telethon.errors.rpcerrorlist.InputUserDeactivatedError: fn.stdout_error(' error.#3: InputUserDeactivatedError') # 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) except telethon.errors.rpcerrorlist.PeerIdInvalidError: fn.stdout_error(' error.#4: PeerIdInvalidError') # 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) except telethon.errors.rpcerrorlist.UserAlreadyParticipantError: fn.stdout_error(' error.#5: UserAlreadyParticipantError') # 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) except telethon.errors.rpcerrorlist.UserIdInvalidError: fn.stdout_error(' error.#6: UserIdInvalidError') # 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) except telethon.errors.rpcerrorlist.UserNotMutualContactError: fn.stdout_error(' error.#7: UserNotMutualContactError') self._db.save_user_not_mutual(user, self._area_code) # 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) except telethon.errors.rpcerrorlist.UsersTooMuchError: fn.stdout_error(' error.#8: UsersTooMuchError') # 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) except telethon.errors.rpcerrorlist.PeerFloodError as e: fn.stdout_error(' error.#9: PeerFloodError') fn.print_warning(' %s' % e) raise TeleErrors.PeerFloodError