forked from techinc/spacebot_modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spacestatechange.py
62 lines (53 loc) · 1.71 KB
/
spacestatechange.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import urllib2
import time
import willie
from willie.module import commands, interval
from checkin import emptylist
INTERVAL = 5
SPACESTATE = "unknown"
CHANNEL = "#techinc"
SPACEURL = "http://techinc.nl/space/spacestate"
def checkstate():
global SPACESTATE
global SPACEURL
response = urllib2.urlopen(SPACEURL)
html = response.read()
return html
def changestate(state):
global SPACESTATE
print 'State: %s' % state
response = urllib2.urlopen('http://techinc.nl/space/index.php?state=%s&key=PASSWORDGOESHERE' % state)
html = response.read()
SPACESTATE = html
return html
@interval(INTERVAL)
def trackstate(bot):
global SPACESTATE
global CHANNEL
state = checkstate()
if SPACESTATE != state:
bot.msg(CHANNEL ,'The space is now ' + state)
newtopic = 'Welcome to Technologia Incognita, we are ' + state + '. https://www.techinc.nl/ - Social night every Wednesday at ACTA'
bot.write(('TOPIC', CHANNEL + ' :' + newtopic))
SPACESTATE = state
@willie.module.commands('togglestate')
@willie.module.example('.togglestate','togglestate')
def togglestate(bot, trigger):
"""Toggles the state of the space (open/closed)"""
currentstate = checkstate()
if currentstate == 'open':
newstate = 'closed'
else:
newstate = 'open'
bot.say('Changing Spacestate from %s to %s' % (currentstate, newstate))
changestate(newstate)
if newstate == 'closed':
emptylist(bot, trigger)
@willie.module.commands('spacestate')
@willie.module.example('.spacestate', 'spacestate')
def spacestate(bot, trigger):
"""Returns the current state of the space (open/closed)"""
global SPACEURL
response = urllib2.urlopen(SPACEURL)
html = response.read()
bot.say('The space is currently ' + html)