Skip to content

Commit

Permalink
update & fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DoroWolf committed Jan 15, 2025
1 parent 3c75196 commit 426a2e9
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 46 deletions.
45 changes: 15 additions & 30 deletions bots/aiocqhttp/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from core.utils.storedata import get_stored_list

enable_analytics = Config("enable_analytics", False)
qq_typing_emoji = str(Config("qq_typing_emoji", 181, (str, int), table_name="bot_aiocqhttp"))


class FinishedSession(FinishedSessionT):
Expand Down Expand Up @@ -430,47 +431,31 @@ def __init__(self, msg: MessageSessionT):
async def __aenter__(self):
if self.msg.target.target_from == target_group_prefix: # wtf onebot 11
obi = await get_onebot_implementation()
if obi == "ntqq":
if obi in ["llonebot", "napcat"]:
await bot.call_action(
"set_msg_emoji_like",
message_id=self.msg.session.message.message_id,
emoji_id=str(
Config(
"qq_typing_emoji",
181,
(str, int),
table_name="bot_aiocqhttp",
)
),
)
emoji_id=qq_typing_emoji)
elif obi == "lagrange":
await bot.call_action(
"set_group_reaction",
group_id=self.msg.session.target,
message_id=self.msg.session.message.message_id,
code=qq_typing_emoji,
is_add=True)
else:
if self.msg.session.sender in last_send_typing_time:
if (
datetime.datetime.now().timestamp()
- last_send_typing_time[self.msg.session.sender]
<= 3600
):
if datetime.datetime.now().timestamp() - last_send_typing_time[self.msg.session.sender] <= 3600:
return
last_send_typing_time[self.msg.session.sender] = (
datetime.datetime.now().timestamp()
)

if obi == "lagrange":
await bot.call_action(
"group_poke",
group_id=self.msg.session.target,
user_id=self.msg.session.sender,
)
elif obi == "shamrock":
last_send_typing_time[self.msg.session.sender] = datetime.datetime.now().timestamp()
if obi == "shamrock":
await bot.send_group_msg(
group_id=self.msg.session.target,
message=f"[CQ:touch,id={self.msg.session.sender}]",
)
message=f"[CQ:touch,id={self.msg.session.sender}]")
elif obi == "go-cqhttp":
await bot.send_group_msg(
group_id=self.msg.session.target,
message=f"[CQ:poke,qq={self.msg.session.sender}]",
)
message=f"[CQ:poke,qq={self.msg.session.sender}]")
else:
pass

Expand Down
4 changes: 2 additions & 2 deletions bots/aiocqhttp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ async def get_onebot_implementation() -> Optional[str]:
Logger.debug(str(data))
app_name = data.get("app_name")

if app_name in ["NapCat.Onebot", "LLOneBot"]:
app_name = "ntqq"
if app_name == "NapCat.Onebot":
app_name = "napcat"
elif app_name == "Lagrange.OneBot":
app_name = "lagrange"

Expand Down
4 changes: 4 additions & 0 deletions bots/qqbot/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ async def send_message(
)
if not msg_quote and quote:
msg = f"<@{self.session.message.author.id}> \n" + msg
msg = "" if not msg else msg
send = await self.session.message.reply(
content=msg, file_image=send_img, message_reference=msg_quote
)
Expand Down Expand Up @@ -151,6 +152,7 @@ async def send_message(
if quote and not send_img
else None
)
msg = "" if not msg else msg
send = await self.session.message.reply(
content=msg, file_image=send_img, message_reference=msg_quote
)
Expand Down Expand Up @@ -183,6 +185,7 @@ async def send_message(
)
if msg and self.session.message.id:
msg = "\n" + msg
msg = "" if not msg else msg
try:
send = await self.session.message.reply(
content=msg,
Expand Down Expand Up @@ -235,6 +238,7 @@ async def send_message(
file_type=1,
file_data=await image_1.get_base64(),
)
msg = "" if not msg else msg
try:
send = await self.session.message.reply(
content=msg,
Expand Down
2 changes: 1 addition & 1 deletion bots/web/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
WEBUI_PORT = Config("webui_port", 8081, table_name="bot_web")

Info.client_name = client_name
PrivateAssets.set(os.path.join(assets_path, "private", "api"))
PrivateAssets.set(os.path.join(assets_path, "private", "web"))


def run_fastapi():
Expand Down
5 changes: 2 additions & 3 deletions core/bot_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def load_secret():


async def load_prompt(bot) -> None:
author_cache = os.path.join(PrivateAssets.path, "cache_restart_author")
author_cache = os.path.join(PrivateAssets.path, ".cache_restart_author")
loader_cache = os.path.join(PrivateAssets.path, ".cache_loader")
if os.path.exists(author_cache):
with open(author_cache, "r", encoding="utf-8") as open_author_cache:
Expand All @@ -70,8 +70,7 @@ async def load_prompt(bot) -> None:
await m.send_direct_message(
m.parent.locale.t("loader.load.success")
)
os.remove(author_cache)
os.remove(loader_cache)
os.remove(author_cache)


__all__ = ["init_async", "load_prompt"]
28 changes: 19 additions & 9 deletions core/parser/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from core.utils.message import remove_duplicate_space

qq_account = Config("qq_account", cfg_type=(int, str), table_name='bot_aiocqhttp')
qq_limited_emoji = str(Config('qq_limited_emoji', 10060, (str, int), table_name='bot_aiocqhttp'))

default_locale = Config("default_locale", cfg_type=str)
enable_tos = Config('enable_tos', True)
Expand Down Expand Up @@ -446,15 +447,24 @@ async def execute_submodule(msg: Bot.MessageSession, command_first_word):
except SendMessageFailed:
if msg.target.target_from == qq_group_prefix: # wtf onebot 11
obi = await get_onebot_implementation()
if obi == 'ntqq':
await msg.call_api('set_msg_emoji_like', message_id=msg.session.message.message_id,
emoji_id=str(Config('qq_limited_emoji', 10060, (str, int), table_name='bot_aiocqhttp')))
elif obi == 'lagrange':
await msg.call_api('group_poke', group_id=msg.session.target, user_id=int(qq_account))
elif obi == 'shamrock':
await msg.call_api('send_group_msg', group_id=msg.session.target, message=f'[CQ:touch,id={qq_account}]')
elif obi == 'go-cqhttp':
await msg.call_api('send_group_msg', group_id=msg.session.target, message=f'[CQ:poke,qq={qq_account}]')
if obi in ["llonebot", "napcat"]:
await msg.call_api("set_msg_emoji_like",
message_id=msg.session.message.message_id,
emoji_id=qq_limited_emoji)
elif obi == "lagrange":
await msg.call_api("set_group_reaction",
group_id=msg.session.target,
message_id=msg.session.message.message_id,
code=qq_limited_emoji,
is_add=True)
elif obi == "shamrock":
await msg.call_api("send_group_msg",
group_id=msg.session.target,
message=f"[CQ:touch,id={qq_account}]")
elif obi == "go-cqhttp":
await msg.call_api("send_group_msg",
group_id=msg.session.target,
message=f"[CQ:poke,qq={qq_account}]")
else:
pass
await msg.send_message(msg.locale.t("error.message.limited"))
Expand Down
2 changes: 1 addition & 1 deletion modules/core/su_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def restart():


def write_version_cache(msg: Bot.MessageSession):
update = os.path.join(PrivateAssets.path, 'cache_restart_author')
update = os.path.join(PrivateAssets.path, '.cache_restart_author')
with open(update, 'wb') as write_version:
write_version.write(json.dumps({'From': msg.target.target_from, 'ID': msg.target.target_id}))

Expand Down

0 comments on commit 426a2e9

Please sign in to comment.