From b1f6ca23c5996a403be8bd12d1ab264dfe3c9a2c Mon Sep 17 00:00:00 2001 From: Yuuki Chan Date: Wed, 21 Feb 2024 21:42:15 +0900 Subject: [PATCH] Updated cookie.py --- cookie.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cookie.py b/cookie.py index 8eedb97..0b4db12 100644 --- a/cookie.py +++ b/cookie.py @@ -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)