[Util] Add Util plugin with custom utility commands

master
ShadowNinja 2014-03-24 15:42:03 -04:00
parent ca07e6ce89
commit b08411f221
4 changed files with 80 additions and 0 deletions

33
Util/__init__.py Normal file
View File

@ -0,0 +1,33 @@
"""
Custom utility commands
"""
import supybot
import supybot.world as world
# Use this for the version of this plugin. You may wish to put a CVS keyword
# in here if you're keeping the plugin in CVS or some similar system.
__version__ = ""
__author__ = supybot.Author("Owen", "ShadowNinja", "shadowninja@minetest.net")
# This is a dictionary mapping supybot.Author instances to lists of
# contributions.
__contributors__ = {}
from . import config
from . import plugin
from imp import reload
reload(plugin)
reload(config)
# In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!
if world.testing:
from . import test
Class = plugin.Class
configure = config.configure

17
Util/config.py Normal file
View File

@ -0,0 +1,17 @@
import supybot.conf as conf
import supybot.registry as registry
def configure(advanced):
# This will be called by supybot to configure this module. advanced is
# a bool that specifies whether the user identified himself as an advanced
# user or not. You should effect your configuration by manipulating the
# registry as appropriate.
from supybot.questions import expect, anything, something, yn
conf.registerPlugin('Util', True)
BotYield = conf.registerPlugin('Util')
# This is where your configuration variables (if any) should go. For example:
# conf.registerGlobalValue(Admin, 'someConfigVariableName',
# registry.Boolean(False, """Help for someConfigVariableName."""))

21
Util/plugin.py Normal file
View File

@ -0,0 +1,21 @@
import supybot.callbacks as callbacks
from supybot.commands import *
class Util(callbacks.Plugin):
"""
Custom utility commands
"""
def stripto(self, irc, msg, args, delim, s):
"""<delemiter> <string>
Returns the portion of string before the first occurance of delemiter.
"""
pos = s.find(delim)
if pos >= 0:
irc.reply(s[0:pos])
else:
irc.error("Delemiter not found.")
stripto = wrap(stripto, ["something", "text"])
Class = Util

9
Util/test.py Normal file
View File

@ -0,0 +1,9 @@
from supybot.test import *
class UtilTestCase(PluginTestCase):
plugins = ("Util",)
def testStripTo(self):
self.assertResponse("stripto - foo-bar", "foo")
self.assertError("stripto - foobar")