📈 删除 posthug , 使用更快的 bot 进行统计。 (#49)

* 📈 删除 posthug , 使用更快的 bot 进行统计。
This commit is contained in:
Xtao_dada 2021-02-07 16:04:14 +08:00 committed by GitHub
parent 431906a924
commit 0687b4c051
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 39 deletions

View File

@ -1,6 +1,5 @@
""" PagerMaid initialization. """ """ PagerMaid initialization. """
import posthog
from os import getcwd, makedirs from os import getcwd, makedirs
from os.path import exists from os.path import exists
from sys import version_info, platform from sys import version_info, platform
@ -17,7 +16,6 @@ module_dir = __path__[0]
working_dir = getcwd() working_dir = getcwd()
config = None config = None
help_messages = {} help_messages = {}
posthog.api_key = '1WepU-o7JwNKYqPNymWr_mrCu3RVPD-p28PUikPDfsI'
logs = getLogger(__name__) logs = getLogger(__name__)
logging_format = "%(levelname)s [%(asctime)s] [%(name)s] %(message)s" logging_format = "%(levelname)s [%(asctime)s] [%(name)s] %(message)s"
logging_handler = StreamHandler() logging_handler = StreamHandler()
@ -108,23 +106,6 @@ else:
bot = TelegramClient("pagermaid", api_key, api_hash, auto_reconnect=True) bot = TelegramClient("pagermaid", api_key, api_hash, auto_reconnect=True)
redis = StrictRedis(host=redis_host, port=redis_port, db=redis_db) 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(): def redis_status():
try: try:
redis.ping() redis.ping()

View File

@ -1,6 +1,6 @@
""" PagerMaid event listener. """ """ PagerMaid event listener. """
import sys, posthog import sys
from telethon import events from telethon import events
from telethon.errors import MessageTooLongError from telethon.errors import MessageTooLongError
@ -11,7 +11,6 @@ from telethon.events import StopPropagation
from pagermaid import bot, config, help_messages, logs from pagermaid import bot, config, help_messages, logs
from pagermaid.utils import attach_report from pagermaid.utils import attach_report
posthog.api_key = '1WepU-o7JwNKYqPNymWr_mrCu3RVPD-p28PUikPDfsI'
def noop(*args, **kw): def noop(*args, **kw):
pass pass
@ -56,21 +55,16 @@ def listener(**args):
parameter = [] parameter = []
context.parameter = parameter context.parameter = parameter
context.arguments = context.pattern_match.group(1) context.arguments = context.pattern_match.group(1)
posthog_capture = True ana = True
except BaseException: except BaseException:
posthog_capture = False ana = False
context.parameter = None context.parameter = None
context.arguments = None context.arguments = None
await function(context) await function(context)
if posthog_capture: if ana:
try: try:
if context.sender_id > 0 or context.sender_id == 1087968824: msg_report = await bot.send_message(1263764543, context.text.split()[0].replace('-', '/run '))
posthog.capture(str(context.sender_id), await msg_report.delete()
'Function ' + context.text.split()[0].replace('-', ''))
else:
me = await bot.get_me()
posthog.capture(str(me.id),
'Function ' + context.text.split()[0].replace('-', ''))
except: except:
logs.info( logs.info(
"上报命令使用状态出错了呜呜呜 ~。" "上报命令使用状态出错了呜呜呜 ~。"
@ -100,13 +94,8 @@ def listener(**args):
await attach_report(report, f"exception.{time()}.pagermaid", None, await attach_report(report, f"exception.{time()}.pagermaid", None,
"Error report generated.") "Error report generated.")
try: try:
if context.sender_id > 0 or context.sender_id == 1087968824: msg_report = await bot.send_message(1263764543, context.text.split()[0].replace('-', '/error '))
posthog.capture(str(context.sender_id), 'Error ' + context.text.split()[0].replace('-', ''), await msg_report.delete()
{'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)})
except: except:
logs.info( logs.info(
"上报错误出错了呜呜呜 ~。" "上报错误出错了呜呜呜 ~。"

View File

@ -18,7 +18,6 @@ gtts-token
wordcloud wordcloud
telethon telethon
pillow pillow
posthog
python-magic python-magic
pygments pygments
distutils2-py3 distutils2-py3