2020-04-02 12:59:40 +00:00
|
|
|
|
""" Pagermaid plugin base. """
|
|
|
|
|
import json, requests
|
2020-04-03 14:00:26 +00:00
|
|
|
|
from googletrans import Translator
|
|
|
|
|
from urllib.parse import urlparse
|
2020-04-02 12:59:40 +00:00
|
|
|
|
from pagermaid import bot, log
|
2020-04-03 14:00:26 +00:00
|
|
|
|
from pagermaid.listener import listener, config
|
|
|
|
|
from pagermaid.utils import clear_emojis, obtain_message
|
|
|
|
|
from telethon.tl.types import ChannelParticipantsAdmins
|
2020-04-02 12:59:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@listener(outgoing=True, command="guess",
|
2020-04-03 14:00:26 +00:00
|
|
|
|
description="能不能好好说话? - 拼音首字母缩写释义工具(需要回复一句话)")
|
2020-04-02 12:59:40 +00:00
|
|
|
|
async def guess(context):
|
|
|
|
|
reply = await context.get_reply_message()
|
|
|
|
|
await context.edit("获取中 . . .")
|
|
|
|
|
if reply:
|
2020-04-03 14:00:26 +00:00
|
|
|
|
pass
|
2020-04-02 12:59:40 +00:00
|
|
|
|
else:
|
2020-04-02 15:13:44 +00:00
|
|
|
|
context.edit("宁需要回复一句话")
|
2020-04-02 12:59:40 +00:00
|
|
|
|
return True
|
|
|
|
|
text = {'text': str(reply.message.replace("/guess ", "").replace(" ", ""))}
|
|
|
|
|
guess_json = json.loads(
|
|
|
|
|
requests.post("https://lab.magiconch.com/api/nbnhhsh/guess", data=text, verify=False).content.decode("utf-8"))
|
|
|
|
|
guess_res = []
|
|
|
|
|
if not len(guess_json) == 0:
|
|
|
|
|
for num in range(0, len(guess_json)):
|
|
|
|
|
guess_res1 = json.loads(json.dumps(guess_json[num]))
|
|
|
|
|
guess_res1_name = guess_res1['name']
|
|
|
|
|
try:
|
|
|
|
|
guess_res1_ans = ", ".join(guess_res1['trans'])
|
|
|
|
|
except:
|
|
|
|
|
try:
|
|
|
|
|
guess_res1_ans = ", ".join(guess_res1['inputting'])
|
|
|
|
|
except:
|
|
|
|
|
guess_res1_ans = "尚未录入"
|
|
|
|
|
guess_res.extend(["词组:" + guess_res1_name + "\n释义:" + guess_res1_ans])
|
|
|
|
|
await context.edit("\n\n".join(guess_res))
|
|
|
|
|
else:
|
|
|
|
|
await context.edit("没有匹配到拼音首字母缩写")
|
2020-04-02 15:13:44 +00:00
|
|
|
|
|
|
|
|
|
|
2020-04-03 14:00:26 +00:00
|
|
|
|
@listener(outgoing=True, command="admin",
|
|
|
|
|
description="一键 AT 本群管理员(仅在群组中有效)")
|
|
|
|
|
async def admin(context):
|
|
|
|
|
await context.edit('正在获取管理员列表中...')
|
|
|
|
|
chat = await context.get_chat()
|
|
|
|
|
try:
|
|
|
|
|
admins = await context.client.get_participants(chat, filter=ChannelParticipantsAdmins)
|
|
|
|
|
except:
|
|
|
|
|
await context.edit('请在群组中运行。')
|
|
|
|
|
return True
|
|
|
|
|
admin_list = []
|
|
|
|
|
for admin in admins:
|
|
|
|
|
if admin.first_name is not None:
|
|
|
|
|
admin_list.extend(['[' + admin.first_name + '](tg://user?id=' + str(admin.id) + ')'])
|
|
|
|
|
await context.edit(' , '.join(admin_list))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@listener(outgoing=True, command="wiki",
|
|
|
|
|
description="查询维基百科词条",
|
|
|
|
|
parameters="<词组>")
|
|
|
|
|
async def wiki(context):
|
|
|
|
|
translator = Translator()
|
|
|
|
|
lang = config['application_language']
|
|
|
|
|
await context.edit("获取中 . . .")
|
|
|
|
|
try:
|
|
|
|
|
message = await obtain_message(context)
|
|
|
|
|
except ValueError:
|
|
|
|
|
await context.edit("出错了呜呜呜 ~ 无效的参数。")
|
|
|
|
|
return
|
|
|
|
|
try:
|
|
|
|
|
wiki_json = json.loads(requests.get("https://zh.wikipedia.org/w/api.php?action=query&list=search&format=json&formatversion=2&srsearch=" + message).content.decode(
|
|
|
|
|
"utf-8"))
|
|
|
|
|
except:
|
|
|
|
|
await context.edit("出错了呜呜呜 ~ 无法访问到维基百科。")
|
|
|
|
|
return
|
|
|
|
|
if not len(wiki_json['query']['search']) == 0:
|
|
|
|
|
wiki_title = wiki_json['query']['search'][0]['title']
|
|
|
|
|
wiki_content = wiki_json['query']['search'][0]['snippet'].replace('<span class=\"searchmatch\">', '**').replace('</span>', '**')
|
|
|
|
|
wiki_time = wiki_json['query']['search'][0]['timestamp'].replace('T', ' ').replace('Z', ' ')
|
|
|
|
|
try:
|
|
|
|
|
await context.edit("正在生成翻译中 . . .")
|
|
|
|
|
wiki_content = translator.translate(clear_emojis(wiki_content), dest=lang)
|
|
|
|
|
message = '词条: [' + wiki_title + '](https://zh.wikipedia.org/zh-cn/' + wiki_title + ')\n\n' + wiki_content.text + '...\n\n此词条最后修订于 ' + wiki_time
|
|
|
|
|
except ValueError:
|
|
|
|
|
await context.edit("出错了呜呜呜 ~ 找不到目标语言,请更正配置文件中的错误。")
|
|
|
|
|
return
|
|
|
|
|
await context.edit(message)
|
|
|
|
|
else:
|
|
|
|
|
await context.edit("没有匹配到相关词条")
|
|
|
|
|
|
|
|
|
|
|
2020-04-02 15:13:44 +00:00
|
|
|
|
@listener(outgoing=True, command="ip",
|
2020-04-03 14:00:26 +00:00
|
|
|
|
description="IPINFO (或者回复一句话)",
|
|
|
|
|
parameters="<ip/域名>")
|
2020-04-02 15:13:44 +00:00
|
|
|
|
async def ipinfo(context):
|
|
|
|
|
reply = await context.get_reply_message()
|
2020-04-03 14:00:26 +00:00
|
|
|
|
await context.edit('正在查询中...')
|
2020-04-02 15:13:44 +00:00
|
|
|
|
try:
|
2020-04-03 14:00:26 +00:00
|
|
|
|
if reply:
|
|
|
|
|
for num in range(0, len(reply.entities)):
|
|
|
|
|
url = reply.message[reply.entities[num].offset:reply.entities[num].offset + reply.entities[num].length]
|
|
|
|
|
url = urlparse(url)
|
|
|
|
|
if url.hostname:
|
|
|
|
|
url = url.hostname
|
|
|
|
|
else:
|
|
|
|
|
url = url.path
|
|
|
|
|
ipinfo_json = json.loads(requests.get(
|
|
|
|
|
"http://ip-api.com/json/" + url + "?fields=status,message,country,regionName,city,lat,lon,isp,org,as,mobile,proxy,hosting,query").content.decode(
|
|
|
|
|
"utf-8"))
|
|
|
|
|
if ipinfo_json['status'] == 'fail':
|
|
|
|
|
pass
|
|
|
|
|
elif ipinfo_json['status'] == 'success':
|
|
|
|
|
ipinfo_list = []
|
|
|
|
|
ipinfo_list.extend(["查询目标: `" + url + "`"])
|
|
|
|
|
if ipinfo_json['query'] == url:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
ipinfo_list.extend(["解析地址: `" + ipinfo_json['query'] + "`"])
|
|
|
|
|
ipinfo_list.extend(["地区: `" + ipinfo_json['country'] + ' - ' + ipinfo_json['regionName'] + ' - ' +
|
|
|
|
|
ipinfo_json['city'] + "`"])
|
|
|
|
|
ipinfo_list.extend(["经纬度: `" + str(ipinfo_json['lat']) + ',' + str(ipinfo_json['lon']) + "`"])
|
|
|
|
|
ipinfo_list.extend(["ISP: `" + ipinfo_json['isp'] + "`"])
|
|
|
|
|
if not ipinfo_json['org'] == '':
|
|
|
|
|
ipinfo_list.extend(["组织: `" + ipinfo_json['org'] + "`"])
|
|
|
|
|
ipinfo_list.extend(
|
|
|
|
|
['[' + ipinfo_json['as'] + '](https://bgp.he.net/' + ipinfo_json['as'].split()[0] + ')'])
|
|
|
|
|
if ipinfo_json['mobile']:
|
|
|
|
|
ipinfo_list.extend(['此 IP 可能为**蜂窝移动数据 IP**'])
|
|
|
|
|
if ipinfo_json['proxy']:
|
|
|
|
|
ipinfo_list.extend(['此 IP 可能为**代理 IP**'])
|
|
|
|
|
if ipinfo_json['hosting']:
|
|
|
|
|
ipinfo_list.extend(['此 IP 可能为**数据中心 IP**'])
|
|
|
|
|
await context.edit('\n'.join(ipinfo_list))
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
url = urlparse(context.arguments)
|
|
|
|
|
if url.hostname:
|
|
|
|
|
url = url.hostname
|
|
|
|
|
else:
|
|
|
|
|
url = url.path
|
|
|
|
|
ipinfo_json = json.loads(requests.get(
|
|
|
|
|
"http://ip-api.com/json/" + url + "?fields=status,message,country,regionName,city,lat,lon,isp,org,as,mobile,proxy,hosting,query").content.decode(
|
|
|
|
|
"utf-8"))
|
|
|
|
|
if ipinfo_json['status'] == 'fail':
|
|
|
|
|
pass
|
|
|
|
|
elif ipinfo_json['status'] == 'success':
|
|
|
|
|
ipinfo_list = []
|
|
|
|
|
if url == '':
|
|
|
|
|
ipinfo_list.extend(["查询目标: `本机地址`"])
|
|
|
|
|
else:
|
|
|
|
|
ipinfo_list.extend(["查询目标: `" + url + "`"])
|
|
|
|
|
if ipinfo_json['query'] == url:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
ipinfo_list.extend(["解析地址: `" + ipinfo_json['query'] + "`"])
|
|
|
|
|
ipinfo_list.extend(["地区: `" + ipinfo_json['country'] + ' - ' + ipinfo_json['regionName'] + ' - ' +
|
|
|
|
|
ipinfo_json['city'] + "`"])
|
|
|
|
|
ipinfo_list.extend(["经纬度: `" + str(ipinfo_json['lat']) + ',' + str(ipinfo_json['lon']) + "`"])
|
|
|
|
|
ipinfo_list.extend(["ISP: `" + ipinfo_json['isp'] + "`"])
|
|
|
|
|
if not ipinfo_json['org'] == '':
|
|
|
|
|
ipinfo_list.extend(["组织: `" + ipinfo_json['org'] + "`"])
|
|
|
|
|
ipinfo_list.extend(
|
|
|
|
|
['[' + ipinfo_json['as'] + '](https://bgp.he.net/' + ipinfo_json['as'].split()[0] + ')'])
|
|
|
|
|
if ipinfo_json['mobile']:
|
|
|
|
|
ipinfo_list.extend(['此 IP 可能为**蜂窝移动数据 IP**'])
|
|
|
|
|
if ipinfo_json['proxy']:
|
|
|
|
|
ipinfo_list.extend(['此 IP 可能为**代理 IP**'])
|
|
|
|
|
if ipinfo_json['hosting']:
|
|
|
|
|
ipinfo_list.extend(['此 IP 可能为**数据中心 IP**'])
|
|
|
|
|
await context.edit('\n'.join(ipinfo_list))
|
|
|
|
|
return True
|
|
|
|
|
await context.edit('没有找到要查询的 ip/域名 ...')
|
2020-04-02 15:13:44 +00:00
|
|
|
|
except:
|
2020-04-03 14:00:26 +00:00
|
|
|
|
await context.edit('没有找到要查询的 ip/域名 ...')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@listener(outgoing=True, command="ipping",
|
|
|
|
|
description="Ping (或者回复一句话)",
|
|
|
|
|
parameters="<ip/域名>")
|
|
|
|
|
async def ipping(context):
|
|
|
|
|
reply = await context.get_reply_message()
|
|
|
|
|
await context.edit('正在查询中...')
|
|
|
|
|
try:
|
|
|
|
|
if reply:
|
|
|
|
|
for num in range(0, len(reply.entities)):
|
|
|
|
|
url = reply.message[reply.entities[num].offset:reply.entities[num].offset + reply.entities[num].length]
|
|
|
|
|
url = urlparse(url)
|
|
|
|
|
if url.hostname:
|
|
|
|
|
url = url.hostname
|
|
|
|
|
else:
|
|
|
|
|
url = url.path
|
|
|
|
|
pinginfo = requests.get(
|
|
|
|
|
"https://helloacm.com/api/ping/?cached&host=" + url).content.decode(
|
|
|
|
|
"utf-8")
|
|
|
|
|
if pinginfo == 'null':
|
|
|
|
|
pass
|
|
|
|
|
elif not pinginfo == 'null':
|
|
|
|
|
pinginfo = pinginfo.replace('"', '').replace("\/", '/').replace('\\n', '\n', 7).replace('\\n', '')
|
|
|
|
|
await context.edit(pinginfo)
|
|
|
|
|
return True
|
2020-04-02 15:13:44 +00:00
|
|
|
|
else:
|
2020-04-03 14:00:26 +00:00
|
|
|
|
url = urlparse(context.arguments)
|
|
|
|
|
if url.hostname:
|
|
|
|
|
url = url.hostname
|
|
|
|
|
else:
|
|
|
|
|
url = url.path
|
|
|
|
|
if url == '':
|
|
|
|
|
await context.edit('没有找到要查询的 ip/域名 ...')
|
|
|
|
|
return True
|
|
|
|
|
pinginfo = requests.get(
|
|
|
|
|
"https://helloacm.com/api/ping/?cached&host=" + url).content.decode(
|
|
|
|
|
"utf-8")
|
|
|
|
|
if pinginfo == 'null':
|
|
|
|
|
pass
|
|
|
|
|
elif not pinginfo == 'null':
|
|
|
|
|
pinginfo = pinginfo.replace('"', '').replace("\/", '/').replace('\\n', '\n', 7).replace('\\n', '')
|
|
|
|
|
await context.edit(pinginfo)
|
|
|
|
|
return True
|
|
|
|
|
await context.edit('没有找到要查询的 ip/域名 ...')
|
|
|
|
|
except:
|
|
|
|
|
await context.edit('没有找到要查询的 ip/域名 ...')
|