Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/wling-art/U1bot
Browse files Browse the repository at this point in the history
  • Loading branch information
wling-art committed Jan 9, 2024
2 parents 8484a69 + 7eef897 commit 29fa599
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 102 deletions.
17 changes: 5 additions & 12 deletions src/plugins/cave/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import random
import re
import base64
from nonebot import logger
from nonebot import get_driver, logger, on_command
import requests
from nonebot.adapters.onebot.v11 import (
Message,
Bot,
GroupMessageEvent,
PrivateMessageEvent,
MessageEvent,
)
from nonebot import on_command, get_driver
from nonebot.plugin import PluginMetadata
from nonebot.matcher import Matcher
from nonebot.params import CommandArg
from nonebot.adapters.onebot.v11 import Bot, Bot, GroupMessageEvent, GroupMessageEvent, Message, Message, MessageEvent, MessageEvent, PrivateMessageEvent, PrivateMessageEvent
from nonebot.plugin import PluginMetadata, PluginMetadata
from nonebot.matcher import Matcher, Matcher
from nonebot.params import CommandArg, CommandArg
from .models import cave_models

SUPERUSER = list(get_driver().config.superusers)
Expand Down
5 changes: 0 additions & 5 deletions src/plugins/ncm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from pathlib import Path
from typing import Tuple, Any, Union
from nonebot import on_regex, on_command, on_message
Expand Down Expand Up @@ -79,7 +77,6 @@ async def music_set_rule(event: Union[GroupMessageEvent, PrivateMessageEvent]) -


async def music_reply_rule(event: Union[GroupMessageEvent, PrivateMessageEvent]):
# logger.info(event.get_plaintext())
return event.reply and event.get_plaintext().strip() == "下载"


Expand Down Expand Up @@ -118,7 +115,6 @@ async def receive_song(bot: Bot,
_id = await nncm.search_song(keyword=str(song), limit=1)
message_id = await bot.send(event=event, message=Message(MessageSegment.music(type_="163", id_=_id)))
nncm.get_song(message_id=message_id["message_id"], nid=_id)
# try:

# except ActionFailed as e:
# logger.error(e.info)
Expand All @@ -145,7 +141,6 @@ async def music_list_receive(bot: Bot, event: Union[GroupMessageEvent, PrivateMe

@music_reply.handle()
async def music_reply_receive(bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent]):
# logger.info(event.dict()["reply"]["message_id"])
nncm.get_session(bot, event)
info = nncm.check_message()
if info is None:
Expand Down
13 changes: 2 additions & 11 deletions src/plugins/ncm/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import httpx
import nonebot
from nonebot.utils import run_sync
from nonebot.adapters.onebot.v11 import MessageSegment, Message, ActionFailed, NetworkError, Bot, GroupMessageEvent, PrivateMessageEvent
from nonebot.log import logger

from pyncm import (
apis,
Expand All @@ -23,17 +25,6 @@
)
from pyncm.apis.cloudsearch import SONG, USER, PLAYLIST

from nonebot.log import logger
from nonebot.adapters.onebot.v11 import (
MessageSegment,
Message,
ActionFailed,
NetworkError,
Bot,
GroupMessageEvent,
PrivateMessageEvent,
)

from .config import ncm_config
from tinydb import TinyDB, Query

Expand Down
10 changes: 0 additions & 10 deletions src/plugins/nonebot_plugin_addFriend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@
from nonebot.adapters import Message
from .configUtil import check_dict_key_bot_id, config, requestorDict, configPath, requestorDictPath, writeData, blackLogPath, numDict, numDictPath
from .utils import getReferIdList, sendMsg, getExist, parseMsg, isNormalAdd, writeLog, filterFriend, parseTime, writeTime
# try:
# scheduler = require('nonebot_plugin_apscheduler').scheduler
# except:
# import nonebot_plugin_apscheduler
# scheduler = nonebot_plugin_apscheduler.scheduler


# 初始化完毕,num文件单独初始化
parseRequest = on_request(priority=1, block=True)
# @event_preprocessor


@parseRequest.handle()
Expand Down Expand Up @@ -57,7 +51,6 @@ async def _(bot: Bot, event: RequestEvent):
return
else:
return
# num,now,old=read_data(numPath,autoType)
agreeAutoApprove, status = isNormalAdd(
config[bot.self_id], autoType, addInfo, agreeAutoApprove) # 正常添加判断,过滤无意义添加,类似xx通知群
if agreeAutoApprove == -1: # 黑名单结果
Expand Down Expand Up @@ -285,7 +278,6 @@ async def _(bot: Bot, event: MessageEvent, args: Message = CommandArg()):
welcome_msg = config[bot.self_id][msgType]['welcome_msg']
await bot.send_private_msg(user_id=requestorId, message=welcome_msg)

# @scheduler.scheduled_job('interval', hour=1, id='check_outdate', timezone="Asia/Shanghai")
delRequestorDict = on_command(
"清理请求表", priority=5, block=True, permission=SUPERUSER)

Expand Down Expand Up @@ -317,7 +309,6 @@ async def check_outdate(bot: Bot, event: MessageEvent):
@reFriendReqNum.handle()
async def _(bot: Bot, event: MessageEvent, args: Message = CommandArg()):
check_dict_key_bot_id(config, requestorDict, numDict, bot)
# text=event.get_plaintext().strip()
argsText = args.extract_plain_text().strip()
if '群聊' in argsText:
argsText = argsText.replace('群聊', '').strip()
Expand All @@ -329,7 +320,6 @@ async def _(bot: Bot, event: MessageEvent, args: Message = CommandArg()):
autoType = 'all'
max = config[bot.self_id]['numControl'][autoType]['maxNum']
now = datetime.now()
# num,now,old=read_data(numPath)
if parseTime(config[bot.self_id]['numControl'][autoType], numDict[bot.self_id][autoType], now) != -1:
await reFriendReqNum.send(message='未增满{}人,人数为{}上次添加时间{}'.format(max, numDict[bot.self_id][autoType]['count'], now))
argsText = argsText.replace('为', '').strip()
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/nonebot_plugin_addFriend/configUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from .utils import writeTime

basedir = dirname(__file__)
# numDictPath=basedir+'/num.txt'
configPath = f"{basedir}/config.json"
requestorDictPath = f"{basedir}/requestor.json"
numDictPath = f"{basedir}/num.json"
Expand All @@ -33,7 +32,9 @@ def check_dict_key_bot_id(config: dict, requestorDict: dict, numDict: dict, bot:
# return True


def readData(path, content={}, update=0) -> dict:
def readData(path, content=None, update=0) -> dict:
if content is None:
content = {}
if not exists(path):
with open(path, "w", encoding="utf-8") as fp:
json.dump(content, fp, ensure_ascii=False)
Expand All @@ -47,7 +48,6 @@ def writeData(path, content):
json.dump(content, fp, ensure_ascii=False)


# if not exists(configPath):
recipientList = list(get_driver().config.superusers)
# recipients=str(recipients)[1:-1].replace(' ','').replace("'",'')
# 可以在这里修改默认模板哦
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/nonebot_plugin_addFriend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import datetime


# from nonebot_plugin_txt2img import Txt2Img
def filterFriend(comment, type, allowTextList):
if type != 'friend':
return True
Expand Down Expand Up @@ -60,7 +59,6 @@ def getExist(plainCommandtext: str, wholeMessageText: str, argsText: str):
return commandText if not plainCommandtext else plainCommandtext in commandText


# def read_time(numPath:str)->dict:
def readTime(numDict: dict) -> dict:
'''读时间'''
# global num,now,old
Expand All @@ -80,7 +78,6 @@ def readTime(numDict: dict) -> dict:
for type in numDict[id].keys():
numDict[id][type]["time"] = datetime.datetime.strptime(
numDict[id][type]["time"], "%Y-%m-%d %H:%M:%S.%f")
# now = datetime.datetime.now()
return numDict


Expand All @@ -92,7 +89,6 @@ def writeTime(numDictPath, numDict: dict) -> dict:
numDictTemp[id][type]["time"] = str(numDictTemp[id][type]["time"])
with open(numDictPath, 'w', encoding='utf-8') as fp:
json.dump(numDictTemp, fp, ensure_ascii=False)
# now = datetime.datetime.now()
return numDictTemp


Expand Down
4 changes: 1 addition & 3 deletions src/plugins/nonebot_plugin_charpic/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ async def text2img(text: str):


async def char_gif(gif: Image.Image):
"""
合成 gif 字符画
"""
"""合成 gif 字符画"""
frame_list: List[str] = []
with contextlib.suppress(EOFError):
while True:
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/nonebot_plugin_heweather/weather_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ def __init__(self, city_name: str, api_key: str, api_type: Union[int, str] = 0):
self.api_type = int(api_type)
self.__url__()

# self.now: Optional[Dict[str, str]] = None
# self.daily = None
# self.air = None
# self.warning = None
self.__reference = "\n请参考: https://dev.qweather.com/docs/start/status-code/"

async def load_data(self):
Expand Down
24 changes: 6 additions & 18 deletions src/plugins/nonebot_plugin_setu_now/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from nonebot.adapters.onebot.v11.permission import GROUP_ADMIN
from nonebot.permission import SUPERUSER
from nonebot import on_command, on_regex, require
from nonebot.adapters.onebot.v11 import GROUP, PRIVATE_FRIEND, Bot, Message, MessageEvent, MessageSegment, GroupMessageEvent, PrivateMessageEvent
from nonebot.exception import ActionFailed
from nonebot.log import logger
from nonebot.params import Depends, RegexGroup
from nonebot.plugin import PluginMetadata
from .r18_whitelist import get_group_white_list_record
from .data_source import SetuHandler
from .perf_timer import PerfTimer
Expand All @@ -20,27 +26,11 @@
autorevoke_send,
)
from nonebot_plugin_tortoise_orm import add_model
from nonebot.adapters.onebot.v11 import (
GROUP,
PRIVATE_FRIEND,
Bot,
Message,
MessageEvent,
MessageSegment,
GroupMessageEvent,
PrivateMessageEvent,
)
from nonebot.exception import ActionFailed
from nonebot.plugin import PluginMetadata
from nonebot.params import Depends, RegexGroup
from nonebot.log import logger
from nonebot import on_regex, on_command
from PIL import UnidentifiedImageError
from pathlib import Path
from typing import Any, Union, Annotated
from re import I, sub
import asyncio
from nonebot import require

require("nonebot_plugin_localstore")
require("nonebot_plugin_tortoise_orm")
Expand Down Expand Up @@ -156,8 +146,6 @@ async def nb_send_handler(setu: Setu) -> None:
if r18 and process_func == EFFECT_FUNC_LIST[0]:
# R18禁止使用默认图像处理方法(do_nothing)
continue
# if process_func == EFFECT_FUNC_LIST[0]:
# continue
logger.debug(f"Using effect {process_func}")
effert_timer = PerfTimer.start("Effect process")
try:
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/nonebot_plugin_status/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
from typing import Any, Dict

from jinja2 import Environment
from jinja2.meta import find_undeclared_variables
from nonebot import get_driver
from nonebot.matcher import Matcher
from nonebot.permission import SUPERUSER
from nonebot.plugin import PluginMetadata
from jinja2.meta import find_undeclared_variables

from .config import Config
from .helpers import humanize_date, relative_time, humanize_delta
Expand Down
6 changes: 0 additions & 6 deletions src/plugins/nonebot_plugin_status/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
CPU_TEMPLATE = r"CPU: {{ '%02d' % cpu_usage }}%"
"""Default CPU status template."""

# PER_CPU_TEMPLATE = (
# "CPU:\n"
# "{%- for core in per_cpu_usage %}\n"
# " core{{ loop.index }}: {{ '%02d' % core }}%\n"
# "{%- endfor %}"
# )

MEMORY_TEMPLATE = r"Memory: {{ '%02d' % memory_usage.percent }}%"
"""Default memory status template."""
Expand Down
6 changes: 2 additions & 4 deletions src/plugins/nonebot_plugin_wordcloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" 词云
"""
"""词云"""
from .utils import (
admin_permission,
ensure_group,
Expand Down Expand Up @@ -33,7 +32,7 @@
from nonebot.permission import SUPERUSER
from nonebot.params import Arg, Depends
from nonebot.adapters import Bot, Event, Message
from nonebot import get_driver
from nonebot import get_driver, require
from arclet.alconna.arparma import Arparma
from arclet.alconna import ArparmaBehavior
import nonebot_plugin_saa as saa
Expand All @@ -42,7 +41,6 @@
from io import BytesIO
from datetime import datetime, timedelta
import re
from nonebot import require

require("nonebot_plugin_apscheduler")
require("nonebot_plugin_alconna")
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/today_yunshi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
这是一个今日运势插件,可以查看今日运势。
"""
"""这是一个今日运势插件,可以查看今日运势。"""

import time
import random
Expand Down
8 changes: 2 additions & 6 deletions src/plugins/waifu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ async def reset_record():


async def waifu_rule(bot: Bot, event: GroupMessageEvent, state: T_State) -> bool:
"""
规则:娶群友
"""
"""规则:娶群友"""
msg = event.message.extract_plain_text()
if not msg.startswith("娶群友"):
return False
Expand Down Expand Up @@ -389,9 +387,7 @@ async def _(bot: Bot, event: GroupMessageEvent):

# 透群友
async def yinpa_rule(bot: Bot, event: GroupMessageEvent, state: T_State) -> bool:
"""
规则:透群友
"""
"""规则:透群友"""
msg = event.message.extract_plain_text()
if not msg.startswith("透群友"):
return False
Expand Down
16 changes: 4 additions & 12 deletions src/plugins/waifu/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ async def download_user_img(user_id: int):


async def user_img(user_id: int) -> bytes:
"""
获取用户头像url
"""
"""获取用户头像url"""
url = f"https://q1.qlogo.cn/g?b=qq&nk={user_id}&s=640"
data = await download_url(url)
if hashlib.md5(data).hexdigest() == "acef72340ac0e914090bd35799f5594e":
Expand All @@ -45,9 +43,7 @@ async def user_img(user_id: int) -> bytes:


def text_to_png(msg):
"""
文字转png
"""
"""文字转png"""
output = io.BytesIO()
Text2Image.from_text(msg, 50, spacing=10).to_image("white", (20, 20)).save(
output, format="png"
Expand All @@ -56,9 +52,7 @@ def text_to_png(msg):


def bbcode_to_png(msg, spacing: int = 10):
"""
bbcode文字转png
"""
"""bbcode文字转png"""
output = io.BytesIO()
Text2Image.from_bbcode_text(msg, 50, spacing=spacing).to_image(
"white", (20, 20)
Expand All @@ -67,7 +61,5 @@ def bbcode_to_png(msg, spacing: int = 10):


def get_message_at(message: Message) -> list:
"""
获取at列表
"""
"""获取at列表"""
return [int(msg.data["qq"]) for msg in message if msg.type == "at"]

0 comments on commit 29fa599

Please sign in to comment.