Typing \leave in a MUC will leave the group chat
This commit is contained in:
parent
8e08efabc9
commit
bd74021ca6
5
bot.py
5
bot.py
|
@ -179,7 +179,10 @@ class Bot():
|
||||||
\\getgroups get current groups from WA
|
\\getgroups get current groups from WA
|
||||||
|
|
||||||
following user commands are available:
|
following user commands are available:
|
||||||
\\lastseen request last online timestamp from buddy""")
|
\\lastseen request last online timestamp from buddy
|
||||||
|
|
||||||
|
following group commands are available
|
||||||
|
\\leave permanently leave group chat""")
|
||||||
|
|
||||||
def _fortune(self, database = '', prefix=''):
|
def _fortune(self, database = '', prefix=''):
|
||||||
if os.path.exists("/usr/share/fortune/%s" % database):
|
if os.path.exists("/usr/share/fortune/%s" % database):
|
||||||
|
|
46
session.py
46
session.py
|
@ -564,15 +564,19 @@ class Session(YowsupApp):
|
||||||
self.msgIDs[waId] = MsgIDs( ID, waId)
|
self.msgIDs[waId] = MsgIDs( ID, waId)
|
||||||
else:
|
else:
|
||||||
room = sender
|
room = sender
|
||||||
try:
|
if message[0] == '\\' and message[:1] != '\\\\':
|
||||||
group = self.groups[self._lengthenGroupId(room)]
|
self.logger.debug("Executing command %s in %s", message, room)
|
||||||
self.logger.info("Group Message from %s to %s Groups: %s",
|
self.executeCommand(message, room)
|
||||||
group.nick , group , self.groups)
|
else:
|
||||||
self.backend.handleMessage(
|
try:
|
||||||
self.user, room, message.decode('utf-8'), group.nick
|
group = self.groups[self._lengthenGroupId(room)]
|
||||||
)
|
self.logger.debug("Group Message from %s to %s Groups: %s",
|
||||||
except KeyError:
|
group.nick , group , self.groups)
|
||||||
self.logger.error('Group not found: %s', room)
|
self.backend.handleMessage(
|
||||||
|
self.user, room, message.decode('utf-8'), group.nick
|
||||||
|
)
|
||||||
|
except KeyError:
|
||||||
|
self.logger.error('Group not found: %s', room)
|
||||||
|
|
||||||
if (".jpg" in message.lower()) or (".webp" in message.lower()):
|
if (".jpg" in message.lower()) or (".webp" in message.lower()):
|
||||||
if (".jpg" in message.lower()):
|
if (".jpg" in message.lower()):
|
||||||
|
@ -630,6 +634,30 @@ class Session(YowsupApp):
|
||||||
self.logger.info("WA Message send to %s with ID %s", buddy, waId)
|
self.logger.info("WA Message send to %s with ID %s", buddy, waId)
|
||||||
#self.sendTextMessage(sender + '@s.whatsapp.net', message)
|
#self.sendTextMessage(sender + '@s.whatsapp.net', message)
|
||||||
|
|
||||||
|
def executeCommand(self, command, room):
|
||||||
|
if command == '\\leave':
|
||||||
|
self.logger.debug("Leaving room %s", room)
|
||||||
|
# Leave group on whatsapp side
|
||||||
|
self.leaveGroup(room)
|
||||||
|
# Delete Room on spectrum side
|
||||||
|
group = self.groups[room]
|
||||||
|
for jid in group.participants:
|
||||||
|
buddy = jid.split("@")[0]
|
||||||
|
self.logger.info("Added %s to room %s", buddy, room)
|
||||||
|
try:
|
||||||
|
nick = self.buddies[buddy].nick
|
||||||
|
except KeyError:
|
||||||
|
nick = buddy
|
||||||
|
if nick == "":
|
||||||
|
nick = buddy
|
||||||
|
if buddy == self.legacyName:
|
||||||
|
nick = group.nick
|
||||||
|
flags = protocol_pb2.PARTICIPANT_FLAG_ROOM_NOT_FOUND
|
||||||
|
self.backend.handleParticipantChanged(
|
||||||
|
self.user, nick, self._shortenGroupId(room), flags,
|
||||||
|
protocol_pb2.STATUS_NONE, buddy)
|
||||||
|
del self.groups[room]
|
||||||
|
|
||||||
def _requestLastSeen(self, buddy):
|
def _requestLastSeen(self, buddy):
|
||||||
|
|
||||||
def onSuccess(buddy, lastseen):
|
def onSuccess(buddy, lastseen):
|
||||||
|
|
|
@ -232,6 +232,16 @@ class YowsupApp(object):
|
||||||
entity = UnsubscribePresenceProtocolEntity(jid)
|
entity = UnsubscribePresenceProtocolEntity(jid)
|
||||||
self.sendEntity(entity)
|
self.sendEntity(entity)
|
||||||
|
|
||||||
|
def leaveGroup(self, group):
|
||||||
|
"""
|
||||||
|
Permanently leave a WhatsApp group
|
||||||
|
|
||||||
|
Args:
|
||||||
|
- group: (str) the group id (e.g. 27831788123-144024456)
|
||||||
|
"""
|
||||||
|
entity = LeaveGroupsIqProtocolEntity([group + '@g.us'])
|
||||||
|
self.sendEntity(entity)
|
||||||
|
|
||||||
def setStatus(self, statusText):
|
def setStatus(self, statusText):
|
||||||
"""
|
"""
|
||||||
Send status to whatsapp
|
Send status to whatsapp
|
||||||
|
@ -595,6 +605,7 @@ class YowsupAppLayer(YowInterfaceLayer):
|
||||||
|
|
||||||
@ProtocolEntityCallback('message')
|
@ProtocolEntityCallback('message')
|
||||||
def onMessageReceived(self, entity):
|
def onMessageReceived(self, entity):
|
||||||
|
self.logger.debug("Received Message: %s", entity)
|
||||||
if entity.getType() == MessageProtocolEntity.MESSAGE_TYPE_TEXT:
|
if entity.getType() == MessageProtocolEntity.MESSAGE_TYPE_TEXT:
|
||||||
self.caller.onTextMessage(
|
self.caller.onTextMessage(
|
||||||
entity._id,
|
entity._id,
|
||||||
|
|
Loading…
Reference in a new issue