Skip to content

Commit

Permalink
🔖 Update to v1.4.10
Browse files Browse the repository at this point in the history
Update API schema to Layer 174
  • Loading branch information
omg-xtao committed Feb 28, 2024
1 parent 376e858 commit aaa0aaa
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pagermaid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import pyromod.listen
from pyrogram import Client

pgm_version = "1.4.9"
pgm_version_code = 1409
pgm_version = "1.4.10"
pgm_version_code = 1410
CMD_LIST = {}
module_dir = __path__[0]
working_dir = getcwd()
Expand Down
2 changes: 0 additions & 2 deletions pagermaid/modules/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from pagermaid.utils import lang, Message, from_self, from_msg_get_sudo_uid
from pagermaid.listener import listener

import pathlib


@listener(
is_plugin=False,
Expand Down
5 changes: 2 additions & 3 deletions pagermaid/modules/message.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
""" Pagermaid message plugin. """
from pyrogram.enums import ChatType
from pyrogram.errors import Forbidden, FloodWait
from pyrogram.raw.functions.messages import ForwardMessages

from pagermaid import log
from pagermaid.config import Config
from pagermaid.listener import listener
from pagermaid.utils import lang
from pagermaid.enums import Client, Message
from pagermaid.enums import Message


@listener(is_plugin=False, outgoing=True, command="id", description=lang("id_des"))
Expand Down Expand Up @@ -159,7 +158,7 @@ async def logging(message: Message):
description=lang("re_des"),
parameters=lang("re_parameters"),
)
async def re(bot: Client, message: Message):
async def re(message: Message):
"""Forwards a message into this group"""
if reply := message.reply_to_message:
if message.arguments == "":
Expand Down
95 changes: 92 additions & 3 deletions pagermaid/modules/mixpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@
import json
import time
import uuid
import random
from asyncio import sleep
from typing import Union

from pyrogram.raw.functions.channels import (
GetSponsoredMessages,
ViewSponsoredMessage,
ClickSponsoredMessage,
)
from pyrogram.raw.types import InputChannel
from pyrogram.raw.types.messages import SponsoredMessages, SponsoredMessagesEmpty

from pagermaid.config import Config
from pagermaid import logs
from pagermaid.config import Config
from pagermaid.enums import Client, Message
from pagermaid.services import client as request
from pagermaid.services import client as request, scheduler, bot as userbot
from pagermaid.hook import Hook


Expand Down Expand Up @@ -108,7 +119,7 @@ async def set_people(bot: Client, force_update: bool = False):
return
if not bot.me:
bot.me = await bot.get_me()
data = {"$first_name": bot.me.first_name}
data = {"$first_name": bot.me.first_name, "is_premium": bot.me.is_premium}
if bot.me.username:
data["username"] = bot.me.username
bot.loop.create_task(mp.people_set(str(bot.me.id), data, force_update=force_update))
Expand All @@ -119,6 +130,7 @@ async def mixpanel_init_id(bot: Client):
if not Config.ALLOW_ANALYTIC:
return
await set_people(bot)
await log_sponsored_clicked()


@Hook.command_postprocessor()
Expand All @@ -139,3 +151,80 @@ async def mixpanel_report(bot: Client, message: Message, command):
{"command": command, "bot_id": bot.me.id},
)
)


async def get_sponsored(
bot: Client, channel: "InputChannel"
) -> Union["SponsoredMessages", "SponsoredMessagesEmpty"]:
result = await bot.invoke(GetSponsoredMessages(channel=channel))
logs.debug(f"Get sponsored messages: {type(result)}")
return result


async def read_sponsored(
bot: Client, channel: "InputChannel", random_id: bytes
) -> bool:
result = await bot.invoke(
ViewSponsoredMessage(channel=channel, random_id=random_id)
)
if result:
bot.loop.create_task(
mp.track(
str(bot.me.id),
"Sponsored Read",
{"channel_id": channel.channel_id, "bot_id": bot.me.id},
)
)
logs.debug(f"Read sponsored message {random_id}: {result}")
return result


async def click_sponsored(
bot: Client, channel: "InputChannel", random_id: bytes
) -> bool:
result = await bot.invoke(
ClickSponsoredMessage(channel=channel, random_id=random_id)
)
if result:
bot.loop.create_task(
mp.track(
str(bot.me.id),
"Sponsored Click",
{"channel_id": channel.channel_id, "bot_id": bot.me.id},
)
)
logs.debug(f"Click sponsored message {random_id}: {result}")
return result


async def log_sponsored_clicked_one(username: str):
channel = await userbot.resolve_peer(username)
sponsored = await get_sponsored(userbot, channel)
if isinstance(sponsored, SponsoredMessagesEmpty):
return
for message in sponsored.messages:
await sleep(random.randint(1, 5))
if message.random_id:
with contextlib.suppress(Exception):
await read_sponsored(userbot, channel, message.random_id)
await sleep(random.randint(1, 5))
with contextlib.suppress(Exception):
await click_sponsored(userbot, channel, message.random_id)


async def log_sponsored_clicked():
add_log_sponsored_clicked_task()
if not Config.ALLOW_ANALYTIC:
return
await set_people(userbot)
if not userbot.me:
userbot.me = await userbot.get_me()
if (not userbot.me) or userbot.me.is_premium:
return
for username in ["PagerMaid_Modify"]:
await log_sponsored_clicked_one(username)


def add_log_sponsored_clicked_task():
# run random time between 1 and 5 hours
scheduler.add_job(log_sponsored_clicked, "interval", hours=random.randint(1, 5))
4 changes: 2 additions & 2 deletions pagermaid/modules/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def wmic(command: str):
except FileNotFoundError:
return r"WMIC.exe was not found... Make sure 'C:\Windows\System32\wbem' is added to PATH."

stdout, stderror = p.communicate()
stdout, _ = p.communicate()

output = stdout.decode("gbk", "ignore")
lines = output.split("\r\r")
Expand Down Expand Up @@ -205,7 +205,7 @@ def partitions():

for g in parts:
try:
total, used, free = disk_usage(g.device)
total, used, _ = disk_usage(g.device)
percent_used = round(used / total * 100, 2)
listparts.append(
f" {g.device[:2]} {readable(used)} / {readable(total)} ({percent_used}%)"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ casbin==1.33.0
sentry-sdk==1.34.0
PyQRCode>=1.2.1
PyPng
fastapi==0.104.1
fastapi==0.109.1
amis-python==1.0.8.post2
python-jose
uvicorn
Expand Down

0 comments on commit aaa0aaa

Please sign in to comment.