Skip to content

Commit

Permalink
add full support for zh-hant
Browse files Browse the repository at this point in the history
  • Loading branch information
Ice9Coffee committed Aug 9, 2020
1 parent 44e4ee4 commit 72acaa0
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 62 deletions.
2 changes: 1 addition & 1 deletion hoshino/modules/botmanage/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def gen_bundle_manual(bundle_name, service_list, gid):
return '\n'.join(manual)


@sv.on_prefix(('help', '帮助', '幫助'))
@sv.on_prefix(('help', '帮助'))
async def send_help(bot, ev: CQEvent):
bundle_name = ev.message.extract_plain_text().strip()
bundles = Service.get_bundles()
Expand Down
2 changes: 1 addition & 1 deletion hoshino/modules/groupmaster/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async def say_hello(session):

sv = Service('chat', visible=False)

@sv.on_fullmatch(('沙雕机器人', '沙雕機器人'))
@sv.on_fullmatch('沙雕机器人')
async def say_sorry(bot, ev):
await bot.send(ev, 'ごめんなさい!嘤嘤嘤(〒︿〒)')

Expand Down
2 changes: 1 addition & 1 deletion hoshino/modules/groupmaster/sleeping_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[给我来一份精致昏睡下午茶套餐] 叫一杯先辈特调红茶(bot需具有群管理权限)
'''.strip())

@sv.on_fullmatch(('睡眠套餐', '休眠套餐', '精致睡眠', '来一份精致睡眠套餐', '精緻睡眠', '來一份精緻睡眠套餐'))
@sv.on_fullmatch(('睡眠套餐', '休眠套餐', '精致睡眠', '来一份精致睡眠套餐'))
async def sleep_8h(bot, ev):
await util.silence(ev, 8*60*60, skip_su=False)

Expand Down
2 changes: 1 addition & 1 deletion hoshino/modules/mikan/mikan.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def mikan_poller():

DISABLE_NOTICE = '本群蜜柑番剧功能已禁用\n使用【启用 bangumi】以启用(需群管理)\n开启本功能后将自动推送字幕组更新'

@sv.on_fullmatch(('来点新番', '來點新番'))
@sv.on_fullmatch('来点新番')
async def send_bangumi(bot, ev):
if not Mikan.rss_cache:
await Mikan.update_cache()
Expand Down
2 changes: 1 addition & 1 deletion hoshino/modules/priconne/arena/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

lmt = FreqLimiter(5)

aliases = ('怎么拆', '怎么解', '怎么打', '如何拆', '如何解', '如何打', '怎麼拆', '怎麼解', '怎麼打', 'jjc查询', 'jjc查詢')
aliases = ('怎么拆', '怎么解', '怎么打', '如何拆', '如何解', '如何打', 'jjc查询')
aliases_b = tuple('b' + a for a in aliases) + tuple('B' + a for a in aliases)
aliases_tw = tuple('台' + a for a in aliases)
aliases_jp = tuple('日' + a for a in aliases)
Expand Down
15 changes: 6 additions & 9 deletions hoshino/modules/priconne/gacha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@ def dump_pool_config():


gacha_10_aliases = ('抽十连', '十连', '十连!', '十连抽', '来个十连', '来发十连', '来次十连', '抽个十连', '抽发十连', '抽次十连', '十连扭蛋', '扭蛋十连',
'10连', '10连!', '10连抽', '来个10连', '来发10连', '来次10连', '抽个10连', '抽发10连', '抽次10连', '10连扭蛋', '扭蛋10连',
'十連', '十連!', '十連抽', '來個十連', '來發十連', '來次十連', '抽個十連', '抽發十連', '抽次十連', '十連轉蛋', '轉蛋十連',
'10連', '10連!', '10連抽', '來個10連', '來發10連', '來次10連', '抽個10連', '抽發10連', '抽次10連', '10連轉蛋', '轉蛋10連')
gacha_1_aliases = ('单抽', '单抽!', '来发单抽', '来个单抽', '来次单抽', '扭蛋单抽', '单抽扭蛋',
'單抽', '單抽!', '來發單抽', '來個單抽', '來次單抽', '轉蛋單抽', '單抽轉蛋')
gacha_300_aliases = ('抽一井', '来一井', '来发井', '抽发井', '天井扭蛋', '扭蛋天井', '天井轉蛋', '轉蛋天井')

@sv.on_fullmatch(('卡池资讯', '查看卡池', '看看卡池', '康康卡池', '卡池資訊', '看看up', '看看UP'))
'10连', '10连!', '10连抽', '来个10连', '来发10连', '来次10连', '抽个10连', '抽发10连', '抽次10连', '10连扭蛋', '扭蛋10连')
gacha_1_aliases = ('单抽', '单抽!', '来发单抽', '来个单抽', '来次单抽', '扭蛋单抽', '单抽扭蛋')
gacha_300_aliases = ('抽一井', '来一井', '来发井', '抽发井', '天井扭蛋', '扭蛋天井')

@sv.on_fullmatch(('卡池资讯', '查看卡池', '看看卡池', '康康卡池', '看看up', '看看UP'))
async def gacha_info(bot, ev: CQEvent):
gid = str(ev.group_id)
gacha = Gacha(_group_pool[gid])
Expand All @@ -64,7 +61,7 @@ async def gacha_info(bot, ev: CQEvent):


POOL_NAME_TIP = '请选择以下卡池\n> 切换卡池jp\n> 切换卡池tw\n> 切换卡池b\n> 切换卡池mix'
@sv.on_prefix(('切换卡池', '选择卡池', '切換卡池', '選擇卡池'))
@sv.on_prefix(('切换卡池', '选择卡池'))
async def set_pool(bot, ev: CQEvent):
if not priv.check_priv(ev, priv.ADMIN):
await bot.finish(ev, '只有群管理才能切换卡池', at_sender=True)
Expand Down
6 changes: 3 additions & 3 deletions hoshino/modules/priconne/query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def rank_sheet(bot, ev):
await util.silence(ev, 60)


@sv.on_fullmatch(('jjc', 'JJC', 'JJC作业', 'JJC作业网', 'JJC数据库', 'jjc作业', 'jjc作业网', 'jjc数据库', 'JJC作業', 'JJC作業網', 'JJC數據庫', 'jjc作業', 'jjc作業網', 'jjc數據庫'))
@sv.on_fullmatch(('jjc', 'JJC', 'JJC作业', 'JJC作业网', 'JJC数据库', 'jjc作业', 'jjc作业网', 'jjc数据库'))
async def say_arina_database(bot, ev):
await bot.send(ev, '公主连接Re:Dive 竞技场编成数据库\n日文:https://nomae.net/arenadb \n中文:https://pcrdfans.com/battle')

Expand Down Expand Up @@ -81,7 +81,7 @@ async def say_arina_database(bot, ev):
{OTHER_KEYWORDS}
※日台服速查请输入【pcr速查】'''

@sv.on_fullmatch(('pcr速查', 'pcr图书馆', 'pcr圖書館', '图书馆', '圖書館'))
@sv.on_fullmatch(('pcr速查', 'pcr图书馆', '图书馆'))
async def pcr_sites(bot, ev: CQEvent):
await bot.send(ev, PCR_SITES, at_sender=True)
await util.silence(ev, 60)
Expand All @@ -91,7 +91,7 @@ async def bcr_sites(bot, ev: CQEvent):
await util.silence(ev, 60)


YUKARI_SHEET_ALIAS = map(lambda x: ''.join(x), itertools.product(('黄骑', '酒鬼', '黃騎'), ('充电', '充电表', '充能', '充能表')))
YUKARI_SHEET_ALIAS = map(lambda x: ''.join(x), itertools.product(('黄骑', '酒鬼'), ('充电', '充电表', '充能', '充能表')))
YUKARI_SHEET = f'''
{R.img('priconne/quick/黄骑充电.jpg').cqcode}
※大圈是1动充电对象 PvP测试
Expand Down
4 changes: 2 additions & 2 deletions hoshino/modules/priconne/query/whois.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

lmt = FreqLimiter(5)

@sv.on_suffix(('是谁', '是誰'))
@sv.on_prefix(('谁是', '誰是'))
@sv.on_suffix('是谁')
@sv.on_prefix('谁是')
async def whois(bot, ev: CQEvent):
uid = ev.user_id
if not lmt.check(uid):
Expand Down
70 changes: 32 additions & 38 deletions hoshino/trigger.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import re

import pygtrie
import zhconv

import hoshino
from hoshino import util
from hoshino.typing import CQEvent


class BaseTrigger:

def add(self, x, sf: "ServiceFunc"):
raise NotImplementedError

Expand All @@ -16,93 +17,90 @@ def find_handler(self, event: CQEvent) -> "ServiceFunc":


class PrefixTrigger(BaseTrigger):

def __init__(self):
super().__init__()
self.trie = pygtrie.CharTrie()


def add(self, prefix: str, sf: "ServiceFunc"):
if prefix in self.trie:
other = self.trie[prefix]
hoshino.logger.warning(f'Failed to add prefix trigger `{prefix}`: Conflicts between {sf.__name__} and {other.__name__}')
hoshino.logger.warning(
f"Failed to add prefix trigger `{prefix}`: Conflicts between {sf.__name__} and {other.__name__}"
)
return
self.trie[prefix] = sf
hoshino.logger.debug(f'Succeed to add prefix trigger `{prefix}`')

self.trie[zhconv.convert(prefix, "zh-hant")] = sf
hoshino.logger.debug(f"Succeed to add prefix trigger `{prefix}`")

def find_handler(self, event: CQEvent):
first_msg_seg = event.message[0]
if first_msg_seg.type != 'text':
if first_msg_seg.type != "text":
return None
first_text = first_msg_seg.data['text'].lstrip()
first_text = first_msg_seg.data["text"].lstrip()
item = self.trie.longest_prefix(first_text)
if not item:
return None
event['prefix'] = item.key
first_text = first_text[len(item.key):].lstrip()

event["prefix"] = item.key
first_text = first_text[len(item.key) :].lstrip()
if not first_text and len(event.message) > 1:
del event.message[0]
else:
first_msg_seg.data['text'] = first_text
first_msg_seg.data["text"] = first_text
return item.value



class SuffixTrigger(BaseTrigger):

def __init__(self):
super().__init__()
self.trie = pygtrie.CharTrie()


def add(self, suffix: str, sf: "ServiceFunc"):
suffix_r = suffix[::-1]
if suffix_r in self.trie:
other = self.trie[suffix_r]
hoshino.logger.warning(f'Failed to add suffix trigger `{suffix}`: Conflicts between {sf.__name__} and {other.__name__}')
hoshino.logger.warning(
f"Failed to add suffix trigger `{suffix}`: Conflicts between {sf.__name__} and {other.__name__}"
)
return
self.trie[suffix_r] = sf
hoshino.logger.debug(f'Succeed to add suffix trigger `{suffix}`')

self.trie[zhconv.convert(suffix_r, "zh-hant")] = sf
hoshino.logger.debug(f"Succeed to add suffix trigger `{suffix}`")

def find_handler(self, event: CQEvent):
last_msg_seg = event.message[-1]
if last_msg_seg.type != 'text':
if last_msg_seg.type != "text":
return None
last_text = last_msg_seg.data['text'].rstrip()
last_text = last_msg_seg.data["text"].rstrip()
item = self.trie.longest_prefix(last_text[::-1])
if not item:
return None
event['suffix'] = item.key[::-1]
last_text = last_text[:-len(item.key)].rstrip()

event["suffix"] = item.key[::-1]
last_text = last_text[: -len(item.key)].rstrip()
if not last_text and len(event.message) > 1:
del event.message[-1]
else:
last_msg_seg.data['text'] = last_text
last_msg_seg.data["text"] = last_text
return item.value



class KeywordTrigger(BaseTrigger):

def __init__(self):
super().__init__()
self.allkw = {}


def add(self, keyword: str, sf: "ServiceFunc"):
if sf.normalize_text:
keyword = util.normalize_str(keyword)
if keyword in self.allkw:
other = self.allkw[keyword]
hoshino.logger.warning(f'Failed to add keyword trigger `{keyword}`: Conflicts between {sf.__name__} and {other.__name__}')
hoshino.logger.warning(
f"Failed to add keyword trigger `{keyword}`: Conflicts between {sf.__name__} and {other.__name__}"
)
return
self.allkw[keyword] = sf
hoshino.logger.debug(f'Succeed to add keyword trigger `{keyword}`')

hoshino.logger.debug(f"Succeed to add keyword trigger `{keyword}`")

def find_handler(self, event: CQEvent) -> "ServiceFunc":
for kw, sf in self.allkw.items():
Expand All @@ -112,34 +110,30 @@ def find_handler(self, event: CQEvent) -> "ServiceFunc":
return None



class RexTrigger(BaseTrigger):

def __init__(self):
super().__init__()
self.allrex = {}



def add(self, rex: re.Pattern, sf: "ServiceFunc"):
self.allrex[rex] = sf
hoshino.logger.debug(f'Succeed to add rex trigger `{rex.pattern}`')

hoshino.logger.debug(f"Succeed to add rex trigger `{rex.pattern}`")

def find_handler(self, event: CQEvent) -> "ServiceFunc":
for rex, sf in self.allrex.items():
text = event.norm_text if sf.normalize_text else event.plain_text
match = rex.search(text)
if match:
event['match'] = match
event["match"] = match
return sf
return None



class _PlainTextExtractor(BaseTrigger):
def find_handler(self, event: CQEvent):
event.plain_text = event.message.extract_plain_text().strip()


class _TextNormalizer(_PlainTextExtractor):
def find_handler(self, event: CQEvent):
super().find_handler(event)
Expand Down
5 changes: 0 additions & 5 deletions hoshino/util/textfilter/sensitive_words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
㊙️
ntr
牛头人

回民吃猪肉
习近平
TMD
Expand Down Expand Up @@ -750,7 +749,6 @@ fuck社。会。正。义。力。量
minhui
免费处女淫女下载看电影性开苞
插你爺爺
骑士
如果你未满29周岁请自觉离开。
许家屯
火辣圖片
Expand Down Expand Up @@ -10448,7 +10446,6 @@ fuck无界浏览器
美国成人激情淫洞网站
开苞
骚b熟女
浪妇
嫩穴 小穴 花心
Expand Down Expand Up @@ -10615,7 +10612,6 @@ fuck兴奋剂
禽獸
明慧网
jiejie
嫩穴
床上激情自拍图
6。4
Expand Down Expand Up @@ -14298,7 +14294,6 @@ ur靠
免费淫奸女A片段 免费在线观看
习近平
姐姐
嫩穴
淫液
操大波波
Expand Down

0 comments on commit 72acaa0

Please sign in to comment.