mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-20 18:06:08 -05:00
Move mutes to new cog, add role-based and temporary mutes (#3634)
* revert the revert the revert git is hard... * and remove old mutes * make voicemutes less yelly * fix error when no args present in mute commands * update docstrings * address review * black * oops * fix voicemutes * remove mutes.py file * Remove _voice_perm_check from mod since it's now in mutes cog * remove naive datetimes prevent muting the bot prevent muting yourself fix error message when lots of channels are present * change alias for channelunmute Be more verbose for creating default mute role * add `[p]activemutes` to show current mutes in the server and time remaining on the mutes * improve resolution of unmute time * black * Show indefinite mutes in activemutes and only show the current servers mutes in activemutes * replace message.created_at with timezone aware timezone * remove "server" from activemutes to clean up look since channelmutes will show channel * better cache management, add tracking for manual muted role removal in the cache and modlog cases * Fix keyerror in mutes command when unsuccessful mutes * add typing indicator and improve config settings * flake8 issue * add one time message when attempting to mute without a role set, consume rate limits across channels for overwrite mutes * Don't clear the whole guilds settings when a mute is finished. Optimize server mutes to better handle migration to API method later. Fix typehints. * Utilize usage to make converter make more sense * remove decorator permission checks and fix doc strings * handle role changes better * More sanely handle channel mutes return and improve failed mutes dialogue. Re-enable task cleaner. Reduce wait time to improve resolution of mute time. * Handle re-mute on leave properly * fix unbound error in overwrites mute * revert the revert the revert git is hard... * and remove old mutes * make voicemutes less yelly * fix error when no args present in mute commands * update docstrings * address review * black * oops * fix voicemutes * Remove _voice_perm_check from mod since it's now in mutes cog * remove naive datetimes prevent muting the bot prevent muting yourself fix error message when lots of channels are present * change alias for channelunmute Be more verbose for creating default mute role * add `[p]activemutes` to show current mutes in the server and time remaining on the mutes * improve resolution of unmute time * black * Show indefinite mutes in activemutes and only show the current servers mutes in activemutes * replace message.created_at with timezone aware timezone * remove "server" from activemutes to clean up look since channelmutes will show channel * better cache management, add tracking for manual muted role removal in the cache and modlog cases * Fix keyerror in mutes command when unsuccessful mutes * add typing indicator and improve config settings * flake8 issue * add one time message when attempting to mute without a role set, consume rate limits across channels for overwrite mutes * Don't clear the whole guilds settings when a mute is finished. Optimize server mutes to better handle migration to API method later. Fix typehints. * Utilize usage to make converter make more sense * remove decorator permission checks and fix doc strings * handle role changes better * More sanely handle channel mutes return and improve failed mutes dialogue. Re-enable task cleaner. Reduce wait time to improve resolution of mute time. * Handle re-mute on leave properly * fix unbound error in overwrites mute * remove mutes.pt * remove reliance on mods is_allowed_by_hierarchy since we don't have a setting to control that anyways inside this. * black * fix hierarchy check * wtf * Cache mute roles for large bots * fix lint * fix this error * Address review 1 * lint * fix string i18n issue * remove unused typing.Coroutine import and fix i18n again * missed this docstring * Put voiceban and voiceunban back in mod where it's more appropriate * Address review 2 electric boogaloo * Make voicemutes use same methods as channel mute * black * handle humanize_list doesn't accept generators * update voicemutes docstrings * make voiceperm check consistent with rest of error handling * bleh * fix modlog case spam when overrides are in place * <a:pandaexplode:639975629793787922> * bleck * use total_seconds() instead of a dict, sorry everyone already using this lmao * <:excited:474074780887285776> This should be everything * black * fix the things * bleh * more cleanup * lmao hang on * fix voice mutes thingy * Title Case Permissions * oh I see * I'm running out of funny one-liners for commit messages * oof * ugh * let's try this * voicemutes manage_permissions * Cleanup mutes if they expire when member is not present * black * linters go brr Co-authored-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>
This commit is contained in:
55
redbot/cogs/mutes/converters.py
Normal file
55
redbot/cogs/mutes/converters.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import logging
|
||||
import re
|
||||
from typing import Union, Dict
|
||||
from datetime import timedelta
|
||||
|
||||
from discord.ext.commands.converter import Converter
|
||||
from redbot.core import commands
|
||||
|
||||
log = logging.getLogger("red.cogs.mutes")
|
||||
|
||||
# the following regex is slightly modified from Red
|
||||
# it's changed to be slightly more strict on matching with finditer
|
||||
# this is to prevent "empty" matches when parsing the full reason
|
||||
# This is also designed more to allow time interval at the beginning or the end of the mute
|
||||
# to account for those times when you think of adding time *after* already typing out the reason
|
||||
# https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/redbot/core/commands/converter.py#L55
|
||||
TIME_RE_STRING = r"|".join(
|
||||
[
|
||||
r"((?P<weeks>\d+?)\s?(weeks?|w))",
|
||||
r"((?P<days>\d+?)\s?(days?|d))",
|
||||
r"((?P<hours>\d+?)\s?(hours?|hrs|hr?))",
|
||||
r"((?P<minutes>\d+?)\s?(minutes?|mins?|m(?!o)))", # prevent matching "months"
|
||||
r"((?P<seconds>\d+?)\s?(seconds?|secs?|s))",
|
||||
]
|
||||
)
|
||||
TIME_RE = re.compile(TIME_RE_STRING, re.I)
|
||||
TIME_SPLIT = re.compile(r"t(?:ime)?=")
|
||||
|
||||
|
||||
class MuteTime(Converter):
|
||||
"""
|
||||
This will parse my defined multi response pattern and provide usable formats
|
||||
to be used in multiple reponses
|
||||
"""
|
||||
|
||||
async def convert(
|
||||
self, ctx: commands.Context, argument: str
|
||||
) -> Dict[str, Union[timedelta, str, None]]:
|
||||
time_split = TIME_SPLIT.split(argument)
|
||||
result: Dict[str, Union[timedelta, str, None]] = {}
|
||||
if time_split:
|
||||
maybe_time = time_split[-1]
|
||||
else:
|
||||
maybe_time = argument
|
||||
|
||||
time_data = {}
|
||||
for time in TIME_RE.finditer(maybe_time):
|
||||
argument = argument.replace(time[0], "")
|
||||
for k, v in time.groupdict().items():
|
||||
if v:
|
||||
time_data[k] = int(v)
|
||||
if time_data:
|
||||
result["duration"] = timedelta(**time_data)
|
||||
result["reason"] = argument
|
||||
return result
|
||||
Reference in New Issue
Block a user