This repository has been archived by the owner on Nov 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
twimanager.py
81 lines (61 loc) · 1.79 KB
/
twimanager.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import time
import random
import config
import tweepy
import constants
import usermanager
import databasemanager
auth = tweepy.OAuthHandler(config.CONSUMER_KEY, config.CONSUMER_SECRET)
auth.set_access_token(config.ACCESS_TOKEN, config.ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
STATE = 'state'
ENTERED_UID = 'entered_name'
LAST_OPENED = 'last_opened'
TIME_TO_SLEEP = 30 * 60
def twi(text):
try:
api.update_status(text)
except:
pass
def get_phrase(ph_type, user):
phrases = constant.twi_prhrases[ph_type]
res = random.choice(phrases)
return res.format(user.name)
def dead(user):
twi(get_phrase('dead', user))
databasemanager.set_variable(ENTERED_UID, 0)
def won(user):
twi(get_phrase('won', user))
databasemanager.set_variable(ENTERED_UID, 0)
def leave(user):
if databasemanager.get_variable(ENTERED_UID, def_val=0) != 0:
twi(get_phrase('leave', user))
databasemanager.set_variable(ENTERED_UID, 0)
databasemanager.set_variable(STATE, 'sleeps')
def enter(user):
if not status()[0]:
return False
databasemanager.set_variable(STATE, 'busy')
databasemanager.set_variable(LAST_OPENED, time.time())
databasemanager.set_variable(ENTERED_UID, user.uid)
twi(get_phrase('enter', user))
def last_opened():
last_o = databasemanager.get_variable(LAST_OPENED, def_val=0)
return time.time() - last_o
def status():
return (False, 'sleeps')
"""
state = databasemanager.get_variable(STATE, def_val='wait')
if last_opened() > TIME_TO_SLEEP and state != 'wait':
if state == 'busy':
uid = databasemanager.get_variable(ENTERED_UID, def_val=0)
if uid != 0:
user = usermanager.get_user(uid)
def foo(*a, **b):
pass
user.open_corridor(foor)
usermanager.save_user(user)
state = 'wait'
databasemanager.get_variable(STATE, def_val='wait')
return (state == 'wait', state)
"""