mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 19:58:54 -05:00
Added ignore channels/servers capabilities
Changed !help behaviour
This commit is contained in:
parent
6def723347
commit
a86389c9e8
120
cogs/mod.py
120
cogs/mod.py
@ -5,16 +5,14 @@ from .utils.dataIO import fileIO
|
|||||||
import __main__
|
import __main__
|
||||||
import os
|
import os
|
||||||
|
|
||||||
main_path = os.path.dirname(os.path.realpath(__main__.__file__))
|
|
||||||
|
|
||||||
|
|
||||||
class Mod:
|
class Mod:
|
||||||
"""Moderation tools."""
|
"""Moderation tools."""
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.whitelist_list = fileIO(main_path + "/data/mod/whitelist.json", "load")
|
self.whitelist_list = fileIO("data/mod/whitelist.json", "load")
|
||||||
self.blacklist_list = fileIO(main_path + "/data/mod/blacklist.json", "load")
|
self.blacklist_list = fileIO("data/mod/blacklist.json", "load")
|
||||||
|
self.ignore_list = fileIO("data/mod/ignorelist.json", "load")
|
||||||
|
|
||||||
@commands.command(no_pm=True)
|
@commands.command(no_pm=True)
|
||||||
@checks.admin_or_permissions(kick_members=True)
|
@checks.admin_or_permissions(kick_members=True)
|
||||||
@ -130,7 +128,7 @@ class Mod:
|
|||||||
"""Adds user to bot's blacklist"""
|
"""Adds user to bot's blacklist"""
|
||||||
if user.id not in self.blacklist_list:
|
if user.id not in self.blacklist_list:
|
||||||
self.blacklist_list.append(user.id)
|
self.blacklist_list.append(user.id)
|
||||||
fileIO(main_path + "/data/mod/blacklist.json", "save", self.blacklist_list)
|
fileIO("data/mod/blacklist.json", "save", self.blacklist_list)
|
||||||
await self.bot.say("User has been added to blacklist.")
|
await self.bot.say("User has been added to blacklist.")
|
||||||
else:
|
else:
|
||||||
await self.bot.say("User is already blacklisted.")
|
await self.bot.say("User is already blacklisted.")
|
||||||
@ -140,7 +138,7 @@ class Mod:
|
|||||||
"""Removes user to bot's blacklist"""
|
"""Removes user to bot's blacklist"""
|
||||||
if user.id in self.blacklist_list:
|
if user.id in self.blacklist_list:
|
||||||
self.blacklist_list.remove(user.id)
|
self.blacklist_list.remove(user.id)
|
||||||
fileIO(main_path + "/data/mod/blacklist.json", "save", self.blacklist_list)
|
fileIO("data/mod/blacklist.json", "save", self.blacklist_list)
|
||||||
await self.bot.say("User has been removed from blacklist.")
|
await self.bot.say("User has been removed from blacklist.")
|
||||||
else:
|
else:
|
||||||
await self.bot.say("User is not in blacklist.")
|
await self.bot.say("User is not in blacklist.")
|
||||||
@ -162,7 +160,7 @@ class Mod:
|
|||||||
else:
|
else:
|
||||||
msg = ""
|
msg = ""
|
||||||
self.whitelist_list.append(user.id)
|
self.whitelist_list.append(user.id)
|
||||||
fileIO(main_path + "/data/mod/whitelist.json", "save", self.whitelist_list)
|
fileIO("data/mod/whitelist.json", "save", self.whitelist_list)
|
||||||
await self.bot.say("User has been added to whitelist." + msg)
|
await self.bot.say("User has been added to whitelist." + msg)
|
||||||
else:
|
else:
|
||||||
await self.bot.say("User is already whitelisted.")
|
await self.bot.say("User is already whitelisted.")
|
||||||
@ -172,11 +170,99 @@ class Mod:
|
|||||||
"""Removes user to bot's whitelist"""
|
"""Removes user to bot's whitelist"""
|
||||||
if user.id in self.whitelist_list:
|
if user.id in self.whitelist_list:
|
||||||
self.whitelist_list.remove(user.id)
|
self.whitelist_list.remove(user.id)
|
||||||
fileIO(main_path + "/data/mod/whitelist.json", "save", self.whitelist_list)
|
fileIO("data/mod/whitelist.json", "save", self.whitelist_list)
|
||||||
await self.bot.say("User has been removed from whitelist.")
|
await self.bot.say("User has been removed from whitelist.")
|
||||||
else:
|
else:
|
||||||
await self.bot.say("User is not in whitelist.")
|
await self.bot.say("User is not in whitelist.")
|
||||||
|
|
||||||
|
@commands.group(pass_context=True, no_pm=True)
|
||||||
|
@checks.admin_or_permissions(manage_channels=True)
|
||||||
|
async def ignore(self, ctx):
|
||||||
|
"""Adds servers/channels to ignorelist"""
|
||||||
|
if ctx.invoked_subcommand is None:
|
||||||
|
|
||||||
|
await self.bot.say(self.count_ignored() + "Type help ignore for info.")
|
||||||
|
|
||||||
|
@ignore.command(name="channel", pass_context=True)
|
||||||
|
async def ignore_channel(self, ctx, channel : discord.Channel=None):
|
||||||
|
"""Ignores channel
|
||||||
|
|
||||||
|
Defaults to current one"""
|
||||||
|
current_ch = ctx.message.channel
|
||||||
|
if not channel:
|
||||||
|
if current_ch.id not in self.ignore_list["CHANNELS"]:
|
||||||
|
self.ignore_list["CHANNELS"].append(current_ch.id)
|
||||||
|
fileIO("data/mod/ignorelist.json", "save", self.ignore_list)
|
||||||
|
await self.bot.say("Channel added to ignore list.")
|
||||||
|
else:
|
||||||
|
await self.bot.say("Channel already in ignore list.")
|
||||||
|
else:
|
||||||
|
if channel.id not in self.ignore_list["CHANNELS"]:
|
||||||
|
self.ignore_list["CHANNELS"].append(channel.id)
|
||||||
|
fileIO("data/mod/ignorelist.json", "save", self.ignore_list)
|
||||||
|
await self.bot.say("Channel added to ignore list.")
|
||||||
|
else:
|
||||||
|
await self.bot.say("Channel already in ignore list.")
|
||||||
|
|
||||||
|
|
||||||
|
@ignore.command(name="server", pass_context=True)
|
||||||
|
async def ignore_server(self, ctx):
|
||||||
|
"""Ignores current server"""
|
||||||
|
server = ctx.message.server
|
||||||
|
if server.id not in self.ignore_list["SERVERS"]:
|
||||||
|
self.ignore_list["SERVERS"].append(server.id)
|
||||||
|
fileIO("data/mod/ignorelist.json", "save", self.ignore_list)
|
||||||
|
await self.bot.say("This server has been added to the ignore list.")
|
||||||
|
else:
|
||||||
|
await self.bot.say("This server is already being ignored.")
|
||||||
|
|
||||||
|
@commands.group(pass_context=True, no_pm=True)
|
||||||
|
@checks.admin_or_permissions(manage_channels=True)
|
||||||
|
async def unignore(self, ctx):
|
||||||
|
"""Removes servers/channels from ignorelist"""
|
||||||
|
if ctx.invoked_subcommand is None:
|
||||||
|
await self.bot.say(self.count_ignored() + "Type help unignore for info.")
|
||||||
|
|
||||||
|
@unignore.command(name="channel", pass_context=True)
|
||||||
|
async def unignore_channel(self, ctx, channel : discord.Channel=None):
|
||||||
|
"""Removes channel from ignore list
|
||||||
|
|
||||||
|
Defaults to current one"""
|
||||||
|
current_ch = ctx.message.channel
|
||||||
|
if not channel:
|
||||||
|
if current_ch.id in self.ignore_list["CHANNELS"]:
|
||||||
|
self.ignore_list["CHANNELS"].remove(current_ch.id)
|
||||||
|
fileIO("data/mod/ignorelist.json", "save", self.ignore_list)
|
||||||
|
await self.bot.say("This channel has been removed from the ignore list.")
|
||||||
|
else:
|
||||||
|
await self.bot.say("This channel is not in the ignore list.")
|
||||||
|
else:
|
||||||
|
if channel.id in self.ignore_list["CHANNELS"]:
|
||||||
|
self.ignore_list["CHANNELS"].remove(channel.id)
|
||||||
|
fileIO("data/mod/ignorelist.json", "save", self.ignore_list)
|
||||||
|
await self.bot.say("Channel removed from ignore list.")
|
||||||
|
else:
|
||||||
|
await self.bot.say("That channel is not in the ignore list.")
|
||||||
|
|
||||||
|
|
||||||
|
@unignore.command(name="server", pass_context=True)
|
||||||
|
async def unignore_server(self, ctx):
|
||||||
|
"""Removes current server from ignore list"""
|
||||||
|
server = ctx.message.server
|
||||||
|
if server.id in self.ignore_list["SERVERS"]:
|
||||||
|
self.ignore_list["SERVERS"].remove(server.id)
|
||||||
|
fileIO("data/mod/ignorelist.json", "save", self.ignore_list)
|
||||||
|
await self.bot.say("This server has been removed from the ignore list.")
|
||||||
|
else:
|
||||||
|
await self.bot.say("This server is not in the ignore list.")
|
||||||
|
|
||||||
|
def count_ignored(self):
|
||||||
|
msg = "```Currently ignoring:\n"
|
||||||
|
msg += str(len(self.ignore_list["CHANNELS"])) + " channels\n"
|
||||||
|
msg += str(len(self.ignore_list["SERVERS"])) + " servers\n```\n"
|
||||||
|
return msg
|
||||||
|
|
||||||
|
|
||||||
def check_folders():
|
def check_folders():
|
||||||
folders = ("data", "data/mod/")
|
folders = ("data", "data/mod/")
|
||||||
for folder in folders:
|
for folder in folders:
|
||||||
@ -185,13 +271,19 @@ def check_folders():
|
|||||||
os.makedirs(folder)
|
os.makedirs(folder)
|
||||||
|
|
||||||
def check_files():
|
def check_files():
|
||||||
if not os.path.isfile(main_path + "/data/mod/blacklist.json"):
|
ignore_list = {"SERVERS" : [], "CHANNELS" : []}
|
||||||
print("Creating empty blacklist.json...")
|
|
||||||
fileIO(main_path + "/data/mod/blacklist.json", "save", [])
|
|
||||||
|
|
||||||
if not os.path.isfile(main_path + "/data/mod/whitelist.json"):
|
if not os.path.isfile("data/mod/blacklist.json"):
|
||||||
|
print("Creating empty blacklist.json...")
|
||||||
|
fileIO("data/mod/blacklist.json", "save", [])
|
||||||
|
|
||||||
|
if not os.path.isfile("data/mod/whitelist.json"):
|
||||||
print("Creating empty whitelist.json...")
|
print("Creating empty whitelist.json...")
|
||||||
fileIO(main_path + "/data/mod/whitelist.json", "save", [])
|
fileIO("data/mod/whitelist.json", "save", [])
|
||||||
|
|
||||||
|
if not os.path.isfile("data/mod/ignorelist.json"):
|
||||||
|
print("Creating empty ignorelist.json...")
|
||||||
|
fileIO("data/mod/ignorelist.json", "save", ignore_list)
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
check_folders()
|
check_folders()
|
||||||
|
|||||||
9
red.py
9
red.py
@ -26,7 +26,7 @@ Red - A multifunction Discord bot by Twentysix
|
|||||||
formatter = commands.HelpFormatter(show_check_failure=False)
|
formatter = commands.HelpFormatter(show_check_failure=False)
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix=["_"], formatter=formatter,
|
bot = commands.Bot(command_prefix=["_"], formatter=formatter,
|
||||||
description=description, pm_help=True)
|
description=description, pm_help=None)
|
||||||
|
|
||||||
lock = False
|
lock = False
|
||||||
|
|
||||||
@ -65,6 +65,13 @@ async def on_message(message):
|
|||||||
if author.id not in mod.whitelist_list:
|
if author.id not in mod.whitelist_list:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not message.channel.is_private:
|
||||||
|
if message.server.id in mod.ignore_list["SERVERS"]:
|
||||||
|
return
|
||||||
|
|
||||||
|
if message.channel.id in mod.ignore_list["CHANNELS"]:
|
||||||
|
return
|
||||||
|
|
||||||
await bot.process_commands(message)
|
await bot.process_commands(message)
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user