Created
June 23, 2014 16:07
-
-
Save dromer/1e7ce429b15e39b9307a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import willie | |
import re | |
from willie.module import commands, interval | |
INTERVAL = 5 | |
SPACESTATE = "unknown" | |
CHANNEL = "#lag" | |
def checkstate(): | |
global SPACESTATE | |
f = open('/home/slug/Source/state.txt') | |
statef = f.read() | |
return statef | |
def readTopic(bot): | |
bot.write(['TOPIC', CHANNEL]) | |
return | |
@interval(INTERVAL) | |
@event('332') | |
@rule('.*') | |
def trackstate(bot): | |
global SPACESTATE | |
global CHANNEL | |
state = checkstate() | |
if SPACESTATE != state: | |
oldtopic = readTopic() | |
newtopic = re.sub(r'we are ' + SPACESTATE, 'we are ' + state, oldtopic) | |
bot.msg(CHANNEL ,'The space is now ' + state) | |
bot.write(('TOPIC', CHANNEL + ' :' + newtopic)) | |
SPACESTATE = state | |
@willie.module.commands('spacestate') | |
def spacestate(bot, trigger): | |
state = checkstate() | |
bot.say('The space is currently ' + state) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment