Skip to content

Commit

Permalink
update v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
HibiKier committed Feb 9, 2022
1 parent 4cb91b4 commit 0efb2bb
Show file tree
Hide file tree
Showing 33 changed files with 875 additions and 84 deletions.
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
## 真寻的帮助
请对真寻说: '真寻帮助' or '管理员帮助' or '超级用户帮助' or '真寻帮助 指令'

## 普通帮助图片
![x](https://github.com/HibiKier/zhenxun_bot/blob/0.0.8.2/docs_image/3238573864-836268675-E2FFBB2AC143EAF4DDDF150438508721.png)

## 提供符合真寻标准的插件仓库

[AkashiCoin/nonebot_plugins_zhenxun_bot](https://github.com/AkashiCoin/nonebot_plugins_zhenxun_bot)

## 来点优点?
一.作为bot:
* 实现了许多功能,且提供了大量功能管理命令
* __..... 更多详细请通过`传送门`查看文档!__

二.作为框架?:
* 通过Config配置项将所有插件配置统计保存至config.yaml,利于统一用户修改
* 方便增删插件,原生nonebot2 matcher,不需要额外修改,仅仅通过简单的配置属性就可以生成`帮助图片``帮助信息`
* 提供了cd,阻塞,每日次数等限制,仅仅通过简单的属性就可以生成一个限制,例如:`__plugin_cd_limit__`
Expand Down Expand Up @@ -67,6 +67,8 @@
- [x] 原神资源查询 (借鉴[Genshin_Impact_bot](https://github.com/H-K-Y/Genshin_Impact_bot)插件)
- [x] 原神便笺查询
- [x] 原神玩家查询
- [x] 原神树脂提醒
- [x] 原神签到/自动签到
- [x] 金币红包
- [x] 微博热搜
- [x] B站主播/UP/番剧订阅
Expand Down Expand Up @@ -147,6 +149,7 @@
- [x] 清理临时数据
- [x] 增删群认证
- [x] 同意/拒绝好友/群聊请求
- [x] 配置重载

#### 超级用户的被动技能
- [x] 邀请入群提醒(别人邀请真寻入群)
Expand All @@ -171,6 +174,7 @@
- [x] 群管理员监控,自动为新晋管理员增加权限,为失去群管理员的用户删除权限
- [x] 群权限系统
- [x] 定时更新权限
- [x] 自动配置重载
</details>

## 详细配置请前往文档,以下为最简部署和配置,如果你有基础并学习过nonebot2的话
Expand Down Expand Up @@ -217,10 +221,25 @@ python bot.py
```


## 使用Docker
__Docker 最新版本由 [Sakuracio](https://github.com/Sakuracio) 提供__
#### GitHub:[Sakuracio/zxenv](https://github.com/Sakuracio/zxenv)
#### DockerHub:[hibikier/zhenxun_bot](https://hub.docker.com/r/hibikier/zhenxun_bot)



## 更新

### 2021/2/9 \[v0.1]

* 新增原神自动签到和手动签到
* 新增原神树脂提醒
* 新增手动重载Config.yaml命令以及重载配置定时任务(极少部分帮助或配置可能需要重启
* 修改了发送本地图库的matcher,改为on_message
* register_use可以通过返回值发送消息
* 修复修改商品时限制时间出错
* 修复超时商品依旧可以被购买

### 2021/1/16 \[v0.0.9.0]

* Ai提供文本敏感词过滤器
Expand All @@ -240,7 +259,7 @@ python bot.py
* “send_success_msg”(发送成功的交互信息->即:使用道具 {name} {num} 次成功)
*_max_num_limit”(该道具单次使用的最多个数,默认1)

### 2021/1/5 \[v0.0.8.3]
### 2021/1/5 \[v0.0.8.2]

* 提供金币消费hook,可在plugins2settings.yaml中配置该功能需要消费的金币
* 商店插件将作为内置插件移动至basic_plugins
Expand Down Expand Up @@ -311,5 +330,5 @@ __..... 更多更新信息请查看文档__
[H-K-Y / Genshin_Impact_bot](https://github.com/H-K-Y/Genshin_Impact_bot) :原神bot,这是一个基于nonebot和HoshinoBot的原神娱乐及信息查询插件
[NothAmor / nonebot2_luxun_says](https://github.com/NothAmor/nonebot2_luxun_says) :基于nonebot2机器人框架的鲁迅说插件
[Kyomotoi / AnimeThesaurus](https://github.com/Kyomotoi/AnimeThesaurus) :一个~~特二刺螈~~(文爱)的适用于任何bot的词库
[Ailitonia / omega-miya](https://github.com/Ailitonia/omega-miya) :基于nonebot2的qq机器人
[Ailitonia / omega-miya](https://github.com/Ailitonia/omega-miya) :基于nonebot2的qq机器人
[KimigaiiWuyi / GenshinUID]("https://github.com/KimigaiiWuyi/GenshinUID") :一个基于HoshinoBot/NoneBot2的原神UID查询插件
1 change: 0 additions & 1 deletion basic_plugins/init_plugin_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
)
from .init import init
from .check_plugin_status import check_plugin_status
from utils.manager import admin_manager
from nonebot.adapters.cqhttp import Bot
from configs.path_config import DATA_PATH
from services.log import logger
Expand Down
12 changes: 12 additions & 0 deletions basic_plugins/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ async def _():
"ALTER TABLE bag_users ADD property json NOT NULL DEFAULT '{}';",
"bag_users",
), # bag_users 新增字段 property 替代 props
(
"ALTER TABLE genshin ADD auto_sign_time timestamp with time zone;",
"genshin"
), # 新增原神自动签到字段
(
"ALTER TABLE genshin ADD resin_remind boolean DEFAULT False;",
"genshin"
), # 新增原神自动签到字段
(
"ALTER TABLE genshin ADD resin_recovery_time timestamp with time zone;",
"genshin"
), # 新增原神自动签到字段
]
for sql in sql_str:
try:
Expand Down
21 changes: 11 additions & 10 deletions basic_plugins/shop/buy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from services.db_context import db
from nonebot.adapters.cqhttp.permission import GROUP
from models.goods_info import GoodsInfo
import time


__zx_plugin_name__ = "商店 - 购买道具"
Expand All @@ -20,7 +21,7 @@
""".strip()
__plugin_des__ = "商店 - 购买道具"
__plugin_cmd__ = ["购买 [序号或名称] ?[数量=1]"]
__plugin_type__ = ('商店',)
__plugin_type__ = ("商店",)
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
Expand All @@ -29,9 +30,7 @@
"limit_superuser": False,
"cmd": ["商店", "购买道具"],
}
__plugin_cd_limit__ = {
"cd": 3
}
__plugin_cd_limit__ = {"cd": 3}


buy = on_command("购买", aliases={"购买道具"}, priority=5, block=True, permission=GROUP)
Expand All @@ -42,26 +41,28 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
goods = None
if get_message_text(event.json()) in ["神秘药水"]:
await buy.finish("你们看看就好啦,这是不可能卖给你们的~", at_sender=True)
goods_lst = await GoodsInfo.get_all_goods()
goods_name_lst = [x.goods_name for x in goods_lst]
goods_name_lst = [
x.goods_name
for x in await GoodsInfo.get_all_goods()
if x.goods_limit_time > time.time() or x.goods_limit_time == 0
]
msg = get_message_text(event.json()).split()
num = 1
if len(msg) > 1:
if is_number(msg[1]) and int(msg[1]) > 0:
num = int(msg[1])
else:
await buy.finish("购买的数量要是数字且大于0!", at_sender=True)
# print(msg, num)
if is_number(msg[0]):
msg = int(msg[0])
if msg > len(goods_lst) or msg < 1:
if msg > len(goods_name_lst) or msg < 1:
await buy.finish("请输入正确的商品id!", at_sender=True)
goods = goods_lst[msg - 1]
goods = goods_name_lst[msg - 1]
else:
if msg[0] in goods_name_lst:
for i in range(len(goods_name_lst)):
if msg[0] == goods_name_lst[i]:
goods = goods_lst[i]
goods = goods_name_lst[i]
break
else:
await buy.finish("请输入正确的商品名称!")
Expand Down
6 changes: 3 additions & 3 deletions basic_plugins/shop/shop_handle/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,12 @@ async def update_goods(**kwargs) -> "str, str, int":
tmp += f'折扣:{discount} --> {kwargs["discount"]}\n'
discount = kwargs["discount"]
if kwargs.get("limit_time"):
kwargs["limit_time"] = float(kwargs["limit_time"])
new_time = time.strftime(
"%Y-%m-%d %H:%M:%S",
time.localtime(time.time() + int(kwargs["limit_time"] * 60 * 60)),
time.localtime(time.time() + kwargs["limit_time"] * 60 * 60),
)
tmp += f"折扣至{new_time}\n"
tmp += f"限时至{new_time}\n"
limit_time = kwargs["limit_time"]
return (
await GoodsInfo.update_goods(
Expand Down Expand Up @@ -249,7 +250,6 @@ def parse_goods_info(msg: str) -> Union[dict, str]:
sp = x.split(":", maxsplit=1)
if str(sp[1]).strip():
sp[1] = sp[1].strip()
print(sp)
if sp[0] == "name":
data["name"] = sp[1]
elif sp[0] == "price":
Expand Down
4 changes: 3 additions & 1 deletion basic_plugins/shop/use/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
await use_props.finish(f"该道具单次只能使用 {n} 个!")
if await BagUser.delete_property(
event.user_id, event.group_id, name, num
) and await effect(bot, event, name, num):
):
if func_manager.check_send_success_message(name):
await use_props.send(f"使用道具 {name} {num} 次成功!", at_sender=True)
if msg := await effect(bot, event, name, num):
await use_props.send(msg, at_sender=True)
logger.info(
f"USER {event.user_id} GROUP {event.group_id} 使用道具 {name} {num} 次成功"
)
Expand Down
18 changes: 10 additions & 8 deletions basic_plugins/shop/use/data_source.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from nonebot.adapters.cqhttp import GroupMessageEvent
from nonebot.adapters.cqhttp import GroupMessageEvent, MessageSegment
from services.log import logger
from nonebot.adapters.cqhttp import Bot
from typing import Optional, Union
import asyncio


Expand Down Expand Up @@ -32,19 +33,19 @@ def get_max_num_limit(self, goods_name: str) -> int:
return self._data[goods_name]["kwargs"]["_max_num_limit"]
return 1

async def use(self, **kwargs):
async def use(self, **kwargs) -> Optional[Union[str, MessageSegment]]:
"""
使用道具
:param kwargs: kwargs
"""
goods_name = kwargs.get("goods_name")
if self.exists(goods_name):
if asyncio.iscoroutinefunction(self._data[goods_name]["func"]):
await self._data[goods_name]["func"](
return await self._data[goods_name]["func"](
**kwargs,
)
else:
self._data[goods_name]["func"](
return self._data[goods_name]["func"](
**kwargs,
)

Expand All @@ -70,7 +71,9 @@ def get_kwargs(self, goods_name: str) -> dict:
func_manager = GoodsUseFuncManager()


async def effect(bot: Bot, event: GroupMessageEvent, goods_name: str, num: int) -> bool:
async def effect(
bot: Bot, event: GroupMessageEvent, goods_name: str, num: int
) -> Optional[Union[str, MessageSegment]]:
"""
商品生效
:param bot: Bot
Expand All @@ -83,7 +86,7 @@ async def effect(bot: Bot, event: GroupMessageEvent, goods_name: str, num: int)
try:
if func_manager.exists(goods_name):
_kwargs = func_manager.get_kwargs(goods_name)
await func_manager.use(
return await func_manager.use(
**{
**_kwargs,
"_bot": bot,
Expand All @@ -94,10 +97,9 @@ async def effect(bot: Bot, event: GroupMessageEvent, goods_name: str, num: int)
"goods_name": goods_name,
}
)
return True
except Exception as e:
logger.error(f"use 商品生效函数effect 发生错误 {type(e)}{e}")
return False
return None


def register_use(goods_name: str, func, **kwargs):
Expand Down
30 changes: 30 additions & 0 deletions basic_plugins/super_cmd/reload_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
group_manager,
)
from nonebot.typing import T_State
from configs.config import Config
from services.log import logger
from nonebot.adapters.cqhttp import Bot, MessageEvent
from utils.utils import scheduler


__zx_plugin_name__ = "重载插件配置 [Superuser]"
Expand All @@ -28,6 +31,18 @@
]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_configs__ = {
"AUTO_RELOAD": {
"value": False,
"help": "自动重载配置文件",
"default_value": False
},
"AUTO_RELOAD_TIME": {
"value": 180,
"help": "控制自动重载配置文件时长",
"default_value": 180
}
}


reload_plugins_manager = on_command(
Expand All @@ -41,4 +56,19 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
plugins2cd_manager.reload()
plugins2block_manager.reload()
group_manager.reload()
Config.reload()
await reload_plugins_manager.send("重载完成...")


@scheduler.scheduled_job(
'interval',
seconds=Config.get_config("reload_setting", "AUTO_RELOAD_TIME", 180),
)
async def _():
if Config.get_config("reload_setting", "AUTO_RELOAD"):
plugins2settings_manager.reload()
plugins2cd_manager.reload()
plugins2block_manager.reload()
group_manager.reload()
Config.reload()
logger.debug("已自动重载所有配置文件...")
6 changes: 4 additions & 2 deletions models/group_member_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ async def set_group_member_nickname(
@classmethod
async def get_user_all_group(cls, user_qq: int) -> List[int]:
"""
获取该用户所在的所有群聊
:param user_qq: 用户qq
说明:
获取该用户所在的所有群聊
参数:
:param user_qq: 用户qq
"""
query = await cls.query.where(cls.user_qq == user_qq).gino.all()
if query:
Expand Down
3 changes: 1 addition & 2 deletions plugins/bilibili_sub/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ async def get_sub_status(id_: int, sub_type: str) -> Optional[str]:
获取订阅状态
:param id_: 订阅 id
:param sub_type: 订阅类型
:return:
"""
try:
if sub_type == "live":
Expand All @@ -203,7 +202,7 @@ async def get_sub_status(id_: int, sub_type: str) -> Optional[str]:
elif sub_type == "season":
return await _get_season_status(id_)
except ResponseCodeException:
return "获取信息失败...请检查订阅Id是否存在或稍后再试..."
return f"Id:{id_} 获取信息失败...请检查订阅Id是否存在或稍后再试..."
# except Exception as e:
# logger.error(f"获取订阅状态发生预料之外的错误 id_:{id_} {type(e)}:{e}")
# return "发生了预料之外的错误..请稍后再试或联系管理员....."
Expand Down
2 changes: 1 addition & 1 deletion plugins/dialogue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
user_id = 0
if is_number(msg[1]):
group_id = int(msg[1])
text = msg[2]
text = " ".join(msg[2:])
else:
await reply.finish("群号错误...", at_sender=True)
else:
Expand Down
13 changes: 0 additions & 13 deletions plugins/draw_card/genshin_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,6 @@ async def update_genshin_info():
data, code = await update_info(
url,
"genshin_arms",
[
"头像",
"名称",
"类型",
"稀有度.alt",
"获取途径",
"初始基础属性1",
"初始基础属性2",
"攻击力(MAX)",
"副属性(MAX)",
"技能",
],
)
if code == 200:
ALL_ARMS = init_game_pool("genshin_arms", data, GenshinChar)
Expand Down Expand Up @@ -177,7 +165,6 @@ def _get_genshin_card(mode: int = 1, pool_name: str = "", add: float = 0.0):
if flag and star > 3 and pool_name:
# 获取up角色列表
up_char_lst = [x.operators for x in data_lst if x.star == star][0]
print(up_char_lst)
# 成功获取up角色
if random.random() < 0.5:
up_char_name = random.choice(up_char_lst)
Expand Down
Loading

0 comments on commit 0efb2bb

Please sign in to comment.