mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-24 09:53:36 +00:00
autocaption 自动获取所发送文件的信息。
This commit is contained in:
parent
00fe3ee7fd
commit
166c628ed7
46
autocaption.py
Normal file
46
autocaption.py
Normal file
@ -0,0 +1,46 @@
|
||||
from pagermaid import version
|
||||
from pagermaid.listener import listener
|
||||
from telethon.tl.custom.message import Message
|
||||
from telethon.tl.types import MessageMediaDocument, DocumentAttributeFilename, DocumentAttributeImageSize
|
||||
|
||||
|
||||
def unit_convert(byte):
|
||||
""" Converts byte into readable formats. """
|
||||
power = 1024
|
||||
zero = 0
|
||||
units = {
|
||||
0: 'B',
|
||||
1: 'KB',
|
||||
2: 'MB',
|
||||
3: 'GB'}
|
||||
while byte > power:
|
||||
byte /= power
|
||||
zero += 1
|
||||
return f"{round(byte, 2)} {units[zero]}"
|
||||
|
||||
|
||||
@listener(is_plugin=True, outgoing=True, incoming=False, ignore_edited=True)
|
||||
async def auto_caption_file(context: Message):
|
||||
if not context.media:
|
||||
return
|
||||
if not isinstance(context.media, MessageMediaDocument):
|
||||
return
|
||||
if context.text:
|
||||
text = f"{context.text}\n`=============`\n"
|
||||
else:
|
||||
text = ""
|
||||
for i in context.media.document.attributes:
|
||||
# 文件名
|
||||
if isinstance(i, DocumentAttributeFilename):
|
||||
text += f"`文件名:{i.file_name}`\n"
|
||||
# 图片尺寸
|
||||
if isinstance(i, DocumentAttributeImageSize):
|
||||
text += f"`图片尺寸:{i.w}x{i.h}`\n"
|
||||
# 文件类型
|
||||
text += f"`文件类型:{context.media.document.mime_type}`\n"
|
||||
# 文件大小
|
||||
text += f"`文件大小:{unit_convert(context.media.document.size)}`\n"
|
||||
# DC
|
||||
text += f"`DC:{context.media.document.dc_id}`\n"
|
||||
# 编辑
|
||||
await context.edit(text)
|
10
list.json
10
list.json
@ -849,6 +849,16 @@
|
||||
"supported": true,
|
||||
"des-short": "查询特定用户的 DC。",
|
||||
"des": "查询特定用户的 DC。\n指令:-dc"
|
||||
},
|
||||
{
|
||||
"name": "autocaption",
|
||||
"version": "1.0",
|
||||
"section": "chat",
|
||||
"maintainer": "xtaodada",
|
||||
"size": "1.47 kb",
|
||||
"supported": true,
|
||||
"des-short": "自动获取所发送文件的信息。",
|
||||
"des": "自动获取所发送文件的信息。"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user