jp (message): message is now a subcommand, and the sending command is moved to message/send
This commit is contained in:
parent
d56e3f1cae
commit
43ecaa5af9
1 changed files with 20 additions and 10 deletions
|
|
@ -25,25 +25,27 @@ from sat.tools.utils import clean_ustr
|
|||
__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 @@ class Message(base.CommandBase):
|
|||
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'))
|
||||
|
|
|
|||
Loading…
Reference in a new issue