Brian S. Stephan
03e1269cf2
note that this removes support for python 3.8 and 3.9! Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""Manage ircbot models and admin actions in the admin interface."""
|
|
|
|
import logging
|
|
import xmlrpc.client
|
|
|
|
from django.contrib import admin
|
|
from django.shortcuts import render
|
|
|
|
from ircbot.forms import PrivmsgForm
|
|
from ircbot.models import Alias, BotUser, IrcChannel, IrcPlugin, IrcServer
|
|
|
|
log = logging.getLogger('ircbot.admin')
|
|
|
|
|
|
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(form.cleaned_data['xmlrpc_host'],
|
|
form.cleaned_data['xmlrpc_port'])
|
|
bot = xmlrpc.client.ServerProxy(bot_url, allow_none=True)
|
|
bot.reply(None, message, False, target)
|
|
form = PrivmsgForm()
|
|
else:
|
|
form = PrivmsgForm()
|
|
|
|
return render(request, 'privmsg.html', {'form': form})
|
|
|
|
|
|
admin.site.register(Alias)
|
|
admin.site.register(BotUser)
|
|
admin.site.register(IrcChannel)
|
|
admin.site.register(IrcPlugin)
|
|
admin.site.register(IrcServer)
|