Skip to content

Commit

Permalink
implemented #13
Browse files Browse the repository at this point in the history
  • Loading branch information
cswimr committed Jun 23, 2023
1 parent 92053ac commit ba80c59
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ DB_HOST=localhost
DB_USER=yourusername
DB_PASSWORD=yourpassword
DB=yourdatabase
REQUIRED_ROLE_ID=yourroleid
30 changes: 30 additions & 0 deletions cogs/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import revolt
from dotenv import load_dotenv
from pytimeparse2 import disable_dateutil, parse
from revolt import utils
from revolt.ext import commands
from utils.embed import CustomEmbed

Expand All @@ -15,6 +16,7 @@
db_user = os.getenv('DB_USER')
db_password = os.getenv('DB_PASSWORD')
db = os.getenv('DB')
required_role_id = os.getenv('REQUIRED_ROLE_ID')

class Moderation(commands.Cog):
def __init__(self, bot):
Expand All @@ -39,6 +41,10 @@ def mysql_log(self, ctx: commands.Context,moderation_type, target_id, duration,

@commands.command(name="timeout", aliases=["mute"])
async def timeout(self, ctx: commands.Context, target: commands.MemberConverter, duration: str, *, reason: str):
required_role = utils.get(ctx.server.roles, id=required_role_id)
if required_role not in ctx.author.roles:
await ctx.message.reply("You do not have permission to use this command!")
return
try:
parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True)
except ValueError:
Expand All @@ -58,6 +64,10 @@ async def timeout(self, ctx: commands.Context, target: commands.MemberConverter,

@commands.command(name="untimeout", aliases=["unmute"])
async def untimeout(self, ctx: commands.Context, target: commands.MemberConverter, *, reason: str):
required_role = utils.get(ctx.server.roles, id=required_role_id)
if required_role not in ctx.author.roles:
await ctx.message.reply("You do not have permission to use this command!")
return
if not reason:
await ctx.message.reply("Please include a reason!")
return
Expand All @@ -73,6 +83,10 @@ async def untimeout(self, ctx: commands.Context, target: commands.MemberConverte

@commands.command()
async def warn(self, ctx: commands.Context, target: commands.MemberConverter, *, reason: str):
required_role = utils.get(ctx.server.roles, id=required_role_id)
if required_role not in ctx.author.roles:
await ctx.message.reply("You do not have permission to use this command!")
return
if not reason:
await ctx.message.reply("Please include a reason!")
return
Expand All @@ -86,6 +100,10 @@ async def warn(self, ctx: commands.Context, target: commands.MemberConverter, *,

@commands.command()
async def kick(self, ctx: commands.Context, target: commands.MemberConverter, *, reason: str):
required_role = utils.get(ctx.server.roles, id=required_role_id)
if required_role not in ctx.author.roles:
await ctx.message.reply("You do not have permission to use this command!")
return
if not reason:
await ctx.message.reply("Please include a reason!")
return
Expand All @@ -99,6 +117,10 @@ async def kick(self, ctx: commands.Context, target: commands.MemberConverter, *,

@commands.command()
async def ban(self, ctx: commands.Context, target: commands.MemberConverter, *, reason: str):
required_role = utils.get(ctx.server.roles, id=required_role_id)
if required_role not in ctx.author.roles:
await ctx.message.reply("You do not have permission to use this command!")
return
if not reason:
await ctx.message.reply("Please include a reason!")
return
Expand All @@ -116,6 +138,10 @@ async def ban(self, ctx: commands.Context, target: commands.MemberConverter, *,

@commands.command()
async def unban(self, ctx: commands.Context, target: commands.UserConverter, *, reason: str):
required_role = utils.get(ctx.server.roles, id=required_role_id)
if required_role not in ctx.author.roles:
await ctx.message.reply("You do not have permission to use this command!")
return
if ctx.channel.channel_type is not revolt.ChannelType.text_channel:
await ctx.message.reply("You cannot use moderation commands in direct messages!")
return
Expand All @@ -139,6 +165,10 @@ async def unban(self, ctx: commands.Context, target: commands.UserConverter, *,

@commands.command(aliases=["tdc"])
async def timedeltaconvert(self, ctx, *, duration):
required_role = utils.get(ctx.server.roles, id=required_role_id)
if required_role not in ctx.author.roles:
await ctx.message.reply("You do not have permission to use this command!")
return
if not duration:
embeds = [CustomEmbed(description=f"## timedeltaconvert\nThis command converts a duration to a `timedelta` Python object.\n### Example Usage\n`{prefix}timedeltaconvert 1 day 15hr 82 minutes 52 s`\n### Output\n`1 day, 16:22:52`", color="#5d82d1")]
await ctx.message.reply(embeds=embeds)
Expand Down

0 comments on commit ba80c59

Please sign in to comment.