From 015eacbe533e3c0daab9b13616263d4e1898685c Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sun, 12 Feb 2017 11:39:40 -0600 Subject: [PATCH] xmlrpc: expose IRCBot.reply, use it over privmsg converts dispatch and the admin form to reply closes bss/dr.botzo#21 --- dispatch/views.py | 4 ++-- ircbot/admin.py | 4 ++-- ircbot/bot.py | 3 ++- ircbot/forms.py | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/dispatch/views.py b/dispatch/views.py index dc12ef0..7d16961 100644 --- a/dispatch/views.py +++ b/dispatch/views.py @@ -77,9 +77,9 @@ class DispatchMessage(generics.GenericAPIView): # connect over XML-RPC and send try: bot_url = 'http://{0:s}:{1:d}/'.format(settings.IRCBOT_XMLRPC_HOST, settings.IRCBOT_XMLRPC_PORT) - bot = xmlrpc.client.ServerProxy(bot_url) + bot = xmlrpc.client.ServerProxy(bot_url, allow_none=True) log.debug("sending '%s' to channel %s", text, action.destination) - bot.privmsg(action.destination, text) + bot.reply(None, text, False, action.destination) except Exception as e: new_data = copy.deepcopy(message.data) new_data['status'] = "FAILED - {0:s}".format(str(e)) diff --git a/ircbot/admin.py b/ircbot/admin.py index d2ef34a..11c02fc 100644 --- a/ircbot/admin.py +++ b/ircbot/admin.py @@ -30,8 +30,8 @@ def send_privmsg(request): message = form.cleaned_data['message'] bot_url = 'http://{0:s}:{1:d}/'.format(settings.IRCBOT_XMLRPC_HOST, settings.IRCBOT_XMLRPC_PORT) - bot = xmlrpc.client.ServerProxy(bot_url) - bot.privmsg(target, message) + bot = xmlrpc.client.ServerProxy(bot_url, allow_none=True) + bot.reply(None, message, False, target) form = PrivmsgForm() else: form = PrivmsgForm() diff --git a/ircbot/bot.py b/ircbot/bot.py index 3d52e07..e01b82a 100644 --- a/ircbot/bot.py +++ b/ircbot/bot.py @@ -377,7 +377,8 @@ class IRCBot(irc.client.SimpleIRCClient): t.start() # register XML-RPC stuff - self.xmlrpc.register_function(self.privmsg, 'privmsg') + self.xmlrpc_register_function(self.privmsg, 'privmsg') + self.xmlrpc_register_function(self.reply, 'reply') def _connected_checker(self): if not self.connection.is_connected(): diff --git a/ircbot/forms.py b/ircbot/forms.py index f413b74..ec89820 100644 --- a/ircbot/forms.py +++ b/ircbot/forms.py @@ -2,7 +2,7 @@ import logging -from django.forms import Form, CharField +from django.forms import Form, CharField, Textarea log = logging.getLogger('markov.forms') @@ -12,4 +12,4 @@ class PrivmsgForm(Form): """Accept a privmsg to send to the ircbot.""" target = CharField() - message = CharField() + message = CharField(widget=Textarea)