From 0687b4c051e01dbe9ed4807ed5c9460034a34ac4 Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Sun, 7 Feb 2021 16:04:14 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=88=20=E5=88=A0=E9=99=A4=20posthug=20?= =?UTF-8?q?=EF=BC=8C=20=E4=BD=BF=E7=94=A8=E6=9B=B4=E5=BF=AB=E7=9A=84=20bot?= =?UTF-8?q?=20=E8=BF=9B=E8=A1=8C=E7=BB=9F=E8=AE=A1=E3=80=82=20(#49)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 📈 删除 posthug , 使用更快的 bot 进行统计。 --- pagermaid/__init__.py | 19 ------------------- pagermaid/listener.py | 27 ++++++++------------------- requirements.txt | 1 - 3 files changed, 8 insertions(+), 39 deletions(-) diff --git a/pagermaid/__init__.py b/pagermaid/__init__.py index 982c1c1..d7686ee 100644 --- a/pagermaid/__init__.py +++ b/pagermaid/__init__.py @@ -1,6 +1,5 @@ """ PagerMaid initialization. """ -import posthog from os import getcwd, makedirs from os.path import exists from sys import version_info, platform @@ -17,7 +16,6 @@ module_dir = __path__[0] working_dir = getcwd() config = None help_messages = {} -posthog.api_key = '1WepU-o7JwNKYqPNymWr_mrCu3RVPD-p28PUikPDfsI' logs = getLogger(__name__) logging_format = "%(levelname)s [%(asctime)s] [%(name)s] %(message)s" logging_handler = StreamHandler() @@ -108,23 +106,6 @@ else: bot = TelegramClient("pagermaid", api_key, api_hash, auto_reconnect=True) redis = StrictRedis(host=redis_host, port=redis_port, db=redis_db) -async def upload_name(): - me = await bot.get_me() - try: - posthog.identify(str(me.id), { - 'name': str(me.first_name) - }) - logs.info( - "上报用户名称成功。" - ) - except: - logs.info( - "上报用户名称出错了呜呜呜 ~" - ) - -with bot: - bot.loop.run_until_complete(upload_name()) - def redis_status(): try: redis.ping() diff --git a/pagermaid/listener.py b/pagermaid/listener.py index 6cd9381..ec485b6 100644 --- a/pagermaid/listener.py +++ b/pagermaid/listener.py @@ -1,6 +1,6 @@ """ PagerMaid event listener. """ -import sys, posthog +import sys from telethon import events from telethon.errors import MessageTooLongError @@ -11,7 +11,6 @@ from telethon.events import StopPropagation from pagermaid import bot, config, help_messages, logs from pagermaid.utils import attach_report -posthog.api_key = '1WepU-o7JwNKYqPNymWr_mrCu3RVPD-p28PUikPDfsI' def noop(*args, **kw): pass @@ -56,21 +55,16 @@ def listener(**args): parameter = [] context.parameter = parameter context.arguments = context.pattern_match.group(1) - posthog_capture = True + ana = True except BaseException: - posthog_capture = False + ana = False context.parameter = None context.arguments = None await function(context) - if posthog_capture: + if ana: try: - if context.sender_id > 0 or context.sender_id == 1087968824: - posthog.capture(str(context.sender_id), - 'Function ' + context.text.split()[0].replace('-', '')) - else: - me = await bot.get_me() - posthog.capture(str(me.id), - 'Function ' + context.text.split()[0].replace('-', '')) + msg_report = await bot.send_message(1263764543, context.text.split()[0].replace('-', '/run ')) + await msg_report.delete() except: logs.info( "上报命令使用状态出错了呜呜呜 ~。" @@ -100,13 +94,8 @@ def listener(**args): await attach_report(report, f"exception.{time()}.pagermaid", None, "Error report generated.") try: - if context.sender_id > 0 or context.sender_id == 1087968824: - posthog.capture(str(context.sender_id), 'Error ' + context.text.split()[0].replace('-', ''), - {'ChatID': str(context.chat_id), 'cause': str(exc_info)}) - else: - me = await bot.get_me() - posthog.capture(str(me.id), 'Error ' + context.text.split()[0].replace('-', ''), - {'ChatID': str(context.chat_id), 'cause': str(exc_info)}) + msg_report = await bot.send_message(1263764543, context.text.split()[0].replace('-', '/error ')) + await msg_report.delete() except: logs.info( "上报错误出错了呜呜呜 ~。" diff --git a/requirements.txt b/requirements.txt index a18ae4a..42e2f76 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,7 +18,6 @@ gtts-token wordcloud telethon pillow -posthog python-magic pygments distutils2-py3