Skip to content

Commit

Permalink
Merge pull request #186 from NekoAria/2.0
Browse files Browse the repository at this point in the history
V2.4.1
  • Loading branch information
Quan authored Sep 16, 2021
2 parents ac227d1 + 02e1f26 commit 61ef44d
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ENVIRONMENT=prod
VERSION='v2.4.0'
VERSION='v2.4.1'
9 changes: 5 additions & 4 deletions docs/2.0 使用教程.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
## 所有订阅

> 命令:showall(所有订阅、selectall)
> 命令:show_all(showall,select_all,selectall,所有订阅
>
> 参数:[关键词](支持正则,过滤生效范围:订阅名、订阅地址、QQ号、群号)
>
Expand Down Expand Up @@ -67,15 +67,16 @@

> 命令:change(修改订阅,moddy)
>
> 参数:订阅名 属性=值 [[属性=值]...]
> 参数:订阅名[,订阅名,...] 属性=值[ 属性=值 ...]
>
> 示例: `change test qq=, 123, 234 ot=1`
> 示例: `change test1[,test2,...] qq=,123,234 qun=-1`
>
> 使用技巧:可以先只发送 `change` ,机器人会返回提示信息,无需记住复杂的参数列表
>
> 对应参数:
>
> 订阅名-name 订阅链接-url QQ-qq 群-qun 更新频率-time
> 订阅名-name 禁止将多个订阅批量改名,会因为名称相同起冲突
> 订阅链接-url QQ-qq 群-qun 更新频率-time
> 代理-proxy 翻译-tl 仅title-ot,仅图片-op,仅含有图片-ohp
> 下载种子-downopen 白名单关键词-wkey 黑名单关键词-bkey 种子上传到群-upgroup
> 去重模式-mode
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ELF_RSS"
version = "2.4.0"
version = "2.4.1"
description = "ELF_RSS"
authors = ["Quan666"]
license = "GPL v3"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="ELF_RSS",
version="2.4.0",
version="2.4.1",
author="Quan666",
author_email="[email protected]",
description="QQ机器人 RSS订阅 插件,订阅源建议选择 RSSHub",
Expand Down
18 changes: 3 additions & 15 deletions src/plugins/ELF_RSS2/RSS/routes/Parsing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import difflib
import re
import sqlite3
import time

from nonebot import logger
from pyquery import PyQuery as Pq
Expand All @@ -19,6 +18,7 @@
insert_into_cache_db,
)
from .cache_manage import cache_filter
from .handle_date import handle_date as hd
from .handle_html_tag import handle_bbcode
from .handle_html_tag import handle_html_tag
from .handle_images import handle_img
Expand Down Expand Up @@ -495,20 +495,8 @@ async def handle_torrent(
async def handle_date(
rss: Rss, state: dict, item: dict, item_msg: str, tmp: str, tmp_state: dict
) -> str:
date = tuple(
item.get("updated_parsed")
if item.get("updated_parsed")
else item.get("published_parsed")
)
if date:
rss_time = time.mktime(date)
# 时差处理,待改进
if rss_time + 28800.0 <= time.time():
rss_time += 28800.0
return "日期:" + time.strftime("%m月%d日 %H:%M:%S", time.localtime(rss_time))
# 没有日期的情况,以当前时间
else:
return "日期:" + time.strftime("%m月%d日 %H:%M:%S", time.localtime())
date = tuple(item.get("published_parsed", item.get("updated_parsed")))
return await hd(date)


# 发送消息
Expand Down
35 changes: 10 additions & 25 deletions src/plugins/ELF_RSS2/RSS/routes/Parsing/check_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@
from typing import Dict, Any


# 处理日期
async def handle_date(date=None) -> str:
if date:
if not isinstance(date, tuple):
date = tuple(date)
rss_time = time.mktime(date)
# 时差处理,待改进
if rss_time + 28800.0 < time.time():
rss_time += 28800.0
return "日期:" + time.strftime("%m月%d日 %H:%M:%S", time.localtime(rss_time))
# 没有日期的情况,以当前时间
else:
return "日期:" + time.strftime("%m月%d日 %H:%M:%S", time.localtime())


# 对 dict 对象计算哈希值,供后续比较
def dict_hash(dictionary: Dict[str, Any]) -> str:
keys = ["id", "link", "published", "updated", "title"]
Expand Down Expand Up @@ -47,13 +32,13 @@ async def check_update(db: TinyDB, new: list) -> list:
to_send_list.append(i)

# 对结果按照发布时间排序
result_with_date = [
(await handle_date(i.get("updated_parsed")), i)
if i.get("updated_parsed")
else (await handle_date(i.get("published_parsed")), i)
for i in to_send_list
]
result_with_date.sort(key=lambda tup: tup[0])
result = [i for key, i in result_with_date]

return result
to_send_list.sort(key=get_item_timestamp)

return to_send_list


def get_item_timestamp(item: dict) -> float:
date = item.get("published_parsed", item.get("updated_parsed"))
if not isinstance(date, tuple):
date = tuple(date)
return time.mktime(date)
16 changes: 16 additions & 0 deletions src/plugins/ELF_RSS2/RSS/routes/Parsing/handle_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import time


# 处理日期
async def handle_date(date=None) -> str:
if date:
if not isinstance(date, tuple):
date = tuple(date)
rss_time = time.mktime(date)
# 时差处理,待改进
if rss_time + 28800.0 < time.time():
rss_time += 28800.0
return "日期:" + time.strftime("%m月%d日 %H:%M:%S", time.localtime(rss_time))
# 没有日期的情况,以当前时间
else:
return "日期:" + time.strftime("%m月%d日 %H:%M:%S", time.localtime())
17 changes: 9 additions & 8 deletions src/plugins/ELF_RSS2/RSS/rss_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def __init__(self):
self.only_pic = False # 仅图片
self.only_has_pic = False # 仅含有图片
self.cookies = ""
self.down_torrent: bool = False # 是否下载种子
self.down_torrent_keyword: str = "" # 过滤关键字,支持正则
self.black_keyword: str = "" # 黑名单关键词
self.is_open_upload_group: bool = True # 默认开启上传到群
self.duplicate_filter_mode: [str] = None # 去重模式
self.max_image_number: int = 0 # 图片数量限制,防止消息太长刷屏
self.content_to_remove: [str] = None # 正文待移除内容,支持正则
self.down_torrent = False # 是否下载种子
self.down_torrent_keyword = "" # 过滤关键字,支持正则
self.black_keyword = "" # 黑名单关键词
self.is_open_upload_group = True # 默认开启上传到群
self.duplicate_filter_mode = None # 去重模式
self.max_image_number = 0 # 图片数量限制,防止消息太长刷屏
self.content_to_remove = None # 正文待移除内容,支持正则
self.stop = False # 停止更新

# 返回订阅链接
Expand Down Expand Up @@ -123,7 +123,8 @@ def delete_rss(self):
# 重命名订阅缓存 json 文件
def rename_file(self, target: str):
this_file_path = DATA_PATH / (self.name + ".json")
this_file_path.rename(target)
if Path.exists(this_file_path):
this_file_path.rename(target)

# 删除订阅缓存 json 文件
def delete_file(self):
Expand Down
25 changes: 11 additions & 14 deletions src/plugins/ELF_RSS2/add_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,19 @@ async def handle_first_receive(bot: Bot, event: Event, state: dict):
state["ADD_COOKIES"] = unescape(args) # 如果用户发送了参数则直接赋值


# 如果只有名称就把该 名称订阅 订阅到当前账号或群组
prompt = (
"请输入:\n"
"名称 cookies\n"
"空格分割\n"
"获取方式:\n"
"PC端 chrome 浏览器按 F12\n"
"找到Console选项卡,输入:\n"
"document.cookie\n"
"输出的字符串就是了"
)


@ADD_COOKIES.got(
"ADD_COOKIES",
prompt=(
"请输入:\n"
"名称 cookies\n"
"空格分割\n"
"获取方式:\n"
"PC端 chrome 浏览器按 F12\n"
"找到Console选项卡,输入:\n"
"document.cookie\n"
"输出的字符串就是了"
),
)
@ADD_COOKIES.got("ADD_COOKIES", prompt=prompt)
async def handle_add_cookies(bot: Bot, event: Event, state: dict):
rss_cookies = unescape(state["ADD_COOKIES"])

Expand Down
Loading

0 comments on commit 61ef44d

Please sign in to comment.