diff --git a/acg-multi.py b/acg-multi.py index ebc35f4..2a498dc 100644 --- a/acg-multi.py +++ b/acg-multi.py @@ -1,17 +1,17 @@ import json import random import requests -from time import sleep from pagermaid.listener import listener +from pagermaid.utils import alias_command from os import remove -@listener(is_plugin=True, outgoing=True, command="acgm", +@listener(is_plugin=True, outgoing=True, command=alias_command("acgm"), description="多网站随机获取二刺螈(bushi) ACG图片") async def joke(context): await context.edit("获取中 . . .") status = False - for _ in range (20): #最多重试20次 + for _ in range(20): # 最多重试20次 website = random.randint(0, 6) filename = "acgm" + str(random.random())[2:] + ".png" try: @@ -24,9 +24,11 @@ async def joke(context): elif website == 3: img = requests.get("https://www.yunboys.cn/sjbz/api.php?method=mobile&lx=dongman") elif website == 4: - headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063','Referer':'https://osk.soloop.ooo/give_me_eropics-l/'} - img = requests.get("https://osk.soloop.ooo/rdm.php?"+ str(random.random()), headers=headers) - elif website == 5: + headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, ' + 'like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063', + 'Referer': 'https://osk.soloop.ooo/give_me_eropics-l/'} + img = requests.get("https://osk.soloop.ooo/rdm.php?" + str(random.random()), headers=headers) + else: img = requests.get('https://api.lolicon.app/setu/?r18=0') if img.status_code == 200: if website == 5: @@ -34,13 +36,13 @@ async def joke(context): img = tmp['data'][0]['url'] img = requests.get(img) if img.status_code != 200: - continue #如果返回不正常就赶紧下一回 + continue # 如果返回不正常就赶紧下一回 with open(filename, 'wb') as f: f.write(img.content) await context.edit("上传中 . . .") - await context.client.send_file(context.chat_id,filename) + await context.client.send_file(context.chat_id, filename) status = True - break #成功了就赶紧结束啦! + break # 成功了就赶紧结束啦! except: try: remove(filename) @@ -64,4 +66,4 @@ async def joke(context): await context.delete() except: pass - await context.client.send_message(context.chat_id,"出错了呜呜呜 ~ 试了好多好多次都无法访问到服务器 。") \ No newline at end of file + await context.client.send_message(context.chat_id, "出错了呜呜呜 ~ 试了好多好多次都无法访问到服务器 。") diff --git a/aff.py b/aff.py index 055cade..c9e94e8 100644 --- a/aff.py +++ b/aff.py @@ -1,14 +1,15 @@ from time import sleep from os.path import exists from os import mkdir, remove -from pagermaid import redis, log, redis_status +from pagermaid.utils import alias_command from pagermaid.listener import listener -@listener(is_plugin=True, outgoing=True, command="aff", + +@listener(is_plugin=True, outgoing=True, command=alias_command("aff"), description="在别人要打算买机场的时候光速发出自己的aff信息(请尽量配合短链接)", parameters=" (可选,用于保存|删除aff信息)") async def aff(context): - if not context.parameter: #发送aff信息 + if not context.parameter: # 发送aff信息 try: with open("plugins/AffExtra/aff.txt", "r", encoding="UTF-8") as f: msg = f.read() @@ -23,7 +24,7 @@ async def aff(context): await context.edit("出错了呜呜呜 ~ 信息无变化。") sleep(3) await context.delete() - elif context.parameter[0] == "save": #保存aff信息 + elif context.parameter[0] == "save": # 保存aff信息 reply = await context.get_reply_message() if not reply: await context.edit("出错了呜呜呜 ~ 请回复一条消息以保存新的Aff信息。") @@ -36,7 +37,7 @@ async def aff(context): await context.edit("好耶 ! Aff信息保存成功。") sleep(3) await context.delete() - elif context.parameter[0] == "remove": #删除aff信息 + elif context.parameter[0] == "remove": # 删除aff信息 try: remove("plugins/AffExtra/aff.txt") await context.edit("好耶 ! Aff信息删除成功。") @@ -47,4 +48,4 @@ async def aff(context): else: await context.edit("出错了呜呜呜 ~ 无效的参数。") sleep(3) - await context.delete() \ No newline at end of file + await context.delete() diff --git a/atadmins_atall.py b/atadmins_atall.py index 22fb17e..1dc018c 100644 --- a/atadmins_atall.py +++ b/atadmins_atall.py @@ -1,12 +1,10 @@ from telethon.tl.types import ChannelParticipantsAdmins -from pagermaid import bot +from pagermaid.utils import alias_command from pagermaid.listener import listener -from telethon.errors.rpcbaseerrors import BadRequestError -from os import remove -import re import time -@listener(is_plugin=True, outgoing=True, command="atadmins", + +@listener(is_plugin=True, outgoing=True, command=alias_command("atadmins"), description="一键 AT 本群管理员(仅在群组中有效)", parameters="回复消息(可选) <要说的话(可选)>") async def atadmins(context): @@ -25,7 +23,7 @@ async def atadmins(context): for admin in admins: if not admin.bot: if admin.username is not None: - admin_list.extend(['@'+ admin.username]) + admin_list.extend(['@' + admin.username]) elif admin.first_name is not None: admin_list.extend(['[' + admin.first_name + '](tg://user?id=' + str(admin.id) + ')']) send_list = ' , '.join(admin_list) @@ -36,7 +34,8 @@ async def atadmins(context): await context.reply(f'{say}:\n{send_list}') await context.delete() -@listener(is_plugin=True, outgoing=True, command="atall", + +@listener(is_plugin=True, outgoing=True, command=alias_command("atall"), description="一键 AT 本群成员(仅在群组中有效)", parameters="回复消息(可选) <要说的话(可选)>") async def atall(context): @@ -56,7 +55,7 @@ async def atall(context): if not user.bot: if len(user_list) < 128: if user.username is not None: - user_list.extend(['@'+ user.username]) + user_list.extend(['@' + user.username]) elif user.first_name is not None: user_list.extend(['[' + user.first_name + '](tg://user?id=' + str(user.id) + ')']) else: diff --git a/autochangename.py b/autochangename.py index 0ddf594..eed2e4c 100644 --- a/autochangename.py +++ b/autochangename.py @@ -7,6 +7,7 @@ from telethon.tl.functions.account import UpdateProfileRequest from emoji import emojize from pagermaid import bot, log from pagermaid.listener import listener +from pagermaid.utils import alias_command dizzy = emojize(":dizzy:", use_aliases=True) cake = emojize(":cake:", use_aliases=True) @@ -14,7 +15,7 @@ all_time_emoji_name = ["clock12", "clock1230", "clock1", "clock130", "clock2", " time_emoji_symb = [emojize(":%s:" %s, use_aliases=True) for s in all_time_emoji_name] -@listener(is_plugin=True, outgoing=True, command="autochangename", +@listener(is_plugin=True, outgoing=True, command=alias_command("autochangename"), description="每 30 秒更新一次 last_name") async def change_name_auto(context): await context.delete() diff --git a/autoreplysticker.py b/autoreplysticker.py index 6b2e527..cb0f1fa 100644 --- a/autoreplysticker.py +++ b/autoreplysticker.py @@ -18,6 +18,8 @@ from telethon.tl.functions.messages import GetStickerSetRequest from telethon.tl.types import InputStickerSetID from pagermaid import log from pagermaid.listener import listener +from pagermaid.utils import alias_command + async def ars_check(message: Message) -> None: try: @@ -43,14 +45,15 @@ async def ars_check(message: Message) -> None: await sleep(15) await _noti.delete() + async def ars_getall(message: Message) -> None: sticker_sets = await message.client(GetAllStickersRequest(0)) sticker_pack_list = [] for sticker_set in sticker_sets.sets: if len(sticker_pack_list) < 10: text = "我发现了一个Sticker Pack,名为\n" + sticker_set.title + "\n" + "ID为: `" + \ - str(sticker_set.id) + "` \n" + "Hash为: `" + str(sticker_set.access_hash) + \ - "` \n" + "共有" + str(sticker_set.count) + "张" + str(sticker_set.id) + "` \n" + "Hash为: `" + str(sticker_set.access_hash) + \ + "` \n" + "共有" + str(sticker_set.count) + "张" sticker_pack_list.extend([text]) else: sticker_pack_list_old = sticker_pack_list @@ -62,6 +65,7 @@ async def ars_getall(message: Message) -> None: await message.client.send_message(message.chat_id, sendtext) await message.delete() + async def ars_help(message: Message) -> None: await message.reply( '欢迎使用自动回复贴纸\n' @@ -74,6 +78,7 @@ async def ars_help(message: Message) -> None: '如有使用问题,请前往 [这里](https://t.me/PagerMaid_Modify) 请求帮助') await message.delete() + async def ars_whitelist(message: Message) -> None: chat_id = str(message.chat_id) try: @@ -108,6 +113,7 @@ async def ars_whitelist(message: Message) -> None: await sleep(5) await _noti.delete() + def set_state(name: str, state: list) -> None: file_name = "./plugins/autoreplysticker/config.yml" if exists(file_name): @@ -121,11 +127,12 @@ def set_state(name: str, state: list) -> None: with open(file_name, 'w', encoding='utf-8') as f: yaml.dump(dc, f) + def get_name(sender: Message.sender) -> str: """ get_name(Message.sender) """ - username = sender.username + username = sender.username first_name = sender.first_name last_name = sender.last_name _id = sender.id @@ -138,6 +145,7 @@ def get_name(sender: Message.sender) -> str: name = f'@{username}' return name + def process_link(chatid: int, msgid: int) -> str: """ process_link(chat_id, message_id) @@ -152,11 +160,12 @@ def process_link(chatid: int, msgid: int) -> str: link = f'https://t.me/c/{chatid}/{msgid}' return link -@listener(is_plugin=True, outgoing=True, command="ars") + +@listener(is_plugin=True, outgoing=True, command=alias_command("ars")) async def ars(context): if not exists('./plugins/autoreplysticker'): mkdir('./plugins/autoreplysticker') - + if len(context.parameter) == 0: await ars_help(context) return @@ -183,7 +192,7 @@ async def ars(context): await sleep(10) await _noti.delete() await ars_check(context) - + elif context.parameter[0] == 'check': await ars_check(context) elif context.parameter[0] == 'getall': @@ -193,13 +202,14 @@ async def ars(context): elif context.parameter[0] == 'w': await ars_whitelist(context) + @listener(incoming=True, ignore_edited=True) async def process_message(context): reply_user_id = 0 link = process_link(context.chat_id, context.id) me = await context.client.get_me() + reply = await context.get_reply_message() try: - reply = await context.get_reply_message() reply_user_id = reply.sender.id if context.sticker: return @@ -207,7 +217,7 @@ async def process_message(context): return except: pass - + try: config = yaml.load(open(r"./plugins/autoreplysticker/config.yml"), Loader=yaml.FullLoader) _sticker_id = int(config['sticker_id']) @@ -228,19 +238,20 @@ async def process_message(context): except: pass - if (reply and reply_user_id == me.id): + if reply and reply_user_id == me.id: stickers = await context.client( GetStickerSetRequest( stickerset=InputStickerSetID( id=_sticker_id, access_hash=_sticker_hash))) try: - i = randint(0, len(_num)-1) + i = randint(0, len(_num) - 1) sticker = await context.client.send_file( context.chat_id, stickers.documents[int(_num[i])], reply_to=context.id) await sleep(_time) await sticker.delete() - await log(f'#被回复\n在 [{context.chat.title}]({process_link(context.chat_id, context.id)})\n获得了 {get_name(context.sender)} 的回复') + await log( + f'#被回复\n在 [{context.chat.title}]({process_link(context.chat_id, context.id)})\n获得了 {get_name(context.sender)} 的回复') except: pass diff --git a/autorespond.py b/autorespond.py index 6ac6798..58b380b 100644 --- a/autorespond.py +++ b/autorespond.py @@ -3,11 +3,12 @@ from telethon.events import StopPropagation from pagermaid import persistent_vars, log from pagermaid.listener import listener +from pagermaid.utils import alias_command persistent_vars.update({'autorespond': {'enabled': False, 'message': None, 'amount': 0}}) -@listener(is_plugin=True, outgoing=True, command="autorespond", +@listener(is_plugin=True, outgoing=True, command=alias_command("autorespond"), description="启用自动回复。", parameters="") async def autorespond(context): diff --git a/autorm.py b/autorm.py index 398722e..4840020 100644 --- a/autorm.py +++ b/autorm.py @@ -5,14 +5,15 @@ try: import dateparser + imported = True except ImportError: imported = False import asyncio, time, traceback -from pagermaid import log from pagermaid.listener import listener -from datetime import datetime +from pagermaid.utils import alias_command + # https://stackoverflow.com/questions/1111056/get-time-zone-information-of-the-system-in-python def local_time_offset(t=None): @@ -26,6 +27,7 @@ def local_time_offset(t=None): else: return -time.timezone + offset = local_time_offset() // 3600 sign = "+" if offset >= 0 else "-" offset = abs(offset) @@ -56,6 +58,7 @@ i.e. 取消所有群和全局 -autorm cancelall """ + @listener(outgoing=True, ignore_edited=True) async def remove_message(context): """ Event handler to infinitely remove messages. """ @@ -82,12 +85,15 @@ async def remove_message(context): except Exception as e: await sendmsg(context, await context.get_chat(), str(e)) -@listener(is_plugin=True, outgoing=True, command="autorm", diagnostics=True, ignore_edited=False, + +@listener(is_plugin=True, outgoing=True, command=alias_command("autorm"), + diagnostics=True, ignore_edited=False, description=helpmsg, parameters="