async def run(self) -> None: resource_id = (uuid.uuid4().hex).upper() resource = 'V2:Fortnite:{0.client.platform.value}::{1}'.format( self, resource_id) self.xmpp_client = aioxmpp.PresenceManagedClient( aioxmpp.JID(self.client.user.id, self.client.service_host, resource), aioxmpp.make_security_layer(self.client.auth.access_token, no_verify=True), override_peer=[(self.client.service_domain, self.client.service_port, XMPPOverWebsocketConnector())], loop=self.client.loop) self.muc_service = self.xmpp_client.summon(aioxmpp.MUCClient) self.setup_callbacks() future = self.client.loop.create_future() self._task = asyncio.ensure_future(self._run(future), loop=self.client.loop) await future self._ping_task = asyncio.ensure_future(self.loop_ping(), loop=self.client.loop) asyncio.ensure_future(self.send_presence_on_start(), loop=self.client.loop) self.client.dispatch_event('xmpp_session_establish')
async def run(self): resource_id = (uuid.uuid4().hex).upper() self.xmpp_client = aioxmpp.PresenceManagedClient( aioxmpp.JID( self.client.user.id, self.client.service_host, 'V2:Fortnite:{0.client.platform.value}::{1}'.format(self, resource_id) ), aioxmpp.make_security_layer( self.client.auth.access_token, no_verify=True ), override_peer=[( self.client.service_domain, self.client.service_port, aioxmpp.connector.STARTTLSConnector() )], loop=self.client.loop ) self.muc_service = self.xmpp_client.summon(aioxmpp.MUCClient) self.setup_callbacks() future = self.client.loop.create_future() self._task = asyncio.ensure_future(self._run(future), loop=self.client.loop) await future self._ping_task = asyncio.ensure_future(self.loop_ping(), loop=self.client.loop)
async def setup(self): print("ReceiverAgent started") self.presence.on_subscribe = self.my_on_subscribe_callback self.presence.set_available(show=aioxmpp.PresenceShow.CHAT) b = self.RecvBehav() # template = Template() # template.set_metadata("performative", "inform") self.add_behaviour(b) # aiml loading self.kernel = aiml.Kernel() self.kernel.learn("startup.xml") self.kernel.respond("load aiml b") # muc behavior self.language_selectors = [ aioxmpp.structs.LanguageRange.fromstr('en'), aioxmpp.structs.LanguageRange.fromstr("*") ] self.mucservice = self.client.summon(aioxmpp.MUCClient) self.room, self.room_future = self.mucservice.join( aioxmpp.JID("samnites", "conference.jabber.hot-chilli.net", None), "cleopatra2") self.room.on_message.connect(self._on_message) '''
async def _process_item(self, state, item, fut): domain, last_seen, is_muc = item address = aioxmpp.JID(localpart=None, domain=domain, resource=None) if not is_muc: threshold = datetime.utcnow() - self.non_muc_rescan_delay if last_seen is not None and last_seen >= threshold: self.logger.debug( "%s is not a MUC service and was scanned since %s; skipping" " it in in this round", domain, threshold) return else: self.logger.debug( "%s is not a MUC service, but it was not successfully " "scanned since %s; including it in this round", domain, threshold, ) else: self.logger.debug("%s is a MUC service, forcing scan", domain) try: info = await self._disco_svc.query_info(address) except aioxmpp.errors.XMPPError as exc: self.logger.error("failed to disco#info %s: %s", address, exc) return try: version_info = await aioxmpp.version.query_version( self.client.stream, address, ) except aioxmpp.errors.XMPPError as exc: self.logger.debug( "failed to query software version of %s (%s), ignoring", address, exc) version_info = None self._update_domain( state, domain, info, version_info, ) try: if "http://jabber.org/protocol/muc" in info.features: # is a MUC domain await self._process_muc_domain(state, address) else: # is unknown domain, use disco#items to find more await self._process_other_domain(state, address) except aioxmpp.errors.XMPPError as exc: self.logger.error("received error response while scanning %s: %s", address, exc) except aioxmpp.errors.ErroneousStanza as exc: self.logger.error( "received invalid response while scanning %s: %s", address, exc)
def _load_accounts(self, cfg): result = [] for username, password in ast.literal_eval(cfg): result.append((aioxmpp.JID(localpart=username, domain=self._domain.domain, resource=None), aioxmpp.make_security_layer(password, **self.__tls_config))) return result
async def _process_item(self, state, item, fut): domain, last_seen, is_muc = item address = aioxmpp.JID(localpart=None, domain=domain, resource=None) if not is_muc: threshold = datetime.utcnow() - self.non_muc_rescan_delay if last_seen is not None and last_seen >= threshold: self.logger.debug( "%s is not a MUC service and was scanned since %s; skipping" " it in in this round", domain, threshold) return else: self.logger.debug( "%s is not a MUC service, but it was not successfully " "scanned since %s; including it in this round", domain, threshold, ) else: self.logger.debug("%s is a MUC service, forcing scan", domain) with time_optional_late(self._domain_scanned_metric) as scan_info_m: scan_info_m["labels"] = [self.DOMAIN_TYPE_FAILED] with time_optional_late( self._disco_info_duration_metric) as disco_info_m: disco_info_m["labels"] = ["timeout"] try: info = await self._disco_svc.query_info(address) disco_info_m["labels"] = ["success"] except aioxmpp.errors.XMPPError as exc: disco_info_m["labels"] = [exc.condition.value[1]] self.logger.error("failed to disco#info %s: %s", address, exc) return with time_optional_late( self._version_duration_metric) as version_info_m: version_info_m["labels"] = ["timeout"] try: version_info = await aioxmpp.version.query_version( self.client.stream, address, ) version_info_m["labels"] = ["success"] except aioxmpp.errors.XMPPError as exc: version_info_m["labels"] = [exc.condition.value[1]] self.logger.debug( "failed to query software version of %s (%s), ignoring", address, exc) version_info = None self._update_domain( state, domain, info, version_info, ) with time_optional_late( self._disco_items_duration_metric) as items_info_m: domain_type = self.DOMAIN_TYPE_FAILED items_info_m["labels"] = [None, "timeout"] try: if "http://jabber.org/protocol/muc" in info.features: # is a MUC domain domain_type = self.DOMAIN_TYPE_MUC await self._process_muc_domain(state, address) else: # is unknown domain, use disco#items to find more domain_type = self.DOMAIN_TYPE_OTHER await self._process_other_domain(state, address) items_info_m["labels"][1] = "success" except aioxmpp.errors.XMPPError as exc: self.logger.error( "received error response while scanning %s: %s", address, exc) items_info_m["labels"][1] = exc.condition.value[1] except aioxmpp.errors.ErroneousStanza as exc: self.logger.error( "received invalid response while scanning %s: %s", address, exc) items_info_m["labels"][1] = "invalid" finally: items_info_m["labels"][0] = domain_type scan_info_m["labels"][0] = domain_type