Skip to content

Commit

Permalink
feat: add fields for drop_location system
Browse files Browse the repository at this point in the history
  • Loading branch information
deadaf committed Jan 22, 2024
1 parent 42e2e5c commit a5f9500
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/cogs/esports/events/scrims.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def on_scrim_registration(self, message: discord.Message):
async with self.__scrim_lock:
ctx = await self.bot.get_context(message)

teamname = utils.find_team(message)
teamname, drop_location = utils.find_team(message), utils.find_drop_location(message)

scrim = await Scrim.get_or_none(pk=scrim.id)

Expand All @@ -82,6 +82,7 @@ async def on_scrim_registration(self, message: discord.Message):
slot = await AssignedSlot.create(
user_id=ctx.author.id,
team_name=utils.truncate_string(teamname, 30),
drop_location=utils.truncate_string(drop_location, 30),
num=slot_num,
jump_url=message.jump_url,
message_id=message.id,
Expand Down
2 changes: 2 additions & 0 deletions src/models/esports/scrims.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Meta:

required_lines = fields.SmallIntField(default=0)
allow_duplicate_tags = fields.BooleanField(default=True)
require_drop_location = fields.BooleanField(default=False)

assigned_slots: fields.ManyToManyRelation["AssignedSlot"] = fields.ManyToManyField("models.AssignedSlot")
reserved_slots: fields.ManyToManyRelation["ReservedSlot"] = fields.ManyToManyField("models.ReservedSlot")
Expand Down Expand Up @@ -651,6 +652,7 @@ class Meta:
num = fields.IntField(null=True) # this will never be null but there are already records in the table so
user_id = fields.BigIntField(null=True)
team_name = fields.TextField(null=True)
drop_location = fields.CharField(max_length=30, null=True)
members = ArrayField(fields.BigIntField(), default=list)


Expand Down
20 changes: 17 additions & 3 deletions src/utils/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def split_list(data: list, per_list: int):


def find_team(message: discord.Message):
"""Finds team name from a message"""
content = message.content.lower()
"""
Finds team name from a message
"""
author = message.author
teamname = re.search(r"team.*", content)
teamname = re.search(r"team.*", message.content)
if teamname is None:
return f"{author}'s team"

Expand All @@ -42,6 +43,19 @@ def find_team(message: discord.Message):
return teamname


def find_drop_location(message: discord.Message):
"""
Find team's drop location from message, if provided.
"""
drop_location = re.search(r"drop.*", message.content)
if drop_location is None:
return None

drop_location = re.sub(r"<@*#*!*&*\d+>|drop|location|[^\w\s]", "", drop_location.group()).strip()

return drop_location.title() if drop_location else None


def regional_indicator(c: str) -> str:
"""Returns a regional indicator emoji given a character."""
return chr(0x1F1E6 - ord("A") + ord(c.upper()))
Expand Down

0 comments on commit a5f9500

Please sign in to comment.