From aca04c9e339a1eedbcf4bdce6367a5b79016388c Mon Sep 17 00:00:00 2001 From: Vivien <34387011+vivien8261@users.noreply.github.com> Date: Wed, 31 Jul 2024 11:33:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?update=20=E6=9B=B4=E6=96=B0=E5=88=86?= =?UTF-8?q?=E7=89=87=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/publish.txt | 2 +- core/database/bot.py | 41 ++++++++++++++++++++++------------ core/server/bot.py | 3 +++ requirements.txt | 2 +- run_plugin_server.py | 53 ++++++++++++++++++++++++++++++++------------ 5 files changed, 71 insertions(+), 30 deletions(-) diff --git a/.github/publish.txt b/.github/publish.txt index 5438f706..b558f3bb 100644 --- a/.github/publish.txt +++ b/.github/publish.txt @@ -1 +1 @@ -v6.5.0 +v6.5.1 diff --git a/core/database/bot.py b/core/database/bot.py index 04f4cc49..b95b49af 100644 --- a/core/database/bot.py +++ b/core/database/bot.py @@ -5,6 +5,7 @@ from core.cosChainBuilder import COSQQGroupChainBuilder from typing import Union +from amiyabot.adapters.tencent.qqGuild import qq_guild_shards from amiyabot.adapters.tencent.qqGlobal import qq_global from amiyabot.adapters.tencent.qqGroup import qq_group, QQGroupChainBuilderOptions from amiyabot.adapters.cqhttp import cq_http @@ -40,13 +41,16 @@ class BotAccounts(BotBaseModel): is_start: int = SmallIntegerField(default=1) is_main: int = SmallIntegerField(default=0) console_channel: str = CharField(null=True) - adapter: str = CharField(default='tencent') + adapter: str = CharField(default='qq_guild') host: str = CharField(null=True) ws_port: int = IntegerField(null=True) http_port: int = IntegerField(null=True) client_secret: str = CharField(null=True) + shard_index: int = SmallIntegerField(default=0) + shards: int = SmallIntegerField(default=1) + @classmethod def get_all_account(cls): select: List[cls] = cls.select() @@ -71,6 +75,7 @@ def build_conf(cls, item): 'com_wechat': com_wechat, } tx_adapters = { + 'qq_guild': qq_guild_shards, 'qq_group': qq_group, 'qq_global': qq_global, } @@ -89,21 +94,29 @@ def build_conf(cls, item): ) if item.adapter in tx_adapters: - opt = QQGroupChainBuilderOptions( - item.host or '0.0.0.0', - item.http_port or 8086, - './resource/group_temp', - ) - if cos_config.activate: - conf['adapter'] = tx_adapters[item.adapter]( - item.client_secret, - default_chain_builder=COSQQGroupChainBuilder(opt), - ) + adapter = tx_adapters[item.adapter] + shards = { + 'shard_index': item.shard_index, + 'shards': item.shards, + } + if item.adapter == 'qq_guild': + conf['adapter'] = adapter(**shards) else: - conf['adapter'] = tx_adapters[item.adapter]( - item.client_secret, - default_chain_builder_options=opt, + opt = QQGroupChainBuilderOptions( + item.host or '0.0.0.0', item.http_port or 8086, './resource/group_temp' ) + if cos_config.activate: + conf['adapter'] = adapter( + item.client_secret, + default_chain_builder=COSQQGroupChainBuilder(opt), + **shards, + ) + else: + conf['adapter'] = adapter( + item.client_secret, + default_chain_builder_options=opt, + **shards, + ) if item.adapter == 'websocket': conf['adapter'] = test_instance(item.host, item.ws_port) diff --git a/core/server/bot.py b/core/server/bot.py index fe7fcfb8..e8fbc35e 100644 --- a/core/server/bot.py +++ b/core/server/bot.py @@ -24,6 +24,9 @@ class BotAccountModel(BotAppId): http_port: Optional[int] = None client_secret: Optional[str] = None + shard_index: int = 0 + shards: int = 1 + start: int = 0 def get_data(self): diff --git a/requirements.txt b/requirements.txt index 63fbff27..5dd80d17 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -amiyabot==1.9.9 +amiyabot==2.0.1 attrdict~=2.0.1 baidu-aip dhash~=1.3 diff --git a/run_plugin_server.py b/run_plugin_server.py index e254a87c..466dfd0a 100644 --- a/run_plugin_server.py +++ b/run_plugin_server.py @@ -1,27 +1,52 @@ -from amiyabot.log import UserLogger +import time +import json +import hashlib +import aiohttp from amiya import run_amiya +from amiyabot.util import argv from pluginsServer.src import server, api +AFDIAN_USER = argv('afdian-user') +AFDIAN_TOKEN = argv('afdian-token') -class Mylogger: - def info(self, text: str): - ... - def error(self, text: str): - ... +@server.server.app.get('/get_sponsors') +async def get_sponsors(): + if not AFDIAN_TOKEN or not AFDIAN_USER: + return [] - def debug(self, text: str): - ... + curr_page = 1 + total_page = 1 + sponsor_list = [] - def warning(self, text: str): - ... + while curr_page <= total_page: + sec = int(time.time()) + params = json.dumps({'page': curr_page}) + data = { + 'user_id': AFDIAN_USER, + 'params': params, + 'ts': sec, + 'sign': hashlib.md5( + f'{AFDIAN_TOKEN}params{params}ts{sec}user_id{AFDIAN_USER}'.encode(encoding='utf-8') + ).hexdigest(), + } + headers = {'Content-Type': 'application/json'} + url = 'https://afdian.com/api/open/query-sponsor' - def critical(self, text: str): - ... + async with aiohttp.ClientSession() as session: + async with session.post(url, data=json.dumps(data), headers=headers) as res: + res_content = await res.json() + if res_content['ec'] == 200: + total_page = res_content['data']['total_page'] + sponsor_list += res_content['data']['list'] + else: + break + curr_page += 1 -UserLogger.logger = Mylogger() + return json.dumps(sponsor_list, ensure_ascii=False) -if __name__ == "__main__": + +if __name__ == '__main__': run_amiya(server.server.serve()) From 2421f344f912cb2e58dfa8aa1b454b887530ac12 Mon Sep 17 00:00:00 2001 From: Vivien <34387011+vivien8261@users.noreply.github.com> Date: Wed, 31 Jul 2024 11:33:41 +0800 Subject: [PATCH 2/2] Update pluginsDev --- pluginsDev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pluginsDev b/pluginsDev index d88a3a36..10ae404a 160000 --- a/pluginsDev +++ b/pluginsDev @@ -1 +1 @@ -Subproject commit d88a3a364ef5a5328e48944cb85be077d7bc3f11 +Subproject commit 10ae404a88e70151d16660b4e4bb13882b0cf01f