Updated cookie.py

This commit is contained in:
Yuuki Chan 2024-02-21 21:42:15 +09:00
parent f11f90e01d
commit b1f6ca23c5

View file

@ -18,6 +18,7 @@ cookie_table = Table(
Column('last', String, default='1999/01/01 00:00:00'),
)
c_db = Database(cookie_table, meta)
df = '%Y/%m/%d %H:%M:%S'
class Plugin(PluginBase):
@ -32,8 +33,8 @@ class Plugin(PluginBase):
cookies = c_db.get(source_nick, 2)
rnd = random.randint(1, 10)
last = datetime.strptime(c_db.get(source_nick, 3), '%Y/%m/%d %H:%M:%S')
current = datetime.strptime(datetime.now().strftime('%Y/%m/%d %H:%M:%S'), '%Y/%m/%d %H:%M:%S')
last = datetime.strptime(c_db.get(source_nick, 3), df)
current = datetime.strptime(datetime.now().strftime(df), df)
diff = round((current - last).total_seconds() / 60.0)
if diff >= 30:
@ -49,10 +50,10 @@ class Plugin(PluginBase):
c_db.set(source_nick, {
'cookies': (cookies + rnd),
'last': current.strftime('%Y/%m/%d %H:%M:%S')
'last': current.strftime(df)
})
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}')
elif len(parts) == 2:
cookies = c_db.get(parts[1], 2)
@ -79,9 +80,8 @@ class Plugin(PluginBase):
conn.commit()
def remaining_time(self, date: str, timeout: int):
diff = (int(time.mktime(
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, '%Y/%m/%d %H:%M:%S').timetuple()) * 1000))
diff = (int(time.mktime(datetime.strptime(datetime.now().strftime(df), df).timetuple()) * 1000) -
int(time.mktime(datetime.strptime(date, df).timetuple()) * 1000))
h = int((timeout - diff) / (60 * 60 * 1000) % 24)
m = int((timeout - diff) / (60 * 1000) % 60)
s = int((timeout - diff) / 1000 % 60)