Skip to content

Commit

Permalink
feat: add global multi ban support
Browse files Browse the repository at this point in the history
  • Loading branch information
tylovejoy committed May 15, 2024
1 parent 301233e commit af1888b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.venv
venv
venv1
venv-linux
.idea
.github
.vscode
6 changes: 6 additions & 0 deletions cogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ async def map_mechanics_autocomplete(
return await _autocomplete(current, itx.client.cache.map_mechanics.choices)


async def map_restrictions_autocomplete(
itx: discord.Interaction[core.Genji], current: str
) -> list[app_commands.Choice[str]]:
return await _autocomplete(current, itx.client.cache.map_restrictions.choices)


async def tags_autocomplete(
itx: discord.Interaction[core.Genji], current: str
) -> list[app_commands.Choice[str]]:
Expand Down
8 changes: 8 additions & 0 deletions cogs/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ async def random_map(
map_type=cogs.map_type_autocomplete,
creator=cogs.creator_autocomplete,
mechanics=cogs.map_mechanics_autocomplete,
restrictions=cogs.map_restrictions_autocomplete,
map_code=cogs.map_codes_autocomplete,
)
@app_commands.guilds(
Expand All @@ -153,6 +154,8 @@ async def map_search(
creator: app_commands.Transform[int, utils.CreatorTransformer] | None = None,
mechanics: app_commands.Transform[str, utils.MapMechanicsTransformer]
| None = None,
restrictions: app_commands.Transform[str, utils.MapRestrictionsTransformer]
| None = None,
map_type: app_commands.Transform[str, utils.MapTypeTransformer] | None = None,
completed: typing.Literal["All", "Not Completed", "Completed"] = "All",
only_playtest: bool = False,
Expand All @@ -170,6 +173,7 @@ async def map_search(
map_code: Specific map code
difficulty: Difficulty filter
mechanics: Mechanics filter
restrictions: Restrictions filter
minimum_rating: Show maps above a specific quality rating
completed: Show completed maps, non completed maps or all
only_playtest: Show only playtest maps
Expand Down Expand Up @@ -199,6 +203,7 @@ async def map_search(
low_range,
high_range,
mechanics,
restrictions,
int(getattr(minimum_rating, "value", 0)),
only_maps_with_medals,
only_playtest,
Expand All @@ -222,6 +227,7 @@ async def _base_map_search(
low_range: float | None = None,
high_range: float | None = None,
mechanics: str | None = None,
restrictions: str | None = None,
minimum_rating: int | None = None,
only_maps_with_medals: bool = False,
only_playtest: bool = False,
Expand Down Expand Up @@ -261,6 +267,7 @@ async def _base_map_search(
AND ($2::text IS NULL OR map_type LIKE $2)
AND ($3::text IS NULL OR map_name = $3)
AND ($4::text IS NULL OR mechanics LIKE $4)
AND ($13::text IS NULL OR restrictions LIKE $13)
AND ($5::numeric(10, 2) IS NULL OR $6::numeric(10, 2) IS NULL OR (difficulty >= $5::numeric(10, 2)
AND difficulty < $6::numeric(10, 2)))
AND ($7::int IS NULL OR quality >= $7)
Expand Down Expand Up @@ -289,6 +296,7 @@ async def _base_map_search(
itx.user.id,
not only_playtest,
only_maps_with_medals,
wrap_string_with_percent(restrictions),
):
maps.append(_map)
return maps
Expand Down
13 changes: 9 additions & 4 deletions cogs/records.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
import typing

import discord
Expand Down Expand Up @@ -153,10 +154,8 @@ async def submit_record(
).get("exists", None):
is_creator = True

query = "SELECT EXISTS(SELECT restriction FROM map_restrictions WHERE map_code = $1 AND restriction = 'Multi Climb')"
check = await itx.client.database.get_row(query, map_code)
if not check.get("exists", True):
raise utils.TemporaryMultiBan
if int(os.environ["GLOBAL_MULTI_BAN"]) == 1:
await self._check_for_global_multi_ban(itx, map_code)

search = [
x
Expand Down Expand Up @@ -266,6 +265,12 @@ async def submit_record(
)
await user_msg.delete()

async def _check_for_global_multi_ban(self, itx, map_code):
query = "SELECT EXISTS(SELECT restriction FROM map_restrictions WHERE map_code = $1 AND restriction = 'Multi Climb')"
check = await itx.client.database.get_row(query, map_code)
if not check.get("exists", True):
raise utils.TemporaryMultiBan

async def check_playtest(self, map_code: str):
row = await self.bot.database.get_row(
"SELECT official FROM maps WHERE map_code = $1", map_code
Expand Down
9 changes: 5 additions & 4 deletions views/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,11 @@ async def check_status(self, itx: discord.Interaction[core.Genji], count: int):
):
self.ready_up_button.disabled = False
await itx.message.edit(view=self)
await self.data.creator.send(
f"**{self.data.map_code}** has received enough completions and votes. "
f"Go to the thread and *Finalize* the submission!"
)
if hasattr(self.data.creator, "send"):
await self.data.creator.send(
f"**{self.data.map_code}** has received enough completions and votes. "
f"Go to the thread and *Finalize* the submission!"
)

async def approve_map(self):
self.stop()
Expand Down

0 comments on commit af1888b

Please sign in to comment.