summaryrefslogtreecommitdiff
path: root/poezio/core
diff options
context:
space:
mode:
authorMaxime “pep” Buquet <pep@bouah.net>2018-06-06 23:25:21 +0100
committerMaxime “pep” Buquet <pep@bouah.net>2018-12-16 16:57:48 +0000
commit0f344b899c0dff685795108fee4d2de850d92cd6 (patch)
treea062cfe58ae1bf0cb9c7f54efe8c2e97e4b09f94 /poezio/core
parentc3e9130d7d8bb290118b95deba2b7168c0dc8647 (diff)
downloadpoezio-0f344b899c0dff685795108fee4d2de850d92cd6.tar.gz
poezio-0f344b899c0dff685795108fee4d2de850d92cd6.tar.bz2
poezio-0f344b899c0dff685795108fee4d2de850d92cd6.tar.xz
poezio-0f344b899c0dff685795108fee4d2de850d92cd6.zip
Initial impromptu command
Add a command that invites people to a newly created room, with a random localpart. The muc component is currently static. The interface for the command might also change later on. Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
Diffstat (limited to 'poezio/core')
-rw-r--r--poezio/core/commands.py14
-rw-r--r--poezio/core/completions.py13
-rw-r--r--poezio/core/core.py30
3 files changed, 57 insertions, 0 deletions
diff --git a/poezio/core/commands.py b/poezio/core/commands.py
index 5c8199c0..f301e801 100644
--- a/poezio/core/commands.py
+++ b/poezio/core/commands.py
@@ -763,6 +763,20 @@ class CommandCore:
self.core.invite(to.full, room, reason=reason)
self.core.information('Invited %s to %s' % (to.bare, room), 'Info')
+ @command_args_parser.quoted(1, 0)
+ def impromptu(self, args):
+ """/impromptu <jid> [<jid> ...]"""
+
+ if args is None:
+ return self.help('impromptu')
+
+ jids = []
+ for jid in common.shell_split(' '.join(args)):
+ jids.append(safeJID(jid).bare)
+
+ self.core.impromptu(jids)
+ self.core.information('Invited %s to a random room' % (' '.join(jids)), 'Info')
+
@command_args_parser.quoted(1, 1, [''])
def decline(self, args):
"""/decline <room@server.tld> [reason]"""
diff --git a/poezio/core/completions.py b/poezio/core/completions.py
index b283950e..87bb2d47 100644
--- a/poezio/core/completions.py
+++ b/poezio/core/completions.py
@@ -289,6 +289,19 @@ class CompletionCore:
return Completion(
the_input.new_completion, rooms, n, '', quotify=True)
+ def impromptu(self, the_input):
+ """Completion for /impromptu"""
+ n = the_input.get_argument_position(quoted=True)
+ onlines = []
+ offlines = []
+ for barejid in roster.jids():
+ if len(roster[barejid]):
+ onlines.append(barejid)
+ else:
+ offlines.append(barejid)
+ comp = sorted(onlines) + sorted(offlines)
+ return Completion(the_input.new_completion, comp, n, quotify=True)
+
def activity(self, the_input):
"""Completion for /activity"""
n = the_input.get_argument_position(quoted=True)
diff --git a/poezio/core/core.py b/poezio/core/core.py
index eec0d49b..985dcbab 100644
--- a/poezio/core/core.py
+++ b/poezio/core/core.py
@@ -13,6 +13,7 @@ import pipes
import sys
import shutil
import time
+import uuid
from collections import defaultdict
from typing import Callable, Dict, List, Optional, Tuple, Type
@@ -868,6 +869,28 @@ class Core:
self.xmpp.plugin['xep_0030'].get_info(
jid=jid, timeout=5, callback=callback)
+ def impromptu(self, jids: List[JID]) -> None:
+ """
+ Generates a new "Impromptu" room with a random localpart on the muc
+ component of the user who initiated the request. One the room is
+ created and the first user has joined, send invites for specified
+ contacts to join in.
+ """
+
+ # Use config.default_muc as muc component if available, otherwise
+ # find muc component by disco#items-ing the user domain. If not, give
+ # up
+ default_muc = 'chat.cluxia.eu'
+
+ nick = self.own_nick
+ room = uuid.uuid4().hex + '@' + default_muc
+
+ self.open_new_room(room, nick).join()
+ self.information('Room %s created' % room, 'Info')
+
+ for jid in jids:
+ self.invite(jid, room)
+
def get_error_message(self, stanza, deprecated: bool = False):
"""
Takes a stanza of the form <message type='error'><error/></message>
@@ -1789,6 +1812,13 @@ class Core:
shortdesc='Invite someone in a room.',
completion=self.completion.invite)
self.register_command(
+ 'impromptu',
+ self.command.impromptu,
+ usage='<jid> [<jid> ...]',
+ desc='Invite people into an impromptu room',
+ shortdesc='Invite someone in a room.',
+ completion=self.completion.impromptu)
+ self.register_command(
'invitations',
self.command.invitations,
shortdesc='Show the pending invitations.')