⚡️📈 Help network bad areas access analytics API. (#111)
* ⚡️📈 帮助网络不好的地区访问统计 API
This commit is contained in:
parent
c17224d882
commit
6b502a1478
@ -75,4 +75,4 @@ update_delete: "True"
|
||||
ipv6: "False"
|
||||
|
||||
# Analytics
|
||||
allow_analytics: "True"
|
||||
allow_analytic: "True"
|
||||
|
@ -5,7 +5,6 @@ from concurrent.futures import CancelledError
|
||||
# Analytics
|
||||
import sentry_sdk
|
||||
from sentry_sdk.integrations.redis import RedisIntegration
|
||||
from mixpanel import Mixpanel
|
||||
|
||||
python36 = True
|
||||
try:
|
||||
@ -90,16 +89,17 @@ def lang(text: str) -> str:
|
||||
return result
|
||||
|
||||
|
||||
analytics = None
|
||||
try:
|
||||
allow_analytics = strtobool(config['allow_analytics'])
|
||||
allow_analytics = strtobool(config['allow_analytic'])
|
||||
except KeyError:
|
||||
allow_analytics = True
|
||||
except ValueError:
|
||||
allow_analytics = True
|
||||
if allow_analytics:
|
||||
mp = Mixpanel("7be1833326f803740214fe276f5a5a3d")
|
||||
else:
|
||||
mp = None
|
||||
import analytics
|
||||
analytics.write_key = 'EI5EyxFl8huwAvv932Au7XoRSdZ63wC4'
|
||||
analytics = analytics
|
||||
if strtobool(config['debug']):
|
||||
logs.setLevel(DEBUG)
|
||||
else:
|
||||
@ -213,11 +213,16 @@ async def save_id():
|
||||
if me.username is not None:
|
||||
sentry_sdk.set_user({"id": user_id, "name": me.first_name, "username": me.username, "ip_address": "{{auto}}"})
|
||||
if allow_analytics:
|
||||
mp.people_set(str(user_id), {'$first_name': me.first_name, "username": me.username})
|
||||
analytics.identify(user_id, {
|
||||
'name': me.first_name,
|
||||
'username': me.username
|
||||
})
|
||||
else:
|
||||
sentry_sdk.set_user({"id": user_id, "name": me.first_name, "ip_address": "{{auto}}"})
|
||||
if allow_analytics:
|
||||
mp.people_set(str(user_id), {'$first_name': me.first_name})
|
||||
analytics.identify(user_id, {
|
||||
'name': me.first_name
|
||||
})
|
||||
logs.info(f"{lang('save_id')} {me.first_name}({user_id})")
|
||||
|
||||
|
||||
|
@ -8,11 +8,11 @@ from distutils2.util import strtobool
|
||||
from traceback import format_exc
|
||||
from time import gmtime, strftime, time
|
||||
from telethon.events import StopPropagation
|
||||
from pagermaid import bot, config, help_messages, logs, mp, user_id
|
||||
from pagermaid import bot, config, help_messages, logs, user_id, analytics
|
||||
from pagermaid.utils import attach_report, lang, alias_command
|
||||
|
||||
try:
|
||||
allow_analytics = strtobool(config['allow_analytics'])
|
||||
allow_analytics = strtobool(config['allow_analytic'])
|
||||
except KeyError:
|
||||
allow_analytics = True
|
||||
except ValueError:
|
||||
@ -57,7 +57,7 @@ def listener(**args):
|
||||
|
||||
async def handler(context):
|
||||
try:
|
||||
analytics = True
|
||||
analytic = True
|
||||
try:
|
||||
parameter = context.pattern_match.group(1).split(' ')
|
||||
if parameter == ['']:
|
||||
@ -65,23 +65,23 @@ def listener(**args):
|
||||
context.parameter = parameter
|
||||
context.arguments = context.pattern_match.group(1)
|
||||
except BaseException:
|
||||
analytics = False
|
||||
analytic = False
|
||||
context.parameter = None
|
||||
context.arguments = None
|
||||
await function(context)
|
||||
if analytics and allow_analytics:
|
||||
if analytic and allow_analytics:
|
||||
try:
|
||||
upload_command = context.text.split()[0].replace('-', '')
|
||||
upload_command = alias_command(upload_command)
|
||||
if context.sender_id:
|
||||
if context.sender_id > 0:
|
||||
mp.track(str(context.sender_id), f'Function {upload_command}',
|
||||
analytics.track(context.sender_id, f'Function {upload_command}',
|
||||
{'command': upload_command})
|
||||
else:
|
||||
mp.track(str(user_id), f'Function {upload_command}',
|
||||
analytics.track(user_id, f'Function {upload_command}',
|
||||
{'command': upload_command})
|
||||
else:
|
||||
mp.track(str(user_id), f'Function {upload_command}',
|
||||
analytics.track(user_id, f'Function {upload_command}',
|
||||
{'command': upload_command})
|
||||
except Exception as e:
|
||||
logs.info(f"Analytics Error ~ {e}")
|
||||
@ -110,7 +110,9 @@ def listener(**args):
|
||||
await attach_report(report, f"exception.{time()}.pagermaid", None,
|
||||
"Error report generated.")
|
||||
try:
|
||||
sentry_sdk.set_context("Target", {"ChatID": str(context.chat_id), "UserID": str(context.sender_id), "Msg": context.text})
|
||||
sentry_sdk.set_context("Target",
|
||||
{"ChatID": str(context.chat_id), "UserID": str(context.sender_id),
|
||||
"Msg": context.text})
|
||||
sentry_sdk.set_tag('com', re.findall("\w+", str.lower(context.text.split()[0]))[0])
|
||||
sentry_sdk.capture_exception(e)
|
||||
except:
|
||||
|
@ -36,5 +36,5 @@ python-socks[asyncio]>=1.2.4
|
||||
certifi>=2021.5.30
|
||||
magic_google>=0.2.9
|
||||
sentry-sdk>=1.3.0
|
||||
mixpanel>=4.9.0
|
||||
analytics-python>=1.4.0
|
||||
beautifulsoup4>=4.9.3
|
||||
|
Loading…
Reference in New Issue
Block a user