2020-02-19 15:31:39 +00:00
|
|
|
|
""" Message related utilities. """
|
|
|
|
|
|
2020-04-01 11:04:56 +00:00
|
|
|
|
import requests
|
|
|
|
|
import json
|
2020-02-19 15:31:39 +00:00
|
|
|
|
from telethon.tl.functions.messages import DeleteChatUserRequest
|
2020-04-02 12:42:38 +00:00
|
|
|
|
from telethon.tl.functions.channels import LeaveChannelRequest, GetParticipantsRequest
|
2020-04-02 12:34:19 +00:00
|
|
|
|
from telethon.tl.types import ChannelParticipantsAdmins
|
2020-02-19 15:31:39 +00:00
|
|
|
|
from telethon.errors.rpcerrorlist import ChatIdInvalidError
|
|
|
|
|
from distutils2.util import strtobool
|
|
|
|
|
from pagermaid import bot, log, config
|
|
|
|
|
from pagermaid.listener import listener
|
|
|
|
|
|
|
|
|
|
|
2020-08-09 15:17:55 +00:00
|
|
|
|
@listener(is_plugin=False, outgoing=True, command="id",
|
2020-06-06 14:40:52 +00:00
|
|
|
|
description="获取一条消息的各种信息。")
|
2020-02-19 15:31:39 +00:00
|
|
|
|
async def userid(context):
|
|
|
|
|
""" Query the UserID of the sender of the message you replied to. """
|
2020-08-08 11:40:54 +00:00
|
|
|
|
message = await context.get_reply_message()
|
|
|
|
|
text = "Message ID: `" + str(context.message.id) + "`\n\n"
|
|
|
|
|
text += "**Chat**\nid:`" + str(context.chat_id) + "`\n"
|
|
|
|
|
if context.is_private:
|
|
|
|
|
try:
|
|
|
|
|
text += "first_name: `" + context.chat.first_name + "`\n"
|
|
|
|
|
except TypeError:
|
|
|
|
|
text += "**死号**\n"
|
|
|
|
|
if context.chat.last_name:
|
|
|
|
|
text += "last_name: `" + context.chat.last_name + "`\n"
|
|
|
|
|
if context.chat.username:
|
|
|
|
|
text += "username: @" + context.chat.username + "\n"
|
|
|
|
|
if context.chat.lang_code:
|
|
|
|
|
text += "lang_code: `" + context.chat.lang_code + "`\n"
|
|
|
|
|
if context.is_group or context.is_channel:
|
|
|
|
|
text += "title: `" + context.chat.title + "`\n"
|
|
|
|
|
if context.chat.username:
|
|
|
|
|
text += "username: @" + context.chat.username + "\n"
|
|
|
|
|
text += "date: `" + str(context.chat.date) + "`\n"
|
2020-02-19 15:31:39 +00:00
|
|
|
|
if message:
|
2020-08-08 11:40:54 +00:00
|
|
|
|
text += "\n以下是被回复消息的信息\nMessage ID: `" + str(message.id) + "`\n\n**User**\nid: `" + str(message.sender.id) + "`"
|
|
|
|
|
if message.sender.bot:
|
|
|
|
|
text += "\nis_bot: 是"
|
|
|
|
|
try:
|
|
|
|
|
text += "\nfirst_name: `" + message.sender.first_name + "`"
|
|
|
|
|
except TypeError:
|
|
|
|
|
text += "\n**死号**"
|
|
|
|
|
if message.sender.last_name:
|
|
|
|
|
text += "\nlast_name: `" + message.sender.last_name + "`"
|
2020-05-17 03:21:05 +00:00
|
|
|
|
if message.sender.username:
|
2020-08-08 11:40:54 +00:00
|
|
|
|
text += "\nusername: @" + message.sender.username
|
|
|
|
|
if message.sender.lang_code:
|
|
|
|
|
text += "\nlang_code: `" + message.sender.lang_code + "`"
|
|
|
|
|
if message.forward:
|
|
|
|
|
if str(message.forward.chat_id).startswith('-100'):
|
|
|
|
|
text += "\n\n**Forward From Channel**\nid: `" + str(
|
|
|
|
|
message.forward.chat_id) + "`\ntitle: `" + message.forward.chat.title + "`"
|
|
|
|
|
if message.forward.chat.username:
|
|
|
|
|
text += "\nusername: @" + message.forward.chat.username
|
|
|
|
|
text += "\nmessage_id: `" + str(message.forward.channel_post) + "`"
|
|
|
|
|
if message.forward.post_author:
|
|
|
|
|
text += "\npost_author: `" + message.forward.post_author + "`"
|
2020-08-08 13:17:46 +00:00
|
|
|
|
text += "\ndate: `" + str(message.forward.date) + "`"
|
2020-08-08 11:40:54 +00:00
|
|
|
|
else:
|
|
|
|
|
if message.forward.sender:
|
|
|
|
|
text += "\n\n**Forward From User**\nid: `" + str(
|
|
|
|
|
message.forward.sender_id) + "`"
|
|
|
|
|
if message.forward.sender.bot:
|
|
|
|
|
text += "\nis_bot: 是"
|
|
|
|
|
try:
|
|
|
|
|
text += "\nfirst_name: `" + message.forward.sender.first_name + "`"
|
|
|
|
|
except TypeError:
|
|
|
|
|
text += "\n**死号**"
|
|
|
|
|
if message.forward.sender.last_name:
|
|
|
|
|
text += "\nlast_name: `" + message.forward.sender.last_name + "`"
|
|
|
|
|
if message.forward.sender.username:
|
|
|
|
|
text += "\nusername: @" + message.forward.sender.username
|
|
|
|
|
if message.forward.sender.lang_code:
|
|
|
|
|
text += "\nlang_code: `" + message.forward.sender.lang_code + "`"
|
|
|
|
|
text += "\ndate: `" + str(message.forward.date) + "`"
|
2020-06-06 14:40:52 +00:00
|
|
|
|
await context.edit(text)
|
2020-02-19 15:31:39 +00:00
|
|
|
|
|
|
|
|
|
|
2020-08-09 15:17:55 +00:00
|
|
|
|
@listener(is_plugin=False, outgoing=True, command="uslog",
|
2020-02-19 15:31:39 +00:00
|
|
|
|
description="转发一条消息到日志。",
|
|
|
|
|
parameters="<string>")
|
2020-03-20 12:15:45 +00:00
|
|
|
|
async def uslog(context):
|
2020-02-19 15:31:39 +00:00
|
|
|
|
""" Forwards a message into log group """
|
|
|
|
|
if strtobool(config['log']):
|
|
|
|
|
if context.reply_to_msg_id:
|
|
|
|
|
reply_msg = await context.get_reply_message()
|
|
|
|
|
await reply_msg.forward_to(int(config['log_chatid']))
|
|
|
|
|
elif context.arguments:
|
|
|
|
|
await log(context.arguments)
|
|
|
|
|
else:
|
|
|
|
|
await context.edit("出错了呜呜呜 ~ 无效的参数。")
|
|
|
|
|
return
|
|
|
|
|
await context.edit("已记录。")
|
|
|
|
|
else:
|
|
|
|
|
await context.edit("出错了呜呜呜 ~ 日志记录已禁用。")
|
|
|
|
|
|
|
|
|
|
|
2020-08-09 15:17:55 +00:00
|
|
|
|
@listener(is_plugin=False, outgoing=True, command="log",
|
2020-03-13 08:48:50 +00:00
|
|
|
|
description="静默转发一条消息到日志。",
|
|
|
|
|
parameters="<string>")
|
|
|
|
|
async def log(context):
|
|
|
|
|
""" Forwards a message into log group """
|
|
|
|
|
if strtobool(config['log']):
|
|
|
|
|
if context.reply_to_msg_id:
|
|
|
|
|
reply_msg = await context.get_reply_message()
|
|
|
|
|
await reply_msg.forward_to(int(config['log_chatid']))
|
|
|
|
|
elif context.arguments:
|
|
|
|
|
await log(context.arguments)
|
|
|
|
|
else:
|
|
|
|
|
await context.edit("出错了呜呜呜 ~ 无效的参数。")
|
|
|
|
|
return
|
|
|
|
|
await context.delete()
|
|
|
|
|
else:
|
|
|
|
|
await context.edit("出错了呜呜呜 ~ 日志记录已禁用。")
|
|
|
|
|
|
|
|
|
|
|
2020-08-09 15:17:55 +00:00
|
|
|
|
@listener(is_plugin=False, outgoing=True, command="re",
|
2020-04-05 03:26:51 +00:00
|
|
|
|
description="在当前会话复读回复的消息。(需要回复一条消息)",
|
2020-04-05 10:01:41 +00:00
|
|
|
|
parameters="<次数>")
|
2020-03-20 12:15:45 +00:00
|
|
|
|
async def re(context):
|
2020-04-05 03:26:51 +00:00
|
|
|
|
""" Forwards a message into this group """
|
|
|
|
|
reply = await context.get_reply_message()
|
|
|
|
|
if reply:
|
|
|
|
|
if context.arguments == '':
|
|
|
|
|
num = 1
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
num = int(context.arguments)
|
|
|
|
|
if num > 100:
|
|
|
|
|
await context.edit('呜呜呜出错了...这个数字太大惹')
|
|
|
|
|
return True
|
|
|
|
|
except:
|
2020-05-23 12:40:28 +00:00
|
|
|
|
await context.edit('呜呜呜出错了...可能参数包含了数字以外的符号')
|
2020-04-05 03:26:51 +00:00
|
|
|
|
return True
|
2020-04-06 13:39:32 +00:00
|
|
|
|
await context.delete()
|
2020-04-05 03:26:51 +00:00
|
|
|
|
for nums in range(0, num):
|
|
|
|
|
await reply.forward_to(int(context.chat_id))
|
2020-03-13 14:08:28 +00:00
|
|
|
|
else:
|
2020-04-05 03:26:51 +00:00
|
|
|
|
await context.edit("出错了呜呜呜 ~ 您好像没有回复一条消息。")
|
2020-03-13 14:08:28 +00:00
|
|
|
|
|
|
|
|
|
|
2020-08-09 15:17:55 +00:00
|
|
|
|
@listener(is_plugin=False, outgoing=True, command="leave",
|
2020-05-23 12:40:28 +00:00
|
|
|
|
description="说 “再见” 然后离开会话。")
|
2020-02-19 15:31:39 +00:00
|
|
|
|
async def leave(context):
|
|
|
|
|
""" It leaves you from the group. """
|
|
|
|
|
if context.is_group:
|
|
|
|
|
await context.edit("贵群真是浪费我的时间,再见。")
|
|
|
|
|
try:
|
|
|
|
|
await bot(DeleteChatUserRequest(chat_id=context.chat_id,
|
|
|
|
|
user_id=context.sender_id
|
|
|
|
|
))
|
|
|
|
|
except ChatIdInvalidError:
|
2020-04-02 01:18:28 +00:00
|
|
|
|
await bot(LeaveChannelRequest(context.chat_id))
|
2020-02-19 15:31:39 +00:00
|
|
|
|
else:
|
2020-04-05 10:01:41 +00:00
|
|
|
|
await context.edit("出错了呜呜呜 ~ 当前聊天似乎不是群聊。")
|
2020-02-19 15:31:39 +00:00
|
|
|
|
|
|
|
|
|
|
2020-08-09 15:17:55 +00:00
|
|
|
|
@listener(is_plugin=False, outgoing=True, command="meter2feet",
|
2020-02-19 15:31:39 +00:00
|
|
|
|
description="将米转换为英尺。",
|
|
|
|
|
parameters="<meters>")
|
|
|
|
|
async def meter2feet(context):
|
|
|
|
|
""" Convert meter to feet. """
|
|
|
|
|
if not len(context.parameter) == 1:
|
|
|
|
|
await context.edit("出错了呜呜呜 ~ 无效的参数。")
|
|
|
|
|
return
|
|
|
|
|
meter = float(context.parameter[0])
|
|
|
|
|
feet = meter / .3048
|
|
|
|
|
await context.edit(f"将 {str(meter)} 米装换为了 {str(feet)} 英尺。")
|
|
|
|
|
|
|
|
|
|
|
2020-08-09 15:17:55 +00:00
|
|
|
|
@listener(is_plugin=False, outgoing=True, command="feet2meter",
|
2020-02-19 15:31:39 +00:00
|
|
|
|
description="将英尺转换为米。",
|
|
|
|
|
parameters="<feet>")
|
|
|
|
|
async def feet2meter(context):
|
|
|
|
|
""" Convert feet to meter. """
|
|
|
|
|
if not len(context.parameter) == 1:
|
|
|
|
|
await context.edit("出错了呜呜呜 ~ 无效的参数。")
|
|
|
|
|
return
|
|
|
|
|
feet = float(context.parameter[0])
|
|
|
|
|
meter = feet * .3048
|
|
|
|
|
await context.edit(f"将 {str(feet)} 英尺转换为了 {str(meter)} 米。")
|
|
|
|
|
|
|
|
|
|
|
2020-08-09 15:17:55 +00:00
|
|
|
|
@listener(is_plugin=False, outgoing=True, command="hitokoto",
|
2020-05-23 12:40:28 +00:00
|
|
|
|
description="每日一言")
|
2020-04-01 11:04:56 +00:00
|
|
|
|
async def hitokoto(context):
|
|
|
|
|
""" Get hitokoto.cn """
|
2020-05-16 15:10:12 +00:00
|
|
|
|
hitokoto_while = 1
|
|
|
|
|
try:
|
|
|
|
|
hitokoto_json = json.loads(requests.get("https://v1.hitokoto.cn/?charset=utf-8").content.decode("utf-8"))
|
|
|
|
|
except (ValueError):
|
|
|
|
|
while hitokoto_while < 10:
|
|
|
|
|
hitokoto_while += 1
|
|
|
|
|
try:
|
|
|
|
|
hitokoto_json = json.loads(requests.get("https://v1.hitokoto.cn/?charset=utf-8").content.decode("utf-8"))
|
|
|
|
|
break
|
|
|
|
|
except:
|
|
|
|
|
continue
|
2020-08-16 12:55:42 +00:00
|
|
|
|
hitokoto_type = ''
|
2020-04-01 11:04:56 +00:00
|
|
|
|
if hitokoto_json['type'] == 'a':
|
|
|
|
|
hitokoto_type = '动画'
|
|
|
|
|
elif hitokoto_json['type'] == 'b':
|
|
|
|
|
hitokoto_type = '漫画'
|
|
|
|
|
elif hitokoto_json['type'] == 'c':
|
|
|
|
|
hitokoto_type = '游戏'
|
|
|
|
|
elif hitokoto_json['type'] == 'd':
|
|
|
|
|
hitokoto_type = '文学'
|
|
|
|
|
elif hitokoto_json['type'] == 'e':
|
|
|
|
|
hitokoto_type = '原创'
|
|
|
|
|
elif hitokoto_json['type'] == 'f':
|
|
|
|
|
hitokoto_type = '来自网络'
|
|
|
|
|
elif hitokoto_json['type'] == 'g':
|
|
|
|
|
hitokoto_type = '其他'
|
|
|
|
|
elif hitokoto_json['type'] == 'h':
|
|
|
|
|
hitokoto_type = '影视'
|
|
|
|
|
elif hitokoto_json['type'] == 'i':
|
|
|
|
|
hitokoto_type = '诗词'
|
|
|
|
|
elif hitokoto_json['type'] == 'j':
|
|
|
|
|
hitokoto_type = '网易云'
|
|
|
|
|
elif hitokoto_json['type'] == 'k':
|
|
|
|
|
hitokoto_type = '哲学'
|
|
|
|
|
elif hitokoto_json['type'] == 'l':
|
|
|
|
|
hitokoto_type = '抖机灵'
|
2020-04-05 10:01:41 +00:00
|
|
|
|
await context.edit(f"{hitokoto_json['hitokoto']} - {hitokoto_json['from']}({str(hitokoto_type)})")
|