changeset 1828:cb4be663a4a7

jp (message): message is now a subcommand, and the sending command is moved to message/send
author Goffi <goffi@goffi.org>
date Fri, 22 Jan 2016 21:06:41 +0100
parents 74014a9cc203
children 6079752ffeae
files frontends/src/jp/cmd_message.py
diffstat 1 files changed, 20 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/jp/cmd_message.py	Fri Jan 22 20:24:17 2016 +0100
+++ b/frontends/src/jp/cmd_message.py	Fri Jan 22 21:06:41 2016 +0100
@@ -25,25 +25,27 @@
 __commands__ = ["Message"]
 
 
-class Message(base.CommandBase):
+class Send(base.CommandBase):
 
     def __init__(self, host):
-        super(Message, self).__init__(host, 'message', help=_('Send a message to a contact'))
+        super(Send, self).__init__(host, 'send', help=_('send a message to a contact'))
 
     def add_parser_options(self):
-        self.parser.add_argument("-s", "--separate", action="store_true", help=_("Separate xmpp messages: send one message per line instead of one message alone."))
-        self.parser.add_argument("-n", "--new-line", action="store_true", help=_("Add a new line at the beginning of the input (usefull for ascii art ;))"))
-        self.parser.add_argument("jid", type=str, help=_("The destination jid"))
+        self.parser.add_argument("-s", "--separate", action="store_true", help=_("separate xmpp messages: send one message per line instead of one message alone."))
+        self.parser.add_argument("-n", "--new-line", action="store_true", help=_("add a new line at the beginning of the input (usefull for ascii art ;))"))
+        self.parser.add_argument("jid", type=str, help=_("the destination jid"))
 
     def connected(self):
-        super(Message, self).connected()
+        super(Send, self).connected()
         jids = self.host.check_jids([self.args.jid])
         jid = jids[0]
-        self.send_stdin(jid)
+        self.sendStdin(jid)
 
-    def send_stdin(self, dest_jid):
+    def sendStdin(self, dest_jid):
         """Send incomming data on stdin to jabber contact
-        @param dest_jid: destination jid"""
+
+        @param dest_jid: destination jid
+        """
         header = "\n" if self.args.new_line else ""
 
         if self.args.separate:  #we send stdin in several messages
@@ -58,4 +60,12 @@
                 self.host.bridge.sendMessage(dest_jid, line.replace("\n",""), profile_key=self.host.profile, callback=lambda: None, errback=lambda ignore: ignore)
 
         else:
-            self.host.bridge.sendMessage(dest_jid, header + clean_ustr(u"".join([stream.decode('utf-8','ignore') for stream in sys.stdin.readlines()])), profile_key=self.host.profile, callback=lambda: None, errback=lambda ignore: ignore)
+            msg = header + clean_ustr(u"".join([stream.decode('utf-8','ignore') for stream in sys.stdin.readlines()]))
+            self.host.bridge.sendMessage(dest_jid, msg, profile_key=self.host.profile, callback=lambda: None, errback=lambda ignore: ignore)
+
+
+class Message(base.CommandBase):
+    subcommands = (Send, )
+
+    def __init__(self, host):
+        super(Message, self).__init__(host, 'message', use_profile=False, help=_('messages handling'))