Updated cookie.py
This commit is contained in:
parent
f11f90e01d
commit
b1f6ca23c5
1 changed files with 7 additions and 7 deletions
14
cookie.py
14
cookie.py
|
@ -18,6 +18,7 @@ cookie_table = Table(
|
||||||
Column('last', String, default='1999/01/01 00:00:00'),
|
Column('last', String, default='1999/01/01 00:00:00'),
|
||||||
)
|
)
|
||||||
c_db = Database(cookie_table, meta)
|
c_db = Database(cookie_table, meta)
|
||||||
|
df = '%Y/%m/%d %H:%M:%S'
|
||||||
|
|
||||||
|
|
||||||
class Plugin(PluginBase):
|
class Plugin(PluginBase):
|
||||||
|
@ -32,8 +33,8 @@ class Plugin(PluginBase):
|
||||||
|
|
||||||
cookies = c_db.get(source_nick, 2)
|
cookies = c_db.get(source_nick, 2)
|
||||||
rnd = random.randint(1, 10)
|
rnd = random.randint(1, 10)
|
||||||
last = datetime.strptime(c_db.get(source_nick, 3), '%Y/%m/%d %H:%M:%S')
|
last = datetime.strptime(c_db.get(source_nick, 3), df)
|
||||||
current = datetime.strptime(datetime.now().strftime('%Y/%m/%d %H:%M:%S'), '%Y/%m/%d %H:%M:%S')
|
current = datetime.strptime(datetime.now().strftime(df), df)
|
||||||
diff = round((current - last).total_seconds() / 60.0)
|
diff = round((current - last).total_seconds() / 60.0)
|
||||||
|
|
||||||
if diff >= 30:
|
if diff >= 30:
|
||||||
|
@ -49,10 +50,10 @@ class Plugin(PluginBase):
|
||||||
|
|
||||||
c_db.set(source_nick, {
|
c_db.set(source_nick, {
|
||||||
'cookies': (cookies + rnd),
|
'cookies': (cookies + rnd),
|
||||||
'last': current.strftime('%Y/%m/%d %H:%M:%S')
|
'last': current.strftime(df)
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
rem = self.remaining_time(last.strftime('%Y/%m/%d %H:%M:%S'), 30 * 60000)
|
rem = self.remaining_time(last.strftime(df), 30 * 60000)
|
||||||
self.bot.ircsend(f'PRIVMSG {channel} :Remaining time: {rem}')
|
self.bot.ircsend(f'PRIVMSG {channel} :Remaining time: {rem}')
|
||||||
elif len(parts) == 2:
|
elif len(parts) == 2:
|
||||||
cookies = c_db.get(parts[1], 2)
|
cookies = c_db.get(parts[1], 2)
|
||||||
|
@ -79,9 +80,8 @@ class Plugin(PluginBase):
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
def remaining_time(self, date: str, timeout: int):
|
def remaining_time(self, date: str, timeout: int):
|
||||||
diff = (int(time.mktime(
|
diff = (int(time.mktime(datetime.strptime(datetime.now().strftime(df), df).timetuple()) * 1000) -
|
||||||
datetime.strptime(datetime.now().strftime('%Y/%m/%d %H:%M:%S'), '%Y/%m/%d %H:%M:%S').timetuple()) * 1000) -
|
int(time.mktime(datetime.strptime(date, df).timetuple()) * 1000))
|
||||||
int(time.mktime(datetime.strptime(date, '%Y/%m/%d %H:%M:%S').timetuple()) * 1000))
|
|
||||||
h = int((timeout - diff) / (60 * 60 * 1000) % 24)
|
h = int((timeout - diff) / (60 * 60 * 1000) % 24)
|
||||||
m = int((timeout - diff) / (60 * 1000) % 60)
|
m = int((timeout - diff) / (60 * 1000) % 60)
|
||||||
s = int((timeout - diff) / 1000 % 60)
|
s = int((timeout - diff) / 1000 % 60)
|
||||||
|
|
Loading…
Add table
Reference in a new issue