-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from AmiyaBot/V6-dev
V6 dev
- Loading branch information
Showing
11 changed files
with
152 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v6.4.4 | ||
v6.4.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
.DS_Store | ||
|
||
config/cos.yaml | ||
config/remote.yaml | ||
main*.py | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .cos import cos_config | ||
from .remote import remote_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule pluginsDev
updated
51 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|