Skip to content

Commit

Permalink
remove blacklist and whitelist references
Browse files Browse the repository at this point in the history
  • Loading branch information
AEnterprise committed Jun 21, 2020
1 parent 178884e commit 9e483de
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 173 deletions.
26 changes: 13 additions & 13 deletions GearBot/Bot/TheRealGearBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,28 @@ async def on_message(bot, message:Message):
await ctx.author.send("Hey, you tried triggering a command in a channel I'm not allowed to send messages in. Please grant me permissions to reply and try again.")
except Forbidden:
pass # closed DMs
elif ctx.author.id in Configuration.get_persistent_var("user_blacklist", []):
elif ctx.author.id in Configuration.get_persistent_var("user_blocklist", []):
try:
await MessageUtils.send_to(ctx, "BAD_USER", "You have been globally blacklisted from using this bot due to abuse", translate=False)
await MessageUtils.send_to(ctx, "BAD_USER", "You have been globally blocked from using this bot due to abuse", translate=False)
except Forbidden:
pass # closed DMs
else:
await bot.invoke(ctx)


async def on_guild_join(guild):
blocked = Configuration.get_persistent_var("server_blacklist", [])
blocked = Configuration.get_persistent_var("server_blocklist", [])
if guild.id in blocked:
GearbotLogging.info(f"Someone tried to add me to blacklisted guild {guild.name} ({guild.id})")
GearbotLogging.info(f"Someone tried to add me to blocked guild {guild.name} ({guild.id})")
try:
await guild.owner.send("Someone tried adding me to {guild.name} (``{guild.id}``) but the server has been blacklisted")
await guild.owner.send("Someone tried adding me to {guild.name} (``{guild.id}``) but the server has been blocked")
except Exception:
pass
await guild.leave()
elif guild.owner.id in Configuration.get_persistent_var("user_blacklist", []):
GearbotLogging.info(f"Someone tried to add me to {guild.name} ({guild.id}) but the owner ({guild.owner} ({guild.owner.id})) is blacklisted")
elif guild.owner.id in Configuration.get_persistent_var("user_blocklist", []):
GearbotLogging.info(f"Someone tried to add me to {guild.name} ({guild.id}) but the owner ({guild.owner} ({guild.owner.id})) is blocked")
try:
await guild.owner.send(f"Someone tried adding me to {guild.name} (``{guild.id}``) but you have been blacklisted due to bot abuse, so i left")
await guild.owner.send(f"Someone tried adding me to {guild.name} (``{guild.id}``) but you have been blocked due to bot abuse, so i left")
except Exception:
pass
await guild.leave()
Expand All @@ -167,19 +167,19 @@ async def on_guild_join(guild):
await GearbotLogging.bot_log(f"{Emoji.get_chat_emoji('JOIN')} A new guild came up: {name} ({guild.id}).", embed=server_info.server_info_embed(guild))

async def on_guild_remove(guild):
blocked = Configuration.get_persistent_var("server_blacklist", [])
blocked_users = Configuration.get_persistent_var("user_blacklist", [])
blocked = Configuration.get_persistent_var("server_blocklist", [])
blocked_users = Configuration.get_persistent_var("user_blocklist", [])
if guild.id not in blocked and guild.owner.id not in blocked_users:
GearbotLogging.info(f"I was removed from a guild: {guild.name} ({guild.id}).")
await GearbotLogging.bot_log(f"{Emoji.get_chat_emoji('LEAVE')} I was removed from a guild: {guild.name} ({guild.id}).", embed=server_info.server_info_embed(guild))


async def on_guild_update(before, after):
if after.owner is not None and after.owner.id in Configuration.get_persistent_var("user_blacklist", []):
if after.owner is not None and after.owner.id in Configuration.get_persistent_var("user_blocklist", []):
GearbotLogging.info(
f"Someone transferred {after.name} ({after.id}) to ({after.owner} ({after.owner.id})) but they are blacklisted")
f"Someone transferred {after.name} ({after.id}) to ({after.owner} ({after.owner.id})) but they are blocked")
try:
await after.owner.send(f"Someone transferred {after.name} (``{after.id}``) to you, but you have been blacklisted due to bot abuse, so i left")
await after.owner.send(f"Someone transferred {after.name} (``{after.id}``) to you, but you have been blocked due to bot abuse, so i left")
except Exception:
pass
await after.leave()
Expand Down
26 changes: 15 additions & 11 deletions GearBot/Cogs/Admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from discord.ext import commands

from Cogs.BaseCog import BaseCog
from Util import GearbotLogging, Utils, Configuration, Pages, Emoji, MessageUtils, Update
from Util import GearbotLogging, Utils, Configuration, Pages, Emoji, MessageUtils, Update, DocUtils
from Util.Converters import UserID, Guild, DiscordUser


Expand All @@ -23,6 +23,10 @@ def cog_unload(self):
async def cog_check(self, ctx):
return await ctx.bot.is_owner(ctx.author) or ctx.author.id in Configuration.get_master_var("BOT_ADMINS", [])

@commands.command()
async def commandlist(self, ctx):
await DocUtils.generate_command_list2(self.bot, ctx.message)


@commands.command(hidden=True)
async def restart(self, ctx):
Expand Down Expand Up @@ -141,25 +145,25 @@ async def update(self, ctx):
await ctx.invoke(self.bot.get_command("hotreload"))

@commands.command()
async def blacklist_server(self, ctx, guild: Guild):
blocked = Configuration.get_persistent_var("server_blacklist", [])
async def block_server(self, ctx, guild: Guild):
blocked = Configuration.get_persistent_var("server_blocklist", [])
blocked.append(guild.id)
Configuration.set_persistent_var("server_blacklist", blocked)
Configuration.set_persistent_var("server_blocklist", blocked)
await guild.leave()
await MessageUtils.send_to(ctx, "YES", f"{Utils.escape_markdown(guild.name)} (``{guild.id}``) has been added to the blacklist", translate=False)
await MessageUtils.send_to(ctx, "YES", f"{Utils.escape_markdown(guild.name)} (``{guild.id}``) has been added to the blocked servers list", translate=False)
await GearbotLogging.bot_log(
f"{Utils.escape_markdown(guild.name)} (``{guild.id}``) has been added to the blacklist by {Utils.clean_user(ctx.author)}")
f"{Utils.escape_markdown(guild.name)} (``{guild.id}``) has been added to the blocked server list by {Utils.clean_user(ctx.author)}")

@commands.command()
async def blacklist_user(self, ctx, user:DiscordUser):
async def block_user(self, ctx, user:DiscordUser):
for guild in self.bot.guilds:
if guild.owner is not None and guild.owner.id == user.id:
await guild.leave()
blocked = Configuration.get_persistent_var("user_blacklist", [])
blocked = Configuration.get_persistent_var("user_blocklist", [])
blocked.append(user.id)
Configuration.set_persistent_var("user_blacklist", blocked)
await MessageUtils.send_to(ctx, "YES", f"{Utils.clean_user(user)} (``{user.id}``) has been added to the blacklist", translate=False)
await GearbotLogging.bot_log(f"{Utils.clean_user(user)} (``{user.id}``) has been added to the blacklist by {Utils.clean_user(ctx.author)}")
Configuration.set_persistent_var("user_blocklist", blocked)
await MessageUtils.send_to(ctx, "YES", f"{Utils.clean_user(user)} (``{user.id}``) has been added to the blocked users list", translate=False)
await GearbotLogging.bot_log(f"{Utils.clean_user(user)} (``{user.id}``) has been added to the blocked users list by {Utils.clean_user(ctx.author)}")

@commands.command()
async def pendingchanges(self, ctx):
Expand Down
18 changes: 9 additions & 9 deletions GearBot/Cogs/Censor.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ async def check_message(self, message: discord.Message):
ctx = await self.bot.get_context(message)
if Permissioncheckers.get_user_lvl(ctx.guild, ctx.author) >= 2:
return
blacklist = Configuration.get_var(message.guild.id, "CENSORING", "TOKEN_BLACKLIST")
word_blacklist = Configuration.get_var(message.guild.id, "CENSORING", "WORD_BLACKLIST")
guilds = Configuration.get_var(message.guild.id, "CENSORING", "INVITE_WHITELIST")
censorlist = Configuration.get_var(message.guild.id, "CENSORING", "TOKEN_CENSORLIST")
word_censorlist = Configuration.get_var(message.guild.id, "CENSORING", "WORD_CENSORLIST")
guilds = Configuration.get_var(message.guild.id, "CENSORING", "ALLOWED_INVITE_LIST")
domain_list = Configuration.get_var(message.guild.id, "CENSORING", "DOMAIN_LIST")
domain_whitelist = Configuration.get_var(message.guild.id, "CENSORING", "DOMAIN_WHITELIST")
domains_allowed = Configuration.get_var(message.guild.id, "CENSORING", "DOMAIN_LIST_ALLOWED")
content = message.content.replace('\\', '')
decoded_content = parse.unquote(content)
censored = False
Expand All @@ -73,15 +73,15 @@ async def check_message(self, message: discord.Message):

if not censored:
content = content.lower()
for bad in (w.lower() for w in blacklist):
for bad in (w.lower() for w in censorlist):
if bad in content:
await self.censor_message(message, bad)
censored = True
break

if not censored and len(word_blacklist) > 0:
if not censored and len(word_censorlist) > 0:
if ctx.guild.id not in self.regexes:
regex = re.compile(r"\b(" + '|'.join(re.escape(word) for word in word_blacklist) + r")\b", re.IGNORECASE)
regex = re.compile(r"\b(" + '|'.join(re.escape(word) for word in word_censorlist) + r")\b", re.IGNORECASE)
self.regexes[ctx.guild.id] = regex
else:
regex = self.regexes[ctx.guild.id]
Expand All @@ -95,8 +95,8 @@ async def check_message(self, message: discord.Message):
for link in link_list:
url = urlparse(link)
domain = url.hostname
if (domain in domain_list) is not domain_whitelist:
await self.censor_message(message, url.hostname, "_domain_whitelist" if domain_whitelist else "_domain_blacklist")
if (domain in domain_list) is not domains_allowed:
await self.censor_message(message, url.hostname, "_domain_blocked")
print(domain)


Expand Down
4 changes: 2 additions & 2 deletions GearBot/Cogs/Moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ async def role_handler(self, ctx, user, role, action):

if Actions.can_act(f"role_{action}", ctx, user):
role_list = Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST")
mode = Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_WHITELIST")
mode_name = "whitelist" if mode else "blacklist"
mode = Configuration.get_var(ctx.guild.id, "ROLES", "ROLE_LIST_MODE")
mode_name = "allow" if mode else "block"
if (drole.id in role_list) is mode:
if drole < ctx.me.top_role:
if drole < ctx.author.top_role or user == ctx.guild.owner:
Expand Down
Loading

0 comments on commit 9e483de

Please sign in to comment.