def process_last(self, user_jid, our_jid, sub, last): if last is not None: sub["last"] = last yield UserSubscriptions(user_jid).subscribe(sub["url"]) yield Subscription.create(sub) self._xmpp.send_presence(to=user_jid, from_=sub["jid"], type_="subscribe") else: yield wait_for_host(sub["host"], level=2) try: page = yield get_page(sub["url"]) except Exception: self._xmpp.send_message( to=user_jid, from_=get_full_jid(our_jid), body=u"Url check failed, subscription aborted. " "Seems like not existing url.") else: parsed = yield self._worker.parse(sub, page) if "last" in parsed and parsed["last"] is not None: self.process_last(user_jid, our_jid, sub, parsed["last"]) else: self._xmpp.send_message( to=user_jid, from_=get_full_jid(our_jid), body=u"Page parsing failed, subscription aborted. " "Seems like not existing url.")
def process_last(self, user_jid, our_jid, sub, last): if last is not None: sub["last"] = last yield UserSubscriptions(user_jid).subscribe(sub["url"]) yield Subscription.create(sub) self._xmpp.send_presence( to=user_jid, from_=sub["jid"], type_="subscribe") else: yield wait_for_host(sub["host"], level=2) try: page = yield get_page(sub["url"]) except Exception: self._xmpp.send_message( to=user_jid, from_=get_full_jid(our_jid), body=u"Url check failed, subscription aborted. " "Seems like not existing url.") else: parsed = yield self._worker.parse(sub, page) if "last" in parsed and parsed["last"] is not None: self.process_last(user_jid, our_jid, sub, parsed["last"]) else: self._xmpp.send_message( to=user_jid, from_=get_full_jid(our_jid), body=u"Page parsing failed, subscription aborted. " "Seems like not existing url.")
def _on_message(self, msg): user_jid = get_bare_jid(msg["from"]) if config.only_admin and user_jid != config.admin_jid: return our_jid = get_bare_jid(msg["to"]) our_full_jid = get_full_jid(our_jid) if (msg.body and len(msg.body.children) > 0 and type(msg.body.children[0]) is unicode): text = msg.body.children[0] else: return reply_msg = self.message(to=msg["from"], from_=our_full_jid) if self.is_filtered_jid(user_jid): self._send_reply((u"Sorry, your server not in whitelist. " "Please use more popular jabber server or " "contact administrator.\nWe can't allow " "all servers because of spam. " "Hope for your understanding."), reply_msg) elif not self._start_request(user_jid): self._send_reply(u"Too many requests. Please, slow down.", reply_msg) else: d = command_handler(user_jid, our_jid, text) d.addCallbacks(self._send_reply, self._send_error_report, callbackArgs=[reply_msg], errbackArgs=[reply_msg, msg]) d.addBoth(self._end_request, user_jid)
def _on_presence(self, prs): # TODO: Save subscriptions to the database and # send appropriate presences to users when go # online/offline (service restart). user_jid = get_bare_jid(prs["from"]) if config.only_admin and user_jid != config.admin_jid: return if self.is_filtered_jid(user_jid): return our_jid = get_bare_jid(prs["to"]) our_full_jid = get_full_jid(our_jid) type_ = prs.getAttribute("type") send_status = False if type_ == "subscribe": self.send_presence(to=user_jid, from_=our_jid, type_="subscribed") if our_jid == config.main_jid: self.send_presence(to=user_jid, from_=our_jid, type_="subscribe") is_exists = yield UserSettings(user_jid).is_exists() if not is_exists: self.send_message( to=prs["from"], from_=our_full_jid, body=(u"Oh hai. Type 'help' (without quotes) " "for help and basic info.")) send_status = True if type_ == "probe" or send_status: self.send_presence(to=prs["from"], from_=our_full_jid)
def _on_message(self, msg): user_jid = get_bare_jid(msg["from"]) if config.only_admin and user_jid != config.admin_jid: return our_jid = get_bare_jid(msg["to"]) our_full_jid = get_full_jid(our_jid) if (msg.body and len(msg.body.children) > 0 and type(msg.body.children[0]) is unicode): text = msg.body.children[0] else: return reply_msg = self.message(to=msg["from"], from_=our_full_jid) if self.is_filtered_jid(user_jid): self._send_reply( (u"Sorry, your server not in whitelist. " "Please use more popular jabber server or " "contact administrator.\nWe can't allow " "all servers because of spam. " "Hope for your understanding."), reply_msg) elif not self._start_request(user_jid): self._send_reply( u"Too many requests. Please, slow down.", reply_msg) else: d = command_handler(user_jid, our_jid, text) d.addCallbacks(self._send_reply, self._send_error_report, callbackArgs=[reply_msg], errbackArgs=[reply_msg, msg]) d.addBoth(self._end_request, user_jid)
def _on_presence(self, prs): # TODO: Save subscriptions to the database and # send appropriate presences to users when go # online/offline (service restart). user_jid = get_bare_jid(prs["from"]) if config.only_admin and user_jid != config.admin_jid: return if self.is_filtered_jid(user_jid): return our_jid = get_bare_jid(prs["to"]) our_full_jid = get_full_jid(our_jid) type_ = prs.getAttribute("type") send_status = False if type_ == "subscribe": self.send_presence( to=user_jid, from_=our_jid, type_="subscribed") if our_jid == config.main_jid: self.send_presence( to=user_jid, from_=our_jid, type_="subscribe") is_exists = yield UserSettings(user_jid).is_exists() if not is_exists: self.send_message( to=prs["from"], from_=our_full_jid, body=(u"Oh hai. Type 'help' (without quotes) " "for help and basic info.")) send_status = True if type_ == "probe" or send_status: self.send_presence(to=prs["from"], from_=our_full_jid)
def dead_url(self, sub): self.debug("URL DEAD: %s" % sub["url"]) from_ = utils.get_full_jid(sub["jid"]) users = yield UserSubscriptions.find(sub["url"]) yield UserSubscriptions.unsubscribe_all(sub["url"]) yield Subscription(sub["url"]).remove() for user in users: self._xmpp.send_message( to=user["jid"], from_=from_, body=u"Url dead.") self._xmpp.send_presence( to=user["jid"], from_=sub["jid"], type_="unsubscribe") self._xmpp.send_presence( to=user["jid"], from_=sub["jid"], type_="unsubscribed")
def dead_url(self, sub): self.debug("URL DEAD: %s" % sub["url"]) from_ = utils.get_full_jid(sub["jid"]) users = yield UserSubscriptions.find(sub["url"]) yield UserSubscriptions.unsubscribe_all(sub["url"]) yield Subscription(sub["url"]).remove() for user in users: self._xmpp.send_message(to=user["jid"], from_=from_, body=u"Url dead.") self._xmpp.send_presence(to=user["jid"], from_=sub["jid"], type_="unsubscribe") self._xmpp.send_presence(to=user["jid"], from_=sub["jid"], type_="unsubscribed")
def process_parsed(self, sub, parsed, last_modified): if "_error" in parsed: return if "updates" in parsed: # Send updates to users from_ = utils.get_full_jid(sub["jid"]) users = yield UserSubscriptions.find(sub["url"]) for user in users: for text, xhtml in parsed["updates"]: self._xmpp.send_message( to=user["jid"], from_=from_, body=text, body_xhtml=xhtml) # Update subscription info subscription = Subscription(sub["url"]) if "last" in parsed: yield subscription.set_last(parsed["last"]) if last_modified: yield subscription.set_last_modified(last_modified)
def process_parsed(self, sub, parsed, last_modified): if "_error" in parsed: return if "updates" in parsed: # Send updates to users from_ = utils.get_full_jid(sub["jid"]) users = yield UserSubscriptions.find(sub["url"]) for user in users: for text, xhtml in parsed["updates"]: self._xmpp.send_message(to=user["jid"], from_=from_, body=text, body_xhtml=xhtml) # Update subscription info subscription = Subscription(sub["url"]) if "last" in parsed: yield subscription.set_last(parsed["last"]) if last_modified: yield subscription.set_last_modified(last_modified)