Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
移除qq_account配置项
重构ab_qq
  • Loading branch information
cloudw233 committed Feb 3, 2025
1 parent c3d5c78 commit 3a867c2
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 42 deletions.
1 change: 0 additions & 1 deletion assets/config_store/en_us/bot_aiocqhttp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

[bot_aiocqhttp]
# The basic config section of the platform. The value ​​filled in here can be displayed in the message. Please do not fill in sensitive information in this section.
qq_account = "<Replace me with (int, str) value>" # Bot QQ number. (Required when using the Onebot Protocol side to deploy the QQ bot)
qq_enable_listening_self_message = false # Whether to enable self-message monitoring when using the Onebot protocol.
qq_disable_temp_session = true # Whether to enable temp sessions when using the Onebot Protocol.
qq_allow_approve_friend = false # Whether to automatically approve friend requests when using the Onebot protocol.
Expand Down
1 change: 0 additions & 1 deletion assets/config_store/zh_cn/bot_aiocqhttp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

[bot_aiocqhttp]
# 平台端的配置部分,此处填写的值可在消息中以明文形式展示。请不要在此部分填写敏感信息。
qq_account = "<Replace me with (int, str) value>" # 机器人 QQ 号。(使用 Onebot 协议端部署 QQ 机器人时需要)
qq_enable_listening_self_message = false # 使用 Onebot 协议时,是否启用自身消息监听。
qq_disable_temp_session = true # 使用 Onebot 协议时,是否启用临时会话。
qq_allow_approve_friend = false # 使用 Onebot 协议时,是否自动同意好友请求。
Expand Down
1 change: 0 additions & 1 deletion assets/config_store/zh_tw/bot_aiocqhttp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

[bot_aiocqhttp]
# 平台端的設定部分,此處填寫的值可在訊息中以明文顯示。請不要在此部分填寫敏感資訊。
qq_account = "<Replace me with (int, str) value>" # 機器人 QQ 號。(使用 Onebot 協定端部署 QQ 機器人時需要)
qq_enable_listening_self_message = false # 使用 Onebot 協定時,是否啟用自身訊息監聽。
qq_disable_temp_session = true # 使用 Onebot 協定時,是否啟用臨時會話。
qq_allow_approve_friend = false # 使用 Onebot 協定時,是否自動同意好友請求。
Expand Down
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
encode = "UTF-8"

bots_and_required_configs = {
"aiocqhttp": ["qq_host", "qq_account"],
"aiocqhttp": ["qq_host"],
"discord": ["discord_token"],
"aiogram": ["telegram_token"],
"kook": ["kook_token"],
Expand Down
7 changes: 5 additions & 2 deletions bots/aiocqhttp/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from core.bot_init import load_prompt, init_async
from core.builtins import PrivateAssets
from core.builtins.utils import command_prefix
from core.config import Config
from core.builtins.temp import Temp
from core.config import Config, CFGManager
from core.constants.default import issue_url_default, ignored_sender_default, qq_host_default
from core.constants.info import Info
from core.constants.path import assets_path
Expand All @@ -28,7 +29,7 @@
PrivateAssets.set(os.path.join(assets_path, 'private', 'aiocqhttp'))
Info.dirty_word_check = Config('enable_dirty_check', False)
Info.use_url_manager = Config('enable_urlmanager', False)
qq_account = Config("qq_account", cfg_type=(int, str), table_name='bot_aiocqhttp')
qq_account = None
enable_listening_self_message = Config("qq_enable_listening_self_message", False, table_name='bot_aiocqhttp')
ignored_sender = Config("ignored_sender", ignored_sender_default)
default_locale = Config("default_locale", cfg_type=str)
Expand All @@ -37,6 +38,8 @@
@bot.on_startup
async def startup():
await init_async()
qq_account = (await bot.call_action('get_login_info')).get('data').get('user_id')
Temp().data['qq_account'] = qq_account
bot.logger.setLevel(logging.WARNING)


Expand Down
1 change: 0 additions & 1 deletion core/config/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def bot_add_enabled_flag(cls):
# aiocqhttp
Reorganize.table = 'aiocqhttp'
Reorganize.bot_add_enabled_flag()
Reorganize.reorganize_bot_key("qq_account")
Reorganize.reorganize_bot_key("qq_access_token", True)
Reorganize.reorganize_bot_key("qq_allow_approve_friend")
Reorganize.reorganize_bot_key("qq_allow_approve_group_invite")
Expand Down
3 changes: 1 addition & 2 deletions core/locales/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"config.comments.no_confirm": "Whether to execute the command without the sender confirming the message.",
"config.comments.proxy": "Proxy service address.",
"config.comments.qq_access_token": "Access Token for connecting to the WebSocket server when using the Onebot protocol.",
"config.comments.qq_account": "Bot QQ number. (Required when using the Onebot Protocol side to deploy the QQ bot)",
"config.comments.qq_allow_approve_friend": "Whether to automatically approve friend requests when using the Onebot protocol.",
"config.comments.qq_allow_approve_group_invite": "Whether to automatically accept group invitations when using the Onebot protocol.",
"config.comments.qq_bot_appid": "The QQ official robot AppID.",
Expand Down Expand Up @@ -186,4 +185,4 @@
"tos.message.warning.count": "You have received ${current_warns} warnings.",
"tos.message.warning.last": "This is the last warning.",
"tos.message.warning.prompt": "Your account will be blocked if you receive more than ${warn_counts} warnings."
}
}
3 changes: 1 addition & 2 deletions core/locales/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"config.comments.no_confirm": "是否无需发送者确认消息后再执行命令。",
"config.comments.proxy": "代理服务地址。",
"config.comments.qq_access_token": "使用 Onebot 协议时,连接 WebSocket 服务器的 Access Token。",
"config.comments.qq_account": "机器人 QQ 号。(使用 Onebot 协议端部署 QQ 机器人时需要)",
"config.comments.qq_allow_approve_friend": "使用 Onebot 协议时,是否自动同意好友请求。",
"config.comments.qq_allow_approve_group_invite": "使用 Onebot 协议时,是否自动同意群邀请。",
"config.comments.qq_bot_appid": "QQ 机器人(官方)的 AppID。",
Expand Down Expand Up @@ -186,4 +185,4 @@
"tos.message.warning.count": "这是第 ${current_warns} 次警告。",
"tos.message.warning.last": "这是最后一次警告。",
"tos.message.warning.prompt": "如超过 ${warn_counts} 次警告,我们将会封禁你的账户。"
}
}
1 change: 0 additions & 1 deletion core/locales/zh_tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"config.comments.no_confirm": "是否無需傳送者確認訊息後再執行指令。",
"config.comments.proxy": "代理服務位址。",
"config.comments.qq_access_token": "使用 Onebot 協定時,連結 WebSocket 伺服器的 Access Token。",
"config.comments.qq_account": "機器人 QQ 號。(使用 Onebot 協定端部署 QQ 機器人時需要)",
"config.comments.qq_allow_approve_friend": "使用 Onebot 協定時,是否自動同意好友請求。",
"config.comments.qq_allow_approve_group_invite": "使用 Onebot 協定時,是否自動同意群組邀請。",
"config.comments.qq_bot_appid": "QQ 機器人(官方)的 AppID。",
Expand Down
4 changes: 2 additions & 2 deletions core/parser/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from bots.aiocqhttp.info import target_group_prefix as qq_group_prefix, target_guild_prefix as qq_guild_prefix
from bots.aiocqhttp.utils import get_onebot_implementation
from core.builtins import command_prefix, ExecutionLockList, ErrorMessage, MessageTaskManager, Url, Bot, \
base_superuser_list
base_superuser_list, Temp
from core.config import Config
from core.constants.default import bug_report_url_default
from core.constants.exceptions import AbuseWarning, FinishedException, InvalidCommandFormatError, \
Expand All @@ -25,7 +25,7 @@
from core.utils.info import Info
from core.utils.message import remove_duplicate_space

qq_account = Config("qq_account", cfg_type=(int, str), table_name='bot_aiocqhttp')
qq_account = Temp().data.get('qq_account')
qq_limited_emoji = str(Config('qq_limited_emoji', 10060, (str, int), table_name='bot_aiocqhttp'))

enable_tos = Config('enable_tos', True)
Expand Down
29 changes: 6 additions & 23 deletions modules/wiki/utils/ab_qq.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from core.builtins import MessageSession
from core.builtins import MessageSession, MessageChain, Plain
from core.config import Config
from core.logger import Logger
from modules.wiki.utils.ab import convert_ab_to_detailed_format
Expand All @@ -7,7 +7,6 @@

async def ab_qq(msg: MessageSession, wiki_url):
wiki = WikiLib(wiki_url)
qq_account = Config("qq_account", cfg_type=(str, int), table_name="bot_aiocqhttp")
query = await wiki.get_json(
action="query",
list="abuselog",
Expand All @@ -16,28 +15,12 @@ async def ab_qq(msg: MessageSession, wiki_url):
_no_login=not msg.options.get("use_bot_account", False),
)
pageurl = wiki.wiki_info.articlepath.replace("$1", "Special:AbuseLog")
nodelist = [
{
"type": "node",
"data": {
"name": msg.locale.t("wiki.message.ab.qq.link.title"),
"uin": int(qq_account),
"content": [{"type": "text", "data": {"text": pageurl}}],
},
}
]

msgchain_lst = [MessageChain([Plain(msg.locale.t("wiki.message.ab.qq.link.title"))]),
MessageChain([Plain(pageurl)]),
MessageChain([Plain(msg.locale.t("wiki.message.ab.qq.title"))])]
ablist = await convert_ab_to_detailed_format(query["query"]["abuselog"], msg)
for x in ablist:
nodelist.append(
{
"type": "node",
"data": {
"name": msg.locale.t("wiki.message.ab.qq.title"),
"uin": int(qq_account),
"content": [{"type": "text", "data": {"text": x}}],
},
}
)
msgchain_lst.append(MessageChain([Plain(x)]))
nodelist = await msg.msgchain2nodelist(msgchain_lst)
Logger.debug(nodelist)
return nodelist
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3a867c2

Please sign in to comment.