Skip to content

Commit

Permalink
Merge pull request #18 from Ailitonia/dev
Browse files Browse the repository at this point in the history
添加好友私聊命令及订阅支持
  • Loading branch information
Ailitonia authored May 6, 2021
2 parents f1d878b + 4a88fd7 commit 23e2083
Show file tree
Hide file tree
Showing 66 changed files with 2,771 additions and 1,244 deletions.
4 changes: 4 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ SECRET_KEY=

# 识图插件 Saucenao API KEY
SAUCENAO_API_KEY=

# Pixiv cookies
# P站cookies配置, 不填也行, 就是r18多图作品获取不到全部图片链接, 另外请确认P站用户设置-浏览限制中启用r18显示
PIXIV_PHPSESSID=
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@
- 基于插件节点的权限管理系统
- 命令冷却系统
- HTTP 代理功能
- 插件帮助功能
- Bot对群组公告功能
- B站动态订阅 (建议配置B站cookies)
- B站直播间监控 (建议配置B站cookies)
- 求签
- 抽卡
- Pixiv助手 (需要 HTTP 代理, 除非部署在外网)
- Pixivision订阅 (需要 HTTP 代理, 除非部署在外网)
- 复读姬
- roll点抽奖
- 搜番剧 (trace.moe API / 建议使用 HTTP 代理)
- 搜二次元图 (Saucenao API 和 ascii2d / 建议使用 HTTP 代理)
- 来点萌图 / 来点涩图 (需要 HTTP 代理, 除非部署在外网 / 图片数据库需要自己导入)
- 表情包制作器
- 猫按钮 (测试)
- 自动锤轴姬 (需要 go-cqhttp v0.9.40 及以上版本)
- 邮箱插件 (仅支持IMAP收件)
- 腾讯云组件 (测试)
- 自动处理加好友和被邀请进群
- 插件帮助功能 (支持群聊 / 私聊)
- Bot对群组公告功能 (仅支持对群组)
- B站动态订阅 (建议配置B站cookies) (支持群聊 / 私聊)
- B站直播间监控 (建议配置B站cookies) (支持群聊 / 私聊)
- 求签 (仅支持群聊)
- 抽卡 (仅支持群聊)
- 能不能好好说话 (lab.magiconch.com API) (支持群聊 / 私聊)
- Pixiv助手 (需要 HTTP 代理, 除非部署在外网) (需要 go-cqhttp v0.9.40 及以上版本) (仅支持群聊)
- Pixivision订阅 (需要 HTTP 代理, 除非部署在外网) (仅支持群聊)
- 复读姬 (仅支持群聊)
- roll点抽奖 (仅支持群聊)
- 搜番剧 (trace.moe API / 建议使用 HTTP 代理) (支持群聊 / 私聊)
- 搜二次元图 (Saucenao API 和 ascii2d / 建议使用 HTTP 代理) (支持群聊 / 私聊)
- 来点萌图 / 来点涩图 (需要 HTTP 代理, 除非部署在外网 / 图片数据库需要自己导入) (支持群聊 / 私聊)
- 表情包制作器 (支持群聊 / 私聊)
- 猫按钮 (测试) (仅支持群聊)
- 自动锤轴姬 (需要 go-cqhttp v0.9.40 及以上版本) (仅支持群聊)
- 邮箱插件 (仅支持IMAP收件) (仅支持群聊)
- 腾讯云组件 (测试) (仅支持群聊)

## 如何使用

Expand Down
19 changes: 10 additions & 9 deletions omega_miya/plugins/Omega_auth_manage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from nonebot.permission import SUPERUSER
from nonebot.typing import T_State
from nonebot.adapters.cqhttp.bot import Bot
from nonebot.adapters.cqhttp.event import Event
from nonebot.adapters.cqhttp.event import MessageEvent
from omega_miya.utils.Omega_Base import DBUser, DBGroup, DBAuth
from omega_miya.utils.Omega_plugin_utils import init_export

Expand All @@ -13,6 +13,7 @@
__plugin_name__ = 'OmegaAuth'
__plugin_usage__ = r'''【OmegaAuth 授权管理插件】
插件特殊权限授权管理
仅限管理员使用
**Usage**
**SuperUser Only**
Expand All @@ -28,7 +29,7 @@

# 修改默认参数处理
@omegaauth.args_parser
async def parse(bot: Bot, event: Event, state: T_State):
async def parse(bot: Bot, event: MessageEvent, state: T_State):
args = str(event.get_plaintext()).strip().split()
if not args:
await omegaauth.reject('你似乎没有发送有效的参数呢QAQ, 请重新发送:')
Expand All @@ -38,7 +39,7 @@ async def parse(bot: Bot, event: Event, state: T_State):


@omegaauth.handle()
async def handle_first_receive(bot: Bot, event: Event, state: T_State):
async def handle_first_receive(bot: Bot, event: MessageEvent, state: T_State):
args = str(event.get_plaintext()).strip().split()
if not args:
pass
Expand All @@ -49,15 +50,15 @@ async def handle_first_receive(bot: Bot, event: Event, state: T_State):


@omegaauth.got('sub_command', prompt='执行操作?\n【allow/deny/clear/list】')
async def handle_sub_command(bot: Bot, event: Event, state: T_State):
async def handle_sub_command(bot: Bot, event: MessageEvent, state: T_State):
sub_command = state["sub_command"]
if sub_command not in ['allow', 'deny', 'clear', 'list']:
await omegaauth.finish('参数错误QAQ')


# 处理显示权限节点列表事件
@omegaauth.got('sub_command', prompt='list:')
async def handle_list_node(bot: Bot, event: Event, state: T_State):
async def handle_list_node(bot: Bot, event: MessageEvent, state: T_State):
sub_command = state["sub_command"]
if sub_command == 'list':
detail_type = event.dict().get(f'{event.get_type()}_type')
Expand All @@ -84,14 +85,14 @@ async def handle_list_node(bot: Bot, event: Event, state: T_State):


@omegaauth.got('auth_type', prompt='授权类型?\n【user/group】')
async def handle_auth_type(bot: Bot, event: Event, state: T_State):
async def handle_auth_type(bot: Bot, event: MessageEvent, state: T_State):
auth_type = state["auth_type"]
if auth_type not in ['user', 'group']:
await omegaauth.finish('参数错误QAQ')


@omegaauth.got('auth_id', prompt='请输入授权用户qq或授权群组群号:')
async def handle_auth_id(bot: Bot, event: Event, state: T_State):
async def handle_auth_id(bot: Bot, event: MessageEvent, state: T_State):
auth_type = state["auth_type"]
auth_id = state["auth_id"]
if not re.match(r'^\d+$', auth_id):
Expand Down Expand Up @@ -129,7 +130,7 @@ async def handle_auth_id(bot: Bot, event: Event, state: T_State):


@omegaauth.got('plugin', prompt='请输入想要配置权限节点的插件名称:')
async def handle_plugin(bot: Bot, event: Event, state: T_State):
async def handle_plugin(bot: Bot, event: MessageEvent, state: T_State):
plugin = state["plugin"]
auth_node_plugin = state["auth_node_plugin"]
if plugin not in auth_node_plugin:
Expand All @@ -142,7 +143,7 @@ async def handle_plugin(bot: Bot, event: Event, state: T_State):


@omegaauth.got('auth_node', prompt='请输入想要配置的权限节点名称:')
async def handle_auth_node(bot: Bot, event: Event, state: T_State):
async def handle_auth_node(bot: Bot, event: MessageEvent, state: T_State):
auth_node = state["auth_node"]
plugin = state["plugin"]
plugin_auth_nodes = state["plugin_auth_nodes"]
Expand Down
1 change: 1 addition & 0 deletions omega_miya/plugins/Omega_email/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
__plugin_name__ = 'OmegaEmail'
__plugin_usage__ = r'''【OmegaEmail 邮箱插件】
主要是用来收验证码OvO
仅限群聊使用
**Permission**
Command
Expand Down
24 changes: 12 additions & 12 deletions omega_miya/plugins/Omega_email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
AES_KEY = global_config.aes_key


async def check_mailbox(address: str, server_host: str, password: str) -> Result:
def __check_mailbox() -> Result:
async def check_mailbox(address: str, server_host: str, password: str) -> Result.IntResult:
def __check_mailbox() -> Result.IntResult:
try:
with EmailImap(host=server_host, address=address, password=password) as m:
m.select()
__result = Result(error=False, info='Success', result=0)
__result = Result.IntResult(error=False, info='Success', result=0)
except Exception as e:
__result = Result(error=True, info=f'Login Failed: {repr(e)}', result=-1)
__result = Result.IntResult(error=True, info=f'Login Failed: {repr(e)}', result=-1)

return __result

Expand All @@ -27,15 +27,15 @@ def __check_mailbox() -> Result:
return result


async def get_unseen_mail_info(address: str, server_host: str, password: str) -> Result:
def __get_unseen_mail_info() -> Result:
async def get_unseen_mail_info(address: str, server_host: str, password: str) -> Result.ListResult:
def __get_unseen_mail_info() -> Result.ListResult:
try:
mail = EmailImap(host=server_host, address=address, password=password)
unseen_mails = mail.get_mail_info(None, 'UNSEEN')
res = [x for x in unseen_mails]
__result = Result(error=False, info='Success', result=res)
__result = Result.ListResult(error=False, info='Success', result=res)
except Exception as e:
__result = Result(error=True, info=repr(e), result=[])
__result = Result.ListResult(error=True, info=repr(e), result=[])
return __result

loop = asyncio.get_running_loop()
Expand All @@ -52,14 +52,14 @@ def encrypt_password(plaintext: str) -> str:
return json.dumps(list(encryptor.encrypt(plaintext)))


def decrypt_password(ciphertext: str) -> Result:
def decrypt_password(ciphertext: str) -> Result.TextResult:
encryptor = AESEncryptStr(key=AES_KEY)
try:
data = json.loads(ciphertext)
stat, plaintext = encryptor.decrypt(data[0], data[1], data[2])
if stat:
return Result(error=False, info='Success', result=plaintext)
return Result.TextResult(error=False, info='Success', result=plaintext)
else:
return Result(error=True, info='Key incorrect or message corrupted', result=plaintext)
return Result.TextResult(error=True, info='Key incorrect or message corrupted', result=plaintext)
except Exception as e:
return Result(error=True, info=f'Ciphertext parse error: {repr(e)}', result='')
return Result.TextResult(error=True, info=f'Ciphertext parse error: {repr(e)}', result='')
14 changes: 8 additions & 6 deletions omega_miya/plugins/Omega_help/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from nonebot.plugin import get_loaded_plugins
from nonebot.typing import T_State
from nonebot.adapters.cqhttp.bot import Bot
from nonebot.adapters.cqhttp.event import GroupMessageEvent
from nonebot.adapters.cqhttp.permission import GROUP
from nonebot.adapters.cqhttp.event import MessageEvent, GroupMessageEvent, PrivateMessageEvent
from nonebot.adapters.cqhttp.permission import GROUP, PRIVATE_FRIEND
from omega_miya.utils.Omega_plugin_utils import init_export, init_permission_state, PluginCoolDown


Expand Down Expand Up @@ -38,13 +38,13 @@
command=True,
level=10,
auth_node='basic'),
permission=GROUP,
permission=GROUP | PRIVATE_FRIEND,
priority=10,
block=True)


@bot_help.handle()
async def handle_first_receive(bot: Bot, event: GroupMessageEvent, state: T_State):
async def handle_first_receive(bot: Bot, event: MessageEvent, state: T_State):
# 获取设置了名称的插件列表
plugins = list(filter(lambda p: set(p.export.keys()).issuperset({'custom_name', 'usage'}), get_loaded_plugins()))
if not plugins:
Expand All @@ -58,11 +58,13 @@ async def handle_first_receive(bot: Bot, event: GroupMessageEvent, state: T_Stat
else:
# 如果用户没有发送参数, 则发送功能列表并结束此命令
plugins_list = '\n'.join(p.export.custom_name for p in plugins)
await bot_help.finish(f'我现在支持的插件有: \n\n{plugins_list}\n\n注意: 群组权限等级未达到要求的命令不会被响应\n输入"/help [插件]"即可查看插件详情及帮助')
await bot_help.finish(f'我现在支持的插件有: \n\n{plugins_list}\n\n'
f'注意: 群组权限等级未达到要求的, 或非好友或未启用私聊功能的命令不会被响应\n\n'
f'输入"/help [插件]"即可查看插件详情及帮助')


@bot_help.got('plugin_name', prompt='你想查询哪个插件的用法呢?')
async def handle_plugin_name(bot: Bot, event: GroupMessageEvent, state: T_State):
async def handle_plugin_name(bot: Bot, event: MessageEvent, state: T_State):
plugin_custom_name = state["plugin_name"]
# 如果发了参数则发送相应命令的使用帮助
for p in state['plugin_list']:
Expand Down
Loading

0 comments on commit 23e2083

Please sign in to comment.