Alias client.plugin["xep_0045"] only once
This commit is contained in:
parent
96c975233c
commit
3bb0824e75
23
hptoad.py
23
hptoad.py
|
@ -30,6 +30,7 @@ class Zhobe:
|
|||
opts["password"])
|
||||
self.client.register_plugin("xep_0199") # XMPP Ping.
|
||||
self.client.register_plugin("xep_0045") # XMPP MUC.
|
||||
self.muc_obj = self.client.plugin["xep_0045"]
|
||||
|
||||
self.jid = opts["jid"]
|
||||
self.connect = opts["connect"]
|
||||
|
@ -45,12 +46,10 @@ class Zhobe:
|
|||
self.on_muc_presence)
|
||||
|
||||
def join_muc(self):
|
||||
muc_plugin = self.client.plugin["xep_0045"]
|
||||
|
||||
if self.muc in muc_plugin.getJoinedRooms():
|
||||
muc_plugin.leaveMUC(self.muc, self.bot_nick,
|
||||
if self.muc in self.muc_obj.getJoinedRooms():
|
||||
self.muc_obj.leaveMUC(self.muc, self.bot_nick,
|
||||
msg="Replaced by new connection")
|
||||
muc_plugin.joinMUC(self.muc, self.bot_nick, wait=True)
|
||||
self.muc_obj.joinMUC(self.muc, self.bot_nick, wait=True)
|
||||
|
||||
@classmethod
|
||||
def log_exception(cls, ex):
|
||||
|
@ -63,11 +62,10 @@ class Zhobe:
|
|||
event["type"], event["body"]))
|
||||
|
||||
def is_muc_admin(self, muc, nick):
|
||||
muc_plugin = self.client.plugin["xep_0045"]
|
||||
if nick not in muc_plugin.rooms[self.muc]:
|
||||
if nick not in self.muc_obj.rooms[self.muc]:
|
||||
return False
|
||||
|
||||
affiliation = muc_plugin.getJidProperty(muc, nick, "affiliation")
|
||||
affiliation = self.muc_obj.getJidProperty(muc, nick, "affiliation")
|
||||
return True if affiliation in ("admin", "owner") else False
|
||||
|
||||
_trim_regexp = re.compile("(`|\\$|\\.\\.)")
|
||||
|
@ -136,8 +134,6 @@ class Zhobe:
|
|||
return reply, err
|
||||
|
||||
def handle_cmd(self, body, nick, from_id, is_admin=False):
|
||||
muc_plugin = self.client.plugin["xep_0045"]
|
||||
|
||||
reply = ""
|
||||
err = None
|
||||
|
||||
|
@ -152,8 +148,8 @@ class Zhobe:
|
|||
|
||||
if is_admin and victim != self.bot_nick:
|
||||
if is_bot_admin and not is_victim_admin and \
|
||||
victim in muc_plugin.rooms[self.muc]:
|
||||
muc_plugin.setRole(self.muc, victim, "none")
|
||||
victim in self.muc_obj.rooms[self.muc]:
|
||||
self.muc_obj.setRole(self.muc, victim, "none")
|
||||
else:
|
||||
reply = "%s: Can't megakick %s." % (nick, victim)
|
||||
else:
|
||||
|
@ -229,7 +225,6 @@ class Zhobe:
|
|||
self.log_exception(e)
|
||||
|
||||
def on_muc_presence(self, event):
|
||||
muc_plugin = self.client.plugin["xep_0045"]
|
||||
try:
|
||||
typ = event["muc"]["type"]
|
||||
from_id = event["from"]
|
||||
|
@ -238,7 +233,7 @@ class Zhobe:
|
|||
if not typ:
|
||||
typ = event["type"]
|
||||
if not nick:
|
||||
nick = muc_plugin.getNick(self.muc, from_id)
|
||||
nick = self.muc_obj.getNick(self.muc, from_id)
|
||||
|
||||
if typ == "error":
|
||||
if event["error"]["code"] == "409":
|
||||
|
|
Loading…
Reference in New Issue