Created
December 21, 2021 00:06
-
-
Save an-dyy/b8c81ce7f332d64e97519b07f95e76f0 to your computer and use it in GitHub Desktop.
A modern mute command using the newly added `communication_disabled_until` property of member. Newly added to the Lefi DAPI wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
import datetime | |
from typing import TYPE_CHECKING | |
import lefi | |
from lefi.exts import commands | |
if TYPE_CHECKING: | |
from ..core import Bot | |
class Moderation(commands.Plugin): | |
VALID_UNITS: dict[str, str] = {"s": "seconds", "m": "minutes", "h": "hours"} | |
def __init__(self, bot: Bot) -> None: | |
self.bot = bot | |
@staticmethod | |
def check_role(ctx: commands.Context) -> bool: | |
if not isinstance(ctx.author, lefi.Member): | |
return False | |
if lefi.utils.get(ctx.author.roles, id=907106592938418276): | |
return True | |
return False | |
@commands.command() | |
@commands.check(lambda ctx: Moderation.check_role(ctx)) | |
async def mute( | |
self, ctx: commands.Context, target: lefi.Member, timeout: str | |
) -> None | lefi.Message: | |
amount: str = timeout[:-1] | |
unit: str = timeout[-1] | |
if unit not in Moderation.VALID_UNITS or not amount.isdigit(): | |
return await ctx.send(f"{unit!r} is not a valid time.") | |
name = Moderation.VALID_UNITS[unit] | |
actual_amount = int(amount) | |
time = datetime.timedelta( | |
seconds=actual_amount if name == "seconds" else 0, | |
minutes=actual_amount if name == "minutes" else 0, | |
hours=actual_amount if name == "hours" else 0, | |
) | |
embed = lefi.Embed(color=self.bot.config["BOT"]["COLOR"]) | |
embed.description = f"Muted {target.username} for {timeout!r}" | |
await target.edit(timeout=datetime.datetime.utcnow() + time) | |
await ctx.send(embed=embed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very much liking this new feature; This new feature means that mutes persist even during downtime, and mutes also don't require a database anymore. 10/10