From e831867c1f58b7b8a7f525e4a8beea02d8f44467 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Fri, 30 Aug 2024 17:16:09 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8domain=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 5 +--- campux/core/app.py | 3 +++ campux/mq/redis.py | 64 +++++++++++++++++++++++--------------------- campux/social/mgr.py | 2 +- 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/.env.example b/.env.example index 3697839..d4df7b4 100644 --- a/.env.example +++ b/.env.example @@ -8,10 +8,6 @@ CAMPUX_TOKEN="campux" CAMPUX_REDIS_HOST="localhost" CAMPUX_REDIS_PORT=6379 CAMPUX_REDIS_PASSWORD="" -CAMPUX_REDIS_PUBLISH_POST_STREAM="campux_publish_post" -CAMPUX_REDIS_NEW_POST_STREAM="campux_new_post" -CAMPUX_REDIS_POST_CANCEL_STREAM="campux_post_cancel" -CAMPUX_REDIS_POST_PUBLISH_STATUS_HASH="campux_post_publish_status" CAMPUX_HELP_MESSAGE="填写未匹配指令时的帮助信息。每用户每60秒只会响应一次。" CAMPUX_REVIEW_HELP_MESSAGE="填写未匹配指令时的审核帮助信息" CAMPUX_REVIEW_QQ_GROUP_ID=123456789 @@ -19,5 +15,6 @@ CAMPUX_QQ_GROUP_REVIEW=true CAMPUX_TEXT_TO_IMAGE_API="https://api.sample.com" CAMPUX_PUBLISH_POST_TIME_DELAY=0 +CAMPUX_DOMAIN="campux" CAMPUX_QQ_BOT_UIN=12345678 CAMPUX_QQ_ADMIN_UIN=12345678 \ No newline at end of file diff --git a/campux/core/app.py b/campux/core/app.py index ac6b60a..6679398 100644 --- a/campux/core/app.py +++ b/campux/core/app.py @@ -31,6 +31,8 @@ def config(self) -> nonebot.config.Config: mq: redis.RedisStreamMQ + redis_name_proxy: redis.RedisNameProxy + social: social_mgr.SocialPlatformManager imbot: imbot_mgr.IMBotManager @@ -71,6 +73,7 @@ async def create_app() -> Application: ap.bot_event_loop = asyncio.get_event_loop() + ap.redis_name_proxy = redis.RedisNameProxy(ap) ap.mq = redis.RedisStreamMQ(ap) await ap.mq.initialize() ap.social = social_mgr.SocialPlatformManager(ap) diff --git a/campux/mq/redis.py b/campux/mq/redis.py index da4bc22..c18e8ec 100644 --- a/campux/mq/redis.py +++ b/campux/mq/redis.py @@ -9,15 +9,29 @@ from ..core import app -streams_name = { - 'campux_redis_publish_post_stream': 'campux_publish_post', - 'campux_redis_new_post_stream': 'campux_new_post', - 'campux_redis_post_cancel_stream': 'campux_post_cancel', -} -hash_table_name = { - 'campux_redis_post_publish_status_hash': 'campux_post_publish_status' -} +class RedisNameProxy: + + ap: app.Application + + def __init__(self, ap: app.Application): + self.ap = ap + + @property + def campux_redis_publish_post_stream(self): + return f"{self.ap.config.campux_domain}.publish_post" + + @property + def campux_redis_new_post_stream(self): + return f"{self.ap.config.campux_domain}.new_post" + + @property + def campux_redis_post_cancel_stream(self): + return f"{self.ap.config.campux_domain}.post_cancel" + + @property + def campux_redis_post_publish_status_hash(self): + return f"{self.ap.config.campux_domain}.post_publish_status" class RedisStreamMQ: @@ -41,24 +55,14 @@ async def initialize(self): db=0, password=self.ap.config.campux_redis_password ) - - # 从config取出各个stream的名字 - for stream_key in streams_name.keys(): - if hasattr(self.ap.config, stream_key): - streams_name[stream_key] = getattr(self.ap.config, stream_key) - - # 从config取出hash table的名称 - for hash_table_key in hash_table_name.keys(): - if hasattr(self.ap.config, hash_table_key): - hash_table_name[hash_table_key] = getattr(self.ap.config, hash_table_key) - - logger.info(f"Redis Streams: {streams_name}") - logger.info(f"Redis Hash Tables: {hash_table_name}") - # 创建xgroup # 检查是否存在同名group - streams_to_check = streams_name.values() + streams_to_check = [ + self.ap.redis_name_proxy.campux_redis_publish_post_stream, + self.ap.redis_name_proxy.campux_redis_new_post_stream, + self.ap.redis_name_proxy.campux_redis_post_cancel_stream, + ] for stream in streams_to_check: group_info = await self.redis_client.xinfo_groups(stream) @@ -79,9 +83,9 @@ async def initialize(self): async def routine_loop(): await asyncio.sleep(10) while True: - await self.process_stream(streams_name['campux_redis_publish_post_stream'], self.check_publish_post) - await self.process_stream(streams_name['campux_redis_new_post_stream'], self.check_new_post) - await self.process_stream(streams_name['campux_redis_post_cancel_stream'], self.check_post_cancel) + await self.process_stream(self.ap.redis_name_proxy.campux_redis_publish_post_stream, self.check_publish_post) + await self.process_stream(self.ap.redis_name_proxy.campux_redis_new_post_stream, self.check_new_post) + await self.process_stream(self.ap.redis_name_proxy.campux_redis_post_cancel_stream, self.check_post_cancel) await asyncio.sleep(30) asyncio.create_task(routine_loop()) @@ -147,7 +151,7 @@ async def check_publish_post(self, message: tuple): if await self.ap.social.can_operate(): asyncio.create_task(self.ap.social.publish_post(post_id)) # 确认消息 - await self.redis_client.xack(streams_name['campux_redis_publish_post_stream'], self.get_instance_identity(), message[0]) + await self.redis_client.xack(self.ap.redis_name_proxy.campux_redis_publish_post_stream, self.get_instance_identity(), message[0]) else: now = time.time() @@ -167,11 +171,11 @@ async def check_new_post(self, message: tuple): await self.ap.imbot.send_new_post_notify(post_id) - await self.redis_client.xack(streams_name['campux_redis_new_post_stream'], self.get_instance_identity(), message[0]) + await self.redis_client.xack(self.ap.redis_name_proxy.campux_redis_new_post_stream, self.get_instance_identity(), message[0]) async def mark_post_published(self, post_id): await self.redis_client.hset( - f"{hash_table_name['campux_redis_post_publish_status_hash']}{post_id}", + f"{self.ap.redis_name_proxy.campux_redis_post_publish_status_hash}{post_id}", self.get_instance_identity(), 1 ) @@ -183,4 +187,4 @@ async def check_post_cancel(self, message: tuple): await self.ap.imbot.send_post_cancel_notify(post_id) - await self.redis_client.xack(streams_name['campux_redis_post_cancel_stream'], self.get_instance_identity(), message[0]) + await self.redis_client.xack(self.ap.redis_name_proxy.campux_redis_post_cancel_stream, self.get_instance_identity(), message[0]) diff --git a/campux/social/mgr.py b/campux/social/mgr.py index f577756..bb25741 100644 --- a/campux/social/mgr.py +++ b/campux/social/mgr.py @@ -86,7 +86,7 @@ async def publish_post(self, post_id: int): )) return except Exception as e: - nonebot.logger.error(f"发表稿件失败:{str(e)}") + nonebot.logger.error(f"发表稿件失败:{traceback.format_exc()}") await self.ap.cpx_api.post_post_log( post_id, From d76f37b6261a81243417c8ada333b40cb22c6cdf Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Fri, 30 Aug 2024 17:23:38 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8=E5=86=92?= =?UTF-8?q?=E5=8F=B7=E5=88=86=E5=89=B2post=5Fpublish=5Fstatus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- campux/mq/redis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/campux/mq/redis.py b/campux/mq/redis.py index c18e8ec..9383628 100644 --- a/campux/mq/redis.py +++ b/campux/mq/redis.py @@ -175,7 +175,7 @@ async def check_new_post(self, message: tuple): async def mark_post_published(self, post_id): await self.redis_client.hset( - f"{self.ap.redis_name_proxy.campux_redis_post_publish_status_hash}{post_id}", + f"{self.ap.redis_name_proxy.campux_redis_post_publish_status_hash}:{post_id}", self.get_instance_identity(), 1 ) From fe8f6c0658f864b199de653e705d66e46c1a4908 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Fri, 30 Aug 2024 22:08:17 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=E4=B8=8D=E5=86=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8.env=E4=BD=9C=E4=B8=BA=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 20 ------------- .gitignore | 3 +- campux/api/api.py | 24 +++++++-------- campux/core/app.py | 49 ++++++++++++++++++++----------- campux/imbot/mgr.py | 8 ++--- campux/imbot/nbmod.py | 16 +++++----- campux/mq/redis.py | 20 ++++++------- campux/social/mgr.py | 12 ++++---- campux/social/qzone/api.py | 2 +- campux/social/render/apirender.py | 6 ++-- main.py | 3 -- templates/config.json | 20 +++++++++++++ templates/metadata.json | 3 ++ 13 files changed, 99 insertions(+), 87 deletions(-) delete mode 100644 .env.example create mode 100644 templates/config.json create mode 100644 templates/metadata.json diff --git a/.env.example b/.env.example deleted file mode 100644 index d4df7b4..0000000 --- a/.env.example +++ /dev/null @@ -1,20 +0,0 @@ -HOST=0.0.0.0 -PORT=8080 -COMMAND_START=["#","#"] -COMMAND_SEP=["."] - -CAMPUX_API="https://sample.com" -CAMPUX_TOKEN="campux" -CAMPUX_REDIS_HOST="localhost" -CAMPUX_REDIS_PORT=6379 -CAMPUX_REDIS_PASSWORD="" -CAMPUX_HELP_MESSAGE="填写未匹配指令时的帮助信息。每用户每60秒只会响应一次。" -CAMPUX_REVIEW_HELP_MESSAGE="填写未匹配指令时的审核帮助信息" -CAMPUX_REVIEW_QQ_GROUP_ID=123456789 -CAMPUX_QQ_GROUP_REVIEW=true -CAMPUX_TEXT_TO_IMAGE_API="https://api.sample.com" -CAMPUX_PUBLISH_POST_TIME_DELAY=0 - -CAMPUX_DOMAIN="campux" -CAMPUX_QQ_BOT_UIN=12345678 -CAMPUX_QQ_ADMIN_UIN=12345678 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8ff84ff..1734c4f 100644 --- a/.gitignore +++ b/.gitignore @@ -159,6 +159,5 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ venv -cache.json -metadata.json +data/ /tests \ No newline at end of file diff --git a/campux/api/api.py b/campux/api/api.py index a9a1f50..78a50c3 100644 --- a/campux/api/api.py +++ b/campux/api/api.py @@ -1,16 +1,19 @@ +from __future__ import annotations + import aiohttp import nonebot from . import errors from ..common import entity +from ..core import app -config = nonebot.get_driver().config +class CampuxAPI: + ap: app.Application -class CampuxAPI: - def __init__(self): - pass + def __init__(self, ap: app.Application): + self.ap = ap async def data( self, @@ -22,10 +25,10 @@ async def data( async with aiohttp.ClientSession() as session: async with session.request( method, - f"{config.campux_api}{path}", + f"{self.ap.config.data['campux_api']}{path}", params=params, json=body, - headers={"Authorization": f"Bearer {config.campux_token}"} + headers={"Authorization": f"Bearer {self.ap.config.data['campux_token']}"} ) as resp: return await self.assert_data(resp) @@ -39,10 +42,10 @@ async def read( async with aiohttp.ClientSession() as session: async with session.request( method, - f"{config.campux_api}{path}", + f"{self.ap.config.data['campux_api']}{path}", params=params, json=body, - headers={"Authorization": f"Bearer {config.campux_token}"} + headers={"Authorization": f"Bearer {self.ap.config.data['campux_token']}"} ) as resp: return await resp.read() @@ -190,8 +193,3 @@ async def submit_post_verbose( "values": values } ) - -campux_api = None - -if campux_api is None: - campux_api = CampuxAPI() diff --git a/campux/core/app.py b/campux/core/app.py index 6679398..512c52c 100644 --- a/campux/core/app.py +++ b/campux/core/app.py @@ -20,15 +20,11 @@ class Application: cache: cache_mgr.CacheManager meta: config_mgr.ConfigManager - - @property - def cpx_api(self) -> api.CampuxAPI: - return api.campux_api - @property - def config(self) -> nonebot.config.Config: - return nonebot.get_driver().config + config: config_mgr.ConfigManager + cpx_api: api.CampuxAPI + mq: redis.RedisStreamMQ redis_name_proxy: redis.RedisNameProxy @@ -48,21 +44,24 @@ def nonebot_thread(): async def create_app() -> Application: - # 注册适配器 - driver = nonebot.get_driver() - driver.register_adapter(OnebotAdapter) - - # 在这里加载插件 - nonebot.load_plugin("campux.imbot.nbmod") # 本地插件 - # 元数据 - meta = await config_mgr.load_json_config("data/metadata.json", template_data={ - "post_publish_text": "'#' + str(post_id)", - }) + meta = await config_mgr.load_json_config( + "data/metadata.json", + template_name="templates/metadata.json" + ) await meta.load_config() await meta.dump_config() + # 配置文件 + config = await config_mgr.load_json_config( + "data/config.json", + template_name="templates/config.json" + ) + + await config.load_config() + await config.dump_config() + # 缓存管理器 cache = cache_mgr.CacheManager() cache.load() @@ -70,6 +69,22 @@ async def create_app() -> Application: ap = Application() ap.cache = cache ap.meta = meta + ap.config = config + + cpx_api = api.CampuxAPI(ap=ap) + + import nonebot + # 初始化 NoneBot + nonebot.init( + **config.data + ) + + # 注册适配器 + driver = nonebot.get_driver() + driver.register_adapter(OnebotAdapter) + + # 在这里加载插件 + nonebot.load_plugin("campux.imbot.nbmod") # 本地插件 ap.bot_event_loop = asyncio.get_event_loop() diff --git a/campux/imbot/mgr.py b/campux/imbot/mgr.py index aeae463..130316f 100644 --- a/campux/imbot/mgr.py +++ b/campux/imbot/mgr.py @@ -56,7 +56,7 @@ async def send_new_post_notify( logger.info(f"新稿件:{post}") - if self.ap.config.campux_qq_group_review: + if self.ap.config.data['campux_qq_group_review']: # 获取所有图片 images = [ @@ -77,7 +77,7 @@ async def send_new_post_notify( ) asyncio.create_task(self.ap.imbot.send_group_message( - self.ap.config.campux_review_qq_group_id, + self.ap.config.data['campux_review_qq_group_id'], msg )) @@ -87,13 +87,13 @@ async def send_post_cancel_notify( ): logger.info(f"稿件已取消:{post_id}") - if self.ap.config.campux_qq_group_review: + if self.ap.config.data['campux_qq_group_review']: msg = [ message.MessageSegment.text(f"稿件已取消: #{post_id}"), ] asyncio.create_task(self.ap.imbot.send_group_message( - self.ap.config.campux_review_qq_group_id, + self.ap.config.data['campux_review_qq_group_id'], msg )) \ No newline at end of file diff --git a/campux/imbot/nbmod.py b/campux/imbot/nbmod.py index 3d83407..f336196 100644 --- a/campux/imbot/nbmod.py +++ b/campux/imbot/nbmod.py @@ -20,7 +20,7 @@ async def is_private(event: Event): return type(event) == ob11_event.PrivateMessageEvent async def not_bot_self(event: Event): - return int(event.get_user_id()) != ap.config.campux_qq_bot_uin + return int(event.get_user_id()) != ap.config.data['campux_qq_bot_uin'] help_message_sent_record: dict[int, int] = {} # user_id, time @@ -77,13 +77,13 @@ async def reset_password_func(event: Event): async def relogin_qzone_func(event: Event): user_id = int(event.get_user_id()) - if user_id != ap.config.campux_qq_admin_uin: + if user_id != ap.config.data['campux_qq_admin_uin']: await relogin_qzone.finish("无权限") return async def qrcode_callback(content: bytes): asyncio.create_task(ap.imbot.send_private_message( - ap.config.campux_qq_admin_uin, + ap.config.data['campux_qq_admin_uin'], message=[ message.MessageSegment.text("请使用QQ扫描以下二维码以登录QQ空间:"), message.MessageSegment.image(content) @@ -117,7 +117,7 @@ async def is_group(event: Event): async def is_review_allow(event: Event): if type(event) == ob11_event.PrivateMessageEvent: return False - return ap.config.campux_qq_group_review and int(event.group_id) == int(ap.config.campux_review_qq_group_id) + return ap.config.data['campux_qq_group_review'] and int(event.group_id) == int(ap.config.data['campux_review_qq_group_id']) # #通过 [id] approve_post = on_command("通过", rule=to_me() & is_group & is_review_allow, priority=10, block=True) @@ -164,7 +164,7 @@ async def approve_post_func(event: Event): else: await approve_post.finish(f"稿件 #{post_id} 状态不是待审核") else: - await approve_post.finish(ap.config.campux_review_help_message) + await approve_post.finish(ap.config.data['campux_review_help_message']) except Exception as e: if isinstance(e, nonebot.exception.FinishedException): return @@ -203,7 +203,7 @@ async def reject_post_func(event: Event): else: await reject_post.finish(f"稿件 #{post_id} 状态不是待审核") else: - await reject_post.finish(ap.config.campux_review_help_message) + await reject_post.finish(ap.config.data['campux_review_help_message']) except Exception as e: if isinstance(e, nonebot.exception.FinishedException): return @@ -229,7 +229,7 @@ async def resend_post_func(event: Event): # 添加到ap.bot_event_loop中 ap.bot_event_loop.create_task(ap.social.publish_post(post_id)) else: - await resend_post.finish(ap.config.campux_review_help_message) + await resend_post.finish(ap.config.data['campux_review_help_message']) except Exception as e: if isinstance(e, nonebot.exception.FinishedException): return @@ -238,4 +238,4 @@ async def resend_post_func(event: Event): @any_message_group.handle() async def any_message_group_func(event: Event): - await any_message_group.finish(ap.config.campux_review_help_message) + await any_message_group.finish(ap.config.data['campux_review_help_message']) diff --git a/campux/mq/redis.py b/campux/mq/redis.py index 9383628..6469845 100644 --- a/campux/mq/redis.py +++ b/campux/mq/redis.py @@ -19,19 +19,19 @@ def __init__(self, ap: app.Application): @property def campux_redis_publish_post_stream(self): - return f"{self.ap.config.campux_domain}.publish_post" + return f"{self.ap.config.data['campux_domain']}.publish_post" @property def campux_redis_new_post_stream(self): - return f"{self.ap.config.campux_domain}.new_post" + return f"{self.ap.config.data['campux_domain']}.new_post" @property def campux_redis_post_cancel_stream(self): - return f"{self.ap.config.campux_domain}.post_cancel" + return f"{self.ap.config.data['campux_domain']}.post_cancel" @property def campux_redis_post_publish_status_hash(self): - return f"{self.ap.config.campux_domain}.post_publish_status" + return f"{self.ap.config.data['campux_domain']}.post_publish_status" class RedisStreamMQ: @@ -46,14 +46,14 @@ def __init__(self, ap: app.Application): self.relogin_notify_times = [] def get_instance_identity(self) -> str: - return f"campuxbot_{self.ap.config.campux_qq_bot_uin}" + return f"campuxbot_{self.ap.config.data['campux_qq_bot_uin']}" async def initialize(self): self.redis_client = redis.Redis( - host=self.ap.config.campux_redis_host, - port=self.ap.config.campux_redis_port, + host=self.ap.config.data['campux_redis_host'], + port=self.ap.config.data['campux_redis_port'], db=0, - password=self.ap.config.campux_redis_password + password=self.ap.config.data['campux_redis_password'] ) # 创建xgroup # 检查是否存在同名group @@ -128,7 +128,7 @@ async def process_stream(self, stream: str, process_message_func: callable): else: streams = await self.redis_client.xreadgroup( groupname=self.get_instance_identity(), - consumername=self.ap.config.campux_qq_bot_uin, + consumername=self.ap.config.data['campux_qq_bot_uin'], streams={stream: '>'}, count=1, block=5000 @@ -158,7 +158,7 @@ async def check_publish_post(self, message: tuple): if len(self.relogin_notify_times) == 0 or now - self.relogin_notify_times[-1] > 120*60: self.relogin_notify_times.append(now) asyncio.create_task(self.ap.imbot.send_private_message( - self.ap.config.campux_qq_admin_uin, + self.ap.config.data['campux_qq_admin_uin'], "空间cookies失效,当前有稿件待发布,请尽快更新cookies。" )) diff --git a/campux/social/mgr.py b/campux/social/mgr.py index bb25741..7533913 100644 --- a/campux/social/mgr.py +++ b/campux/social/mgr.py @@ -59,7 +59,7 @@ async def schedule_task(self): nonebot.logger.info("QQ空间cookies已失效,发送通知。") asyncio.create_task(self.ap.imbot.send_private_message( - self.ap.config.campux_qq_admin_uin, + self.ap.config.data['campux_qq_admin_uin'], "QQ空间cookies已失效,请发送 #更新cookies 命令进行重新登录。" )) @@ -72,7 +72,7 @@ async def can_operate(self) -> bool: async def publish_post(self, post_id: int): # 强制延迟 - await asyncio.sleep(self.ap.config.campux_publish_post_time_delay) + await asyncio.sleep(self.ap.config.data['campux_publish_post_time_delay']) max_retry = 3 @@ -81,7 +81,7 @@ async def publish_post(self, post_id: int): try: await self._publish_post(post_id) asyncio.create_task(self.ap.imbot.send_group_message( - self.ap.config.campux_review_qq_group_id, + self.ap.config.data['campux_review_qq_group_id'], f"已成功发表:#{post_id}" )) return @@ -93,12 +93,12 @@ async def publish_post(self, post_id: int): op=0, old_stat="in_queue", new_stat="in_queue", - comment=f"{self.ap.config.campux_qq_bot_uin} 发表失败({i}): {str(e)}" + comment=f"{self.ap.config.data['campux_qq_bot_uin']} 发表失败({i}): {str(e)}" ) if i == max_retry - 1: asyncio.create_task(self.ap.imbot.send_group_message( - self.ap.config.campux_review_qq_group_id, + self.ap.config.data['campux_review_qq_group_id'], f"发表失败:#{post_id}\n{str(e)}" )) else: @@ -131,7 +131,7 @@ async def _publish_post(self, post_id: int): op=0, old_stat="in_queue", new_stat="in_queue", - comment=f"{self.ap.config.campux_qq_bot_uin} 发表稿件" + comment=f"{self.ap.config.data['campux_qq_bot_uin']} 发表稿件" ) # 提交post verbose diff --git a/campux/social/qzone/api.py b/campux/social/qzone/api.py index ed68067..e477334 100644 --- a/campux/social/qzone/api.py +++ b/campux/social/qzone/api.py @@ -129,7 +129,7 @@ async def relogin(self, callback: callable): self.uin = int(self.cookies['uin'][1:]) asyncio.create_task(self.ap.imbot.send_private_message( - self.ap.config.campux_qq_admin_uin, + self.ap.config.data['campux_qq_admin_uin'], "登录流程完成。" )) diff --git a/campux/social/render/apirender.py b/campux/social/render/apirender.py index a8419fe..2e9d2ca 100644 --- a/campux/social/render/apirender.py +++ b/campux/social/render/apirender.py @@ -129,7 +129,7 @@ async def render(self, post: entity.Post) -> bytes: "content": post.text, "foot_left_hint": f"{post.uin} 发表于 {time_str}", "foot_right_hint": "开发 @RockChinQ | @Soulter", - "bg_fixed_br": f"https://q1.qlogo.cn/g?b=qq&nk={self.ap.config.campux_qq_bot_uin}&s=640", + "bg_fixed_br": f"https://q1.qlogo.cn/g?b=qq&nk={self.ap.config.data['campux_qq_bot_uin']}&s=640", "banner": "", } @@ -147,7 +147,7 @@ async def render(self, post: entity.Post) -> bytes: async with aiohttp.ClientSession() as session: async with session.post( - self.ap.config.campux_text_to_image_api+"/generate", + self.ap.config.data['campux_text_to_image_api']+"/generate", json={ "tmpl": jinja_template, "tmpldata": jinja_data, @@ -160,7 +160,7 @@ async def render(self, post: entity.Post) -> bytes: resp_json = await resp.json() img = await session.get( - self.ap.config.campux_text_to_image_api+"/"+resp_json['data']['id'] + self.ap.config.data['campux_text_to_image_api']+"/"+resp_json['data']['id'] ) return await img.read() diff --git a/main.py b/main.py index 42b675f..8588637 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,6 @@ import asyncio import os -import nonebot -# 初始化 NoneBot -nonebot.init() from campux.core import app diff --git a/templates/config.json b/templates/config.json new file mode 100644 index 0000000..b22e33b --- /dev/null +++ b/templates/config.json @@ -0,0 +1,20 @@ +{ + "host": "0.0.0.0", + "port": 8282, + "command_start": ["#", "#"], + "command_sep": ["."], + "campux_api": "http://campux:8080", + "campux_token": "campux123456", + "campux_redis_host": "redis", + "campux_redis_port": 6379, + "campux_redis_password": "", + "campux_help_message": "填写未匹配指令时的帮助信息。每用户每60秒只会响应一次。", + "campux_review_help_message": "填写未匹配指令时的审核帮助信息", + "campux_review_qq_group_id": 123456789, + "campux_qq_group_review": true, + "campux_text_to_image_api": "http://campuxutility:8999/text2img", + "campux_publish_post_time_delay": 0, + "campux_domain": "campux", + "campux_qq_bot_uin": 123456789, + "campux_qq_admin_uin": 234567890 +} \ No newline at end of file diff --git a/templates/metadata.json b/templates/metadata.json new file mode 100644 index 0000000..6dba23b --- /dev/null +++ b/templates/metadata.json @@ -0,0 +1,3 @@ +{ + "post_publish_text": "'#' + str(post_id)" +} \ No newline at end of file From 4b8fb6214154b059566fb00b1fd8abd752aa2845 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Fri, 30 Aug 2024 22:14:21 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=E6=9C=AA=E8=AE=BE=E7=BD=AE=20cpx=5F?= =?UTF-8?q?api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- campux/core/app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/campux/core/app.py b/campux/core/app.py index 512c52c..2650c99 100644 --- a/campux/core/app.py +++ b/campux/core/app.py @@ -72,6 +72,7 @@ async def create_app() -> Application: ap.config = config cpx_api = api.CampuxAPI(ap=ap) + ap.cpx_api = cpx_api import nonebot # 初始化 NoneBot From d7fdd5432ecef737666dc2f0b4573b599abca9a7 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Fri, 30 Aug 2024 23:00:36 +0800 Subject: [PATCH 5/5] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96config.json=20?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/config.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/templates/config.json b/templates/config.json index b22e33b..9db944c 100644 --- a/templates/config.json +++ b/templates/config.json @@ -3,17 +3,17 @@ "port": 8282, "command_start": ["#", "#"], "command_sep": ["."], - "campux_api": "http://campux:8080", + "campux_api": "http://campux:8081", "campux_token": "campux123456", - "campux_redis_host": "redis", + "campux_redis_host": "campux-redis", "campux_redis_port": 6379, - "campux_redis_password": "", - "campux_help_message": "填写未匹配指令时的帮助信息。每用户每60秒只会响应一次。", - "campux_review_help_message": "填写未匹配指令时的审核帮助信息", - "campux_review_qq_group_id": 123456789, + "campux_redis_password": "campux123456", "campux_qq_group_review": true, - "campux_text_to_image_api": "http://campuxutility:8999/text2img", + "campux_text_to_image_api": "http://campux-utility:8999/text2img", "campux_publish_post_time_delay": 0, + "campux_help_message": "发送 #注册账号 以此QQ号注册一个新账号(前面需要加#号)\n发送 #重置密码 重置你的账号密码\n\n投稿地址 https://gz.idoknow.top (若打不开请更换浏览器尝试)", + "campux_review_help_message": "审核命令:\n#通过 <稿件id>\n\n#拒绝 <理由> <稿件id>\n\n例如:\n#通过 10\n#拒绝 测试理由 10", + "campux_review_qq_group_id": 123456789, "campux_domain": "campux", "campux_qq_bot_uin": 123456789, "campux_qq_admin_uin": 234567890