Coder Social home page Coder Social logo

nonebot-plugin-watermarker's Introduction

PoweredByNonebotLogo

NoneBotPluginLogo

NoneBotPluginText

nonebot-plugin-watermarker

✨ 为你的bot发出的图片添加水印! ✨

license pypi python

📖简介

为bot发出的所有图片都加上水印(有的时候水印很烦,但是帅气的水印能增加图片的美感,不是吗?)

💿安装方法

nb脚手架

使用 nb-cli 安装 在 nonebot2 项目的根目录下打开命令行, 输入以下指令即可安装
nb plugin install nonebot-piugin-watermarker

pip

pip安装

命令行输入以下命令

pip install nonebot-plugin-watermarker

打开 nonebot2 项目根目录下的 pyproject.toml 文件, 在 [tool.nonebot] 部分追加写入

plugins = ["nonebot_plugin_rename"]

[tool.nonebot]
plugins = []
plugin_dirs = ["src/plugins"]

💬可以使用的指令

指令 参数 用法示例
水印 watermarker(没完工) add+要添加的不加水印的插件的名称,可以跟多个,相反的是del.on,off /watermarker on用于打开水印添加的功能

⚙插件配置项

变量名 变量类型 变量概述 使用示例
watermark_image_path str 水印图片存放目录,目录下的所有水印图片会被随机选取 F:\image
watermark_image_size float 水印相对图片的大小(保持水印原来的形状) 0.15
watermark_image_exculed_plugin List[str] 不想被贴水印的插件 [插件位置.plugins.插件名称](如src.plugins.nonebot_plugin_petpet)

🎉目前已实现的功能

加水印捏

效果图

6PHLH{(JH $R~J2H@8{{XBE

太小了看不见放大看(

G37PR_ KAWEUINI_ _B)H2E

💡待实现的功能

  1. 对特定的插件的图片不进行贴水印操作
  2. 对GIF图片进行适配
  3. 更多不同的贴水印方式
  4. 贴图片怎么够,我要贴文字!
  5. 待补充.....

💣已知bug

水印小概率贴不上,应该是base64的原因,但是我一直找不到真正的问题源,因为有时候贴的上有时候贴不上(已解决,base64解码问题,为末位不足位没有补上=)

🔥鸣谢

Nonebot2,不用说,没有Nonebot就没有这个插件

我自己,因为我做的PoweredByNonebot的Logo

💦其他

没有其他,想到再补

nonebot-plugin-watermarker's People

Contributors

chenxu233 avatar

Stargazers

 avatar 兔兔 avatar

Watchers

 avatar

nonebot-plugin-watermarker's Issues

无法正确识别水印文件夹位置

05-06 18:56:52 [ERROR] nonebot | Error when running CallingAPI hook. Running cancelled!
Traceback (most recent call last):
  File "/usr/lib/python3.11/urllib/request.py", line 1505, in open_local_file
    stats = os.stat(localfile)
FileNotFoundError: [Errno 2] No such file or directory: '/home/Neko/Bot/zhenxun'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/Neko/Bot/zhenxun_bot/bot.py", line 33, in <module>
    nonebot.run()
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/__init__.py", line 309, in run
    get_driver().run(*args, **kwargs)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/drivers/fastapi.py", line 198, in run
    uvicorn.run(
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/uvicorn/main.py", line 578, in run
    server.run()
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/uvicorn/server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/message.py", line 141, in _check_matcher
    await _run_matcher(Matcher, bot, event, state, stack, dependency_cache)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/message.py", line 187, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 753, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 728, in simple_run
    await handler(
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/dependencies/__init__.py", line 108, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
  File "/home/Neko/Bot/zhenxun_bot/plugins/ai/__init__.py", line 65, in _
    await ai.finish(hello())
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 481, in finish
    await cls.send(message, **kwargs)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 466, in send
    return await bot.send(event=event, message=_message, **kwargs)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot_plugin_guild_patch/__init__.py", line 30, in patched_send
    return await original_send(self, event, message, **kwargs)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/adapters/onebot/v11/bot.py", line 220, in send
    return await self.__class__.send_handler(self, event, message, **kwargs)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/adapters/onebot/v11/bot.py", line 174, in send
    return await bot.send_msg(**params)
> File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/internal/adapter/bot.py", line 83, in call_api
    await asyncio.gather(*coros)
  File "/home/Neko/Bot/zhenxun_bot/extensive_plugin/nonebot_plugin_watermarker/__init__.py", line 36, in _handle
    if image := str2img(file):
  File "/home/Neko/Bot/zhenxun_bot/extensive_plugin/nonebot_plugin_watermarker/fuctions.py", line 32, in str2img
    bytes = urllib.request.urlopen(string).read()
  File "/usr/lib/python3.11/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.11/urllib/request.py", line 519, in open
    response = self._open(req, data)
  File "/usr/lib/python3.11/urllib/request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/lib/python3.11/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.11/urllib/request.py", line 1483, in file_open
    return self.open_local_file(req)
  File "/usr/lib/python3.11/urllib/request.py", line 1522, in open_local_file
    raise URLError(exp)
urllib.error.URLError: <urlopen error [Errno 2] No such file or directory: '/home/Neko/Bot/zhenxun'>

用的是真寻bot,正确的文件夹路径应该是/home/Neko/Bot/zhenxun_bot/extensive_plugin/nonebot_plugin_watermarker/watermarker_image,但是运行的时候就出现上面的报错

图片如下
image
image

hook报错

image
发送图片后日志如上图,hook会报错,但是图片可以正常发送,配置保证都对

发送图片报错,图片是发出去了,但是水印没加上去

05-03 14:34:52 [ERROR] nonebot | Error when running CallingAPI hook. Running cancelled!
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1503, in open_local_file
stats = os.stat(localfile)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。: '\D'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-bot-l9AehN_x-py3.9\lib\site-packages\nonebot\adapters\onebot\v11\bot.py", line 174, in send
return await bot.send_msg(**params)
File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-bot-l9AehN_x-py3.9\lib\site-packages\nonebot\internal\adapter\bot.py", line 83, in call_api
await asyncio.gather(*coros)
File "D:\BOT\zhenxun_bot\extensive_plugin\nonebot_plugin_watermarker_init_.py", line 36, in _handle
if image := str2img(file):
File "D:\BOT\zhenxun_bot\extensive_plugin\nonebot_plugin_watermarker\fuctions.py", line 32, in str2img
bytes = urllib.request.urlopen(string).read()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 517, in open
response = self._open(req, data)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 534, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
result = func(*args)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1481, in file_open
return self.open_local_file(req)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1520, in open_local_file
raise URLError(exp)
urllib.error.URLError: <urlopen error [WinError 2] 系统找不到指定的文件。: '\D'>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.