目录
前言
如果没有安装请自行安装 PagerMaid-Modify
仓库:https://github.com/Xtao-Labs/PagerMaid-Modify
API获取 https://my.telegram.org/apps
本文以一键脚本安装版为例,安装命令
wget https://raw.githubusercontent.com/Xtao-Labs/PagerMaid-Modify/master/install.sh -O install.sh&& chmod +x install.sh && bash install.sh
路径与原理
要手动安装就得知道原理,插件本质上是py程序
而通过一键脚本的默认路径 是 /var/lib/pagermaid/plugins
然后其中的py程序中较为开头的位置有一句
@listener(is_plugin=False, outgoing=True, command=alias_command("XXXXXX"),
XXXXX即为触发命令,按照惯例,一般保持文件名和命令一致
关于手动新建PY程序,可以去宝塔面板新建,也可以自己本地新建,但是要注意文件隐藏格式,可以使用 Edit Plus 修改
- 文件换行格式:UNIX/MAC
- 文本编码:一般为UTF-8
你需要做的就是把PY程序放在对应目录,然后重启BOT程序即可
虚拟币插件代码
import json
import string
import time
from requests import get
from pagermaid.listener import listener
endpoint = 'https://api.gateio.ws/api/v4/spot/tickers'
@listener(is_plugin=True, outgoing=True, command="xnb",
description="获取虚拟货币兑USDT价格,数据基于GATEIO Exchange",
parameters="BTC")
async def xnb(context):
await context.edit("获取中 . . .")
req = get(endpoint)
if req.status_code == 200:
response = json.loads(req.text)
update_timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
support_coins = []
if len(context.parameter) > 0:
for x in range(len(context.parameter)):
support_coins.append( str.upper(context.parameter[x]) + "_USDT")
else:
support_coins = ['XMR_USDT','BTC_USDT','ETH_USDT']
coins = {}
for coin in response:
# 名称
currency_pair = coin['currency_pair']
if currency_pair not in support_coins:
continue
coins[currency_pair] = coin
res = ''
for support_coin in support_coins:
try:
coin = coins[support_coin]
# 名称
currency_pair = coin['currency_pair'][0:coin['currency_pair'].find('_')]
# 最新价格
price = format(float(coin['last']), '.7f')
# 24h 变化率
change_percentage = coin['change_percentage']
# 24h 最高价
high_24h = coin['high_24h']
# 24h 最低价
low_24h = coin['low_24h']
res += '%s: %s, 涨幅: %s
\n' % (currency_pair, price, change_percentage) except: await context.edit("你输入了个嘛啊!来,你告诉我 "+support_coin[0:support_coin.find('_')]+"是个什么币?再乱来打你哦!") time.sleep(3) continue res += '\n更新时间: %s
' % (update_timestamp) await context.edit(res, parse_mode='html', link_preview=False) elif req.status_code == 400: response = json.loads(req.text) await context.edit(response.message) else: await context.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。")
如果需要修改默认币种,则改 support_coins 默认均USDT币对,不同Exchange数据略有不同
Comments NOTHING