Skip to content

Commit

Permalink
add auto_manhole envvar
Browse files Browse the repository at this point in the history
  • Loading branch information
thepaul committed May 6, 2011
1 parent b3be3a6 commit 2fd64e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cassbot_plugins/open_manhole.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def getManhole(self, bot):
except KeyError:
return None

def makeManhole(self, bot, port):
env = {'botserv': bot.service}
def makeManhole(self, botserv, port):
env = {'botserv': botserv}
hole = internet.TCPServer(port, MagicManholeFactory(env))
hole.setName(self.service_name)
hole.setServiceParent(bot.service)
hole.setServiceParent(botserv)
return hole

def command_open_manhole(self, bot, user, channel, args):
Expand All @@ -25,7 +25,7 @@ def command_open_manhole(self, bot, user, channel, args):
hole = self.getManhole(bot)
if hole is not None:
return bot.address_msg(user, channel, "Manhole is already open.")
self.makeManhole(bot, int(args[0]))
self.makeManhole(bot.service, int(args[0]))
bot.address_msg(user, channel, 'Opened.')

@defer.inlineCallbacks
Expand Down
9 changes: 9 additions & 0 deletions tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shlex
from twisted.internet import reactor
from twisted.application import service
from twisted.python import log

nickname = os.environ.get('nickname', 'CassBotJr')
channels = shlex.split(os.environ.get('channels', ''))
Expand Down Expand Up @@ -32,4 +33,12 @@ def setup():
auto_admin = os.environ.get('auto_admin', os.environ['LOGNAME'])
bot.auth.addPriv(auto_admin, 'admin')

auto_manhole = os.environ.get('auto_manhole')
if auto_manhole is not None:
port = int(auto_manhole)
d = bot.enable_plugin_by_name('OpenManhole')
d.addCallback(lambda p: p.makeManhole(bot, port))
d.addCallback(lambda _: log.msg("Auto-manhole opened on %d." % port))
d.addErrback(log.err, "Auto-manhole failed")

reactor.callWhenRunning(setup)

0 comments on commit 2fd64e9

Please sign in to comment.