Skip to content

Commit

Permalink
0.1.0-pre.1: readme没写,熬不动了
Browse files Browse the repository at this point in the history
  • Loading branch information
shengwang52005 committed Aug 15, 2024
1 parent dca9638 commit 7dbbc0e
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Miaowing

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 13 additions & 0 deletions nonebot_plugin_muteme/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from nonebot.plugin import PluginMetadata

from . import __main__

# 插件信息
__plugin_meta__ = PluginMetadata(
name="nonebot_plugin_muteme",
description="唔唔?你想被禁言嘛~?",
usage="禁我",
type="application",
homepage="https://github.com/shengwang52005/nonebot_plugin_muteme",
supported_adapters={"~onebot.v11"},
)
53 changes: 53 additions & 0 deletions nonebot_plugin_muteme/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from nonebot import on_command
from nonebot.adapters.onebot.v11 import Bot, Event
from nonebot.typing import T_State
import random

# 自定义的禁言时间列表(单位:分钟)
mute_times = [1, 5, 10, 30]

mute = on_command(
"禁我",
priority=100,
block=True
)

@mute.handle()
async def handle_mute_request(bot: Bot, event: Event, state: T_State):
# 获取当前发送消息的用户
user_id = event.user_id
group_id = event.group_id

# 检查 bot 是否有管理员权限
try:
member_info = await bot.get_group_member_info(group_id=group_id, user_id=bot.self_id)
if member_info["role"] not in ["admin", "owner"]:
await mute.send("呀呀呀,似乎禁言不了呢……")
return
except Exception:
await mute.send("呀呀呀,似乎禁言不了呢……")
return

# 检查发送消息者的角色
try:
sender_info = await bot.get_group_member_info(group_id=group_id, user_id=user_id)
if sender_info["role"] == "owner":
await mute.send("呀呀呀,似乎禁言不了呢……")
return
except Exception:
await mute.send("呀呀呀,似乎禁言不了呢……")
return

# 随机选择一个禁言时间
mute_time = random.choice(mute_times)

# 禁言操作
try:
await bot.set_group_ban(
group_id=group_id,
user_id=user_id,
duration=mute_time * 60 # 禁言时间转化为秒
)
await mute.send(f"那就满足你叭~ 药效 {mute_time} 分钟哦~")
except Exception:
await mute.send("呜呜呜……满足不了你的愿望呢……")
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tool.poetry]
name = "nonebot_plugin_muteme"
version = "0.0.1"
description = "唔唔?你想被禁言嘛~?"
authors = ["Miaowing <[email protected]>"]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/shengwang52005/nonebot_plugin_muteme"
repository = "https://github.com/shengwang52005/nonebot_plugin_muteme"

[tool.poetry.dependencies]
python = "^3.10"
nonebot2 = ">=2.3.2"
nonebot-adapter-onebot = ">=2.3.1"
httpx = ">=0.27.0"
pil_utils = "0.1.10"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

0 comments on commit 7dbbc0e

Please sign in to comment.