def change_status(self, mode, args, default_priority=None): if self.away_saved_presence: self.away_saved_presence = None self.cjc.remove_event_handler("keypressed", self.ev_keypressed) if not self.cjc.stream: self.error("Connect first!") return to = None priority = default_priority keep = self.settings.get("keep_description") while 1: opt = args.get() if opt == "-keep": keep = True args.shift() continue elif opt == "-clear": keep = False args.shift() continue elif opt == "-to": args.shift() to = args.shift() if not to: self.error("'/%s -to' without any argument", mode) return try: to = pyxmpp.JID(to) except ValueError: return continue break reason = args.all() current = self.cjc.get_user_info(self.cjc.jid, "presence") if keep and not reason: reason = current.get_status() if mode == "offline": p = pyxmpp.Presence(status=reason, to_jid=to, stanza_type="unavailable") else: if priority is None: priority = self.settings.get("priority", 1) if mode == "online": show = None elif mode == "chatready": show = "chat" else: show = mode p = pyxmpp.Presence(show=show, status=reason, to_jid=to, priority=priority) self.set_presence(p)
def subscribe_back_decision(self, accept, stanza, buf): if accept: p = pyxmpp.Presence(stanza_type="subscribe", to_jid=stanza.get_from()) self.cjc.stream.send(p) buf.close() stanza.free()
def session_started(self, stream): self.cjc.stream.set_presence_handler("error", self.presence_error) self.cjc.stream.set_presence_handler(None, self.presence_available) self.cjc.stream.set_presence_handler("unavailable", self.presence_unavailable) self.cjc.stream.set_presence_handler("subscribe", self.presence_subscribe) self.cjc.stream.set_presence_handler("unsubscribe", self.presence_subscription_change) self.cjc.stream.set_presence_handler("subscribed", self.presence_subscription_change) self.cjc.stream.set_presence_handler("unsubscribed", self.presence_subscription_change) self.set_presence(pyxmpp.Presence(priority=self.settings["priority"]))
def cmd_cancel(self, args): user = args.shift() if not user: self.error("/cancel without an argument") return args.finish() user = self.cjc.get_user(user) if user is None: return if user.bare() == self.cjc.stream.me.bare(): self.error("Self presence subscription is automatic." " Cannot cancel own presence subscription.") return p = pyxmpp.Presence(stanza_type="unsubscribed", to_jid=user) self.cjc.stream.send(p)
def ev_idle(self, event, arg): if not self.cjc.stream: return auto_away = self.settings.get("auto_away") auto_xa = self.settings.get("auto_xa") if auto_away and auto_xa: minidle = min(auto_away, auto_xa) elif auto_away: minidle = auto_away elif auto_xa: minidle = auto_xa else: return idle = int(arg / 60) if idle < minidle: return p = self.cjc.get_user_info(self.cjc.jid, "presence") if (not p or p.get_type() == "unavailable" or (p.get_show() in self.settings["no_auto_away_when"] and not self.away_saved_presence)): return if not self.away_saved_presence: self.away_saved_presence = p.copy() self.away_saved_presence.set_to(None) insert_time = False if auto_xa and idle >= auto_xa: if p.get_show() == "xa": return show = "xa" prio = self.settings.get( "xa_priority", self.settings.get("away_priority", self.settings.get("priority", 0))) status = self.settings.get("auto_xa_msg", "") if status: insert_time = True elif self.settings.get("keep_description"): status = p.get_status() elif auto_away and idle >= auto_away: if p.get_show() == "away": return show = "away" prio = self.settings.get("away_priority", self.settings.get("priority", 0)) status = self.settings.get("auto_away_msg", "") if status: insert_time = True elif self.settings.get("keep_description"): status = p.get_status() else: return self.cjc.add_event_handler("keypressed", self.ev_keypressed) if insert_time and "%i" in status: p = pyxmpp.Presence(priority=prio, show=show, status=status % (idle, )) else: p = pyxmpp.Presence(priority=prio, show=show, status=status) self.set_presence(p)
def ev_disconnect_request(self, event, arg): p = pyxmpp.Presence(stanza_type="unavailable", status=arg) self.set_presence(p)
if item.jid in self.cjc.roster: local_item = self.cjc.roster.get_item_by_jid(item.jid) else: self.info(u"Adding entry: %s (%s)", unicode(item.jid), unicode(item.name)) local_item = self.cjc.roster.add_item(item.jid, name=item.name, groups=item.groups) iq = local_item.make_roster_push() self.cjc.stream.send(iq) if item.subscription in ( 'both', 'to') and local_item.subscription in ('none', 'from'): self.info(u"Sending supscription request to: %s", unicode(local_item.jid)) p = pyxmpp.Presence(stanza_type='subscribe', to_jid=local_item.jid) self.cjc.stream.send(p) ui.CommandTable("roster_ei", 50, ( ui.Command("export_roster", Plugin.cmd_export_roster, "/export_roster filename", "Export roster as an XML file.", ("filename", )), ui.Command("import_roster", Plugin.cmd_import_roster, "/import_roster filename", "Import roster as an XML file.", ("filename", )), )).install() # vi: sts=4 et sw=4