-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeTrigger.py
executable file
·43 lines (35 loc) · 1.02 KB
/
TimeTrigger.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import traceback
import time
from menus import Menus
from menus import Menus
class TimeTrigger(object):
known_triggers = {}
def __init__(self,ref,menus):
self.menus = menus
self.ref = ref
self.base = None
self.triggered = False
TimeTrigger.known_triggers[ref] = self
def reset(self):
self.base = int(time.time())
self.triggered = False
def trigger(self):
if not self.triggered:
if self.base:
if int(time.time()) - self.base > self.menus.options[self.ref][3]:
self.triggered = True
return True
return False
@staticmethod
def resets():
for key, value in TimeTrigger.known_triggers.items():
value.reset()
@staticmethod
def triggers():
trigs = []
for key, value in TimeTrigger.known_triggers.items():
if value.trigger():
trigs = trigs + key
return trigs