PagerMaid_Plugins/bin.py

67 lines
2.1 KiB
Python
Raw Normal View History

2022-01-18 08:47:20 +00:00
import json
import requests
2021-07-15 08:12:49 +00:00
from json.decoder import JSONDecodeError
2022-01-18 08:47:20 +00:00
from pagermaid import version
2021-07-12 05:58:12 +00:00
from pagermaid.listener import listener
from pagermaid.utils import obtain_message, alias_command
2021-07-15 08:12:49 +00:00
2021-07-12 05:58:12 +00:00
@listener(is_plugin=True, outgoing=True, command=alias_command("bin"),
description="查询信用卡信息",
parameters="<bin4到8位数字>")
async def card(context):
await context.edit('正在查询中...')
try:
card_bin = await obtain_message(context)
except ValueError:
await context.edit("出错了呜呜呜 ~ 无效的参数。")
return
try:
r = requests.get("https://lookup.binlist.net/" + card_bin)
except:
await context.edit("出错了呜呜呜 ~ 无法访问到binlist。")
return
if r.status_code == 404:
await context.edit("出错了呜呜呜 ~ 目标卡头不存在")
return
if r.status_code == 429:
await context.edit("出错了呜呜呜 ~ 每分钟限额超过,请等待一分钟再试")
return
2021-07-15 08:12:49 +00:00
try:
bin_json = json.loads(r.content.decode("utf-8"))
except JSONDecodeError:
await context.edit("出错了呜呜呜 ~ 无效的参数。")
return
2021-07-12 05:58:12 +00:00
msg_out = []
msg_out.extend(["BIN" + card_bin])
try:
msg_out.extend(["卡品牌:" + bin_json['scheme']])
2021-10-31 14:56:18 +00:00
except (KeyError, TypeError):
2021-07-12 05:58:12 +00:00
pass
try:
msg_out.extend(["卡类型:" + bin_json['type']])
2021-10-31 14:56:18 +00:00
except (KeyError, TypeError):
2021-07-12 05:58:12 +00:00
pass
try:
msg_out.extend(["卡种类:" + bin_json['brand']])
2021-10-31 14:56:18 +00:00
except (KeyError, TypeError):
2021-07-12 05:58:12 +00:00
pass
try:
msg_out.extend(["发卡行:" + bin_json['bank']["name"]])
2021-10-31 14:56:18 +00:00
except (KeyError, TypeError):
2021-07-12 05:58:12 +00:00
pass
try:
if bin_json['prepaid']:
msg_out.extend(["是否预付:是"])
else:
msg_out.extend(["是否预付:否"])
2021-10-31 14:56:18 +00:00
except (KeyError, TypeError):
2021-07-12 05:58:12 +00:00
pass
try:
msg_out.extend(["发卡国家:" + bin_json['country']['name']])
2021-10-31 14:56:18 +00:00
except (KeyError, TypeError):
2021-07-12 05:58:12 +00:00
pass
await context.edit("\n".join(msg_out))