Skip to content

Instantly share code, notes, and snippets.

@dromer
Created June 23, 2014 16:07
Show Gist options
  • Save dromer/1e7ce429b15e39b9307a to your computer and use it in GitHub Desktop.
Save dromer/1e7ce429b15e39b9307a to your computer and use it in GitHub Desktop.
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