diff options
Diffstat (limited to 'ATRI/plugins/utils')
-rw-r--r-- | ATRI/plugins/utils/__init__.py | 67 | ||||
-rw-r--r-- | ATRI/plugins/utils/data_source.py | 102 |
2 files changed, 81 insertions, 88 deletions
diff --git a/ATRI/plugins/utils/__init__.py b/ATRI/plugins/utils/__init__.py index fa59690..608f1f5 100644 --- a/ATRI/plugins/utils/__init__.py +++ b/ATRI/plugins/utils/__init__.py @@ -20,37 +20,36 @@ roll一下 /roll 1d10+10d9+4d5+2d3 """ -roll = sv.on_command( - cmd="/roll", - docs=__doc__, - rule=is_in_service('roll') -) +roll = sv.on_command(cmd="/roll", docs=__doc__, rule=is_in_service("roll")) + @roll.args_parser # type: ignore async def _load_roll(bot: Bot, event: MessageEvent, state: T_State) -> None: msg = str(event.message).strip() - quit_list = ['算了', '罢了', '取消'] + quit_list = ["算了", "罢了", "取消"] if msg in quit_list: - await roll.finish('好吧...') + await roll.finish("好吧...") if not msg: - await roll.reject('点呢?(1d10+...)') + await roll.reject("点呢?(1d10+...)") else: - state['resu'] = msg + state["resu"] = msg + @roll.handle() async def _roll(bot: Bot, event: MessageEvent, state: T_State) -> None: args = str(event.message).strip() if args: - state['resu'] = args + state["resu"] = args + @roll.got("resu", prompt="roll 参数不能为空~!\ndemo:1d10 或 2d10+2d10") async def _deal_roll(bot: Bot, event: MessageEvent, state: T_State) -> None: - resu = state['resu'] - match = re.match(r'^([\dd+\s]+?)$', resu) - + resu = state["resu"] + match = re.match(r"^([\dd+\s]+?)$", resu) + if not match: await roll.finish("请输入正确的参数!!\ndemo:1d10 或 2d10+2d10") - + await roll.finish(roll_dice(resu)) @@ -66,25 +65,22 @@ __doc__ = """ /enc e アトリは高性能ですから! """ -encrypt = sv.on_command( - cmd="/enc", - docs=__doc__, - rule=is_in_service('enc') -) +encrypt = sv.on_command(cmd="/enc", docs=__doc__, rule=is_in_service("enc")) + @encrypt.handle() async def _encrypt(bot: Bot, event: MessageEvent) -> None: - msg = str(event.message).split(' ') + msg = str(event.message).split(" ") _type = msg[0] s = msg[1] e = Encrypt() - + if _type == "e": await encrypt.finish(e.encode(s)) elif _type == "d": await encrypt.finish(e.decode(s)) else: - await encrypt.finish('请检查输入~!') + await encrypt.finish("请检查输入~!") __doc__ = """ @@ -94,32 +90,31 @@ __doc__ = """ 涩批一下 (msg) """ -sepi = sv.on_command( - cmd="涩批一下", - docs=__doc__, - rule=is_in_service('涩批一下') -) +sepi = sv.on_command(cmd="涩批一下", docs=__doc__, rule=is_in_service("涩批一下")) + @sepi.handle() async def _load_sepi(bot: Bot, event: MessageEvent, state: T_State) -> None: msg = str(event.message).strip() - quit_list = ['算了', '罢了', '取消'] + quit_list = ["算了", "罢了", "取消"] if msg in quit_list: - await sepi.finish('好吧...') + await sepi.finish("好吧...") if not msg: - await sepi.reject('话呢?') + await sepi.reject("话呢?") else: - state['sepi_msg'] = msg + state["sepi_msg"] = msg + @sepi.handle() async def _sepi(bot: Bot, event: MessageEvent, state: T_State) -> None: msg = str(event.message).strip() if msg: - state['sepi_msg'] = msg + state["sepi_msg"] = msg + [email protected]('sepi_msg', prompt='话呢?') [email protected]("sepi_msg", prompt="话呢?") async def _deal_sepi(bot: Bot, event: MessageEvent, state: T_State) -> None: - msg = state['sepi_msg'] + msg = state["sepi_msg"] if len(msg) < 4: - await sepi.finish('这么短?涩不起来!') - await sepi.finish(Yinglish.deal(msg, random()))
\ No newline at end of file + await sepi.finish("这么短?涩不起来!") + await sepi.finish(Yinglish.deal(msg, random())) diff --git a/ATRI/plugins/utils/data_source.py b/ATRI/plugins/utils/data_source.py index 98b2b37..92ae930 100644 --- a/ATRI/plugins/utils/data_source.py +++ b/ATRI/plugins/utils/data_source.py @@ -7,41 +7,41 @@ from random import random, choice, randint def roll_dice(par: str) -> str: result = 0 - proc = '' + proc = "" proc_list = [] p = par.split("+") - + for i in p: args = re.findall(r"(\d{0,10})(?:(d)(\d{1,10}))", i) args = list(args[0]) - + args[0] = args[0] or 1 if int(args[0]) >= 5000 or int(args[2]) >= 5000: return "阿...好大......" - + for a in range(1, int(args[0]) + 1): rd = randint(1, int(args[2])) result = result + rd - + if len(proc_list) <= 10: proc_list.append(rd) - + if len(proc_list) <= 10: proc += "+".join(map(str, proc_list)) elif len(proc_list) > 10: proc += "太长了不展示了就酱w" else: proc += str(result) - + result = f"{par}=({proc})={result}" return result class Encrypt: - cr = 'ĀāĂ㥹ÀÁÂÃÄÅ' - cc = 'ŢţŤťŦŧṪṫṬṭṮṯṰṱ' - cn = 'ŔŕŘřṘṙŖŗȐȑȒȓṚṛṜṝṞṟɌɍⱤɽᵲᶉɼɾᵳʀRr' - cb = 'ĨĩĪīĬĭĮįİı' + cr = "ĀāĂ㥹ÀÁÂÃÄÅ" + cc = "ŢţŤťŦŧṪṫṬṭṮṯṰṱ" + cn = "ŔŕŘřṘṙŖŗȐȑȒȓṚṛṜṝṞṟɌɍⱤɽᵲᶉɼɾᵳʀRr" + cb = "ĨĩĪīĬĭĮįİı" sr = len(cr) sc = len(cc) @@ -56,7 +56,7 @@ class Encrypt: def _encodeByte(self, i) -> Union[str, None]: if i > 0xFF: - raise ValueError('ERROR! at/ri overflow') + raise ValueError("ERROR! at/ri overflow") if i > 0x7F: i = i & 0x7F @@ -66,7 +66,7 @@ class Encrypt: def _encodeShort(self, i) -> str: if i > 0xFFFF: - raise ValueError('ERROR! atri overflow') + raise ValueError("ERROR! atri overflow") reverse = False if i > 0x7FFF: @@ -76,17 +76,15 @@ class Encrypt: char = [ self._div(i, self.scnb), self._div(i % self.scnb, self.snb), - self._div(i % self.snb, self.sb), i % self.sb - ] - char = [ - self.cr[char[0]], self.cc[char[1]], self.cn[char[2]], - self.cb[char[3]] + self._div(i % self.snb, self.sb), + i % self.sb, ] + char = [self.cr[char[0]], self.cc[char[1]], self.cn[char[2]], self.cb[char[3]]] if reverse: return char[2] + char[3] + char[0] + char[1] - return ''.join(char) + return "".join(char) def _decodeByte(self, c) -> int: nb = False @@ -94,12 +92,11 @@ class Encrypt: if idx[0] < 0 or idx[1] < 0: idx = [self.cn.index(c[0]), self.cb.index(c[1])] nb = True - raise ValueError('ERROR! at/ri overflow') + raise ValueError("ERROR! at/ri overflow") - result = idx[0] * self.sb + idx[1] \ - if nb else idx[0] * self.sc + idx[1] + result = idx[0] * self.sb + idx[1] if nb else idx[0] * self.sc + idx[1] if result > 0x7F: - raise ValueError('ERROR! at/ri overflow') + raise ValueError("ERROR! at/ri overflow") return result | 0x80 if nb else 0 @@ -110,23 +107,22 @@ class Encrypt: self.cr.index(c[0]), self.cc.index(c[1]), self.cn.index(c[2]), - self.cb.index(c[3]) + self.cb.index(c[3]), ] else: idx = [ self.cr.index(c[2]), self.cc.index(c[3]), self.cn.index(c[0]), - self.cb.index(c[1]) + self.cb.index(c[1]), ] if idx[0] < 0 or idx[1] < 0 or idx[2] < 0 or idx[3] < 0: - raise ValueError('ERROR! not atri') + raise ValueError("ERROR! not atri") - result = idx[0] * self.scnb + idx[1] * self.snb + idx[ - 2] * self.sb + idx[3] + result = idx[0] * self.scnb + idx[1] * self.snb + idx[2] * self.sb + idx[3] if result > 0x7FFF: - raise ValueError('ERROR! atri overflow') + raise ValueError("ERROR! atri overflow") result |= 0x8000 if reverse else 0 return result @@ -139,40 +135,39 @@ class Encrypt: if len(b) & 1 == 1: result.append(self._encodeByte(b[-1])) - return ''.join(result) + return "".join(result) - def encode(self, s: str, encoding: str = 'utf-8'): + def encode(self, s: str, encoding: str = "utf-8"): if not isinstance(s, str): - raise ValueError('Please enter str instead of other') + raise ValueError("Please enter str instead of other") return self._encodeBytes(s.encode(encoding)) def _decodeBytes(self, s: str): if not isinstance(s, str): - raise ValueError('Please enter str instead of other') + raise ValueError("Please enter str instead of other") if len(s) & 1: - raise ValueError('ERROR length') + raise ValueError("ERROR length") result = [] for i in range(0, (len(s) >> 2)): - result.append(bytes([self._decodeShort(s[i * 4:i * 4 + 4]) >> 8])) - result.append(bytes([ - self._decodeShort(s[i * 4:i * 4 + 4]) & 0xFF])) + result.append(bytes([self._decodeShort(s[i * 4 : i * 4 + 4]) >> 8])) + result.append(bytes([self._decodeShort(s[i * 4 : i * 4 + 4]) & 0xFF])) if (len(s) & 2) == 2: result.append(bytes([self._decodeByte(s[-2:])])) - return b''.join(result) + return b"".join(result) - def decode(self, s: str, encoding: str = 'utf-8') -> str: + def decode(self, s: str, encoding: str = "utf-8") -> str: if not isinstance(s, str): - raise ValueError('Please enter str instead of other') + raise ValueError("Please enter str instead of other") try: return self._decodeBytes(s).decode(encoding) except UnicodeDecodeError: - raise ValueError('Decoding failed') + raise ValueError("Decoding failed") class Yinglish: @@ -180,22 +175,25 @@ class Yinglish: def _to_ying(x, y, ying) -> str: if random() > ying: return x - if x in [',', '。']: - return str(choice(['..', '...', '....', '......'])) - if x in ['!', '!']: + if x in [",", "。"]: + return str(choice(["..", "...", "....", "......"])) + if x in ["!", "!"]: return "❤" if len(x) > 1 and random() < 0.5: - return str(choice([ - f"{x[0]}..{x}", f"{x[0]}...{x}", - f"{x[0]}....{x}", f"{x[0]}......{x}" - ])) + return str( + choice( + [ + f"{x[0]}..{x}", + f"{x[0]}...{x}", + f"{x[0]}....{x}", + f"{x[0]}......{x}", + ] + ) + ) else: if y == "n" and random() < 0.5: x = "〇" * len(x) - return str(choice([ - f"...{x}", f"....{x}", - f".....{x}", f"......{x}" - ])) + return str(choice([f"...{x}", f"....{x}", f".....{x}", f"......{x}"])) @classmethod def deal(cls, text, ying: Optional[float] = 0.5) -> str: |