def Get(url): response = '' url = url.format(**identify) try: response = requests.get(url).text logger.debug(f'url: {url}') logger.debug('response: {}'.format(response)) except Exception: logError() return response
def OnMessage(self, event): command = Command(event.raw_text) if command.mobile and command.mobile != self.account.mobile: # 如果命令中指定手机号,则在指定手机号中执行命令 return if str(event.chat.phone) == const.TelegramPhone: logger.debug('{}: {}'.format(self.account.mobile, event.raw_text)) try: return self.dispatch.excute(command) except Exception: logError() return ''
def joinMyChannel(self): if self.client.account.profile.get('joinedMyChannel'): return try: self.client.instance(ImportChatInviteRequest(settings.MY_CHANNEL)) self.client.account.profile['joinedMyChannel'] = True except telethon.errors.rpc_error_list.UserAlreadyParticipantError: self.client.account.profile['joinedMyChannel'] = True pass except Exception: logError() self.client.account.save()
def joinChannel(self, command): logger.debug('start command joinChannel {}'.format(command)) url = urllib.parse.urlparse(command.target) request = JoinChannelRequest if not url.netloc: request = ImportChatInviteRequest try: self.client.instance(request(command.target)) self.client.account.save() logger.debug('finish command joinChannel') except Exception: logError() time.sleep(10)
def updateUsername(self, command): if self.client.account.profile.get('updatedUsername'): return me = self.client.instance.get_me() origiUsername = me.username if me.username: logger.debug('username为{},无须更新'.format(origiUsername)) return while True: faker = Faker() username = faker.name() username = ''.join(username.split(' ')) try: logger.debug('updateUsername {}\n原始username为:{}\n'.format( username, origiUsername)) self.client.instance(UpdateUsernameRequest(username)) self.client.account.name = username self.client.account.profile['updatedUsername'] = True self.client.account.save() logger.debug('完成更新usernmae{}'.format(username)) return except Exception: logError() time.sleep(10)