Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions mute/mute.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import discord
from discord.ext import commands
from .utils import checks
import asyncio
import re
from discord.ext import commands
from .utils import checks

TIMESPEC_TRANSLATE = {'s': 1, 'm': 60, 'h': 60*60, 'd': 60*60*24}


class Mute:
def __init__(self, bot):
self.bot = bot
self.role_name="Mute"
self.role_name = "Mute"

@commands.command(no_pm=True)
@checks.admin_or_permissions(kick_members=True)
async def mute(self, user : discord.Member, time, *, reason : str=None):
async def mute(self, user: discord.Member, time, *, reason: str=None):
"""Mutes a user for a specified time period, with an optional reason.
Time specification is any combination of number with the units s,m,h,d.
Example: !mute @idiot 1.1h10m Enough bitching already!
Expand All @@ -33,7 +35,8 @@ async def mute(self, user : discord.Member, time, *, reason : str=None):
except discord.errors.Forbidden:
await self.bot.reply("I don't have permissions to modify roles.")
else:
await self.bot.reply("the {} role doesn't exist; I can't do anything.".format(self.role_name))
await self.bot.reply("The {} role doesn't exist; I can't do anything.".format(self.role_name))


def _parse_time(time):
if any(u in time for u in TIMESPEC_TRANSLATE.keys()):
Expand All @@ -42,13 +45,15 @@ def _parse_time(time):
time = sum([_timespec_sec(t) for t in time if t != ''])
return int(time)


def _timespec_sec(t):
timespec = t[-1]
if timespec.lower() not in TIMESPEC_TRANSLATE:
raise ValueError('Unknown time unit "%c"' % timespec)
timeint = float(t[:-1])
return timeint * TIMESPEC_TRANSLATE[timespec]


def setup(bot):
n = Mute(bot)
bot.add_cog(n)