-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
369 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,41 @@ | ||
from nonebot import require | ||
from nonebot import get_driver | ||
from nonebot import on_message | ||
from nonebot.adapters.onebot.v11 import Event | ||
from nonebot.adapters.onebot.v11 import GroupMessageEvent | ||
|
||
from .config import Config | ||
|
||
from src.common_utils.database import Database | ||
from src.common_utils.system import BeanContainer, is_plugin_enable | ||
from src.common_utils.system import BeanContainer | ||
from src.common_utils.aliyun import Green | ||
from .image import Image | ||
|
||
require('core') | ||
from src.plugins.core.core import GlobalCore | ||
|
||
global_config = get_driver().config | ||
config = Config.parse_obj(global_config) | ||
plugin_name = "adult" | ||
|
||
core_db = Database() | ||
if not core_db.connect_table("core"): | ||
raise Exception("connect core table error") | ||
global_core = GlobalCore() | ||
green = Green(config.ali_access_id, config.ali_access_key, config.ali_region_sh) | ||
|
||
bean_container = BeanContainer() | ||
bean_container.register(green) | ||
bean_container.register(config) | ||
|
||
module_image = Image(bean_container) | ||
|
||
adult = on_message(priority=10) | ||
|
||
async def check_enable(event: GroupMessageEvent) -> bool: | ||
if not isinstance(event, GroupMessageEvent): | ||
return False | ||
return global_core.is_plugin_enable(plugin_name, event.group_id) | ||
|
||
adult = on_message(priority=10, rule=check_enable) | ||
|
||
|
||
@adult.handle() | ||
async def handle(event: Event): | ||
url_list = [] | ||
for seg in event.get_message(): | ||
if seg.type == "image": | ||
url_list.append(seg.data["url"]) | ||
if len(url_list) == 0: | ||
return | ||
enable = await is_plugin_enable(event, core_db, plugin_name) | ||
if enable is False: | ||
return | ||
handle_ret, score = await module_image.handle(url_list) | ||
if handle_ret is False or score < 0.5: | ||
return | ||
|
||
count = round(score / 20.0) + 1 | ||
await adult.send("💦" * count) | ||
async def handle(event: GroupMessageEvent): | ||
message = await module_image.handle_event(event) | ||
if message is not None: | ||
await adult.finish(message) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,42 @@ | ||
from nonebot import require | ||
from nonebot import get_driver | ||
from nonebot import on_message | ||
from nonebot.adapters.onebot.v11 import Event, GroupMessageEvent | ||
from nonebot.adapters.onebot.v11 import GroupMessageEvent | ||
|
||
from .config import Config | ||
|
||
from src.common_utils.database import Database | ||
from src.common_utils.system import BeanContainer, is_plugin_enable | ||
from src.common_utils.system import BeanContainer | ||
from src.common_utils.aliyun import Nlp | ||
from .chatter import Chatter | ||
|
||
require('core') | ||
from src.plugins.core.core import GlobalCore | ||
|
||
global_config = get_driver().config | ||
config = Config.parse_obj(global_config) | ||
plugin_name = "chat" | ||
|
||
core_db = Database() | ||
if not core_db.connect_table("core"): | ||
raise Exception("connect core table error") | ||
global_core = GlobalCore() | ||
nlp = Nlp(config.ali_access_id, config.ali_access_key, config.ali_region_hz) | ||
|
||
bean_container = BeanContainer() | ||
bean_container.register(config) | ||
|
||
nlp = Nlp(config.ali_access_id, config.ali_access_key, config.ali_region_hz) | ||
bean_container.register(nlp) | ||
|
||
module_chatter = Chatter(bean_container) | ||
|
||
chat = on_message(priority=10) | ||
|
||
async def check_enable(event: GroupMessageEvent) -> bool: | ||
if not isinstance(event, GroupMessageEvent): | ||
return False | ||
return global_core.is_plugin_enable(plugin_name, event.group_id) | ||
|
||
@chat.handle() | ||
async def handle(event: Event): | ||
text = event.get_plaintext() | ||
if len(text) == 0 or text.strip() == "": | ||
return | ||
enable = await is_plugin_enable(event, core_db, plugin_name) | ||
if enable is False: | ||
return | ||
chat = on_message(priority=10, rule=check_enable) | ||
|
||
if not isinstance(event, GroupMessageEvent): | ||
return | ||
|
||
if event.reply is not None \ | ||
and event.reply.sender.user_id == event.self_id \ | ||
and text == "不可以": | ||
search_text = event.reply.message.extract_plain_text() | ||
db_ret, exist = await module_chatter.reply_exist(search_text) | ||
if db_ret is False: | ||
await chat.send("下次还敢") | ||
return | ||
if exist is False: | ||
await chat.send("不是我说的") | ||
return | ||
remove_ret = await module_chatter.reply_delete(search_text) | ||
if remove_ret is False: | ||
await chat.send("下次还敢") | ||
else: | ||
await chat.send("我错了") | ||
else: | ||
handle_ret, reply_text = await module_chatter.handle(event.group_id, text) | ||
if handle_ret is False or len(reply_text) == 0: | ||
return | ||
await chat.send(reply_text) | ||
@chat.handle() | ||
async def handle(event: GroupMessageEvent): | ||
message = await module_chatter.handle_event(event) | ||
if message is not None: | ||
await chat.finish(message) | ||
|
||
|
Oops, something went wrong.