Skip to content

Commit

Permalink
New submodule subscribe.
Browse files Browse the repository at this point in the history
  • Loading branch information
HornCopper committed Aug 19, 2022
1 parent b88630d commit ec6f1c3
Show file tree
Hide file tree
Showing 8 changed files with 735 additions and 9 deletions.
32 changes: 29 additions & 3 deletions initialization.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import os, json
import os
import json

def space():
print("----------------------分割线----------------------")

try:
os.mkdir("./src/data")
except FileExistsError:
print("检测到`data`文件夹已创建。")

try:
os.mkdir("./src/cache")
except FileExistsError:
print("检测到`cache`文件夹已创建。")

try:
os.mkdir("./src/assets")
os.mkdir("./src/assets/arcaea")
Expand All @@ -24,10 +29,13 @@ def space():
os.mkdir("./src/assets/jx3/adventure")
except FileExistsError:
print("检测到`assets`文件夹已创建,已自动补全所有需要的文件夹。")

def write(file, something):
with open(f"./src/tools/{file}",mode="w") as cache:
cache.write(something)

json_ = {}

if __name__ == "__main__":
print("模块`github`需要使用`web_path`,如果您填写的值为`/a`,那么通过`http://127.0.0.1:2333/a`可传入Webhook,但内网显然不行,因此您需要手动配置Nginx或Apache2进行反向代理,代理地址为`http://127.0.0.1:2333/a`。")
print("此处提供Nginx配置文件写法(当填入值为`/a`时:)")
Expand Down Expand Up @@ -80,20 +88,38 @@ def write(file, something):
print("Token也是必要的,没有固定格式,请输入AUA开发者给予你的Token。")
aua_token = input("请输入Token:")
json_["aua_token"] = aua_token
space()
print("模块`jx3`需要使用JX3API的Socket API,请查询`https://www.jx3api.com`,获取`Socket API`地址并填写。")
print("格式为:`wss://xxxx.xxxx.xxx`")
jx3api_link = input("请输入JX3API的Socket API地址:")
json_["jx3api_link"] = jx3api_link
space()
print("Token并非必要,但推荐填写,需要找JX3API购买。")
print("如果您没有Token,请输入数字`0`。")
jx3api_token = input("请输入Token:")
if jx3api_token.isdecimal():
if int(jx3api_token) == 0:
json_["jx3api_token"] = None
else:
json_["jx3api_token"] = jx3api_token
else:
json_["jx3api_token"] = jx3api_token
space()
final = json.dumps(json_)
write("config.json",final)
space()
def clear():
clean = input("是否需要重置ban.json、nnl.json和permission三个json文件,若初次使用请填写y(y/n):")
clean = input("是否需要重置ban.json、nnl.json、permission.json、subscribe.json?若初次使用请填写y(y/n):")
if clean == "y":
write("ban.json","[]")
write("permission.json",json.dumps(permission))
write("nnl.json","[]")
write("subscribe.json","[]")
return
elif clean == "n":
return
else:
print("输出错误,请重试。")
clear()
clear()
space()
space()
51 changes: 50 additions & 1 deletion src/plugins/jx3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import sys
import nonebot
import json

from nonebot import get_driver
from nonebot import on_command
from nonebot.adapters import Message
from nonebot.params import CommandArg, Arg
from nonebot.adapters.onebot.v11 import MessageSegment as ms
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent
from nonebot.typing import T_State

TOOLS = nonebot.get_driver().config.tools_path
sys.path.append(TOOLS)
from .jx3 import *

from utils import checknumber
from file import read, write

from .jx3 import *
from .skilldatalib import getAllSkillsInfo, getSingleSkill, getSingleTalent
from .achievement import getAchievementFinishMethod
from .adventure import getAdventure, getAchievementsIcon
from .pet import get_pet
from .task import getTask, getTaskChain
from .jx3apiws import ws_client
from .jx3_event import RecvEvent

horse = on_command("jx3_horse",aliases={"马"},priority=5)
@horse.handle()
Expand Down Expand Up @@ -290,3 +299,43 @@ async def _(state: T_State, num: Message = Arg()):
await task_.finish(msg)
else:
await task_.finish("唔……输入的不是数字哦,取消搜索。")

subscribe = on_command("jx3_subscribe", aliases={"订阅"}, priority=5)
@subscribe.handle()
async def _(event: GroupMessageEvent):
now = json.loads(read(TOOLS + "/subscribe.json"))
if str(event.group_id) not in now:
now.append(str(event.group_id))
write(TOOLS + "/subscribe.json", json.dumps(now))
await subscribe.finish("已开启本群的订阅!当收到事件时会自动推送。")
else:
await subscribe.finish("已经订阅了,不能重复订阅哦~")

unsubscribe = on_command("jx3_unsubscribe", aliases={"退订"}, priority=5)
@unsubscribe.handle()
async def _(event: GroupMessageEvent):
now = json.loads(read(TOOLS + "/subscribe.json"))
if str(event.group_id) not in now:
await unsubscribe.finish("尚未订阅,无法退订哦~")
else:
now.remove(str(event.group_id))
write(TOOLS + "/unubscribe.json", json.dumps(now))
await unsubscribe.finish("退订成功!不会再收到订阅了,需要的话请使用命令重新订阅~")

driver = get_driver()

@driver.on_startup
async def _():
logger.info("Connecting to JX3API...Please wait.")
await ws_client.init()
logger.info("Connected to JX3API successfully.")

async def _(bot: Bot, event: RecvEvent):
message = event.get_message()
groups = json.loads(read(TOOLS + "/subscribe.json"))
for i in groups:
try:
await bot.call_api("send_group_msg", group_id = int(i), message = message)
return
except:
logger.info(f"向群({i})推送失败,可能是因为风控、禁言或者未加入该群。")
2 changes: 1 addition & 1 deletion src/plugins/jx3/info.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"author":"HornCopper","version":"1.6-Release","name":"剑网三搜索器(jx3)","admin":"N/A","aliases":"+jx3_horse -> +马$+jx3_server -> +服务器$+jx3_macro -> +宏$+jx3_daily -> +日常、+周常$+jx3_exam -> +科举$+jx3_matrix -> +阵眼$+jx3_equip -> +装备$+jx3_require -> +奇遇信息$+jx3_news -> +新闻$+jx3_random -> +骚话$+jx3_heighten -> +小药$+jx3_price -> +物价$+jx3_demon -> +金价$+jx3_kungfu -> +心法$+jx3_skill -> +技能$+jx3_achievement -> +奇遇$+jx3_talent -> +奇穴$+jx3_pet -> +宠物$+jx3_adventure -> +成就$+jx3_task -> +任务","desc":"获取马匹刷新地点:+jx3_horse <马驹名>$获取服务器状态:+jx3_server <服务器名>$获取剑网3宏命令:+jx3_macro <心法名>$获取日常/周常:+jx3_daily [服务器名(可选)]$获取科举答案:+jx3_exam <问题关键词>$获取阵眼效果:+jx3_matrix <心法名>$获取推荐装备:+jx3_equip <心法名>$获取绝世/珍稀奇遇前置条件:+jx3_require <奇遇名>$获取剑网3新闻:+jx3_news$获取剑网3“万花谷”频道骚话:+jx3_random$获取心法当前赛季适合的小药:+jx3_heighten <心法名>$获取服务器外观物价:+jx3_price <外观物品名>$获取服务器金价:+jx3_demon <服务器名>$(大概率失败)获取心法所有技能:+jx3_kungfu <心法名>$获取技能:+jx3_skill <心法名> <技能名>$获取奇遇(支持宠物奇遇):+jx3_achievement <奇遇名/ID>$获取奇穴信息:+jx3_talent <心法名> <奇穴名>$获取宠物信息:+jx3_pet <宠物名>$获取成就信息:+jx3_adventure <成就名>$查询任务信息:+jx3_task <任务名>"}
{"author":"HornCopper","version":"1.6-Release","name":"剑网三搜索器(jx3)","admin":"N/A","aliases":"+jx3_horse -> +马$+jx3_server -> +服务器$+jx3_macro -> +宏$+jx3_daily -> +日常、+周常$+jx3_exam -> +科举$+jx3_matrix -> +阵眼$+jx3_equip -> +装备$+jx3_require -> +奇遇信息$+jx3_news -> +新闻$+jx3_random -> +骚话$+jx3_heighten -> +小药$+jx3_price -> +物价$+jx3_demon -> +金价$+jx3_kungfu -> +心法$+jx3_skill -> +技能$+jx3_achievement -> +奇遇$+jx3_talent -> +奇穴$+jx3_pet -> +宠物$+jx3_adventure -> +成就$+jx3_task -> +任务$+jx3_subscribe -> +订阅$+jx3_unsubscribe -> +退订","desc":"获取马匹刷新地点:+jx3_horse <马驹名>$获取服务器状态:+jx3_server <服务器名>$获取剑网3宏命令:+jx3_macro <心法名>$获取日常/周常:+jx3_daily [服务器名(可选)]$获取科举答案:+jx3_exam <问题关键词>$获取阵眼效果:+jx3_matrix <心法名>$获取推荐装备:+jx3_equip <心法名>$获取绝世/珍稀奇遇前置条件:+jx3_require <奇遇名>$获取剑网3新闻:+jx3_news$获取剑网3“万花谷”频道骚话:+jx3_random$获取心法当前赛季适合的小药:+jx3_heighten <心法名>$获取服务器外观物价:+jx3_price <外观物品名>$获取服务器金价:+jx3_demon <服务器名>$(大概率失败)获取心法所有技能:+jx3_kungfu <心法名>$获取技能:+jx3_skill <心法名> <技能名>$获取奇遇(支持宠物奇遇):+jx3_achievement <奇遇名/ID>$获取奇穴信息:+jx3_talent <心法名> <奇穴名>$获取宠物信息:+jx3_pet <宠物名>$获取成就信息:+jx3_adventure <成就名>$查询任务信息:+jx3_task <任务名>$订阅事件推送:+jx3_subscribe$取消订阅事件推送:+jx3_unsubscribe"}
Loading

0 comments on commit ec6f1c3

Please sign in to comment.