Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
canxin121 committed Jul 18, 2023
1 parent 78781bf commit e6b05b0
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 54 deletions.
28 changes: 14 additions & 14 deletions nonebot_plugin_genshin_cos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ async def _(event: GroupMessageEvent, args: Tuple[str, ...] = RegexGroup()):

@hot_cos.handle()
async def _(
bot: Bot, matcher: Matcher, event: MessageEvent, arg: Message = CommandArg()
bot: Bot, matcher: Matcher, event: MessageEvent, arg: Message = CommandArg()
):
if not arg:
await hot_cos.finish("请指定cos类型")
Expand All @@ -213,10 +213,10 @@ async def _(

@rank_cos.handle()
async def _(
bot: Bot,
matcher: Matcher,
event: MessageEvent,
group: Tuple[str, ...] = RegexGroup(),
bot: Bot,
matcher: Matcher,
event: MessageEvent,
group: Tuple[str, ...] = RegexGroup(),
):
if not group[1]:
await rank_cos.finish("请指定cos类型")
Expand All @@ -243,7 +243,7 @@ async def _(

@latest_cos.handle()
async def _(
bot: Bot, matcher: Matcher, event: MessageEvent, arg: Message = CommandArg()
bot: Bot, matcher: Matcher, event: MessageEvent, arg: Message = CommandArg()
):
if not arg:
await latest_cos.finish("请指定cos类型")
Expand All @@ -263,7 +263,7 @@ async def _(

@good_cos.handle()
async def _(
bot: Bot, matcher: Matcher, event: MessageEvent, arg: Message = CommandArg()
bot: Bot, matcher: Matcher, event: MessageEvent, arg: Message = CommandArg()
):
if not arg:
await good_cos.finish("请指定cos类型")
Expand Down Expand Up @@ -315,8 +315,8 @@ async def aps_send(aps_goup_id: str):
continue
for saved_group_id, time in dict.items():
if not (
datetime.now().hour == int(time.split(":")[0])
and datetime.now().minute == int(time.split(":")[1])
datetime.now().hour == int(time.split(":")[0])
and datetime.now().minute == int(time.split(":")[1])
):
continue
elif saved_group_id != aps_goup_id:
Expand Down Expand Up @@ -351,11 +351,11 @@ async def aps_send(aps_goup_id: str):


async def send_images(
bot: Bot,
matcher: Matcher,
args: list,
event: MessageEvent,
send_type: HoyoBasicSpider,
bot: Bot,
matcher: Matcher,
args: list,
event: MessageEvent,
send_type: HoyoBasicSpider,
):
"""
发送图片
Expand Down
15 changes: 7 additions & 8 deletions nonebot_plugin_genshin_cos/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from typing import Optional
from pydantic import Extra, BaseModel
from pathlib import Path

class Config(BaseModel,extra=Extra.ignore):
cos_max:int = 5
cos_path:str = "data/genshin_cos"
cos_cd:int = 30
cos_forward_msg:bool = True
cos_delay:float = 0.5

class Config(BaseModel, extra=Extra.ignore):
cos_max: int = 5
cos_path: str = "data/genshin_cos"
cos_cd: int = 30
cos_forward_msg: bool = True
cos_delay: float = 0.5
30 changes: 17 additions & 13 deletions nonebot_plugin_genshin_cos/hoyospider.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from enum import Enum, unique
from typing import Dict, List

import httpx
from httpx import Response


##########################################################################################

# 类定义
Expand Down Expand Up @@ -37,7 +39,7 @@ def sync_get_urls(self, page_size: int) -> str:
:return: urls
"""
pass

def sync_get_name(self, page_size: int) -> str:
"""同步获取names
:param page_size: 每页数量
Expand All @@ -54,7 +56,7 @@ def sync_get(self, params: dict = None, is_good: bool = False):

response = httpx.get(self.api, params=params, headers=self.headers)
return self.handle_response(response, is_good)

def sync_name(self, params: dict = None, is_good: bool = False):
"""同步获取
:param params: 参数
Expand Down Expand Up @@ -101,7 +103,7 @@ async def async_name(self, params: dict = None, is_good: bool = False):
async with httpx.AsyncClient() as client:
response = await client.get(self.api, params=params, headers=self.headers)
return self.get_rsp_name(response, is_good)

def handle_response(self, response: Response, is_good: bool = False) -> List:
"""处理响应
:param response: 响应
Expand Down Expand Up @@ -133,6 +135,7 @@ def get_rsp_name(self, response: Response, is_good: bool = False) -> list:
names.append(post['post']['subject'])
return names


@unique
class RankType(Enum):
'''
Expand Down Expand Up @@ -175,7 +178,7 @@ class ForumType(Enum):
DBYCOS = 47 # 大别野cos
DBYPIC = 39 # 大别野同人图
StarRailPic = 56 # 星穹铁道同人图
StarRailCos = 62 # 星穹铁道cos
StarRailCos = 62 # 星穹铁道cos
Honkai2Pic = 40 # 崩坏2同人图
TearsOfThemisPic = 38 # 泪水同人图

Expand Down Expand Up @@ -232,11 +235,12 @@ async def async_get_urls(self, page_size: int = 21) -> List:
async def async_get_name(self, page_size: int = 21) -> List:
params = self.get_params(page_size)
return await self.async_name(params)

def sync_get_name(self, page_size: int = 21) -> List:
params = self.get_params(page_size)
return self.sync_name(params)


class Hot(HoyoBasicSpider):
'''
获取热门帖子
Expand Down Expand Up @@ -267,11 +271,11 @@ def sync_get_urls(self, page_size: int = 20) -> List:
async def async_get_urls(self, page_size: int = 20) -> List:
params = self.get_params(page_size)
return await self.async_get(params)

def sync_get_name(self, page_size: int = 20) -> List:
params = self.get_params(page_size)
return self.sync_name(params)

async def async_get_name(self, page_size: int = 20) -> List:
params = self.get_params(page_size)
return await self.async_name(params)
Expand Down Expand Up @@ -306,11 +310,11 @@ def sync_get_urls(self, page_size: int = 20) -> List:
async def async_get_urls(self, page_size: int = 20) -> List:
params = self.get_params(page_size)
return await self.async_get(params, is_good=True)

def sync_get_name(self, page_size: int = 20) -> List:
params = self.get_params(page_size)
return self.sync_name(params, is_good=True)

async def async_get_name(self, page_size: int = 20) -> List:
params = self.get_params(page_size)
return await self.async_name(params, is_good=True)
Expand Down Expand Up @@ -346,17 +350,17 @@ def sync_get_urls(self, page_size: int = 20) -> List:
async def async_get_urls(self, page_size: int = 20) -> List:
params = self.get_params(page_size)
return await self.async_get(params)

def sync_get_name(self, page_size: int = 20) -> List:
params = self.get_params(page_size)
return self.sync_name(params)

async def async_get_name(self, page_size: int = 20) -> List:
params = self.get_params(page_size)
return await self.async_name(params)


#实例化对象

# 实例化对象

genshin_rank_daily = Rank(ForumType.GenshinCos, RankType.Daily)
genshin_hot = Hot(ForumType.GenshinCos)
Expand Down
46 changes: 27 additions & 19 deletions nonebot_plugin_genshin_cos/utils.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
from asyncio import sleep
from datetime import datetime, timedelta
from pathlib import Path
from nonebot import get_driver
from .config import Config
from typing import Dict, List, Tuple
from datetime import datetime, timedelta
from httpx import TimeoutException

import httpx
from httpx import TimeoutException
from nonebot import get_driver
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent, Message, GROUP_ADMIN, GROUP_OWNER
from nonebot.permission import SUPERUSER
from nonebot.matcher import Matcher
from nonebot.log import logger
from nonebot.exception import ActionFailed
from asyncio import sleep
from nonebot.log import logger
from nonebot.matcher import Matcher
from nonebot.permission import SUPERUSER

from .config import Config

#######################################################

# 拓展的异常类和函数
SUPER_PERMISSION = GROUP_ADMIN | GROUP_OWNER | SUPERUSER
GENSHIN_NAME = ["原神",'OP','op','欧泡','⭕','🅾️','🅾️P','🅾️p','原','圆']
HONKAI3RD_NAME = ['崩坏3', '崩崩崩', '蹦蹦蹦','崩坏三','崩三','崩崩崩三','崩坏3rd','崩坏3Rd','崩坏3RD','崩坏3rd','崩坏3RD','崩坏3Rd']
DBY_NAME = ['大别野','DBY','dby']
STAR_RAIL = ['星穹铁道','星穹','崩铁','铁道','星铁','穹p','穹铁']
GENSHIN_NAME = ["原神", 'OP', 'op', '欧泡', '⭕', '🅾️', '🅾️P', '🅾️p', '原', '圆']
HONKAI3RD_NAME = ['崩坏3', '崩崩崩', '蹦蹦蹦', '崩坏三', '崩三', '崩崩崩三', '崩坏3rd', '崩坏3Rd', '崩坏3RD', '崩坏3rd',
'崩坏3RD', '崩坏3Rd']
DBY_NAME = ['大别野', 'DBY', 'dby']
STAR_RAIL = ['星穹铁道', '星穹', '崩铁', '铁道', '星铁', '穹p', '穹铁']


class WriteError(Exception):
"""写入错误"""
Expand Down Expand Up @@ -89,11 +94,11 @@ async def download_from_urls(urls: List[str], path: Path):


async def send_forward_msg(
bot: Bot,
event: MessageEvent,
name: str,
uin: str,
msgs: list,
bot: Bot,
event: MessageEvent,
name: str,
uin: str,
msgs: list,
) -> dict:
"""调用合并转发API
Expand All @@ -104,6 +109,7 @@ async def send_forward_msg(
uin: 发送者账号,
msgs: 消息列表,
"""

def to_json(msg: Message):
return {"type": "node", "data": {"name": name, "uin": uin, "content": msg}}

Expand All @@ -128,12 +134,14 @@ def msglist2forward(name: str, uin: str, msgs: list) -> list:
uin: 发送者账号
msgs: 消息列表
"""

def to_json(msg: Message):
return {"type": "node", "data": {"name": name, "uin": uin, "content": msg}}

return [to_json(msg) for msg in msgs]
return [to_json(msg) for msg in msgs]


async def send_regular_msg(matcher: Matcher,messages:list):
async def send_regular_msg(matcher: Matcher, messages: list):
'''
发送常规消息
:param matcher: Matcher
Expand Down

0 comments on commit e6b05b0

Please sign in to comment.