forked from sanshanya/hoshino_xcw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sanshanya
committed
Nov 8, 2020
1 parent
aafad85
commit 2fdadf4
Showing
13 changed files
with
726 additions
and
20 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
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
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
207 changes: 207 additions & 0 deletions
207
XCW/hoshino/hoshino/modules/hoshino_training/functions/chara.py.disable
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,207 @@ | ||
import os | ||
import re | ||
import json | ||
import hoshino | ||
import nonebot | ||
import aiohttp | ||
import random | ||
import traceback | ||
import csv | ||
from ast import literal_eval | ||
|
||
from hoshino.modules.hoshino_training.util.module import * | ||
|
||
from hoshino.modules.priconne.chara import Roster, Chara | ||
from hoshino.modules.priconne.gacha.gacha import Gacha | ||
|
||
#可以在此加入自定义角色 | ||
#需要将头像命名为 icon_unit_[四位数ID]31.png 放置到 res\img\priconne\unit 目录 | ||
CUSTOM_CHARA = { | ||
3322: ['陈睿', 'チン エイ', '叔叔', '睿总', '二次元教父'], | ||
} | ||
|
||
startup_job = None | ||
|
||
data = { | ||
'chara': {}, | ||
'gacha': {}, | ||
} | ||
|
||
pool_name = { | ||
'BL': {'BL', 'bl', 'Bl', 'bL', 'CN', 'cn'}, | ||
'TW': {'TW', 'tw', 'so-net', 'sonet'}, | ||
'JP': {'JP', 'jp'}, | ||
'MIX': {'MIX', 'mix', 'Mix', 'All', 'all', 'ALL'} | ||
} | ||
|
||
jp = re.compile(r'[\u3040-\u309F\u30A0-\u30FF]') | ||
|
||
#查角色 | ||
class NewRoster(Roster): | ||
|
||
def __init__(self): | ||
super(NewRoster, self).__init__() | ||
self.update() | ||
|
||
def update(self): | ||
super(NewRoster, self).update() | ||
if 'chara' in data: | ||
for idx, names in data['chara'].items(): | ||
for name in names: | ||
name = hoshino.util.normalize_str(name) | ||
if name not in self._roster: | ||
self._roster[name] = idx | ||
self._all_name_list = self._roster.keys() | ||
|
||
#角色信息 | ||
class NewChara(Chara): | ||
|
||
def __init__(self, id_, star=0, equip=0): | ||
super(NewChara, self).__init__(id_, star, equip) | ||
|
||
@property | ||
def name(self): | ||
name = super(NewChara, self).name | ||
if name == '未知角色' and self.id in data['chara']: | ||
name = data['chara'][self.id][0] | ||
if jp.search(name) and len(data['chara'][self.id]) > 1: | ||
name = data['chara'][self.id][1] | ||
return name | ||
|
||
#抽卡 | ||
class NewGacha(Gacha): | ||
|
||
def __init__(self, pool_name:str = "MIX"): | ||
super(NewGacha, self).__init__(pool_name) | ||
|
||
def load_pool(self, pool_name:str): | ||
super(NewGacha, self).load_pool(pool_name) | ||
if 'gacha' in data and 'chara' in data and pool_name in data['gacha']: | ||
pool = data['gacha'][pool_name] | ||
self.up_prob = pool["up_prob"] | ||
self.s3_prob = pool["s3_prob"] | ||
self.s2_prob = pool["s2_prob"] | ||
self.s1_prob = 1000 - self.s2_prob - self.s3_prob | ||
self.up = pool["up"] | ||
self.star3 = pool["star3"] | ||
self.star2 = pool["star2"] | ||
self.star1 = pool["star1"] | ||
|
||
async def query_data(url, is_json = False): | ||
try: | ||
async with aiohttp.ClientSession() as session: | ||
async with session.get(url) as resp: | ||
if is_json: | ||
data = await resp.json() | ||
else: | ||
data = await resp.text() | ||
except: | ||
traceback.print_exc() | ||
return None | ||
return data | ||
|
||
def save_data(): | ||
path = os.path.join(os.path.dirname(__file__), 'chara.json') | ||
try: | ||
with open(path, 'w', encoding='utf8') as f: | ||
json.dump(data, f, ensure_ascii=False, indent=2) | ||
except: | ||
traceback.print_exc() | ||
|
||
def load_data(): | ||
path = os.path.join(os.path.dirname(__file__), 'chara.json') | ||
if not os.path.exists(path): | ||
return | ||
try: | ||
with open(path, encoding='utf8') as f: | ||
d = json.load(f) | ||
if 'gacha' in d: | ||
data['gacha'] = d['gacha'] | ||
if 'chara' in d: | ||
data['chara'] = {} | ||
for k, v in d['chara'].items(): | ||
data['chara'][int(k)] = v | ||
except: | ||
traceback.print_exc() | ||
|
||
def ids_to_names(id_list): | ||
name_list = [] | ||
for id_ in id_list: | ||
chara = NewChara(id_) | ||
name_list.append(chara.name) | ||
return name_list | ||
|
||
async def update_data(): | ||
|
||
#pcrbot/pcr-nickname | ||
csv_data = await query_data('https://raw.fastgit.org/pcrbot/pcr-nickname/master/nicknames.csv') | ||
if csv_data: | ||
reader = csv.reader(csv_data.strip().split('\n')) | ||
for row in reader: | ||
if row[0].isdigit(): | ||
row[1], row[2] = row[2], row[1] | ||
data['chara'][int(row[0])] = row[1:] | ||
|
||
#unitdata.py | ||
chara_data = await query_data('https://api.redive.lolikon.icu/gacha/unitdata.py') | ||
if chara_data: | ||
chara_data = chara_data.replace('CHARA_NAME = ', '') | ||
try: | ||
chara_data = literal_eval(chara_data) | ||
except: | ||
chara_data = {} | ||
for k, v in chara_data.items(): | ||
if k in data['chara']: | ||
for sv in v: | ||
if sv not in data['chara'][k]: | ||
data['chara'][k].append(sv) | ||
else: | ||
data['chara'][k] = v | ||
|
||
#加入自定义角色 | ||
for k, v in CUSTOM_CHARA.items(): | ||
if k not in data['chara']: | ||
data['chara'][k] = v | ||
|
||
#update roster | ||
new_roster.update() | ||
|
||
#抽卡 | ||
gacha_data = await query_data('https://api.redive.lolikon.icu/gacha/default_gacha.json', True) | ||
if chara_data: | ||
for k, v in gacha_data.items(): | ||
if 'up' in v: | ||
v['up'] = ids_to_names(v['up']) | ||
if 'star1' in v: | ||
v['star1'] = ids_to_names(v['star1']) | ||
if 'star2' in v: | ||
v['star2'] = ids_to_names(v['star2']) | ||
if 'star3' in v: | ||
v['star3'] = ids_to_names(v['star3']) | ||
if k in pool_name['JP']: | ||
data['gacha']['JP'] = v | ||
elif k in pool_name['TW']: | ||
data['gacha']['TW'] = v | ||
elif k in pool_name['BL']: | ||
data['gacha']['BL'] = v | ||
#ALL池不使用 | ||
|
||
save_data() | ||
|
||
async def check_pool_update(): | ||
global startup_job | ||
if startup_job: | ||
startup_job.remove() | ||
startup_job = None | ||
await update_data() | ||
|
||
load_data() | ||
|
||
new_roster = NewRoster() | ||
|
||
module_replace('hoshino.modules.priconne.chara', 'roster', new_roster) | ||
module_replace('hoshino.modules.priconne.chara', 'Chara', NewChara) | ||
module_replace('hoshino.modules.priconne.gacha', 'Gacha', NewGacha) | ||
|
||
startup_job = nonebot.scheduler.add_job(check_pool_update, 'interval', seconds=5) | ||
nonebot.scheduler.add_job(check_pool_update, 'interval', hours=4) |
4 changes: 4 additions & 0 deletions
4
XCW/hoshino/hoshino/modules/hoshino_training/functions/news.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from hoshino.modules.hoshino_training.util.scheduler import * | ||
|
||
scheduler_remove('hoshino.modules.priconne.news:bili_news_poller') | ||
scheduler_remove('hoshino.modules.priconne.news:sonet_news_poller') |
7 changes: 7 additions & 0 deletions
7
XCW/hoshino/hoshino/modules/hoshino_training/functions/util.py.disable
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,7 @@ | ||
# hoshino\util\__init__.py | ||
from hoshino.modules.hoshino_training.util.module import * | ||
|
||
async def silence(ev, ban_time, skip_su=True): | ||
pass | ||
|
||
module_replace('hoshino.modules.priconne.gacha', 'silence', silence) |
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,46 @@ | ||
# rss | ||
|
||
适用于Hoshino v2的rss订阅插件 | ||
|
||
项目地址 https://github.com/zyujs/rss | ||
|
||
## 安装方法: | ||
|
||
1. 在HoshinoBot的插件目录modules下clone本项目 `git clone https://github.com/zyujs/rss.git` | ||
1. 在 `config/__bot__.py`的模块列表里加入 `rss` | ||
1. 进入本项目根目录,执行 `pip3 install -r requirements.txt` 安装依赖 | ||
1. 重启HoshinoBot | ||
|
||
默认订阅公主连结b站官方号动态, 请使用指令自行添加/删除关注项. | ||
|
||
可以修改插件运行后生成的 `data.json` 文件的 `rsshub` 项自定义rsshub服务器地址. | ||
|
||
## 指令列表 : | ||
|
||
- `rss help` : 查看帮助 | ||
- `rss add rss地址` : 添加rss订阅,需使用完整rss订阅网址. | ||
- `rss addb up主id` 或 `rss add-bilibili up主id` : 添加b站up主订阅 | ||
- `rss addr route` 或 `rss add-route route` : 添加rsshub route订阅, route请查询rsshub文档. | ||
- `rss list` : 查看订阅列表 | ||
- `rss rm 序号` 或 `rss remove 序号` : 删除订阅列表指定项 | ||
- `rss mode 模式id` : 设置推送消息模式 0=标准模式(默认),推送消息包含详情及图片 1=简略模式,推送消息仅包含标题 | ||
|
||
例: | ||
``` | ||
rss addr /pcr/news #订阅pcr日服官网新闻 | ||
rss addr /pcr/news-cn #订阅pcr国服官网新闻 | ||
rss addr /pcr/news-tw #订阅pcr台服官网新闻 | ||
rss addb 14454663 #订阅席巴鸽b站动态 | ||
rss add https://www.zhihu.com/rss #订阅知乎每日精选 | ||
rss list #查看订阅列表 | ||
rss remove 0 #删除订阅列表中第1条订阅 | ||
rss mode 0 #设置推送消息模式为标准模式 | ||
``` | ||
|
||
## 鸣谢 | ||
|
||
- @[地河君](https://github.com/Chendihe4975) : 本项目使用 [地河云](https://michikawachin.art/) 的 [RSSHub](https://rsshub.di.he.cn/) 服务作为默认rsshub服务器, 地河喵kkp! | ||
|
||
## 许可 | ||
|
||
本插件以GPL-v3协议开源 |
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,2 @@ | ||
feedparser~=5.2 | ||
pillow~=6.2 |
Oops, something went wrong.