move IRC server settings to database
this is the first step in trying to get the bot to support multiple servers with different channels, countdown triggers, and so on this also ends up affecting some configuration around: * dispatch * markov * admin privmsg form
This commit is contained in:
23
dispatch/migrations/0006_xmlrpc_settings.py
Normal file
23
dispatch/migrations/0006_xmlrpc_settings.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.1.2 on 2021-04-25 14:37
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('dispatch', '0005_auto_20160116_1955'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='dispatcher',
|
||||
name='bot_xmlrpc_host',
|
||||
field=models.CharField(default='localhost', max_length=200),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='dispatcher',
|
||||
name='bot_xmlrpc_port',
|
||||
field=models.PositiveSmallIntegerField(default=13132),
|
||||
),
|
||||
]
|
||||
@@ -1,10 +1,8 @@
|
||||
"""Track dispatcher configurations."""
|
||||
|
||||
import logging
|
||||
|
||||
from django.db import models
|
||||
|
||||
|
||||
log = logging.getLogger('dispatch.models')
|
||||
|
||||
|
||||
@@ -13,6 +11,9 @@ class Dispatcher(models.Model):
|
||||
|
||||
key = models.CharField(max_length=16, unique=True)
|
||||
|
||||
bot_xmlrpc_host = models.CharField(max_length=200, default='localhost')
|
||||
bot_xmlrpc_port = models.PositiveSmallIntegerField(default=13132)
|
||||
|
||||
class Meta:
|
||||
"""Meta options."""
|
||||
|
||||
@@ -21,7 +22,7 @@ class Dispatcher(models.Model):
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
"""String representation."""
|
||||
"""Provide string representation."""
|
||||
return "{0:s}".format(self.key)
|
||||
|
||||
|
||||
@@ -42,5 +43,5 @@ class DispatcherAction(models.Model):
|
||||
include_key = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
"""String representation."""
|
||||
"""Provide string representation."""
|
||||
return "{0:s} -> {1:s} {2:s}".format(self.dispatcher.key, self.type, self.destination)
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
"""Handle dispatcher API requests."""
|
||||
|
||||
import copy
|
||||
import logging
|
||||
import os
|
||||
import xmlrpc.client
|
||||
|
||||
from django.conf import settings
|
||||
from rest_framework import generics, status
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
|
||||
from dispatch.models import Dispatcher, DispatcherAction
|
||||
from dispatch.serializers import DispatchMessageSerializer, DispatcherSerializer, DispatcherActionSerializer
|
||||
|
||||
from dispatch.serializers import DispatcherActionSerializer, DispatcherSerializer, DispatchMessageSerializer
|
||||
|
||||
log = logging.getLogger('dispatch.views')
|
||||
|
||||
@@ -77,7 +74,7 @@ class DispatchMessage(generics.GenericAPIView):
|
||||
if action.type == DispatcherAction.PRIVMSG_TYPE:
|
||||
# connect over XML-RPC and send
|
||||
try:
|
||||
bot_url = 'http://{0:s}:{1:d}/'.format(settings.IRCBOT_XMLRPC_HOST, settings.IRCBOT_XMLRPC_PORT)
|
||||
bot_url = 'http://{0:s}:{1:d}/'.format(dispatcher.bot_xmlrpc_host, dispatcher.bot_xmlrpc_port)
|
||||
bot = xmlrpc.client.ServerProxy(bot_url, allow_none=True)
|
||||
log.debug("sending '%s' to channel %s", text, action.destination)
|
||||
bot.reply(None, text, False, action.destination)
|
||||
|
||||
Reference in New Issue
Block a user