📈 Add user Experience Program. (#108)

* 📈 添加用户体验计划。
This commit is contained in:
Xtao_dada 2021-07-18 01:25:54 +08:00 committed by GitHub
parent 20346db737
commit 57c16d4d42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 6 deletions

View File

@ -73,3 +73,6 @@ update_delete: "True"
# ipv6
ipv6: "False"
# Analytics
allow_analytics: "True"

View File

@ -2,8 +2,10 @@
from concurrent.futures import CancelledError
# Analytics
import sentry_sdk
from sentry_sdk.integrations.redis import RedisIntegration
from mixpanel import Mixpanel
python36 = True
try:
@ -41,6 +43,7 @@ module_dir = __path__[0]
working_dir = getcwd()
config = None
help_messages = {}
mp = Mixpanel("7be1833326f803740214fe276f5a5a3d")
logs = getLogger(__name__)
logging_format = "%(levelname)s [%(asctime)s] [%(name)s] %(message)s"
logging_handler = StreamHandler()
@ -190,16 +193,21 @@ elif not mtp_addr == '' and not mtp_port == '' and not mtp_secret == '':
use_ipv6=use_ipv6)
else:
bot = TelegramClient("pagermaid", api_key, api_hash, auto_reconnect=True, use_ipv6=use_ipv6)
user_id = 0
redis = StrictRedis(host=redis_host, port=redis_port, db=redis_db)
async def save_id():
global user_id
me = await bot.get_me()
user_id = me.id
if me.username is not None:
sentry_sdk.set_user({"id": me.id, "name": me.first_name, "username": me.username, "ip_address": "{{auto}}"})
sentry_sdk.set_user({"id": user_id, "name": me.first_name, "username": me.username, "ip_address": "{{auto}}"})
mp.people_set(str(user_id), {'$first_name': me.first_name, "username": me.username})
else:
sentry_sdk.set_user({"id": me.id, "name": me.first_name, "ip_address": "{{auto}}"})
logs.info(f"{lang('save_id')} {me.first_name}({me.id})")
sentry_sdk.set_user({"id": user_id, "name": me.first_name, "ip_address": "{{auto}}"})
mp.people_set(str(user_id), {'$first_name': me.first_name})
logs.info(f"{lang('save_id')} {me.first_name}({user_id})")
with bot:

View File

@ -8,9 +8,16 @@ 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
from pagermaid import bot, config, help_messages, logs, mp, user_id
from pagermaid.utils import attach_report, lang
try:
allow_analytics = strtobool(config['allow_analytics'])
except KeyError:
allow_analytics = True
except ValueError:
allow_analytics = True
def noop(*args, **kw):
pass
@ -50,6 +57,7 @@ def listener(**args):
async def handler(context):
try:
analytics = True
try:
parameter = context.pattern_match.group(1).split(' ')
if parameter == ['']:
@ -57,9 +65,25 @@ def listener(**args):
context.parameter = parameter
context.arguments = context.pattern_match.group(1)
except BaseException:
analytics = False
context.parameter = None
context.arguments = None
await function(context)
if analytics:
try:
upload_command = context.text.split()[0].replace('-', '')
if context.sender_id:
if context.sender_id > 0:
mp.track(str(context.sender_id), f'Function {upload_command}',
{'command': upload_command})
else:
mp.track(str(user_id), f'Function {upload_command}',
{'command': upload_command})
else:
mp.track(str(user_id), f'Function {upload_command}',
{'command': upload_command})
except Exception as e:
logs.info(f"Analytics Error ~ {e}")
except StopPropagation:
raise StopPropagation
except MessageTooLongError:

View File

@ -17,7 +17,7 @@ translate>=3.5.0
gTTS>=2.2.2
gTTS-token>=1.1.4
wordcloud>=1.8.1
Telethon>=1.22.0
Telethon>=1.23.0
Pillow>=8.2.0
python-magic>=0.4.24
Pygments>=2.9.0
@ -35,4 +35,5 @@ cheroot>=8.5.2
python-socks[asyncio]>=1.2.4
certifi>=2021.5.30
magic_google>=0.2.9
sentry-sdk>=1.1.0
sentry-sdk>=1.3.0
mixpanel>=4.9.0