Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Multi channel support, misc fixes/changes.

  • Loading branch information...
commit d61e33b13bed137c04faa66a41afe6550fa60c9c 1 parent 9e29cb0
@mythmon mythmon authored
View
6 bravo/ibravo.py
@@ -1,5 +1,4 @@
from twisted.python.components import registerAdapter
-from twisted.web.resource import IResource
from zope.interface import implements, invariant, Attribute, Interface
from bravo.errors import InvariantException
@@ -449,8 +448,3 @@ def stop():
After this method is called, the automaton should not continue
processing data; it needs to stop immediately.
"""
-
-class IWorldResource(IBravoPlugin, IResource):
- """
- Interface for a world specific web resource.
- """
View
3  hamper.conf.dist
@@ -1,5 +1,6 @@
nickname: cool_bot
-channel: "#awesome-channel"
server: irc.freenode.net
port: 6667
db: "sqlite:///hamper.db"
+
+channels: ["#awesome-channel", "#cool-channel"]
View
10 hamper/commander.py
@@ -24,11 +24,12 @@ def _get_db(self):
db = property(_get_db)
def signedOn(self):
- self.join(self.factory.channel)
+ for c in self.factory.channels:
+ self.join(c)
print "Signed on as %s." % (self.nickname,)
def joined(self, channel):
- print "Joined %s." % (channel,)
+ print "Joined {}.".format(channel)
def privmsg(self, user, channel, msg):
"""I received a message."""
@@ -114,9 +115,6 @@ def connectionLost(self, reason):
self.factory.db.commit()
reactor.stop()
- def say(self, msg):
- self.msg(self.factory.channel, msg)
-
def removePlugin(self, plugin):
self.factory.pluginsToRemove.append(plugin)
@@ -134,7 +132,7 @@ class CommanderFactory(protocol.ClientFactory):
protocol = CommanderProtocol
def __init__(self, config):
- self.channel = config['channel']
+ self.channels = config['channels']
self.nickname = config['nickname']
self.history = {}
View
10 hamper/plugins/commands.py
@@ -13,7 +13,7 @@ class QuitCommand(Command):
regex = 'go away'
def command(self, bot, comm, groups):
- bot.say('Bye!')
+ bot.msg(comm['channel'], 'Bye!')
bot.leaveChannel(comm['channel'])
return True
@@ -37,7 +37,7 @@ def command(self, bot, comm, groups):
key = comm['channel']
if key not in bot.factory.history:
- bot.say('Who are you?! How did you get in my house?!')
+ bot.msg(comm['channel'], 'Who are you?! How did you get in my house?!')
return
for hist in reversed(bot.factory.history[key]):
@@ -50,11 +50,11 @@ def command(self, bot, comm, groups):
if usr_regex.search(hist['message']):
new_msg = usr_regex.sub(usr_replace, hist['message'], count)
- bot.say('{0} actually meant: {1}'
+ bot.msg(comm['channel'], '{0} actually meant: {1}'
.format(hist['user'], new_msg))
break
else:
- bot.say("Sorry, I couldn't match /{0}/.".format(usr_regex.pattern))
+ bot.msg(comm['channel'], "Sorry, I couldn't match /{0}/.".format(usr_regex.pattern))
class LetMeGoogleThatForYou(Command):
"""Link to the sarcastic letmegooglethatforyou.com."""
@@ -68,7 +68,7 @@ def command(self, bot, comm, groups):
if comm['target']:
target = comm['target'] + ': '
args = groups[0].replace(' ', '+')
- bot.say(target + 'http://lmgtfy.com/?q=' + args)
+ bot.msg(comm['channel'], target + 'http://lmgtfy.com/?q=' + args)
lmgtfy = LetMeGoogleThatForYou()
sed = Sed()
View
7 hamper/plugins/friendly.py
@@ -15,14 +15,14 @@ class Friendly(object):
priority = 2
def setup(self, factory):
- self.greetings = ['hi', 'hello', 'hey']
+ self.greetings = ['hi', 'hello', 'hey', 'sup', 'yo', 'hola']
def process(self, bot, comm):
if not comm['directed']:
return
if comm['message'].strip() in self.greetings:
- bot.say('{0} {1[user]}'
+ bot.msg(comm['channel'], '{0} {1[user]}'
.format(random.choice(self.greetings), comm))
return True
@@ -38,14 +38,13 @@ class OmgPonies(object):
def setup(self, factory):
self.last_pony_time = datetime.now()
- pass
def process(self, bot, comm):
if re.match(r'.*pon(y|ies).*', comm['message'], re.I):
now = datetime.now()
since_last_pony = now - self.last_pony_time
if since_last_pony.total_seconds() >= self.cooldown:
- bot.say('OMG!!! PONIES!!!')
+ bot.msg(comm['channel'], 'OMG!!! PONIES!!!')
self.last_pony_time = now
else:
print('too many ponies')
View
13 hamper/plugins/plugin_utils.py
@@ -24,27 +24,26 @@ def command(self, bot, comm, groups):
print args
if len(args) == 0:
- self.listPlugins(bot, *args)
+ self.listPlugins(bot, comm, *args)
return True
if args[0] in dispatch:
- dispatch[args[0]](bot, *args)
+ dispatch[args[0]](bot, comm, *args)
return True
- def listPlugins(self, bot, *args):
+ def listPlugins(self, bot, comm, *args):
"""Reply with a list of all currently loaded plugins."""
- bot.say('Loaded Plugins: {0}.'.format(
+ bot.msg(comm['channel'], 'Loaded Plugins: {0}.'.format(
', '.join([c.name for c in bot.factory.plugins])))
- def reloadPlugin(self, bot, *args):
+ def reloadPlugin(self, bot, comm, *args):
"""Reload a named plugin."""
name = ' '.join(args[1:])
ps = bot.factory.plugins
-
matched_plugins = [p for p in ps if p.name == name]
if len(matched_plugins) == 0:
- bot.say("I can't find a plugin named %s!" % name)
+ bot.msg(comm['channel'], "I can't find a plugin named %s!" % name)
return
target_plugin = matched_plugins[0]
View
9 hamper/plugins/quote.py
@@ -33,17 +33,18 @@ def command(self, bot, comm, groups):
index = random.randrange(0, bot.db.query(Quote).count() + 1)
quote = bot.factory.db.query(Quote)[index]
# Lame twisted irc doesn't support unicode.
- bot.say(str(quote.text))
+ bot.msg(comm['channel'], str(quote.text))
elif args[0] == '--args':
# Add a quote
text = ' '.join(args[1:])
quote = Quote(text, comm['user'])
bot.factory.db.add(quote)
- bot.say('Succesfully added quote.')
+ bot.msg(comm['channel'], 'Succesfully added quote.')
elif args[0] == '--count':
- bot.say('I know {0} quotes.'.format(bot.db.query(Quote).count()))
+ count = bot.db.query(Quote).count()
+ bot.msg(comm['channel'], 'I know {0} quotes.'.format(count))
else:
- bot.say('Wait, what?')
+ bot.msg(comm['channel'], 'Wait, what?')
class Quote(SQLAlchemyBase):
View
2  scripts/hamper
@@ -13,7 +13,7 @@ if __name__ == '__main__':
config = yaml.load(open('hamper.conf'))
- for key in ['server', 'port', 'nickname', 'channel']:
+ for key in ['server', 'port', 'nickname', 'channels']:
if (key not in config) or (not config[key]):
print('You need to define {0} in the config file.'.format(key))
sys.exit();
Please sign in to comment.
Something went wrong with that request. Please try again.