Commit 85b12222 authored by Link Mauve's avatar Link Mauve Committed by Link Mauve

Add (back?) reason and altroom arguments for /destroy_room.

Also make use of slixmpp’s new destroy_room() function.
parent 826fa779
......@@ -56,7 +56,7 @@ These commands work in *any* tab.
- ``/join / password``
/destroy_room
**Usage:** ``/destroy_room [room JID]``
**Usage:** ``/destroy_room [room JID [reason [alternative venue]]]``
Try to destroy the room given as a parameter, or the current room
is not parameter is given and the current tab is a chatroom.
......
......@@ -8,7 +8,7 @@ from typing import List, Optional, Tuple
import logging
from slixmpp import Iq, JID, InvalidJID
from slixmpp.exceptions import XMPPError
from slixmpp.exceptions import XMPPError, IqError, IqTimeout
from slixmpp.xmlstream.xmlstream import NotConnectedError
from slixmpp.xmlstream.stanzabase import StanzaBase
from slixmpp.xmlstream.handler import Callback
......@@ -1151,26 +1151,43 @@ class CommandCore:
"disconnected", self.core.exit, disposable=True)
self.core.disconnect(msg)
@command_args_parser.quoted(0, 1, [''])
def destroy_room(self, args: List[str]) -> None:
@command_args_parser.quoted(0, 3, ['', '', ''])
def destroy_room(self, args: List[str]):
"""
/destroy_room [JID]
/destroy_room [JID [reason [alternative room JID]]]
"""
async def do_destroy(room: JID, reason: str, altroom: JID):
try:
await self.core.xmpp['xep_0045'].destroy(room, reason, altroom)
except (IqError, IqTimeout) as e:
xmpp.core.information('Unable to destroy room %s: %s' % (room, e), 'Info')
else:
xmpp.core.information('Room %s destroyed' % room, 'Info')
if not args[0] and isinstance(self.core.tabs.current_tab, tabs.MucTab):
muc.destroy_room(self.core.xmpp,
self.core.tabs.current_tab.general_jid)
return None
room = self.core.tabs.current_tab.general_jid
else:
try:
room = JID(args[0])
except InvalidJID:
room = None
else:
if room.resource:
room = None
try:
room = JID(args[0]).bare
if room:
muc.destroy_room(self.core.xmpp, room)
return None
except InvalidJID:
pass
if room is None:
self.core.information('Invalid room JID: "%s"' % args[0], 'Error')
return
reason = args[1]
if args[2]:
try:
altroom = JID(args[2])
except InvalidJID:
self.core.information('Invalid alternative room JID: "%s"' % args[2], 'Error')
return
self.core.information('Invalid JID: "%s"' % args[0], 'Error')
return None
asyncio.ensure_future(do_destroy(room, reason, altroom))
@command_args_parser.quoted(1, 1, [''])
def bind(self, args):
......
......@@ -39,41 +39,6 @@ NS_MUC_ADMIN = 'http://jabber.org/protocol/muc#admin'
NS_MUC_OWNER = 'http://jabber.org/protocol/muc#owner'
def destroy_room(
xmpp: ClientXMPP,
room: str,
reason: str = '',
altroom: str = ''
) -> bool:
"""
destroy a room
"""
room = safeJID(room)
if not room:
return False
iq = xmpp.make_iq_set()
iq['to'] = room
query = ET.Element('{%s}query' % NS_MUC_OWNER)
destroy = ET.Element('{%s}destroy' % NS_MUC_OWNER)
if altroom:
destroy.attrib['jid'] = altroom
if reason:
xreason = ET.Element('{%s}reason' % NS_MUC_OWNER)
xreason.text = reason
destroy.append(xreason)
query.append(destroy)
iq.append(query)
def callback(iq: Iq) -> None:
if not iq or iq['type'] == 'error':
xmpp.core.information('Unable to destroy room %s' % room, 'Info')
else:
xmpp.core.information('Room %s destroyed' % room, 'Info')
iq.send(callback=callback)
return True
def change_show(
xmpp: ClientXMPP,
jid: JID,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment