diff options
| -rw-r--r-- | ircbot/main.py | 11 | ||||
| -rw-r--r-- | irclog/view.html | 137 | ||||
| -rw-r--r-- | teleirc/.gitignore | 1 | ||||
| -rw-r--r-- | teleirc/config.toml.example | 24 | ||||
| -rw-r--r-- | teleirc/deploy.sh | 2 |
5 files changed, 165 insertions, 10 deletions
diff --git a/ircbot/main.py b/ircbot/main.py index 05aac2b..28745c4 100644 --- a/ircbot/main.py +++ b/ircbot/main.py @@ -13,6 +13,7 @@ NICKNAME = "android" IDENT = NICKNAME REALNAME = "bot" CHANNELS = ["#main", "#ezl9fd7fa13c4bad4f4"] +GREETINGS = ["#main"] LOGPATH = '/volume/webroot/irclog' BUFFER_SIZE = 2048 @@ -56,14 +57,14 @@ def yesterday_log(chan): @command("log") def log_command(chan, sender, args): - log1 = today_log(chan) - log0 = yesterday_log(chan) - return "今天: " + log1 + '\n' + "昨天: " + log0 + return today_log(chan) @command("join") def join_command(chan, sender, args): if sender == NICKNAME: return '' + if not chan in GREETINGS: + return '' return "Dōmo, " + sender + ' san.' @command("dict") @@ -156,9 +157,7 @@ def write_log(channel, nick, msg): return if msg.startswith('!log'): return - if msg.startswith('今天: https://raye.mistivia.com/irclog/') and nick == NICKNAME: - return - if msg.startswith('昨天: https://raye.mistivia.com/irclog/') and nick == NICKNAME: + if msg.startswith('https://raye.mistivia.com/irclog/') and nick == NICKNAME: return now = datetime.datetime.now() base_dir = LOGPATH diff --git a/irclog/view.html b/irclog/view.html index 6d8385c..34b5154 100644 --- a/irclog/view.html +++ b/irclog/view.html @@ -2,6 +2,7 @@ <html lang="en"> <head> <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover"> <title>IRC Log Viewer</title> <style> body { @@ -14,14 +15,15 @@ border: 1px solid #ccc; padding: 15px; background-color: #fff; - white-space: pre-wrap; + white-space: pre-wrap; /* 允许文本在新行换行 */ } pre { + /* 确保 pre 标签内的内容保持预格式化文本的特点 */ font-family: Consolas, monospace; margin: 0; padding: 0; overflow-wrap: anywhere; - white-space: pre-wrap; + white-space: pre-wrap; /* 允许文本在新行换行 */ } .error { color: red; @@ -30,20 +32,37 @@ .loading { color: blue; } +@media (max-width: 600px) { + pre { + font-size: 0.7em; + } +} </style> </head> <body> <h1>IRC Log Viewer</h1> + <!-- 新增日期选择界面 --> + <div id="controls"> + <label for="log-date">选择日期:</label> + <input type="date" id="log-date" value=""> + <br> + <br> + </div> <div id="status"></div> + <button onclick="setPreviousDay()">上一天</button> + <button onclick="setNextDay()">下一天</button> <div id="log-container"> </div> + <button onclick="setPreviousDay()">上一天</button> + <button onclick="setNextDay()">下一天</button> <script> document.addEventListener('DOMContentLoaded', () => { const statusDiv = document.getElementById('status'); const logContainer = document.getElementById('log-container'); + // 1. 读取URL的哈希值 (去掉开头的 #) let urlHash = window.location.hash.substring(1); if (!urlHash) { @@ -51,7 +70,24 @@ statusDiv.textContent = 'Error: No hash fragment found in the URL. Please append a hash (e.g., #2023-01-01) to the URL.'; return; } +var dateRegex = /(\d{4})\/(\d{2})-(\d{2})/; + +var match = urlHash.match(dateRegex); +var formattedDate = null; + +if (match) { + formattedDate = match[1] + '-' + match[2] + '-' + match[3]; + document.getElementById("log-date").value = formattedDate; +} + urlHash = urlHash.replace(/#/g, '%23'); +var parts = urlHash.split('/'); + + var chan = ""; +if (parts.length >= 1) { + chan= parts[0]; + } + // 2. 构造TXT文件的URL const logBaseUrl = 'https://raye.mistivia.com/irclog/'; let targetUrl = `${logBaseUrl}${urlHash}.txt`; // 假设日志文件是 .txt 格式 @@ -85,6 +121,7 @@ }); } + function loadLog(targetUrl) { fetch(targetUrl) .then(response => { if (!response.ok) { @@ -104,10 +141,102 @@ .catch(error => { console.error('Fetch error:', error); statusDiv.className = 'error'; - statusDiv.textContent = `Failed to load log. ${error.message}`; - logContainer.innerHTML = `<pre class="error">Could not fetch log. Please check the console for details. (CORS or network issue likely).</pre>`; + logContainer.innerHTML = ''; }); + } + loadLog(targetUrl); +function ondatechange() { + var dateInput = this; + var dateValue = dateInput.value; // 获取当前选择的日期,格式为 yyyy-mm-dd + + if (dateValue && chan) { + + var dateParts = dateValue.split('-'); // 结果如: ["2025", "10", "21"] + + var year = dateParts[0]; + var month = dateParts[1]; + var day = dateParts[2]; + + var finalPath = "https://raye.mistivia.com/irclog/" + chan + "/" + year + "/" + month + '-' + day + '.txt'; + loadLog(finalPath); +const currentUrl = window.location.href; +const datePattern = /(\/)\d{4}(\/)\d{2}-\d{2}$/; +const newDateReplacement = `$1${year}$2${month + '-' + day}`; +const newUrl = currentUrl.replace(datePattern, newDateReplacement); +window.history.pushState(null, '', newUrl); + } +} + + +document.getElementById("log-date").addEventListener('change', ondatechange, false); + }); + + const dateInput = document.getElementById('log-date'); + + /** + * 格式化 Date 对象为 YYYY-MM-DD 字符串 + * @param {Date} date - 要格式化的 Date 对象 + * @returns {string} 格式化后的日期字符串 (YYYY-MM-DD) + */ + function formatDate(date) { + const year = date.getFullYear(); + // getMonth() 返回 0-11,所以需要 +1 + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; + } + + /** + * 设置日期输入框的值 + * @param {number} days - 要调整的天数 (例如: -1 为前一天, 1 为后一天) + */ + function changeDate(days) { + let currentDate; + + // 1. 获取当前值,如果为空,则使用当前日期 + const value = dateInput.value; + if (value) { + // 如果有值,从 ISO 格式 (YYYY-MM-DD) 创建 Date 对象 + // 使用 new Date(string) 可能会有时区问题,但对于 YYYY-MM-DD 格式,它通常会解析为 UTC 午夜, + // 然后转换为本地时间。为了避免这个问题,可以手动解析或使用 new Date(year, monthIndex, day)。 + // 另一种更简单的办法是创建一个新的 Date 对象,然后使用 setDate() + currentDate = new Date(value); + } else { + // 如果没有值,使用今天的日期 + currentDate = new Date(); + } + + // 2. 调整日期 + // new Date() 可能会包含时间部分,我们只需要日期。 + // 确保使用正确的方法来处理月份和年份的正确跨越。 + // setDate() 方法可以自动处理月份和年份的进位或退位。 + // 获取当前日期的“日”数 + const currentDay = currentDate.getDate(); + // 设置新的“日”数 (例如: 当前日 - 1 或 当前日 + 1) + currentDate.setDate(currentDay + days); + + // 3. 格式化并设置回输入框 + dateInput.value = formatDate(currentDate); + dateInput.dispatchEvent(new Event('change')); + } + + /** + * 设置日期为前一天 + */ + function setPreviousDay() { + changeDate(-1); + window.scrollTo(0, 0); + } + + /** + * 设置日期为后一天 + */ + function setNextDay() { + changeDate(1); + window.scrollTo(0, 0); + } + </script> </body> diff --git a/teleirc/.gitignore b/teleirc/.gitignore new file mode 100644 index 0000000..5b6c096 --- /dev/null +++ b/teleirc/.gitignore @@ -0,0 +1 @@ +config.toml diff --git a/teleirc/config.toml.example b/teleirc/config.toml.example new file mode 100644 index 0000000..5e98b6d --- /dev/null +++ b/teleirc/config.toml.example @@ -0,0 +1,24 @@ +[general] +MediaDownloadPath="/var/www/tmp" +MediaServerDownload="https://yourserver.com/matterbridge" + +[irc.myirc] +Server="raye.mistivia.com:6697" +Nick="TeleIRC" +UseTLS=true +SkipTLSVerify=false +RemoteNickFormat="<{NICK}> " + +[telegram.mytelegram] +Token="xxxxxxxxxxxxxx" +RemoteNickFormat="<{NICK}> " + +[[gateway]] +name="g1" +enable=true +[[gateway.inout]] +account="telegram.mytelegram" +channel="-0000000000000" +[[gateway.inout]] +account="irc.myirc" +channel="#test" diff --git a/teleirc/deploy.sh b/teleirc/deploy.sh new file mode 100644 index 0000000..e390c1d --- /dev/null +++ b/teleirc/deploy.sh @@ -0,0 +1,2 @@ +scp config.toml root@raye:/etc/matterbridge/ +ssh root@raye 'nitroctl restart teleirc' |
