Skip to content

Commit

Permalink
Merge pull request #279 from AmiyaBot/V6-dev
Browse files Browse the repository at this point in the history
V6 dev
  • Loading branch information
vivien8261 authored Jul 31, 2024
2 parents 3cd3431 + 2421f34 commit 83194a4
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/publish.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v6.5.0
v6.5.1
41 changes: 27 additions & 14 deletions core/database/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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,
}
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions core/server/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
amiyabot==1.9.9
amiyabot==2.0.1
attrdict~=2.0.1
baidu-aip
dhash~=1.3
Expand Down
53 changes: 39 additions & 14 deletions run_plugin_server.py
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit 83194a4

Please sign in to comment.