diff options
| author | Mistivia <i@mistivia.com> | 2025-11-04 23:19:52 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-11-04 23:19:52 +0800 |
| commit | 8dbcdce76cbd4cd3b2ad2dcfce5bf828d91aa07c (patch) | |
| tree | cb0f93e5df84353fc1f1257f71b3792d42edb2d2 | |
| parent | 6c66b7c72013f8e335d93b28e743101883f30bb9 (diff) | |
better log
| -rw-r--r-- | ircbot/main.py | 17 | ||||
| -rw-r--r-- | irclog/view/index.html | 18 | ||||
| -rw-r--r-- | irclog/view/view7.js (renamed from irclog/view/view4.js) | 28 |
3 files changed, 53 insertions, 10 deletions
diff --git a/ircbot/main.py b/ircbot/main.py index 3d5b4e8..a106dc1 100644 --- a/ircbot/main.py +++ b/ircbot/main.py @@ -96,7 +96,18 @@ def meet_cmd(chan, sender, args): def log_command(chan, sender, args): return f"https://raye.mistivia.com/irclog/view/?chan={chan[1:]}" -LAST_SEEN = dict() +def load_lastseen(): + try: + with open("lastseen", "r") as fp: + return json.load(fp) + except: + return dict() + +LAST_SEEN = load_lastseen() + +def save_lastseen(): + with open("lastseen", "w") as fp: + json.dump(LAST_SEEN, fp) def get_greeting(chan, sender, args): if sender == NICKNAME: @@ -109,10 +120,12 @@ def get_greeting(chan, sender, args): and sender in LAST_SEEN[chan] \ and time.time() - LAST_SEEN[chan][sender] < 300: LAST_SEEN[chan][sender] = time.time() + save_lastseen() return '' if chan not in LAST_SEEN: LAST_SEEN[chan] = dict() LAST_SEEN[chan][sender] = time.time() + save_lastseen() return "Dōmo, " + sender + ' san.' @command("join") @@ -463,6 +476,7 @@ class IRCBot: for chan in LAST_SEEN: if sender_nick in LAST_SEEN[chan]: LAST_SEEN[chan][sender_nick] = time.time() + save_lastseen() elif command == 'PART': args = params if len(params) >= 1: @@ -471,6 +485,7 @@ class IRCBot: chan = trailing if chan in LAST_SEEN: LAST_SEEN[chan][sender_nick] = time.time() + save_lastseen() elif command == "PRIVMSG": if sender_nick == NICKNAME: return diff --git a/irclog/view/index.html b/irclog/view/index.html index 490e9c3..41c33da 100644 --- a/irclog/view/index.html +++ b/irclog/view/index.html @@ -40,6 +40,22 @@ #searchlink { visibility: hidden; } + .logline { + color: black; + text-decoration: none; + } + .logline:link { + color: black; + text-decoration: none; + } + .logline:hover { + color: black; + text-decoration: underline; + } + .logline:visited { + color: black; + text-decoration: none; + } </style> </head> <body> @@ -57,6 +73,6 @@ <div id="log-container"></div> <button onclick="setPreviousDay()">上一天</button> <button onclick="setNextDay()">下一天</button> - <script src="./view4.js"></script> + <script src="./view7.js"></script> </body> </html> diff --git a/irclog/view/view4.js b/irclog/view/view7.js index 1863f64..29eed6c 100644 --- a/irclog/view/view4.js +++ b/irclog/view/view7.js @@ -44,11 +44,15 @@ function setDateState(date) { month = String(date.getMonth() + 1).padStart(2, '0'); day = String(date.getDate()).padStart(2, '0'); dateInput.value = formatDate(getDate(year, month, day)); - window.history.replaceState(null, '', window.location.origin + window.location.pathname + + let newurl = window.location.origin + window.location.pathname + '?chan=' + chan + '&y=' + year + '&m=' + month + - '&d=' + day); + '&d=' + day; + if (hashtag !== '') { + newurl = newurl + '#' + hashtag; + } + window.history.replaceState(null, '', newurl); } setDateState(getDate(year, month, day)); @@ -79,20 +83,28 @@ function linkify(text) { }); } +function sethash(time) { + let newurl = window.location.pathname + window.location.search + '#' + time; + window.history.replaceState(null, '', newurl); +} + function insertTag(text) { let res = ''; let lines = text.split('\n'); let scrollToInserted = false; for (let line of lines) { let time = line.substring(1, 9); - if (!scrollToInserted && time == hashtag && time !== '') { - res += '<span id="scrollTo"></span>'; - scrollToInserted = true; - res += '<span style="color:red;">' + line + '</span>\n'; + if (time == hashtag && time !== '') { + if (!scrollToInserted) { + res += '<span id="scrollTo"></span>'; + scrollToInserted = true; + } + res += '<a class="logline" href="#' + time + '" style="color:red;">' + line + '</span>\n'; } else { - res += line + '\n'; + res += '<a class="logline" href="#' + time + '">' + line + '</a>\n'; } } + hashtag = ''; return res; } @@ -117,7 +129,7 @@ function loadLog() { logContainer.innerHTML = `<pre>${logProcess(text)}</pre>`; let scrollTo = document.getElementById('scrollTo'); if (scrollTo) { - scrollTo.scrollIntoView(); + scrollTo.scrollIntoView({behavior: 'smooth', block: 'center'}); } }) .catch(error => { |
