import os import requests from nonebot import CommandSession, on_command from utils.configsReader import configsReader, copyFileInText from utils.decorators import CatchRequestsException, SyncToAsync from utils.message import processSession from utils.network import NetworkUtils from utils.manager import PluginManager __plugin_name__ = "wikipedia" PluginManager.registerPlugin(__plugin_name__) CONFIG_PATH = "configs/wikipedia.yml" DEFAULT_PATH = "configs/default.wikipedia.yml" if not os.path.isfile(CONFIG_PATH): copyFileInText(DEFAULT_PATH, CONFIG_PATH) CONFIG_READ = Config = configsReader(CONFIG_PATH, DEFAULT_PATH) @CatchRequestsException(prompt="从维基获取数据出错") def getWiki(keyword: str) -> dict: requestParam = { "action": "query", "generator": "prefixsearch", "gpssearch": keyword, "format": "json",
from nonebot import CommandSession, MessageSegment, on_command from nonebot.command.argfilter.extractors import extract_numbers from nonebot.permission import GROUP_ADMIN, PRIVATE_FRIEND, SUPERUSER from utils.decorators import SyncToAsync, WithKeyword from utils.manager import PluginManager, nameJoin from utils.message import processSession from .config import Config from .network import downloadMultiImage, getImageList __plugin_name__ = "NSFWImages" OPERATING_METHOD = nameJoin(__plugin_name__, "ops") POWER_GROUP = GROUP_ADMIN | PRIVATE_FRIEND | SUPERUSER PluginManager.registerPlugin(__plugin_name__, defaultStatus=False) PluginManager.registerPlugin(OPERATING_METHOD) @on_command(__plugin_name__, aliases=("setu", "涩图", "色图")) @processSession(pluginName=__plugin_name__) @WithKeyword("来一张涩图", command=__plugin_name__) @SyncToAsync def NSFWImage(session: CommandSession): rank: str = session.get_optional("rank", Config.send.default) pictureCount: int = session.get_optional("num", 1) pictureCount = ( pictureCount if pictureCount <= Config.send.size else Config.send.size ) session.send(f"{rank.upper()}级涩图加载中,将发送最多{pictureCount}张") imageInfoList: List[Dict[str, Any]] = getImageList()
from utils.message import processSession from .config import Config from .parse import parseMultiImage, parseSingleImage from .tools import cache, downloadMutliImage, pixiv __plugin_name__ = "pixiv" GET_IMAGE_METHOD = nameJoin(__plugin_name__, "get") SEARCH_IMAGE_METHOD = nameJoin(__plugin_name__, "search") MEMBER_IMAGE_METHOD = nameJoin(__plugin_name__, "member") RANK_IMAGE_METHOD = nameJoin(__plugin_name__, "rank") OPERATING_METHOD = nameJoin(__plugin_name__, "ops") POWER_GROUP = GROUP_ADMIN | SUPERUSER | PRIVATE_FRIEND PluginManager.registerPlugin(GET_IMAGE_METHOD, defaultSettings={"r-18": False}) PluginManager.registerPlugin(SEARCH_IMAGE_METHOD, defaultSettings={"r-18": False}) PluginManager.registerPlugin(MEMBER_IMAGE_METHOD, defaultSettings={"r-18": False}) PluginManager.registerPlugin(RANK_IMAGE_METHOD) PluginManager.registerPlugin(OPERATING_METHOD) _RANK_CACHE = {} @on_command(GET_IMAGE_METHOD, aliases=("点图", "获取图片")) @processSession(pluginName=GET_IMAGE_METHOD) @WithKeyword("p站点图", command=GET_IMAGE_METHOD) @SyncToAsync def getImage(session: CommandSession): allowR18: bool = PluginManager.settings(GET_IMAGE_METHOD, ctx=session.ctx).settings[ "r-18"
from random import randint from nonebot import CommandSession, NLPSession, logger, on_command, on_natural_language from nonebot.permission import GROUP_ADMIN, GROUP_MEMBER, SUPERUSER from utils.decorators import SyncToAsync from utils.message import processSession from utils.objects import SyncWrapper from utils.manager import PluginManager __plugin_name__ = "repeater" PluginManager.registerPlugin(__plugin_name__, defaultStatus=True, defaultSettings={"rate": 20}) @on_natural_language(permission=GROUP_MEMBER, only_to_me=False) @processSession(pluginName=__plugin_name__) @SyncToAsync def _(session: NLPSession): groupRate = PluginManager.settings(__plugin_name__, ctx=session.ctx).settings["rate"] randomNum, msgID = randint(0, groupRate - 1), session.ctx["message_id"] groupID = session.ctx.get("group_id") if not groupID: return logger.debug( f"Chat {groupID} has a repeat probability of {1/groupRate:.3%}." + f"The random number of the current session {msgID} is {randomNum}.") if not randomNum:
from aiocqhttp import Event from nonebot import CommandSession, NoneBot, on_command, MessageSegment from nonebot.command.argfilter.extractors import extract_numbers from nonebot.message import CanceledException, message_preprocessor from nonebot.permission import GROUP_ADMIN, SUPERUSER from utils.botConfig import settings from utils.decorators import SyncToAsync from utils.objects import callModuleAPI from utils.manager import PluginManager from utils.message import processSession __plugin_name__ = "blacklist" POWER_GROUP = GROUP_ADMIN | SUPERUSER PluginManager.registerPlugin(__plugin_name__, defaultSettings=[]) @message_preprocessor async def _(bot: NoneBot, event: Event, _): if event.user_id in settings.SUPERUSERS: return if "group_id" not in event: return blacklists = PluginManager.settings(__plugin_name__, event).settings if event.user_id in blacklists: raise CanceledException(f"User {event.user_id} is in blacklist") @on_command("blacklist_add", aliases=("黑名单添加", "拉黑"), permission=POWER_GROUP) @processSession
from nonetrip import CommandSession, on_command from nonetrip.permission import GROUP_ADMIN, PRIVATE_FRIEND, SUPERUSER from utils.decorators import SyncToAsync, WithKeyword from utils.manager import PluginManager from utils.message import processSession from .config import Config from .parse import getCorrectInfo, searchImage __plugin_name__ = "illust_search" PluginManager.registerPlugin(__plugin_name__, defaultStatus=False) POWER_GROUP = GROUP_ADMIN | SUPERUSER | PRIVATE_FRIEND @on_command(__plugin_name__, aliases=("以图搜图", "搜图")) @processSession(pluginName=__plugin_name__) @WithKeyword("以图搜图", command=__plugin_name__) @SyncToAsync def illustSearch(session: CommandSession): imageURL = session.get("image") session.send("开始以图搜图") searchContent = searchImage(imageURL) searchParse = getCorrectInfo(searchContent) messageRepeat = [ str(Config.customize.repeat).format(**subject) for subject in searchParse["subject"] ] fullMessage = (str(Config.customize.prefix).format(**searchParse) + "".join(messageRepeat[:Config.customize.size]) + str(Config.customize.suffix).format(**searchParse))