parent
4740cd7808
commit
cd31bbb489
@ -0,0 +1,7 @@
|
||||
"""Facts allows storage of arbitrarily defined sets of strings.
|
||||
|
||||
The "fact" part is tongue-in-cheek, you can put random options for a decision,
|
||||
roulette style game modes, 8-ball type functionality, and total falsehoods
|
||||
in here too. When fact categories are queried, a random one is returned if
|
||||
you don't know what you're looking for.
|
||||
"""
|
@ -1,3 +1,4 @@
|
||||
"""Admin interface for the facts app."""
|
||||
from django.contrib import admin
|
||||
|
||||
from facts.models import Fact, FactCategory
|
||||
|
@ -1,5 +1,4 @@
|
||||
"""IRC plugin for retrieval of facts."""
|
||||
|
||||
import logging
|
||||
|
||||
from irc.client import NickMask
|
||||
@ -7,17 +6,14 @@ from irc.client import NickMask
|
||||
from ircbot.lib import Plugin, has_permission
|
||||
from facts.models import Fact, FactCategory
|
||||
|
||||
|
||||
log = logging.getLogger('facts.ircplugin')
|
||||
|
||||
|
||||
class Facts(Plugin):
|
||||
|
||||
"""Present facts to IRC."""
|
||||
|
||||
def start(self):
|
||||
"""Set up the handlers."""
|
||||
|
||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!facts\s+add\s+(\S+)\s+(.*)$',
|
||||
self.handle_add_fact, -20)
|
||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!facts\s+(\S+)(\s+(.*)$|$)',
|
||||
@ -27,7 +23,6 @@ class Facts(Plugin):
|
||||
|
||||
def stop(self):
|
||||
"""Tear down handlers."""
|
||||
|
||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_add_fact)
|
||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_facts)
|
||||
|
||||
@ -35,7 +30,6 @@ class Facts(Plugin):
|
||||
|
||||
def handle_facts(self, connection, event, match):
|
||||
"""Respond to the facts command with desired fact."""
|
||||
|
||||
category = match.group(1)
|
||||
regex = None
|
||||
if match.group(2) != '':
|
||||
@ -53,7 +47,6 @@ class Facts(Plugin):
|
||||
|
||||
def handle_add_fact(self, connection, event, match):
|
||||
"""Add a new fact to the database."""
|
||||
|
||||
category_name = match.group(1)
|
||||
fact_text = match.group(2)
|
||||
|
||||
|
@ -1,37 +1,33 @@
|
||||
"""Store "facts"."""
|
||||
|
||||
import logging
|
||||
import random
|
||||
|
||||
from django.db import models
|
||||
|
||||
|
||||
log = logging.getLogger('facts.models')
|
||||
|
||||
|
||||
class FactCategory(models.Model):
|
||||
|
||||
"""Define categories for facts."""
|
||||
|
||||
name = models.CharField(max_length=200, unique=True)
|
||||
show_source = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
"""Meta options."""
|
||||
|
||||
verbose_name_plural = 'fact categories'
|
||||
|
||||
def __str__(self):
|
||||
"""String representation."""
|
||||
|
||||
return "{0:s}".format(self.name)
|
||||
|
||||
|
||||
class FactManager(models.Manager):
|
||||
|
||||
"""Queries against Fact."""
|
||||
|
||||
def random_fact(self, category, regex=None):
|
||||
"""Get a random fact from the database."""
|
||||
|
||||
try:
|
||||
fact_category = FactCategory.objects.get(name=category)
|
||||
except FactCategory.DoesNotExist:
|
||||
@ -48,7 +44,6 @@ class FactManager(models.Manager):
|
||||
|
||||
|
||||
class Fact(models.Model):
|
||||
|
||||
"""Define facts."""
|
||||
|
||||
fact = models.TextField()
|
||||
@ -60,5 +55,4 @@ class Fact(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
"""String representation."""
|
||||
|
||||
return "{0:s} - {1:s}".format(self.category.name, self.fact)
|
||||
|
Loading…
Reference in New Issue
Block a user