aboutsummaryrefslogtreecommitdiff
path: root/modules/factoids.py
blob: 7ac84dcd7fec65c1cd3353e86b2958d0bad867d4 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from src import ModuleManager, utils

class Module(ModuleManager.BaseModule):
    @utils.hook("received.command.factoid", min_args=1)
    def factoid(self, event):
        """
        :help: Set/get a factoid
        :usage: <key> [= value]
        """
        if "=" in event["args"]:
            key, _, value = event["args"].partition("=")
            factoid = key.lower().strip()
            event["server"].set_setting("factoid-%s" % factoid, value.strip())

            event["stdout"].write("Set factoid '%s'" % factoid)
        else:
            factoid = event["args"].lower().strip()
            value = event["server"].get_setting("factoid-%s" % factoid, None)

            if value == None:
                raise utils.EventError("Unknown factoid '%s'" % factoid)
            event["stdout"].write("%s: %s" % (factoid, value))