Skip to content

Commit

Permalink
cleaner specification of xmpp config
Browse files Browse the repository at this point in the history
  • Loading branch information
paul cannon committed May 4, 2011
1 parent 0aea7a4 commit b3be3a6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion run_cassbot
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ fi

[ -n "$pidfile" ] || pidfile="$defdir/cassbot.pid"

export nickname channels server statefile autoload_modules auto_admin jid password jabber_server conference_server alias
export nickname channels server statefile autoload_modules auto_admin jid password jabber_server conference_server

exec "$twistd" $twistd_opts -y "$start_tap" --pidfile "$pidfile" $extra_opts
19 changes: 15 additions & 4 deletions tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@
import shlex
from twisted.internet import reactor
from twisted.application import service
from cassbot import CassBotService

nickname = os.environ.get('nickname', 'CassBotJr')
channels = shlex.split(os.environ.get('channels', ''))
server = os.environ.get('server', 'tcp:host=irc.freenode.net:port=6667')
statefile = os.environ.get('statefile', 'cassbot.state.db')

jid = os.environ.get('jid', None)
if jid is not None:
from xmppbot import XMPPCassBotService
password = os.environ['password']
jabber_server = os.environ.get('jabber_server', None)
conference_server = os.environ.get('conference_server', None)
bot = XMPPCassBotService(jid, password, jabber_server, conference_server,
nickname=nickname, init_channels=channels,
statefile=statefile)
else:
from cassbot import CassBotService
server = os.environ.get('server', 'tcp:host=irc.freenode.net:port=6667')
bot = CassBotService(server, nickname=nickname, init_channels=channels,
statefile=statefile)

application = service.Application(nickname)
bot = CassBotService(server, nickname=nickname, init_channels=channels,
statefile=statefile)
bot.setServiceParent(application)

def setup():
Expand Down
23 changes: 21 additions & 2 deletions xmppbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,33 @@ def pingServer(self):
class XMPPCassBotService(cassbot.CassBotService):
xmppbot = None

def __init__(self, user_jid, password, jabber_server=None, conference_server=None,
nickname=None, init_channels=(), statefile='cassbot.state.db',
reactor=None):
self.jid = jid.internJID(user_jid)
if nickname is None:
nickname = self.jid.user

cassbot.CassBotService.__init__(self, self.jid.full(), nickname=nickname,
init_channels=init_channels, reactor=reactor,
statefile=statefile)

self.password = password
if jabber_server is None:
jabber_server = self.jid.host
if conference_server is None:
conference_server = self.jid.host
self.jabber_server = jabber_server
self.conference_server = conference_server

def setupConnectionParams(self, conffile):
self.endpoint_desc = 'conffile=%s' % (conffile,)

def setupConnection(self):
xmppclient = XMPPClient(jid.internJID(self.jid), self.password, self.jabber_server)
xmppclient = XMPPClient(self.jid, self.password, self.jabber_server)
xmppclient.logTraffic = False

xmppbot = XMPPCassBot(self, self.alias)
xmppbot = XMPPCassBot(self, self.state['nickname'])
xmppbot.conference_server = self.conference_server
xmppbot.setHandlerParent(xmppclient)

Expand Down

0 comments on commit b3be3a6

Please sign in to comment.