diff --git a/config.gen.yml b/config.gen.yml index 62188e2..290649d 100644 --- a/config.gen.yml +++ b/config.gen.yml @@ -75,4 +75,4 @@ update_delete: "True" ipv6: "False" # Analytics -allow_analytics: "True" +allow_analytic: "True" diff --git a/pagermaid/__init__.py b/pagermaid/__init__.py index c05e650..352014d 100644 --- a/pagermaid/__init__.py +++ b/pagermaid/__init__.py @@ -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})") diff --git a/pagermaid/listener.py b/pagermaid/listener.py index 847227c..5529d7f 100644 --- a/pagermaid/listener.py +++ b/pagermaid/listener.py @@ -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,24 +65,24 @@ 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}', - {'command': upload_command}) + analytics.track(context.sender_id, f'Function {upload_command}', + {'command': upload_command}) else: - mp.track(str(user_id), f'Function {upload_command}', - {'command': upload_command}) + analytics.track(user_id, f'Function {upload_command}', + {'command': upload_command}) else: - mp.track(str(user_id), f'Function {upload_command}', - {'command': upload_command}) + analytics.track(user_id, f'Function {upload_command}', + {'command': upload_command}) except Exception as e: logs.info(f"Analytics Error ~ {e}") except StopPropagation: @@ -110,8 +110,10 @@ 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_tag('com', re.findall("\w+",str.lower(context.text.split()[0]))[0]) + 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: logs.info( diff --git a/requirements.txt b/requirements.txt index d1b6de1..8a423ca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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