Skip to content

Commit

Permalink
Feat: Add switch to NLP.
Browse files Browse the repository at this point in the history
  • Loading branch information
remiliacn committed Feb 7, 2022
1 parent a7a4efb commit eb29b63
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
18 changes: 14 additions & 4 deletions awesome/plugins/admin_setting/admin_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@

import config
from awesome.adminControl import permission as perm
from awesome.adminControl.permission import OWNER
from awesome.plugins.shadiao.shadiao import setu_control
from awesome.plugins.util.helper_util import get_downloaded_image_path
from awesome.plugins.util.helper_util import get_downloaded_image_path, set_group_permission
from qq_bot_core import alarm_api
from qq_bot_core import user_control_module

get_privilege = lambda x, y: user_control_module.get_user_privilege(x, y)


@nonebot.on_command('测试', only_to_me=False)
async def test_json(session: nonebot.CommandSession):
await session.send('')
@nonebot.on_command('自由发言', only_to_me=False)
async def free_speech_switch(session: nonebot.CommandSession):
ctx = session.ctx.copy()
user_id = ctx['user_id']
group_id = ctx['group_id'] if 'group_id' in ctx else -1

if group_id == -1 or not get_privilege(user_id, OWNER):
await session.finish()

arg = session.current_arg_text
set_group_permission(arg, group_id, 'FREE_SPEECH')
await session.finish('我好了')


@nonebot.on_command('警报解除', only_to_me=False)
Expand Down
49 changes: 25 additions & 24 deletions awesome/plugins/natural_language/natural_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,36 @@ async def natural_language_proc(session: nonebot.NLPSession):
await session.send(f'已添加!(当前总语录条数:{admin_control.get_group_quote_count(group_id)})')
return

if match(r'.*?哼{2,}啊+', message):
await session.send('别臭了别臭了!孩子要臭傻了')
return

if '为什么' in message and randint(0, 4) == 1:
await session.send('因为你不厉害')
return

auto_reply = _do_auto_reply_retrieve(user_id, group_id, message)
if auto_reply:
await session.send(auto_reply)
return

reply_response = await _check_reply_keywords(message, session.self_id)
if reply_response:
await session.send(reply_response)
return

if admin_control.get_group_permission(group_id, 'flash', default_if_none=False):
fetch_flash_image = await _get_flash_image_entry(message)
if fetch_flash_image:
await session.send(f'已拦截到闪照~\n'
f'[CQ:image,file={fetch_flash_image}]')

message = message.strip()
fetch_result = _repeat_and_palindrome_fetch(message)
if fetch_result:
await session.send(fetch_result)
return
if admin_control.get_group_permission(group_id, 'FREE_SPEECH'):
if match(r'.*?哼{2,}啊+', message):
await session.send('别臭了别臭了!孩子要臭傻了')
return

if '为什么' in message and randint(0, 4) == 1:
await session.send('因为你不厉害')
return

auto_reply = _do_auto_reply_retrieve(user_id, group_id, message)
if auto_reply:
await session.send(auto_reply)
return

if admin_control.get_group_permission(group_id, 'flash', default_if_none=False):
fetch_flash_image = await _get_flash_image_entry(message)
if fetch_flash_image:
await session.send(f'已拦截到闪照~\n'
f'[CQ:image,file={fetch_flash_image}]')

message = message.strip()
fetch_result = _repeat_and_palindrome_fetch(message)
if fetch_result:
await session.send(fetch_result)
return

fetch_result = await _check_if_asking_definition(message)
if fetch_result:
Expand Down
1 change: 1 addition & 0 deletions awesome/plugins/util/helper_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


def set_group_permission(message: str, group_id: Union[str, int], tag: str) -> bool:
group_id = str(group_id)
if '开' in message:
admin_control.set_group_permission(group_id=group_id, tag=tag, stat=True)
return True
Expand Down

0 comments on commit eb29b63

Please sign in to comment.