diff options
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 35 |
1 files changed, 29 insertions, 6 deletions
@@ -25,12 +25,35 @@ def getScore(): return myScore +def sendLog(msg): + numLines = msg.split(' ')[1] if len(msg.split(' ')) > 1 else 5 + try: + numLines = int(numLines) + except ValueError: + numLines = 5 + with open(os.getenv('LOGFILE'), 'r') as f: + lines = f.readlines() + maxLines = len(lines) - 1 + if maxLines < 0: + bot.sendMessage("Log kosong") + startLine = max(len(lines) - numLines, 0) + lines = lines[startLine:] + bot.sendMessage(f"Menampilkan log. Mulai dari line: {startLine}") + for line in lines: + bot.sendMessage(line) + bot.sendMessage(f"Selesai menampilkan log. Line terakhir: {maxLines}") + + def processMessages(messages): - if 'update' in (msg.lower() for msg in messages): - logger.info("EXPLICIT SCORE UPDATE REQUESTED") - score = getScore() - msg = f"Score leantime bulan ini = {score}%" if score >= 0 else "Connection problem with report dashboard" - bot.sendMessage(msg) + for msg in messages: + msg = msg.lower() + if msg == 'update': + logger.info("EXPLICIT SCORE UPDATE REQUESTED") + score = getScore() + msg = f"Score leantime bulan ini = {score}%" if score >= 0 else "Koneksi ke dashboard bermasalah" + bot.sendMessage(msg) + elif 'log' in msg: + sendLog(msg) @repeat(every().day.at("09:00")) @@ -40,7 +63,7 @@ def main(): weekday = today.weekday() if weekday not in [5, 6]: # jangan ganggu aku di akhir pekan myScore = getScore() - msg = f"Leantime score = {myScore}%. <i>Jangan lupa isi leantime</i>" if myScore >= 0 else "Connection problem with report dashboard" + msg = f"Leantime score = {myScore}%. <i>Jangan lupa isi leantime</i>" if myScore >= 0 else "Koneksi ke dashboard bermasalah" if (17 <= today.day <= 24) and (0 <= myScore < 70): # seminggu sebelumnya udah ngingetin msg = f'<b>WARNING!</b> SEKARANG UDAH TANGGAL {today.day}, SCORE LEANTIME MASIH {myScore}%' |