fix some bugs

This commit is contained in:
xtaodada 2021-07-02 20:04:08 +08:00
parent e2e781cb85
commit cfd94e667a
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
9 changed files with 55 additions and 22 deletions

12
dme.py
View File

@ -2,7 +2,7 @@
from asyncio import sleep from asyncio import sleep
from os import path, remove from os import path, remove
from os.path import exists from os.path import exists
from PIL import Image from PIL import Image, UnidentifiedImageError
from pagermaid import redis, log, redis_status from pagermaid import redis, log, redis_status
from pagermaid.listener import listener from pagermaid.listener import listener
from pagermaid.utils import alias_command from pagermaid.utils import alias_command
@ -20,14 +20,18 @@ async def dme(context):
remove('plugins/dme.jpg') remove('plugins/dme.jpg')
target_file = reply.photo target_file = reply.photo
await context.client.download_media( await context.client.download_media(
await context.get_reply_message(), file = "plugins/dme.jpg" await context.get_reply_message(), file="plugins/dme.jpg"
) )
await context.edit("替换图片设置完成。") await context.edit("替换图片设置完成。")
elif reply and reply.sticker: elif reply and reply.sticker:
if exists('plugins/dme.jpg'): if exists('plugins/dme.jpg'):
remove('plugins/dme.jpg') remove('plugins/dme.jpg')
await context.client.download_media(reply.media.document, file = "plugins/dme.webp") await context.client.download_media(reply.media.document, file="plugins/dme.webp")
im = Image.open("plugins/dme.webp") try:
im = Image.open("plugins/dme.webp")
except UnidentifiedImageError:
await context.edit("替换图片设置发生错误。")
return
im.save('plugins/dme.png', "png") im.save('plugins/dme.png', "png")
remove('plugins/dme.webp') remove('plugins/dme.webp')
target_file = await context.client.upload_file('plugins/dme.png') target_file = await context.client.upload_file('plugins/dme.png')

5
eat.py
View File

@ -7,6 +7,7 @@ from requests import get
from random import randint from random import randint
from telethon.tl.functions.users import GetFullUserRequest from telethon.tl.functions.users import GetFullUserRequest
from telethon.tl.types import MessageEntityMentionName from telethon.tl.types import MessageEntityMentionName
from telethon.errors.rpcerrorlist import ChatSendStickersForbiddenError
from struct import error as StructError from struct import error as StructError
from pagermaid.listener import listener from pagermaid.listener import listener
from pagermaid.utils import alias_command from pagermaid.utils import alias_command
@ -138,6 +139,8 @@ async def eat(context):
return return
except TypeError: except TypeError:
await context.edit("此用户未设置头像或头像对您不可见。") await context.edit("此用户未设置头像或头像对您不可见。")
except ChatSendStickersForbiddenError:
await context.edit("此群组无法发送贴纸。")
else: else:
try: try:
await context.client.send_file( await context.client.send_file(
@ -155,3 +158,5 @@ async def eat(context):
return return
except TypeError: except TypeError:
await context.edit("此用户未设置头像或头像对您不可见。") await context.edit("此用户未设置头像或头像对您不可见。")
except ChatSendStickersForbiddenError:
await context.edit("此群组无法发送贴纸。")

View File

@ -12,7 +12,7 @@
}, },
{ {
"name": "dme", "name": "dme",
"version": "1.11", "version": "1.12",
"section": "chat", "section": "chat",
"maintainer": "xtaodada", "maintainer": "xtaodada",
"size": "4.3 kb", "size": "4.3 kb",
@ -72,7 +72,7 @@
}, },
{ {
"name": "yb-dl", "name": "yb-dl",
"version": "1.01", "version": "1.02",
"section": "daily", "section": "daily",
"maintainer": "xtaodada", "maintainer": "xtaodada",
"size": "18.8 kb", "size": "18.8 kb",
@ -82,7 +82,7 @@
}, },
{ {
"name": "throwit", "name": "throwit",
"version": "1.611", "version": "1.612",
"section": "profile", "section": "profile",
"maintainer": "xtaodada", "maintainer": "xtaodada",
"size": "6.9 kb", "size": "6.9 kb",
@ -142,7 +142,7 @@
}, },
{ {
"name": "nthmsg", "name": "nthmsg",
"version": "1.01", "version": "1.02",
"section": "chat", "section": "chat",
"maintainer": "seiuneko", "maintainer": "seiuneko",
"size": "0.9 kb", "size": "0.9 kb",
@ -192,7 +192,7 @@
}, },
{ {
"name": "whois", "name": "whois",
"version": "1.13", "version": "1.131",
"section": "daily", "section": "daily",
"maintainer": "KorenKrita", "maintainer": "KorenKrita",
"size": "1.1 kb", "size": "1.1 kb",
@ -202,7 +202,7 @@
}, },
{ {
"name": "eat", "name": "eat",
"version": "1.02", "version": "1.03",
"section": "profile", "section": "profile",
"maintainer": "SF_PICK", "maintainer": "SF_PICK",
"size": "6.4 kb", "size": "6.4 kb",
@ -342,7 +342,7 @@
}, },
{ {
"name": "vip", "name": "vip",
"version": "0.3", "version": "0.31",
"section": "chat", "section": "chat",
"maintainer": "xtaodada", "maintainer": "xtaodada",
"size": "4.0 kb", "size": "4.0 kb",
@ -492,7 +492,7 @@
}, },
{ {
"name": "rape", "name": "rape",
"version": "1.02", "version": "1.03",
"section": "chat", "section": "chat",
"maintainer": "Pentacene", "maintainer": "Pentacene",
"size": "4.0 kb", "size": "4.0 kb",

View File

@ -17,6 +17,10 @@ async def nthmsg(context):
m = object() m = object()
async for m in context.client.iter_messages(context.chat_id, from_user="me", reverse=True, limit=n): async for m in context.client.iter_messages(context.chat_id, from_user="me", reverse=True, limit=n):
pass pass
r = await context.client( try:
functions.channels.ExportMessageLinkRequest(channel=m.to_id, id=m.id, grouped=True)) r = await context.client(
functions.channels.ExportMessageLinkRequest(channel=m.to_id, id=m.id, grouped=True))
except AttributeError:
await context.edit('获取失败。')
return
await context.edit(r.link) await context.edit(r.link)

View File

@ -63,7 +63,11 @@ async def rape(context):
if context.arguments == '': if context.arguments == '':
return return
else: else:
userid = int(context.arguments) try:
userid = int(context.arguments)
except ValueError:
await context.edit('无法识别的账号 id 。')
return
admins = await context.client.get_participants(context.chat, filter=ChannelParticipantsAdmins) admins = await context.client.get_participants(context.chat, filter=ChannelParticipantsAdmins)
if context.sender in admins: if context.sender in admins:
try: try:

View File

@ -7,6 +7,7 @@ from requests import get
from random import randint from random import randint
from telethon.tl.functions.users import GetFullUserRequest from telethon.tl.functions.users import GetFullUserRequest
from telethon.tl.types import MessageEntityMentionName from telethon.tl.types import MessageEntityMentionName
from telethon.errors.rpcerrorlist import ChatSendStickersForbiddenError
from struct import error as StructError from struct import error as StructError
from pagermaid.listener import listener from pagermaid.listener import listener
from pagermaid.utils import alias_command from pagermaid.utils import alias_command
@ -158,6 +159,8 @@ async def throwit(context):
return return
except TypeError: except TypeError:
await context.edit("此用户未设置头像或头像对您不可见。") await context.edit("此用户未设置头像或头像对您不可见。")
except ChatSendStickersForbiddenError:
await context.edit("此群组无法发送贴纸。")
else: else:
try: try:
await context.client.send_file( await context.client.send_file(
@ -174,3 +177,5 @@ async def throwit(context):
return return
except TypeError: except TypeError:
await context.edit("此用户未设置头像或头像对您不可见。") await context.edit("此用户未设置头像或头像对您不可见。")
except ChatSendStickersForbiddenError:
await context.edit("此群组无法发送贴纸。")

6
vip.py
View File

@ -79,13 +79,15 @@ async def pixiv(context):
pixiv_albums = pixiv_list[1].split('|||') pixiv_albums = pixiv_list[1].split('|||')
pixiv_album = [] pixiv_album = []
await context.edit("下载图片中 . . .") await context.edit("下载图片中 . . .")
for i in range(0, len(pixiv_albums)): if len(pixiv_albums) > 8:
await context.edit('获取的图片数大于 8 将只发送前8张图片下载图片中 . . .')
for i in range(0, min(len(pixiv_albums), 8)):
r = get(pixiv_albums[i]) r = get(pixiv_albums[i])
with open("pixiv." + str(i) + ".jpg", "wb") as code: with open("pixiv." + str(i) + ".jpg", "wb") as code:
code.write(r.content) code.write(r.content)
pixiv_album.extend(["pixiv." + str(i) + ".jpg"]) pixiv_album.extend(["pixiv." + str(i) + ".jpg"])
await context.client.send_file(context.chat_id, pixiv_album, await context.client.send_file(context.chat_id, pixiv_album,
caption=pixiv_list[0]) caption=pixiv_list[0])
await context.delete() await context.delete()
for i in pixiv_album: for i in pixiv_album:
try: try:

View File

@ -16,7 +16,11 @@ async def whois(context):
return return
req = get("https://tenapi.cn/whois/?url=" + message) req = get("https://tenapi.cn/whois/?url=" + message)
if req.status_code == 200: if req.status_code == 200:
data = json.loads(req.text)['data'] try:
data = json.loads(req.text)['data']
except KeyError:
await context.edit("出错了呜呜呜 ~ 可能是域名不正确。")
return
res = '域名: `' + data['url'] + '`\n注册商: `' + str(data['registrar']) + '`\n联系人: `' + str( res = '域名: `' + data['url'] + '`\n注册商: `' + str(data['registrar']) + '`\n联系人: `' + str(
data['registrant']) + '`\n联系邮箱: `' + str(data['mail']) + '`\n注册时间: `' + str( data['registrant']) + '`\n联系邮箱: `' + str(data['mail']) + '`\n注册时间: `' + str(
data['registration']) + '`\n过期时间: `' + str(data['expiration']) + '`\nDNS ' + str(data['dns']).replace( data['registration']) + '`\n过期时间: `' + str(data['expiration']) + '`\nDNS ' + str(data['dns']).replace(

View File

@ -3,6 +3,7 @@
from os import remove from os import remove
from os.path import exists from os.path import exists
from youtube_dl import YoutubeDL from youtube_dl import YoutubeDL
from youtube_dl.utils import DownloadError
from re import compile as regex_compile from re import compile as regex_compile
from pagermaid import bot, log from pagermaid import bot, log
from pagermaid.listener import listener from pagermaid.listener import listener
@ -26,16 +27,20 @@ async def ybdl(context):
bilibili_pattern = regex_compile(r"^(http(s)?://)?((w){3}.)?bilibili(\.com)?/.+") bilibili_pattern = regex_compile(r"^(http(s)?://)?((w){3}.)?bilibili(\.com)?/.+")
youtube_pattern = regex_compile(r"^(http(s)?://)?((w){3}.)?youtu(be|.be)?(\.com)?/.+") youtube_pattern = regex_compile(r"^(http(s)?://)?((w){3}.)?youtu(be|.be)?(\.com)?/.+")
if youtube_pattern.match(url): if youtube_pattern.match(url):
if not await fetch_video(url, context.chat_id, reply_id): try:
await context.edit("出错了呜呜呜 ~ 视频下载失败。") if not await fetch_video(url, context.chat_id, reply_id):
await log(f"已拉取UTB视频地址 {url}.") await context.edit("出错了呜呜呜 ~ 视频下载失败。")
await context.edit("视频获取成功!") await log(f"已拉取UTB视频地址 {url}.")
await context.edit("视频获取成功!")
except DownloadError:
await context.edit("视频下载失败,可能是视频受到 DRM 保护。")
if bilibili_pattern.match(url): if bilibili_pattern.match(url):
if not await fetch_video(url, context.chat_id, reply_id): if not await fetch_video(url, context.chat_id, reply_id):
await context.edit("出错了呜呜呜 ~ 视频下载失败。") await context.edit("出错了呜呜呜 ~ 视频下载失败。")
await log(f"已拉取 Bilibili 视频,地址: {url}.") await log(f"已拉取 Bilibili 视频,地址: {url}.")
await context.edit("视频获取成功!") await context.edit("视频获取成功!")
async def fetch_video(url, chat_id, reply_id): async def fetch_video(url, chat_id, reply_id):
""" Extracts and uploads YouTube video. """ """ Extracts and uploads YouTube video. """
youtube_dl_options = { youtube_dl_options = {