Compare commits
5 Commits
3da2c2266f
...
v0.7.10
| Author | SHA1 | Date | |
|---|---|---|---|
| afda0680ec | |||
| 021133954e | |||
| 7baa04dbc2 | |||
| e55bdbdf4a | |||
| a30c7b8093 |
2
konabot/docs/concepts/罗文.txt
Normal file
2
konabot/docs/concepts/罗文.txt
Normal file
@ -0,0 +1,2 @@
|
||||
关于罗文和洛温:
|
||||
AdoreLowen 希望和洛温阿特金森区分,所以最好就不要叫他洛温了!此方 BOT 会在一些群提醒叫错了的人。
|
||||
9
konabot/docs/sys/怪话过滤.txt
Normal file
9
konabot/docs/sys/怪话过滤.txt
Normal file
@ -0,0 +1,9 @@
|
||||
指令介绍
|
||||
怪话过滤 - 去除含有关键词的怪话
|
||||
|
||||
使用方法
|
||||
`怪话过滤 说的道理`
|
||||
去除所有含有“说的道理”的怪话
|
||||
|
||||
另见
|
||||
怪话(1)
|
||||
12
konabot/docs/user/怪话.txt
Normal file
12
konabot/docs/user/怪话.txt
Normal file
@ -0,0 +1,12 @@
|
||||
指令介绍
|
||||
说点怪话/说些怪话 - 让 BOT 学群友胡言乱语
|
||||
|
||||
适用范围
|
||||
为保证安全,只有少数授权的群聊可以使用该指令
|
||||
|
||||
使用方法
|
||||
`说点怪话 今天吃什么`
|
||||
期待 Bot 会回答你什么吧
|
||||
|
||||
`说些怪话 明天不想上体育课`
|
||||
Bot 会回复你三句怪话
|
||||
@ -2,9 +2,10 @@ import asyncio
|
||||
from nonebot import get_plugin_config, on_command, on_message
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.adapters.onebot.v11.event import GroupMessageEvent
|
||||
from nonebot_plugin_alconna import UniMessage, UniMsg
|
||||
from nonebot_plugin_alconna import Alconna, Args, UniMessage, UniMsg, on_alconna
|
||||
from pydantic import BaseModel
|
||||
|
||||
from konabot.common.nb.is_admin import is_admin
|
||||
from konabot.common.path import DATA_PATH
|
||||
|
||||
from .random_text_record import RandomTextManager
|
||||
@ -30,7 +31,7 @@ evt_collector = on_message(rule=is_collect_target)
|
||||
@evt_collector.handle()
|
||||
async def _(msg: UniMsg):
|
||||
txt = msg.extract_plain_text()
|
||||
if len(txt) > 50:
|
||||
if len(txt) > 50 or not txt.strip():
|
||||
return
|
||||
if txt.startswith("说点怪话") or txt.startswith("说些怪话") or txt.startswith("怪话过滤"):
|
||||
return
|
||||
@ -53,3 +54,15 @@ async def _(bot: Bot):
|
||||
await cmd_guaihuas.send(await UniMessage().text(fortune_wtf.choice()).export(bot))
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
cmd_filter_guaihua = on_alconna(Alconna(
|
||||
"怪话过滤",
|
||||
Args["keyword", str],
|
||||
), rule=is_admin)
|
||||
|
||||
@cmd_filter_guaihua.handle()
|
||||
async def _(keyword: str, bot: Bot):
|
||||
async with fortune_insert_lock:
|
||||
c = fortune_wtf.filter_out(keyword)
|
||||
await cmd_filter_guaihua.send(await UniMessage().text(f"删除了 {c} 条怪话").export(bot))
|
||||
|
||||
|
||||
@ -1,10 +1,17 @@
|
||||
import base64
|
||||
import math
|
||||
import random
|
||||
import time
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def dec_func(t: float) -> float:
|
||||
if t < 86400:
|
||||
return 0.5 * (1 + math.tanh(t / 43200 - 1))
|
||||
return math.exp(-0.00000043 * (t - 86400))
|
||||
|
||||
|
||||
class RandomTextManager:
|
||||
_cache: list[tuple[float, str]]
|
||||
|
||||
@ -31,6 +38,14 @@ class RandomTextManager:
|
||||
continue
|
||||
self._cache.append((ts, base64.b64decode(cn).decode("utf-8")))
|
||||
|
||||
def save(self):
|
||||
lines = [
|
||||
str(ts) + "|" + base64.b64encode(cn.encode("utf-8")).decode()
|
||||
for ts, cn in self._cache
|
||||
]
|
||||
with self.fp.open("w") as f:
|
||||
f.writelines(lines)
|
||||
|
||||
def insert(self, text: str, timestamp: float | None = None):
|
||||
if timestamp is None:
|
||||
timestamp = time.time()
|
||||
@ -47,7 +62,17 @@ class RandomTextManager:
|
||||
|
||||
for ts, cn in self._cache:
|
||||
contents.append(cn)
|
||||
weights.append((abs(now - ts) + 0.01) ** (-1))
|
||||
# weights.append((abs(now - ts) + 0.01) ** (-1))
|
||||
weights.append(dec_func(now - ts))
|
||||
|
||||
return random.choices(contents, weights)[0]
|
||||
|
||||
def filter_out(self, keyword: str):
|
||||
len1 = len(self._cache)
|
||||
self._cache = [
|
||||
(ts, cn) for ts, cn in self._cache
|
||||
if keyword not in cn
|
||||
]
|
||||
self.save()
|
||||
return len1 - len(self._cache)
|
||||
|
||||
|
||||
@ -53,7 +53,7 @@ async def _(
|
||||
if doc is None:
|
||||
# 检索模式
|
||||
if section is None:
|
||||
section_set = {1}
|
||||
section_set = {1, 7}
|
||||
else:
|
||||
section_set = {section}
|
||||
if 1 in section_set and is_admin(event):
|
||||
|
||||
Reference in New Issue
Block a user