aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/__main__.py2
-rw-r--r--bot/bot.py14
-rw-r--r--bot/cogs/antimalware.py2
-rw-r--r--bot/cogs/filter_lists.py (renamed from bot/cogs/allow_deny_lists.py)44
-rw-r--r--bot/cogs/filtering.py16
-rw-r--r--bot/converters.py10
-rw-r--r--tests/bot/cogs/test_antimalware.py2
7 files changed, 45 insertions, 45 deletions
diff --git a/bot/__main__.py b/bot/__main__.py
index 932aa705c..c2271cd16 100644
--- a/bot/__main__.py
+++ b/bot/__main__.py
@@ -53,7 +53,7 @@ bot.load_extension("bot.cogs.verification")
# Feature cogs
bot.load_extension("bot.cogs.alias")
-bot.load_extension("bot.cogs.allow_deny_lists")
+bot.load_extension("bot.cogs.filter_lists")
bot.load_extension("bot.cogs.defcon")
bot.load_extension("bot.cogs.dm_relay")
bot.load_extension("bot.cogs.duck_pond")
diff --git a/bot/bot.py b/bot/bot.py
index d834c151b..3dfb4e948 100644
--- a/bot/bot.py
+++ b/bot/bot.py
@@ -34,7 +34,7 @@ class Bot(commands.Bot):
self.redis_ready = asyncio.Event()
self.redis_closed = False
self.api_client = api.APIClient(loop=self.loop)
- self.allow_deny_list_cache = {}
+ self.filter_list_cache = {}
self._connector = None
self._resolver = None
@@ -50,9 +50,9 @@ class Bot(commands.Bot):
self.stats = AsyncStatsClient(self.loop, statsd_url, 8125, prefix="bot")
- async def _cache_allow_deny_list_data(self) -> None:
- """Cache all the data in the AllowDenyList on the site."""
- full_cache = await self.api_client.get('bot/allow_deny_lists')
+ async def _cache_filter_list_data(self) -> None:
+ """Cache all the data in the FilterList on the site."""
+ full_cache = await self.api_client.get('bot/filter-lists')
for item in full_cache:
type_ = item.get("type")
@@ -64,7 +64,7 @@ class Bot(commands.Bot):
"created_at": item.get("created_at"),
"updated_at": item.get("updated_at"),
}
- self.allow_deny_list_cache.setdefault(f"{type_}.{allowed}", []).append(metadata)
+ self.filter_list_cache.setdefault(f"{type_}.{allowed}", []).append(metadata)
async def _create_redis_session(self) -> None:
"""
@@ -176,8 +176,8 @@ class Bot(commands.Bot):
self.http_session = aiohttp.ClientSession(connector=self._connector)
self.api_client.recreate(force=True, connector=self._connector)
- # Build the AllowDenyList cache
- self.loop.create_task(self._cache_allow_deny_list_data())
+ # Build the FilterList cache
+ self.loop.create_task(self._cache_filter_list_data())
async def on_guild_available(self, guild: discord.Guild) -> None:
"""
diff --git a/bot/cogs/antimalware.py b/bot/cogs/antimalware.py
index 5b56f937f..9a100b3fc 100644
--- a/bot/cogs/antimalware.py
+++ b/bot/cogs/antimalware.py
@@ -40,7 +40,7 @@ class AntiMalware(Cog):
def _get_whitelisted_file_formats(self) -> list:
"""Get the file formats currently on the whitelist."""
- return [item['content'] for item in self.bot.allow_deny_list_cache['file_format.True']]
+ return [item['content'] for item in self.bot.filter_list_cache['file_format.True']]
def _get_disallowed_extensions(self, message: Message) -> t.Iterable[str]:
"""Get an iterable containing all the disallowed extensions of attachments."""
diff --git a/bot/cogs/allow_deny_lists.py b/bot/cogs/filter_lists.py
index e28e32bd6..d1db9830e 100644
--- a/bot/cogs/allow_deny_lists.py
+++ b/bot/cogs/filter_lists.py
@@ -7,14 +7,14 @@ from discord.ext.commands import BadArgument, Cog, Context, IDConverter, group
from bot import constants
from bot.api import ResponseCodeError
from bot.bot import Bot
-from bot.converters import ValidAllowDenyListType, ValidDiscordServerInvite
+from bot.converters import ValidDiscordServerInvite, ValidFilterListType
from bot.pagination import LinePaginator
from bot.utils.checks import with_role_check
log = logging.getLogger(__name__)
-class AllowDenyLists(Cog):
+class FilterLists(Cog):
"""Commands for blacklisting and whitelisting things."""
def __init__(self, bot: Bot) -> None:
@@ -24,11 +24,11 @@ class AllowDenyLists(Cog):
self,
ctx: Context,
allowed: bool,
- list_type: ValidAllowDenyListType,
+ list_type: ValidFilterListType,
content: str,
comment: Optional[str] = None,
) -> None:
- """Add an item to an allow or denylist."""
+ """Add an item to a filterlist."""
allow_type = "whitelist" if allowed else "blacklist"
# If this is a server invite, we gotta validate it.
@@ -60,7 +60,7 @@ class AllowDenyLists(Cog):
try:
item = await self.bot.api_client.post(
- "bot/allow_deny_lists",
+ "bot/filter-lists",
json=payload
)
except ResponseCodeError as e:
@@ -88,11 +88,11 @@ class AllowDenyLists(Cog):
"created_at": item.get("created_at"),
"updated_at": item.get("updated_at"),
}
- self.bot.allow_deny_list_cache.setdefault(f"{type_}.{allowed}", []).append(metadata)
+ self.bot.filter_list_cache.setdefault(f"{type_}.{allowed}", []).append(metadata)
await ctx.message.add_reaction("✅")
- async def _delete_data(self, ctx: Context, allowed: bool, list_type: ValidAllowDenyListType, content: str) -> None:
- """Remove an item from an allow or denylist."""
+ async def _delete_data(self, ctx: Context, allowed: bool, list_type: ValidFilterListType, content: str) -> None:
+ """Remove an item from a filterlist."""
item = None
allow_type = "whitelist" if allowed else "blacklist"
id_converter = IDConverter()
@@ -110,22 +110,22 @@ class AllowDenyLists(Cog):
# Find the content and delete it.
log.trace(f"Trying to delete the {content} item from the {list_type} {allow_type}")
- for allow_list in self.bot.allow_deny_list_cache.get(f"{list_type}.{allowed}", []):
+ for allow_list in self.bot.filter_list_cache.get(f"{list_type}.{allowed}", []):
if content == allow_list.get("content"):
item = allow_list
break
if item is not None:
await self.bot.api_client.delete(
- f"bot/allow_deny_lists/{item.get('id')}"
+ f"bot/filter-lists/{item.get('id')}"
)
- self.bot.allow_deny_list_cache[f"{list_type}.{allowed}"].remove(item)
+ self.bot.filter_list_cache[f"{list_type}.{allowed}"].remove(item)
await ctx.message.add_reaction("✅")
- async def _list_all_data(self, ctx: Context, allowed: bool, list_type: ValidAllowDenyListType) -> None:
- """Paginate and display all items in an allow or denylist."""
+ async def _list_all_data(self, ctx: Context, allowed: bool, list_type: ValidFilterListType) -> None:
+ """Paginate and display all items in a filterlist."""
allow_type = "whitelist" if allowed else "blacklist"
- result = self.bot.allow_deny_list_cache.get(f"{list_type}.{allowed}", [])
+ result = self.bot.filter_list_cache.get(f"{list_type}.{allowed}", [])
# Build a list of lines we want to show in the paginator
lines = []
@@ -168,7 +168,7 @@ class AllowDenyLists(Cog):
async def allow_add(
self,
ctx: Context,
- list_type: ValidAllowDenyListType,
+ list_type: ValidFilterListType,
content: str,
*,
comment: Optional[str] = None,
@@ -180,7 +180,7 @@ class AllowDenyLists(Cog):
async def deny_add(
self,
ctx: Context,
- list_type: ValidAllowDenyListType,
+ list_type: ValidFilterListType,
content: str,
*,
comment: Optional[str] = None,
@@ -189,22 +189,22 @@ class AllowDenyLists(Cog):
await self._add_data(ctx, False, list_type, content, comment)
@whitelist.command(name="remove", aliases=("delete", "rm",))
- async def allow_delete(self, ctx: Context, list_type: ValidAllowDenyListType, content: str) -> None:
+ async def allow_delete(self, ctx: Context, list_type: ValidFilterListType, content: str) -> None:
"""Remove an item from the specified allowlist."""
await self._delete_data(ctx, True, list_type, content)
@blacklist.command(name="remove", aliases=("delete", "rm",))
- async def deny_delete(self, ctx: Context, list_type: ValidAllowDenyListType, content: str) -> None:
+ async def deny_delete(self, ctx: Context, list_type: ValidFilterListType, content: str) -> None:
"""Remove an item from the specified denylist."""
await self._delete_data(ctx, False, list_type, content)
@whitelist.command(name="get", aliases=("list", "ls", "fetch", "show"))
- async def allow_get(self, ctx: Context, list_type: ValidAllowDenyListType) -> None:
+ async def allow_get(self, ctx: Context, list_type: ValidFilterListType) -> None:
"""Get the contents of a specified allowlist."""
await self._list_all_data(ctx, True, list_type)
@blacklist.command(name="get", aliases=("list", "ls", "fetch", "show"))
- async def deny_get(self, ctx: Context, list_type: ValidAllowDenyListType) -> None:
+ async def deny_get(self, ctx: Context, list_type: ValidFilterListType) -> None:
"""Get the contents of a specified denylist."""
await self._list_all_data(ctx, False, list_type)
@@ -214,5 +214,5 @@ class AllowDenyLists(Cog):
def setup(bot: Bot) -> None:
- """Load the AllowDenyLists cog."""
- bot.add_cog(AllowDenyLists(bot))
+ """Load the FilterLists cog."""
+ bot.add_cog(FilterLists(bot))
diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py
index 8897cbaf9..652af5ff5 100644
--- a/bot/cogs/filtering.py
+++ b/bot/cogs/filtering.py
@@ -99,9 +99,9 @@ class Filtering(Cog):
self.bot.loop.create_task(self.reschedule_offensive_msg_deletion())
- def _get_allowlist_items(self, list_type: str, *, allowed: bool, compiled: Optional[bool] = False) -> list:
- """Fetch items from the allow_deny_list_cache."""
- items = self.bot.allow_deny_list_cache.get(f"{list_type.upper()}.{allowed}", [])
+ def _get_filterlist_items(self, list_type: str, *, allowed: bool, compiled: Optional[bool] = False) -> list:
+ """Fetch items from the filter_list_cache."""
+ items = self.bot.filter_list_cache.get(f"{list_type.upper()}.{allowed}", [])
if compiled:
return [re.compile(fr'{item["content"]}', flags=re.IGNORECASE) for item in items]
@@ -143,7 +143,7 @@ class Filtering(Cog):
def get_name_matches(self, name: str) -> List[re.Match]:
"""Check bad words from passed string (name). Return list of matches."""
matches = []
- watchlist_patterns = self._get_allowlist_items('word_watchlist', allowed=False, compiled=True)
+ watchlist_patterns = self._get_filterlist_items('word_watchlist', allowed=False, compiled=True)
for pattern in watchlist_patterns:
if match := pattern.search(name):
matches.append(match)
@@ -408,7 +408,7 @@ class Filtering(Cog):
if URL_RE.search(text):
return False
- watchlist_patterns = self._get_allowlist_items('word_watchlist', allowed=False, compiled=True)
+ watchlist_patterns = self._get_filterlist_items('word_watchlist', allowed=False, compiled=True)
for pattern in watchlist_patterns:
match = pattern.search(text)
if match:
@@ -420,7 +420,7 @@ class Filtering(Cog):
return False
text = text.lower()
- domain_blacklist = self._get_allowlist_items("domain_name", allowed=False)
+ domain_blacklist = self._get_filterlist_items("domain_name", allowed=False)
for url in domain_blacklist:
if url.lower() in text:
@@ -468,8 +468,8 @@ class Filtering(Cog):
return True
guild_id = guild.get("id")
- guild_invite_whitelist = self._get_allowlist_items("guild_invite", allowed=True)
- guild_invite_blacklist = self._get_allowlist_items("guild_invite", allowed=False)
+ guild_invite_whitelist = self._get_filterlist_items("guild_invite", allowed=True)
+ guild_invite_blacklist = self._get_filterlist_items("guild_invite", allowed=False)
# Is this invite allowed?
guild_partnered_or_verified = (
diff --git a/bot/converters.py b/bot/converters.py
index 41cd3f3e5..158bf1a16 100644
--- a/bot/converters.py
+++ b/bot/converters.py
@@ -72,18 +72,18 @@ class ValidDiscordServerInvite(Converter):
raise BadArgument("This does not appear to be a valid Discord server invite.")
-class ValidAllowDenyListType(Converter):
+class ValidFilterListType(Converter):
"""
- A converter that checks whether the given string is a valid AllowDenyList type.
+ A converter that checks whether the given string is a valid FilterList type.
- Raises `BadArgument` if the argument is not a valid AllowDenyList type, and simply
+ Raises `BadArgument` if the argument is not a valid FilterList type, and simply
passes through the given argument otherwise.
"""
async def convert(self, ctx: Context, list_type: str) -> str:
- """Checks whether the given string is a valid AllowDenyList type."""
+ """Checks whether the given string is a valid FilterList type."""
try:
- valid_types = await ctx.bot.api_client.get('bot/allow_deny_lists/get_types')
+ valid_types = await ctx.bot.api_client.get('bot/filter-lists/get-types')
except ResponseCodeError:
raise BadArgument("Cannot validate list_type: Unable to fetch valid types from API.")
diff --git a/tests/bot/cogs/test_antimalware.py b/tests/bot/cogs/test_antimalware.py
index 1e010d2ce..664fa8f19 100644
--- a/tests/bot/cogs/test_antimalware.py
+++ b/tests/bot/cogs/test_antimalware.py
@@ -14,7 +14,7 @@ class AntiMalwareCogTests(unittest.IsolatedAsyncioTestCase):
def setUp(self):
"""Sets up fresh objects for each test."""
self.bot = MockBot()
- self.bot.allow_deny_list_cache = {
+ self.bot.filter_list_cache = {
"file_format.True": [
{"content": ".first"},
{"content": ".second"},