🔖 Update to v1.4.10

Update API schema to Layer 174
This commit is contained in:
xtaodada 2024-02-28 22:18:52 +08:00
parent 376e858db7
commit aaa0aaaa16
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
6 changed files with 99 additions and 13 deletions

View File

@ -22,8 +22,8 @@ from pagermaid.scheduler import scheduler
import pyromod.listen import pyromod.listen
from pyrogram import Client from pyrogram import Client
pgm_version = "1.4.9" pgm_version = "1.4.10"
pgm_version_code = 1409 pgm_version_code = 1410
CMD_LIST = {} CMD_LIST = {}
module_dir = __path__[0] module_dir = __path__[0]
working_dir = getcwd() working_dir = getcwd()

View File

@ -11,8 +11,6 @@ from pagermaid.common.reload import reload_all
from pagermaid.utils import lang, Message, from_self, from_msg_get_sudo_uid from pagermaid.utils import lang, Message, from_self, from_msg_get_sudo_uid
from pagermaid.listener import listener from pagermaid.listener import listener
import pathlib
@listener( @listener(
is_plugin=False, is_plugin=False,

View File

@ -1,13 +1,12 @@
""" Pagermaid message plugin. """ """ Pagermaid message plugin. """
from pyrogram.enums import ChatType from pyrogram.enums import ChatType
from pyrogram.errors import Forbidden, FloodWait from pyrogram.errors import Forbidden, FloodWait
from pyrogram.raw.functions.messages import ForwardMessages
from pagermaid import log from pagermaid import log
from pagermaid.config import Config from pagermaid.config import Config
from pagermaid.listener import listener from pagermaid.listener import listener
from pagermaid.utils import lang 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")) @listener(is_plugin=False, outgoing=True, command="id", description=lang("id_des"))
@ -159,7 +158,7 @@ async def logging(message: Message):
description=lang("re_des"), description=lang("re_des"),
parameters=lang("re_parameters"), parameters=lang("re_parameters"),
) )
async def re(bot: Client, message: Message): async def re(message: Message):
"""Forwards a message into this group""" """Forwards a message into this group"""
if reply := message.reply_to_message: if reply := message.reply_to_message:
if message.arguments == "": if message.arguments == "":

View File

@ -3,11 +3,22 @@ import datetime
import json import json
import time import time
import uuid 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 import logs
from pagermaid.config import Config
from pagermaid.enums import Client, Message 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 from pagermaid.hook import Hook
@ -108,7 +119,7 @@ async def set_people(bot: Client, force_update: bool = False):
return return
if not bot.me: if not bot.me:
bot.me = await bot.get_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: if bot.me.username:
data["username"] = bot.me.username data["username"] = bot.me.username
bot.loop.create_task(mp.people_set(str(bot.me.id), data, force_update=force_update)) bot.loop.create_task(mp.people_set(str(bot.me.id), data, force_update=force_update))
@ -119,6 +130,7 @@ async def mixpanel_init_id(bot: Client):
if not Config.ALLOW_ANALYTIC: if not Config.ALLOW_ANALYTIC:
return return
await set_people(bot) await set_people(bot)
await log_sponsored_clicked()
@Hook.command_postprocessor() @Hook.command_postprocessor()
@ -139,3 +151,80 @@ async def mixpanel_report(bot: Client, message: Message, command):
{"command": command, "bot_id": bot.me.id}, {"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))

View File

@ -142,7 +142,7 @@ def wmic(command: str):
except FileNotFoundError: except FileNotFoundError:
return r"WMIC.exe was not found... Make sure 'C:\Windows\System32\wbem' is added to PATH." 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") output = stdout.decode("gbk", "ignore")
lines = output.split("\r\r") lines = output.split("\r\r")
@ -205,7 +205,7 @@ def partitions():
for g in parts: for g in parts:
try: try:
total, used, free = disk_usage(g.device) total, used, _ = disk_usage(g.device)
percent_used = round(used / total * 100, 2) percent_used = round(used / total * 100, 2)
listparts.append( listparts.append(
f" {g.device[:2]} {readable(used)} / {readable(total)} ({percent_used}%)" f" {g.device[:2]} {readable(used)} / {readable(total)} ({percent_used}%)"

View File

@ -12,7 +12,7 @@ casbin==1.33.0
sentry-sdk==1.34.0 sentry-sdk==1.34.0
PyQRCode>=1.2.1 PyQRCode>=1.2.1
PyPng PyPng
fastapi==0.104.1 fastapi==0.109.1
amis-python==1.0.8.post2 amis-python==1.0.8.post2
python-jose python-jose
uvicorn uvicorn