2015-06-13 13:07:52 -05:00
|
|
|
"""Manage ircbot models and admin actions in the admin interface."""
|
2015-05-10 10:02:25 -05:00
|
|
|
|
2015-06-13 13:07:52 -05:00
|
|
|
import logging
|
2016-01-16 17:58:11 -06:00
|
|
|
import xmlrpc.client
|
2015-06-13 13:07:52 -05:00
|
|
|
|
|
|
|
from django.conf import settings
|
2015-05-10 10:02:25 -05:00
|
|
|
from django.contrib import admin
|
2015-06-13 13:07:52 -05:00
|
|
|
from django.shortcuts import render
|
2015-05-10 10:02:25 -05:00
|
|
|
|
2015-06-13 13:07:52 -05:00
|
|
|
from ircbot.forms import PrivmsgForm
|
2015-06-20 09:31:28 -05:00
|
|
|
from ircbot.models import Alias, BotUser, IrcChannel, IrcPlugin
|
2015-05-10 10:02:25 -05:00
|
|
|
|
|
|
|
|
2015-06-13 13:07:52 -05:00
|
|
|
log = logging.getLogger('ircbot.admin')
|
|
|
|
|
|
|
|
|
2015-05-14 21:39:20 -05:00
|
|
|
admin.site.register(Alias)
|
2015-06-20 09:31:28 -05:00
|
|
|
admin.site.register(BotUser)
|
2015-05-10 10:02:25 -05:00
|
|
|
admin.site.register(IrcChannel)
|
2015-05-12 20:45:18 -05:00
|
|
|
admin.site.register(IrcPlugin)
|
2015-06-13 13:07:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
def send_privmsg(request):
|
|
|
|
"""Send a privmsg over XML-RPC to the IRC bot."""
|
|
|
|
if request.method == 'POST':
|
|
|
|
form = PrivmsgForm(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
target = form.cleaned_data['target']
|
|
|
|
message = form.cleaned_data['message']
|
|
|
|
|
|
|
|
bot_url = 'http://{0:s}:{1:d}/'.format(settings.IRCBOT_XMLRPC_HOST, settings.IRCBOT_XMLRPC_PORT)
|
2017-02-12 11:39:40 -06:00
|
|
|
bot = xmlrpc.client.ServerProxy(bot_url, allow_none=True)
|
|
|
|
bot.reply(None, message, False, target)
|
2015-06-13 13:07:52 -05:00
|
|
|
form = PrivmsgForm()
|
|
|
|
else:
|
|
|
|
form = PrivmsgForm()
|
|
|
|
|
|
|
|
return render(request, 'privmsg.html', {'form': form})
|
|
|
|
|
|
|
|
admin.site.register_view('ircbot/privmsg/', "Ircbot - privmsg", view=send_privmsg, urlname='ircbot_privmsg')
|