rename BotAdmin to BotUser other stuff will check whether or not they're an "admin", which will actually be standard django permissions
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
"""Manage ircbot models and admin actions in the admin interface."""
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import logging
|
|
import xmlrpclib
|
|
|
|
from django.conf import settings
|
|
from django.contrib import admin
|
|
from django.shortcuts import render
|
|
|
|
from ircbot.forms import PrivmsgForm
|
|
from ircbot.models import Alias, BotUser, IrcChannel, IrcPlugin
|
|
|
|
|
|
log = logging.getLogger('ircbot.admin')
|
|
|
|
|
|
admin.site.register(Alias)
|
|
admin.site.register(BotUser)
|
|
admin.site.register(IrcChannel)
|
|
admin.site.register(IrcPlugin)
|
|
|
|
|
|
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)
|
|
bot = xmlrpclib.ServerProxy(bot_url)
|
|
bot.privmsg(target, message)
|
|
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')
|