mirror of
https://github.com/TriM-Organization/LiteyukiBot-TriM.git
synced 2024-11-25 00:25:04 +08:00
⚡ 启用联合黑名单
This commit is contained in:
parent
38b496d800
commit
b3aa5c9e02
@ -1,4 +1,5 @@
|
|||||||
from nonebot.plugin import PluginMetadata
|
from nonebot.plugin import PluginMetadata
|
||||||
|
from .api import *
|
||||||
|
|
||||||
__author__ = "snowykami"
|
__author__ = "snowykami"
|
||||||
__plugin_meta__ = PluginMetadata(
|
__plugin_meta__ = PluginMetadata(
|
||||||
|
59
liteyuki/plugins/liteyuki_uniblacklist/api.py
Normal file
59
liteyuki/plugins/liteyuki_uniblacklist/api.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import datetime
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
import nonebot
|
||||||
|
from nonebot import require
|
||||||
|
from nonebot.exception import IgnoredException
|
||||||
|
from nonebot.message import event_preprocessor
|
||||||
|
from nonebot_plugin_alconna.typings import Event
|
||||||
|
|
||||||
|
require("nonebot_plugin_apscheduler")
|
||||||
|
|
||||||
|
from nonebot_plugin_apscheduler import scheduler
|
||||||
|
|
||||||
|
blacklist_data: dict[str, set[str]] = {}
|
||||||
|
blacklist: set[str] = set()
|
||||||
|
|
||||||
|
|
||||||
|
@scheduler.scheduled_job("interval", minutes=10, next_run_time=datetime.datetime.now())
|
||||||
|
async def update_blacklist():
|
||||||
|
await request_for_blacklist()
|
||||||
|
|
||||||
|
|
||||||
|
async def request_for_blacklist():
|
||||||
|
global blacklist
|
||||||
|
urls = [
|
||||||
|
"https://cdn.liteyuki.icu/static/ubl/"
|
||||||
|
]
|
||||||
|
|
||||||
|
platforms = [
|
||||||
|
"qq"
|
||||||
|
]
|
||||||
|
|
||||||
|
for plat in platforms:
|
||||||
|
for url in urls:
|
||||||
|
url += f"{plat}.txt"
|
||||||
|
async with httpx.AsyncClient() as client:
|
||||||
|
resp = await client.get(url)
|
||||||
|
blacklist_data[plat] = set(resp.text.splitlines())
|
||||||
|
blacklist = get_uni_set()
|
||||||
|
nonebot.logger.info("blacklists updated")
|
||||||
|
|
||||||
|
|
||||||
|
def get_uni_set() -> set:
|
||||||
|
s = set()
|
||||||
|
for new_set in blacklist_data.values():
|
||||||
|
s.update(new_set)
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
@event_preprocessor
|
||||||
|
async def pre_handle(event: Event):
|
||||||
|
try:
|
||||||
|
user_id = str(event.get_user_id())
|
||||||
|
|
||||||
|
except:
|
||||||
|
return
|
||||||
|
|
||||||
|
if user_id in get_uni_set():
|
||||||
|
raise IgnoredException("UserId in blacklist")
|
3
main.py
3
main.py
@ -5,13 +5,12 @@ from liteyuki.utils.base.config import load_from_yaml
|
|||||||
from liteyuki.utils.base.data_manager import StoredConfig, common_db
|
from liteyuki.utils.base.data_manager import StoredConfig, common_db
|
||||||
from liteyuki.utils.base.ly_api import liteyuki_api
|
from liteyuki.utils.base.ly_api import liteyuki_api
|
||||||
|
|
||||||
|
if __name__ == "__mp_main__":
|
||||||
init()
|
init()
|
||||||
store_config: dict = common_db.first(StoredConfig(), default=StoredConfig()).config
|
store_config: dict = common_db.first(StoredConfig(), default=StoredConfig()).config
|
||||||
static_config = load_from_yaml("config.yml")
|
static_config = load_from_yaml("config.yml")
|
||||||
store_config.update(static_config)
|
store_config.update(static_config)
|
||||||
nonebot.init(**store_config)
|
nonebot.init(**store_config)
|
||||||
|
|
||||||
if __name__ == "__mp_main__":
|
|
||||||
adapters = [v11.Adapter, v12.Adapter]
|
adapters = [v11.Adapter, v12.Adapter]
|
||||||
driver = nonebot.get_driver()
|
driver = nonebot.get_driver()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user