Skip to content
This repository has been archived by the owner on Nov 3, 2018. It is now read-only.

Commit

Permalink
Added topic handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jaseg committed Jun 17, 2014
1 parent 8ea5c41 commit 31c4bc5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions afrab0t.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@ def __init__(self, db, channel, nickname, server, port=6667):
self.catpiccache = []
self.reddit = praw.Reddit(user_agent='AfRAb0t/0.23 by jaseg')
self.moincount = 0
self._topic = None


def on_currenttopic(self, c, e):
if e.arguments[0] == self.channel:
newtop = ' '.join(e.arguments[1:])
log('\033[92m TOPIC '+newtop+'\033[0m')
self._topic = newtop
else:
log('\033[91m Got a spurious topic message for '+e.arguments[0]+'\033[0m')

@property
def topic(self):
return self._topic

@topic.setter
def topic(self, newtop):
if self._topic is not None:
log('\033[92mSetting topic to '+newtop+'\033[0m')
self.send('ChanServ', 'TOPIC #afra '+newtop)
self._topic = newtop
else:
log('\033[91mNot setting topic since topic not yet known\033[0m')

def send(self, target, msg):
self.connection.privmsg(target, msg)
Expand Down Expand Up @@ -220,6 +243,8 @@ def do_command(self, e, cmd, nick, target, reply, dm):
reply('Did you mean {} (U+{:x}) with “{}”?'.format(uchar, ord(uchar), emoticon))
break

def spacetop(state):
self.topic = re.sub('space: (open|closed)', 'space: '+state, self.topic)
if cmd.startswith('open'):
if '?' in cmd or '‽' in cmd:
if cmd.count('?') >= 5:
Expand All @@ -237,6 +262,7 @@ def do_command(self, e, cmd, nick, target, reply, dm):
reply('u mad bro?')
return
self.sendchan('Space is open!')
spacetop('open')
self.lastopen = time.ctime()
self.spaceopen = True
return
Expand All @@ -254,6 +280,7 @@ def do_command(self, e, cmd, nick, target, reply, dm):
reply('u mad bro?')
return
self.sendchan('Space is closed! Please remember to follow the shutdown protocol.')
spacetop('closed')
if target != self.channel:
reply('Please remember to follow the shutdown protocol.')
self.lastopen = time.ctime()
Expand Down

0 comments on commit 31c4bc5

Please sign in to comment.