Skip to content

Commit

Permalink
bug fix: 修复了nCoV2019重复播报的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Ice9Coffee committed Jan 28, 2020
1 parent c4bf5f3 commit 9c709cc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion hoshino/modules/botmanage/service_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from hoshino.service import Service

@on_command('lssv', aliases=('查看所有服务',), permission=perm.GROUP, only_to_me=False)
@on_command('lssv', aliases=('查看所有服务', '查看所有功能', '功能', '功能列表', '服务列表', '菜单'), permission=perm.GROUP, only_to_me=False)
async def lssv(session:CommandSession):
group_id = session.ctx['group_id']
all_service = '\n'.join([ f"{'on | ' if group_id in sv.enable_group or sv.enable_on_default and group_id not in sv.disable_group else 'off | '} {sv.name}" for sv in Service.get_loaded_services()])
Expand Down
2 changes: 1 addition & 1 deletion hoshino/modules/priconne/comic.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def download_comic(id_):
json.dump(index, f, ensure_ascii=False)


@nonebot.scheduler.scheduled_job('cron', minute='*/5', second='25', jitter=4, misfire_grace_time=10, coalesce=True)
@nonebot.scheduler.scheduled_job('cron', minute='*/5', second='25', misfire_grace_time=10, coalesce=True)
async def update_seeker():
'''
轮询官方四格漫画更新
Expand Down
10 changes: 5 additions & 5 deletions hoshino/modules/priconne/priconne_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class _PriconneData:
1057: ["吉塔", "ジータ", "Jiita", "团长", "吉他"],
1058: ["贪吃佩可", "ペコリーヌ", "Pecoriinu", "吃货", "佩可", "公主", "饭团", "🍙"],
1059: ["可可萝", "コッコロ", "Kokkoro", "可可罗", "妈", "普白"],
1060: ["凯留", "キャル", "Kyaru", "黑猫", "臭鼬"],
1060: ["凯留", "キャル", "Kyaru", "黑猫", "臭鼬", "凯露"],
1061: ["矛依未", "ムイミ", "Muimi", "夏娜", "511", "无意义"],

1063: ["亚里莎", "アリサ", "Arisa", "鸭梨瞎", "瞎子", "亚里沙", "鸭梨傻", "亚丽莎", "亚莉莎", "瞎子弓", "🍐🦐"],
Expand All @@ -85,11 +85,11 @@ class _PriconneData:
1075: ["贪吃佩可(夏日)", "ペコリーヌ(サマー)", "Pekoriinu(Summer)", "水吃", "水饭", "水吃货", "水佩可", "水公主", "水饭团", "水🍙", "泳吃", "泳饭", "泳吃货", "泳佩可", "泳公主", "泳饭团", "泳🍙", "泳装吃货", "泳装公主", "泳装饭团", "泳装🍙", "佩可(夏日)"],
1076: ["可可萝(夏日)", "コッコロ(サマー)", "Kokkoro(Summer)", "水白", "水可", "水可可", "水可可萝", "水可可罗", "泳装可可萝", "泳装可可罗"],
1077: ["铃莓(夏日)", "スズメ(サマー)", "Suzume(Summer)", "水女仆", "水妹抖"],
1078: ["凯留(夏日)", "キャル(サマー)", "Kyaru(Summer)", "水黑", "水黑猫", "水臭鼬", "泳装黑猫", "泳装臭鼬"],
1078: ["凯留(夏日)", "キャル(サマー)", "Kyaru(Summer)", "水黑", "水黑猫", "水臭鼬", "泳装黑猫", "泳装臭鼬", "潶"],
1079: ["珠希(夏日)", "タマキ(サマー)", "Tamaki(Summer)", "水猫剑", "水猫"],
1080: ["美冬(夏日)", "ミフユ(サマー)", "Mifuyu(Summer)", "水子龙", "水美冬"],
1081: ["忍(万圣节)", "シノブ(ハロウィン)", "Shinobu(Halloween)", "万圣忍", "瓜忍", "🎃忍", "🎃💀"],
1082: ["宫子(万圣节)", "ミヤコ(ハロウィン)", "Miyako(Halloween)", "万圣布丁", "狼丁", "狼布丁", "万圣🍮", "🐺🍮"],
1082: ["宫子(万圣节)", "ミヤコ(ハロウィン)", "Miyako(Halloween)", "万圣布丁", "狼丁", "狼布丁", "万圣🍮", "🐺🍮", "万圣宫子"],
1083: ["美咲(万圣节)", "ミサキ(ハロウィン)", "Misaki(Halloween)", "万圣美咲", "万圣大眼"],
1084: ["千歌(圣诞节)", "チカ(クリスマス)", "Chika(Xmas)", "圣诞千歌", "圣千", "蛋鸽"],
1085: ["胡桃(圣诞节)", "クルミ(クリスマス)", "Kurumi(Xmas)", "圣诞胡桃", "圣诞铃铛"],
Expand All @@ -107,13 +107,13 @@ class _PriconneData:
1097: ["雷姆", "レム", "Remu", "蕾姆"],
1098: ["拉姆", "ラム", "Ramu"],
1099: ["爱蜜莉雅", "エミリア", "Emiria", "艾米莉亚", "emt", "EMT"],
1100: ["铃奈(夏日)", "スズナ(サマー)", "Suzuna(Summer)", "瀑击弓", "水爆", "水爆弓", "水暴", "水暴弓", "泳装暴弓", "泳装爆弓"],
1100: ["铃奈(夏日)", "スズナ(サマー)", "Suzuna(Summer)", "瀑击弓", "水爆", "水爆弓", "水暴", "瀑", "水暴弓", "瀑弓", "泳装暴弓", "泳装爆弓"],
1101: ["伊绪(夏日)", "イオ(サマー)", "Io(Summer)", "水魅魔", "水老师", "泳装魅魔", "泳装老师"],
1102: ["美咲(夏日)", "ミサキ(サマー)", "Misaki(Summer)", "水大眼", "泳装大眼"],
1103: ["咲恋(夏日)", "サレン(サマー)", "Saren(Summer)", "水电", "泳装充电宝", "泳装咲恋", "水着咲恋", "水电站", "水电宝"],
1104: ["真琴(夏日)", "マコト(サマー)", "Makoto(Summer)", "水狼", "浪", "水🐺"],
1105: ["香织(夏日)", "カオリ(サマー)", "Kaori(Summer)", "水狗", "泃", "水🐶", "水🐕"],
1106: ["真步(夏日)", "マホ(サマー)", "Maho(Summer)", "水狐狸", "水真步", "水maho"],
1106: ["真步(夏日)", "マホ(サマー)", "Maho(Summer)", "水狐狸", "水真步", "水maho", "水壶"],
1107: ["碧(插班生)", "アオイ(編入生)", "Aoi(Hennyuusei)", "生菜", "新香菜"],
1108: ["克萝依", "クロエ", "Kuroe", "华哥"],
1109: ["琪爱儿", "チエル", "Chieru", "切露", "茄露", "茄噜", "切噜"],
Expand Down
2 changes: 1 addition & 1 deletion hoshino/modules/subscribe/mikan.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def update_cache():



@sv.scheduled_job('cron', minute='*/3', second='15', jitter=4, misfire_grace_time=10, coalesce=True)
@sv.scheduled_job('cron', minute='*/3', second='15', misfire_grace_time=10, coalesce=True)
async def mikan_poller(group_list):

if not Mikan.rss_cache:
Expand Down
50 changes: 26 additions & 24 deletions hoshino/modules/subscribe/nCoV2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
from nonebot import CommandSession, MessageSegment
from hoshino.service import Service

sv = Service('nCoV2019')
sv = Service('nCoV2019', enable_on_default=False)


class nCoV2019:

url = "https://3g.dxy.cn/newh5/view/pneumonia"
news_cache = []
latest_news_id = -1
news_id_cache = set()

@staticmethod
def _get_content():
return requests.get(nCoV2019.url, timeout=5).content.decode("utf-8")

@staticmethod
def get_overview():
resp = requests.get(nCoV2019.url).content.decode("utf-8")
resp = nCoV2019._get_content()
reg = r'<script id="getStatisticsService">.+?window.getStatisticsService\s=\s(.+?)\}catch\(e\)\{\}</script>'
result = re.search(reg, resp).group(1)
data = json.loads(result)
Expand All @@ -29,7 +33,7 @@ def get_overview():

@staticmethod
def get_news():
resp = requests.get(nCoV2019.url).content.decode("utf-8")
resp = nCoV2019._get_content()
reg = r'<script id="getTimelineService">.+?window.getTimelineService\s=\s(\[.+?\])\}catch\(e\)\{\}</script>'
result = re.search(reg, resp).group(1)
data = json.loads(result)
Expand All @@ -41,16 +45,16 @@ def update_news():
news = nCoV2019.get_news()
new_ones = []
for item in news:
if item['id'] > nCoV2019.latest_news_id:
if item['id'] not in nCoV2019.news_id_cache:
nCoV2019.news_id_cache.add(item['id'])
new_ones.append(item)
nCoV2019.news_cache = news
nCoV2019.latest_news_id = news[0]['id']
return new_ones


@staticmethod
def get_distribution():
resp = requests.get(nCoV2019.url).content.decode("utf-8")
resp = nCoV2019._get_content()
reg = r'<script id="getAreaStat">.+?window.getAreaStat\s=\s(\[.+?\])\}catch\(e\)\{\}</script>'
result = re.search(reg, resp).group(1)
data = json.loads(result)
Expand Down Expand Up @@ -83,24 +87,22 @@ async def cough(session:CommandSession):

else: # show overview
data = nCoV2019.get_overview()
text = f"新型冠状病毒肺炎疫情\n{data['countRemark']}{MessageSegment.image(data['imgUrl'])}{MessageSegment.image(data['dailyPic'])}"
text = f"新型冠状病毒肺炎疫情\n确诊{data['confirmedCount']}例 疑似{data['suspectedCount']}例 死亡{data['deadCount']}例 治愈{data['curedCount']}\n{MessageSegment.image(data['dailyPic'])}"
await session.send(text)


@sv.on_command('咳咳咳', only_to_me=False)
async def cough_news(session:CommandSession):
if not nCoV2019.news_cache:
nCoV2019.update_news()

nCoV2019.update_news()
msg = [ f"{i['infoSource']}:【{i['title']}{i['pubDateStr']}\n{i['summary']}" for i in nCoV2019.news_cache[:min(5, len(nCoV2019.news_cache))] ]
msg = '\n'.join(msg)
await session.send(f'新冠酱活动报告\n{msg}')
await session.send(f'新冠活动报告\n{msg}')


@sv.scheduled_job('cron', minute='*/2', second='15', jitter=4, misfire_grace_time=10, coalesce=True)
@sv.scheduled_job('cron', minute='*/15', misfire_grace_time=10, coalesce=True)
async def news_poller(group_list):

TAG = '2019-nCoV 新闻'
TAG = '2019-nCoV新闻'

if not nCoV2019.news_cache:
nCoV2019.update_news()
Expand All @@ -113,14 +115,14 @@ async def news_poller(group_list):
msg = [ f"{i['infoSource']}:【{i['title']}{i['pubDateStr']}\n{i['summary']}" for i in news ]

bot = sv.bot
for group in group_list:
await asyncio.sleep(1.0) # 降低发送频率,避免被腾讯ban
try:
for m in reversed(msg):
await asyncio.sleep(0.5)
await bot.send_group_msg(group_id=group, message=f'新冠酱提醒:\n{m}')
sv.logger.info(f'群{group} 投递{TAG}成功')
except Exception as e:
sv.logger.error(f'Error:群{group} 投递{TAG}更新失败 {type(e)}')
for m in reversed(msg):
await asyncio.sleep(10) # 降低发送频率,避免被腾讯ban
for group in group_list:
try:
await asyncio.sleep(0.5)
await bot.send_group_msg(group_id=group, message=m)
sv.logger.info(f'群{group} 投递{TAG}成功')
except Exception as e:
sv.logger.error(f'Error:群{group} 投递{TAG}更新失败 {type(e)}')
else:
sv.logger.info(f'未检索到{TAG}更新!')

0 comments on commit 9c709cc

Please sign in to comment.