When adding event, an ID is generated to found the event later. Can delete event.
This commit is contained in:
parent
2e3ad0ba35
commit
5c5e0fbe8f
18
bot.py
18
bot.py
@ -26,6 +26,8 @@ import event
|
|||||||
from networkbot import NetworkBot
|
from networkbot import NetworkBot
|
||||||
from server import Server
|
from server import Server
|
||||||
|
|
||||||
|
ID_letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
|
||||||
class Bot(BotCaps):
|
class Bot(BotCaps):
|
||||||
def __init__(self, servers=dict(), modules=dict(), mp=list()):
|
def __init__(self, servers=dict(), modules=dict(), mp=list()):
|
||||||
BotCaps.__init__(self, 3.2, "3.2-dev")
|
BotCaps.__init__(self, 3.2, "3.2-dev")
|
||||||
@ -52,7 +54,11 @@ class Bot(BotCaps):
|
|||||||
|
|
||||||
|
|
||||||
def add_event(self, evt):
|
def add_event(self, evt):
|
||||||
"""Register an event"""
|
"""Register an event and return its identifiant for futur update"""
|
||||||
|
# Find ID
|
||||||
|
now = datetime.now()
|
||||||
|
evt.id = "%d%c%d%d%c%d%d%c%d" % (now.year, ID_letters[now.microsecond % 52], now.month, now.day, ID_letters[now.microsecond % 42], now.hour, now.minute, ID_letters[now.microsecond % 32], now.second)
|
||||||
|
|
||||||
# Add the event in place
|
# Add the event in place
|
||||||
t = evt.current
|
t = evt.current
|
||||||
i = 0
|
i = 0
|
||||||
@ -63,6 +69,16 @@ class Bot(BotCaps):
|
|||||||
if i == 0:
|
if i == 0:
|
||||||
self.update_timer()
|
self.update_timer()
|
||||||
|
|
||||||
|
return evt.id
|
||||||
|
|
||||||
|
def del_event(self, id):
|
||||||
|
"""Find and remove an event from list"""
|
||||||
|
for evt in self.events:
|
||||||
|
if evt.id == id:
|
||||||
|
self.events.remove(evt)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def update_timer(self):
|
def update_timer(self):
|
||||||
"""Relaunch the timer to end with the closest event"""
|
"""Relaunch the timer to end with the closest event"""
|
||||||
# Reset the timer if this is the first item
|
# Reset the timer if this is the first item
|
||||||
|
Loading…
x
Reference in New Issue
Block a user