Skip to content

Commit

Permalink
Merge pull request #267 from AmiyaBot/V6-dev
Browse files Browse the repository at this point in the history
V6 dev
  • Loading branch information
vivien8261 authored Feb 28, 2024
2 parents ebcdfc5 + 2a9ad19 commit 7766156
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/publish.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v6.4.4
v6.4.5
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

.DS_Store

config/cos.yaml
config/remote.yaml
main*.py

Expand Down
11 changes: 9 additions & 2 deletions build/uploadFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def __init__(
bucket: str = None,
logger_level: int = logging.DEBUG,
):
logging.basicConfig(level=logger_level, stream=sys.stdout)
if logger_level:
logging.basicConfig(level=logger_level, stream=sys.stdout)
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key)

self.client = CosS3Client(config)
Expand Down Expand Up @@ -43,7 +44,13 @@ def delete_file(self, files: Union[list, str]):
for file in files:
delete_list.append({'Key': file})

self.client.delete_objects(Bucket=self.bucket, Delete={'Object': delete_list})
return self.client.delete_objects(
Bucket=self.bucket,
Delete={
'Quiet': 'true',
'Object': delete_list,
},
)

def delete_folder(self, folders: Union[list, str], max_keys: int = 100):
if type(folders) is not list:
Expand Down
1 change: 1 addition & 0 deletions core/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .cos import cos_config
from .remote import remote_config
18 changes: 18 additions & 0 deletions core/config/cos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from dataclasses import dataclass
from core.util import init_config_file


@dataclass
class CosConfig:
activate: bool = False
secret_id: str = ''
secret_key: str = ''
domain: str = ''
folder: str = ''


def init(file: str) -> CosConfig:
return init_config_file(file, CosConfig)


cos_config = init('config/cos.yaml')
13 changes: 3 additions & 10 deletions core/config/remote.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os

from dataclasses import dataclass, asdict, field
from core.util import read_yaml, create_yaml, merge_dict
from dataclasses import dataclass, field
from core.util import init_config_file


@dataclass
Expand All @@ -18,12 +16,7 @@ class RemoteConfig:


def init(file: str) -> RemoteConfig:
config = {}
if os.path.exists(file):
config = read_yaml(file, _dict=True)

create_yaml(file, merge_dict(config, asdict(RemoteConfig())), True)
return read_yaml(file)
return init_config_file(file, RemoteConfig)


remote_config = init('config/remote.yaml')
90 changes: 90 additions & 0 deletions core/cosChainBuilder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import os
import logging
import asyncio

from typing import Union, Optional
from amiyabot.adapters.tencent.qqGroup import QQGroupChainBuilder, QQGroupChainBuilderOptions
from build.uploadFile import COSUploader
from core.util import run_in_thread_pool
from core.config import cos_config


class COSQQGroupChainBuilder(QQGroupChainBuilder):
def __init__(self, options: QQGroupChainBuilderOptions):
super().__init__(options)

self.cos: Optional[COSUploader] = None
self.cos_caches = {}

if cos_config.secret_id and cos_config.secret_key:
self.cos = COSUploader(
cos_config.secret_id,
cos_config.secret_key,
logger_level=logging.NOTSET,
)

@property
def domain(self):
return cos_config.domain + cos_config.folder

def start(self):
...

def temp_filename(self, suffix: str):
path, url = super().temp_filename(suffix)

self.cos_caches[url] = f'{cos_config.folder}/{os.path.basename(path)}'

return path, url

def remove_file(self, url: str):
super().remove_file(url)

if url in self.cos_caches:
asyncio.create_task(
run_in_thread_pool(
self.cos.client.delete_object,
self.cos.bucket,
self.cos_caches[url],
)
)
del self.cos_caches[url]

async def get_image(self, image: Union[str, bytes]) -> Union[str, bytes]:
if isinstance(image, str) and image.startswith('http'):
return image

url = await super().get_image(image)

self.cos.upload_file(
self.file_caches[url],
self.cos_caches[url],
)

return url

async def get_voice(self, voice_file: str) -> str:
if voice_file.startswith('http'):
return voice_file

url = await super().get_voice(voice_file)

self.cos.upload_file(
self.file_caches[url],
self.cos_caches[url],
)

return url

async def get_video(self, video_file: str) -> str:
if video_file.startswith('http'):
return video_file

url = await super().get_video(video_file)

self.cos.upload_file(
self.file_caches[url],
self.cos_caches[url],
)

return url
23 changes: 16 additions & 7 deletions core/database/bot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from amiyabot import AmiyaBot, KOOKBotInstance
from amiyabot.database import *
from core.config import cos_config
from core.database import config, is_mysql
from core.cosChainBuilder import COSQQGroupChainBuilder
from typing import Union

from amiyabot.adapters.tencent.qqGroup import qq_group, QQGroupChainBuilderOptions
Expand Down Expand Up @@ -82,14 +84,21 @@ def build_conf(cls, item):
)

if item.adapter == 'qq_group':
conf['adapter'] = qq_group(
item.client_secret,
default_chain_builder_options=QQGroupChainBuilderOptions(
item.host or '0.0.0.0',
item.http_port or 8086,
'./resource/group_temp',
),
opt = QQGroupChainBuilderOptions(
item.host or '0.0.0.0',
item.http_port or 8086,
'./resource/group_temp',
)
if cos_config.activate:
conf['adapter'] = qq_group(
item.client_secret,
default_chain_builder=COSQQGroupChainBuilder(opt),
)
else:
conf['adapter'] = qq_group(
item.client_secret,
default_chain_builder_options=opt,
)

if item.adapter == 'websocket':
conf['adapter'] = test_instance(item.host, item.ws_port)
Expand Down
12 changes: 11 additions & 1 deletion core/util/yamlManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

from yaml import SafeDumper
from attrdict import AttrDict
from dataclasses import asdict

from .common import create_dir
from .common import create_dir, merge_dict


class YamlManager:
Expand Down Expand Up @@ -41,3 +42,12 @@ def create_yaml(cls, path: str, data: dict, overwrite: bool = False):
yaml.safe_dump(data, file, indent=4, default_flow_style=False, allow_unicode=True)

return True


def init_config_file(file: str, build_cls):
config = {}
if os.path.exists(file):
config = YamlManager.read_yaml(file, _dict=True)

YamlManager.create_yaml(file, merge_dict(config, asdict(build_cls())), True)
return YamlManager.read_yaml(file)
2 changes: 1 addition & 1 deletion pluginsDev
Submodule pluginsDev updated 51 files
+1 −0 src/admin/README-public.md
+1 −1 src/admin/main.py
+3 −3 src/arknights/arknightsGameData/builder/__init__.py
+4 −2 src/arknights/arknightsGameData/builder/operatorBuilder.py
+9 −3 src/arknights/arknightsGameData/builder/wiki.py
+6 −0 src/arknights/calculator/README-public.md
+7 −3 src/arknights/calculator/main.py
+4 −0 src/arknights/enemy/README-public.md
+1 −1 src/arknights/enemy/main.py
+12 −0 src/arknights/gacha/README_USE-public.md
+1 −1 src/arknights/gacha/main.py
+3 −0 src/arknights/intellect/README_USE-public.md
+1 −1 src/arknights/intellect/main.py
+4 −0 src/arknights/material/README-public.md
+1 −1 src/arknights/material/main.py
+17 −0 src/arknights/operatorArchives/README_USE-public.md
+19 −4 src/arknights/operatorArchives/main.py
+6 −5 src/arknights/operatorArchives/operatorCore.py
+6 −0 src/arknights/recruit/README_USE-public.md
+2 −2 src/arknights/recruit/main.py
+14 −0 src/arknights/stage/README-public.md
+13 −6 src/arknights/stage/README.md
+27 −4 src/arknights/stage/main.py
+73 −0 src/arknights/stage/sxys.json
+1 −7 src/func/README.md
+3 −0 src/func/README_USE-public.md
+11 −0 src/func/README_USE.md
+50 −15 src/func/main.py
+6 −4 src/func/template.md
+30 −0 src/game/guess/README-public.md
+36 −4 src/game/guess/guessBuilder.py
+39 −25 src/game/guess/guessStart.py
+81 −0 src/game/guess/guessTools.py
+13 −10 src/game/guess/main.py
+30 −0 src/game/wordle2/README-public.md
+1 −1 src/game/wordle2/main.py
+1 −0 src/replace/README_USE-public.md
+4 −4 src/replace/README_USE.md
+1 −1 src/replace/main.py
+5 −5 src/talking/main.py
+28 −0 src/user/README_USE-public.md
+7 −0 src/user/README_USE.md
+4 −0 src/user/baiduCloud.yaml
+78 −0 src/user/main.py
+1 −1 src/user/mainBot.py
+ src/user/template/avatar.webp
+22 −1 src/user/template/userInfo.css
+24 −3 src/user/template/userInfo.html
+9 −0 src/weibo/README_USE-public.md
+7 −0 src/weibo/README_USE.md
+26 −15 src/weibo/main.py
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
amiyabot==1.8.7
amiyabot==1.9.0
attrdict~=2.0.1
baidu-aip
dhash~=1.3
Expand Down

0 comments on commit 7766156

Please sign in to comment.