🐛️ fix double log and add uptime (#129)

🐛 修复双重日志
️ 添加在线时间查看
This commit is contained in:
Xtao_dada 2021-09-04 16:28:38 +08:00 committed by GitHub
parent 34c567c1f2
commit 9e6db8caaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 44 additions and 9 deletions

View File

@ -84,3 +84,5 @@ speed_test_path: ""
# 24 default # 24 default
time_form: "%H:%M" time_form: "%H:%M"
date_form: "%A %y/%m/%d" date_form: "%A %y/%m/%d"
# only support %m %d %H %M %S
start_form: "%m/%d %H:%M"

View File

@ -159,6 +159,7 @@ handle_failure_error: Something went wrong oh woo woo ~ Please report this probl
time_des: Display the time in a specific area. If the parameter is empty, the configuration value will be displayed by default. time_des: Display the time in a specific area. If the parameter is empty, the configuration value will be displayed by default.
time_parameters: <area> time_parameters: <area>
time_time: time time_time: time
time_config: Something went wrong oh woo woo ~ Please check your config file.
# external # external
# translate # translate
translate_des: Translate the target message into the specified language through Google Translate. (Support reply) translate_des: Translate the target message into the specified language through Google Translate. (Support reply)
@ -363,13 +364,13 @@ status_des: Output the running status of PagerMaid-Modify.
status_online: online status_online: online
status_offline: offline status_offline: offline
status_hint: PagerMaid-Modify running status status_hint: PagerMaid-Modify running status
status_name: host name status_name: Host name
status_platform: host platform status_platform: Host platform
status_release: Kernel version status_release: Kernel version
status_python: Python version status_python: Python version
status_telethon: Telethon version status_telethon: Telethon version
status_db: database status status_db: Database status
status_dialogs: total number of conversations status_uptime: Uptime
# stats # stats
stats_des: View conversation statistics. stats_des: View conversation statistics.
stats_loading: Loading... stats_loading: Loading...

View File

@ -167,6 +167,7 @@ handle_failure_error: 出错了呜呜呜 ~ 请报告此问题。
time_des: 显示特定区域的时间,如果参数为空,则默认显示配置值。 time_des: 显示特定区域的时间,如果参数为空,则默认显示配置值。
time_parameters: <地区> time_parameters: <地区>
time_time: 时间 time_time: 时间
time_config: 出错了呜呜呜 ~ 配置文件填写错误
# external # external
## translate ## translate
@ -383,6 +384,7 @@ status_release: Kernel 版本
status_python: Python 版本 status_python: Python 版本
status_telethon: Telethon 版本 status_telethon: Telethon 版本
status_db: 数据库状态 status_db: 数据库状态
status_uptime: 运行时间
## stats ## stats
stats_des: 查看我的对话统计信息。 stats_des: 查看我的对话统计信息。
stats_loading: 加载中 . . . stats_loading: 加载中 . . .

View File

@ -154,6 +154,7 @@ handle_failure_error: Error請報告此問題。
time_des: 顯示特定區域的時間。 time_des: 顯示特定區域的時間。
time_parameters: <地區> time_parameters: <地區>
time_time: 時間 time_time: 時間
time_config: 出錯了嗚嗚嗚 ~ 配置文件填寫錯誤
# external # external
# translate # translate
translate_des: 透過Google翻譯把目標訊息翻譯成指定的語言。支援回覆 translate_des: 透過Google翻譯把目標訊息翻譯成指定的語言。支援回覆
@ -364,7 +365,7 @@ status_release: Kernel版本
status_python: Python版本 status_python: Python版本
status_telethon: Telethon版本 status_telethon: Telethon版本
status_db: 數據庫狀態 status_db: 數據庫狀態
status_dialogs: 聊天總數 status_uptime: 運行時間
# stats # stats
stats_des: 查看我的對話統計信息。 stats_des: 查看我的對話統計信息。
stats_loading: 加載中 . . . stats_loading: 加載中 . . .

View File

@ -14,6 +14,7 @@ try:
except: except:
pass pass
from subprocess import run, PIPE from subprocess import run, PIPE
from datetime import datetime
from time import time from time import time
from os import getcwd, makedirs, environ from os import getcwd, makedirs, environ
from os.path import exists from os.path import exists
@ -345,6 +346,7 @@ def before_send(event, hint):
report_time = time() report_time = time()
start_time = datetime.utcnow()
git_hash = run("git rev-parse HEAD", stdout=PIPE, shell=True).stdout.decode() git_hash = run("git rev-parse HEAD", stdout=PIPE, shell=True).stdout.decode()
sentry_sdk.init( sentry_sdk.init(
"https://935d04099b7d4bd889e7ffac488579fc@o416616.ingest.sentry.io/5312335", "https://935d04099b7d4bd889e7ffac488579fc@o416616.ingest.sentry.io/5312335",

View File

@ -55,7 +55,7 @@ def start():
if strtobool(config['web_interface']['enable']) or environ.get('PORT'): if strtobool(config['web_interface']['enable']) or environ.get('PORT'):
logs.info(f"已经启动Web界面 {web_host}:{web_port}") logs.info(f"已经启动Web界面 {web_host}:{web_port}")
app.logger.removeHandler(default_handler) app.logger.removeHandler(default_handler)
app.logger.addHandler(logging_handler) # app.logger.addHandler(logging_handler)
try: try:
server.start() server.start()
except OSError: except OSError:

View File

@ -36,7 +36,7 @@ async def time(context):
time_zone = await get_timezone(country) time_zone = await get_timezone(country)
if not time_zone: if not time_zone:
if len(context.parameter) < 1: if len(context.parameter) < 1:
await context.edit('出错了呜呜呜 ~ 配置文件填写错误') await context.edit(lang('time_config'))
return return
try: try:
time_num, utc_num = int(context.parameter[0]), int(context.parameter[0]) time_num, utc_num = int(context.parameter[0]), int(context.parameter[0])

View File

@ -15,7 +15,7 @@ from telethon.tl.types import User, Chat, Channel
from sys import platform from sys import platform
from re import sub, findall from re import sub, findall
from pathlib import Path from pathlib import Path
from pagermaid import log, config, redis_status from pagermaid import log, config, redis_status, start_time
from pagermaid.utils import execute, upload_attachment from pagermaid.utils import execute, upload_attachment
from pagermaid.listener import listener from pagermaid.listener import listener
from pagermaid.utils import lang, alias_command from pagermaid.utils import lang, alias_command
@ -83,14 +83,41 @@ async def tty(context):
@listener(is_plugin=False, outgoing=True, command=alias_command("status"), @listener(is_plugin=False, outgoing=True, command=alias_command("status"),
description=lang('status_des')) description=lang('status_des'))
async def status(context): async def status(context):
# database
database = lang('status_online') if redis_status() else lang('status_offline') database = lang('status_online') if redis_status() else lang('status_offline')
# uptime https://gist.github.com/borgstrom/936ca741e885a1438c374824efb038b3
time_units = (
('%m', 60 * 60 * 24 * 30),
('%d', 60 * 60 * 24),
('%H', 60 * 60),
('%M', 60),
('%S', 1)
)
async def human_time_duration(seconds):
parts = {}
for unit, div in time_units:
amount, seconds = divmod(int(seconds), div)
parts[unit] = str(amount)
try:
time_form = config['start_form']
except (ValueError, KeyError):
time_form = "%m/%d %H:%M"
for key, value in parts.items():
time_form = time_form.replace(key, value)
return time_form
current_time = datetime.utcnow()
uptime_sec = (current_time - start_time).total_seconds()
uptime = await human_time_duration(int(uptime_sec))
text = (f"**{lang('status_hint')}** \n" text = (f"**{lang('status_hint')}** \n"
f"{lang('status_name')}: `{uname().node}` \n" f"{lang('status_name')}: `{uname().node}` \n"
f"{lang('status_platform')}: `{platform}` \n" f"{lang('status_platform')}: `{platform}` \n"
f"{lang('status_release')}: `{uname().release}` \n" f"{lang('status_release')}: `{uname().release}` \n"
f"{lang('status_python')}: `{python_version()}` \n" f"{lang('status_python')}: `{python_version()}` \n"
f"{lang('status_telethon')}: `{telethon_version.__version__}` \n" f"{lang('status_telethon')}: `{telethon_version.__version__}` \n"
f"{lang('status_db')}: `{database}`" f"{lang('status_db')}: `{database}` \n"
f"{lang('status_uptime')}: `{uptime}`"
) )
await context.edit(text) await context.edit(text)