update filter again
This commit is contained in:
parent
6359f4d19a
commit
3ccb468f0e
1 changed files with 23 additions and 43 deletions
|
@ -34,36 +34,36 @@ class FilterCog(commands.Cog):
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
print(f"{self.__class__.__name__} cog has been loaded.")
|
print(f"{self.__class__.__name__} cog has been loaded.")
|
||||||
|
|
||||||
@commands.slash_command()
|
@commands.hybrid_command()
|
||||||
async def addword(self, ctx, word: str):
|
async def addword(self, ctx, word: str):
|
||||||
"""Add a word to the filter list."""
|
"""Add a word to the filter list."""
|
||||||
async with self.config.words() as words:
|
async with self.config.words() as words:
|
||||||
words.append(word)
|
words.append(word)
|
||||||
await ctx.respond(f"Added `{word}` to the filter list.")
|
await ctx.send(f"Added `{word}` to the filter list.")
|
||||||
|
|
||||||
@commands.slash_command()
|
@commands.hybrid_command()
|
||||||
async def removeword(self, ctx, word: str):
|
async def removeword(self, ctx, word: str):
|
||||||
"""Remove a word from the filter list."""
|
"""Remove a word from the filter list."""
|
||||||
async with self.config.words() as words:
|
async with self.config.words() as words:
|
||||||
if word in words:
|
if word in words:
|
||||||
words.remove(word)
|
words.remove(word)
|
||||||
await ctx.respond(f"Removed `{word}` from the filter list.")
|
await ctx.send(f"Removed `{word}` from the filter list.")
|
||||||
else:
|
else:
|
||||||
await ctx.respond(f"`{word}` was not found in the filter list.")
|
await ctx.send(f"`{word}` was not found in the filter list.")
|
||||||
|
|
||||||
@commands.slash_command()
|
@commands.hybrid_command()
|
||||||
async def listwords(self, ctx):
|
async def listwords(self, ctx):
|
||||||
"""List all words in the filter."""
|
"""List all words in the filter."""
|
||||||
words = await self.config.words()
|
words = await self.config.words()
|
||||||
await ctx.respond(f"Filtered words: {', '.join(words) if words else 'None'}")
|
await ctx.send(f"Filtered words: {', '.join(words) if words else 'None'}")
|
||||||
|
|
||||||
@commands.slash_command()
|
@commands.hybrid_command()
|
||||||
async def clearwords(self, ctx):
|
async def clearwords(self, ctx):
|
||||||
"""Clear all words from the filter list."""
|
"""Clear all words from the filter list."""
|
||||||
await self.config.words.set([])
|
await self.config.words.set([])
|
||||||
await ctx.respond("All filtered words have been cleared.")
|
await ctx.send("All filtered words have been cleared.")
|
||||||
|
|
||||||
@commands.slash_command()
|
@commands.hybrid_command()
|
||||||
async def importconfig(self, ctx, file: discord.Attachment):
|
async def importconfig(self, ctx, file: discord.Attachment):
|
||||||
"""Import a config file."""
|
"""Import a config file."""
|
||||||
if file.filename.endswith(".json"):
|
if file.filename.endswith(".json"):
|
||||||
|
@ -74,62 +74,42 @@ class FilterCog(commands.Cog):
|
||||||
for key in config.keys():
|
for key in config.keys():
|
||||||
if key in config_data:
|
if key in config_data:
|
||||||
config[key] = config_data[key]
|
config[key] = config_data[key]
|
||||||
await ctx.respond("Config imported successfully.")
|
await ctx.send("Config imported successfully.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await ctx.respond(f"Failed to import config: {str(e)}")
|
await ctx.send(f"Failed to import config: {str(e)}")
|
||||||
else:
|
else:
|
||||||
await ctx.respond("Please upload a JSON file.")
|
await ctx.send("Please upload a JSON file.")
|
||||||
|
|
||||||
@commands.slash_command()
|
@commands.hybrid_command()
|
||||||
async def exportconfig(self, ctx):
|
async def exportconfig(self, ctx):
|
||||||
"""Export the current config as a JSON file."""
|
"""Export the current config as a JSON file."""
|
||||||
config_data = await self.config.all()
|
config_data = await self.config.all()
|
||||||
file = discord.File(io.BytesIO(json.dumps(config_data, indent=4).encode()), filename="config.json")
|
file = discord.File(io.BytesIO(json.dumps(config_data, indent=4).encode()), filename="config.json")
|
||||||
await ctx.respond("Here is the current configuration:", file=file)
|
await ctx.send("Here is the current configuration:", file=file)
|
||||||
|
|
||||||
@commands.slash_command()
|
@commands.hybrid_command()
|
||||||
async def togglelogging(self, ctx):
|
async def togglelogging(self, ctx):
|
||||||
"""Toggle logging on or off."""
|
"""Toggle logging on or off."""
|
||||||
current = await self.config.logFiltered()
|
current = await self.config.logFiltered()
|
||||||
await self.config.logFiltered.set(not current)
|
await self.config.logFiltered.set(not current)
|
||||||
await ctx.respond(f"Logging is now {'enabled' if not current else 'disabled'}.")
|
await ctx.send(f"Logging is now {'enabled' if not current else 'disabled'}.")
|
||||||
|
|
||||||
@commands.slash_command()
|
@commands.hybrid_command()
|
||||||
async def setmuteoffense(self, ctx, number: int):
|
async def setmuteoffense(self, ctx, number: int):
|
||||||
"""Set the number of offenses before muting a user."""
|
"""Set the number of offenses before muting a user."""
|
||||||
await self.config.muteAfterOffenseNumber.set(number)
|
await self.config.muteAfterOffenseNumber.set(number)
|
||||||
await ctx.respond(f"Users will now be muted after {number} offenses.")
|
await ctx.send(f"Users will now be muted after {number} offenses.")
|
||||||
|
|
||||||
@commands.slash_command()
|
@commands.hybrid_command()
|
||||||
async def enableautomod(self, ctx):
|
|
||||||
"""Enable Discord's built-in AutoMod."""
|
|
||||||
guild = ctx.guild
|
|
||||||
if guild:
|
|
||||||
await guild.edit(automod_enabled=True)
|
|
||||||
await ctx.respond("AutoMod has been enabled.")
|
|
||||||
else:
|
|
||||||
await ctx.respond("This command must be used in a server.")
|
|
||||||
|
|
||||||
@commands.slash_command()
|
|
||||||
async def disableautomod(self, ctx):
|
|
||||||
"""Disable Discord's built-in AutoMod."""
|
|
||||||
guild = ctx.guild
|
|
||||||
if guild:
|
|
||||||
await guild.edit(automod_enabled=False)
|
|
||||||
await ctx.respond("AutoMod has been disabled.")
|
|
||||||
else:
|
|
||||||
await ctx.respond("This command must be used in a server.")
|
|
||||||
|
|
||||||
@commands.slash_command()
|
|
||||||
async def listautomodrules(self, ctx):
|
async def listautomodrules(self, ctx):
|
||||||
"""List all AutoMod rules in the server."""
|
"""List all AutoMod rules in the server."""
|
||||||
guild = ctx.guild
|
guild = ctx.guild
|
||||||
if guild:
|
if guild:
|
||||||
rules = await guild.fetch_automod_rules()
|
rules = await guild.automod_rules()
|
||||||
rule_names = [rule.name for rule in rules]
|
rule_names = [rule.name for rule in rules]
|
||||||
await ctx.respond(f"AutoMod Rules: {', '.join(rule_names) if rule_names else 'None'}")
|
await ctx.send(f"AutoMod Rules: {', '.join(rule_names) if rule_names else 'None'}")
|
||||||
else:
|
else:
|
||||||
await ctx.respond("This command must be used in a server.")
|
await ctx.send("This command must be used in a server.")
|
||||||
|
|
||||||
async def setup(bot):
|
async def setup(bot):
|
||||||
await bot.add_cog(FilterCog(bot))
|
await bot.add_cog(FilterCog(bot))
|
||||||
|
|
Loading…
Add table
Reference in a new issue