Implemented /stage edit and /stage delete (#2)
This commit is contained in:
@@ -2,9 +2,11 @@ from datetime import datetime
|
||||
from typing import List, Dict, Any
|
||||
from zoneinfo import ZoneInfo, available_timezones
|
||||
|
||||
from bson import ObjectId
|
||||
from discord import AutocompleteContext, OptionChoice
|
||||
from pymongo import ASCENDING
|
||||
|
||||
from modules.database import col_events
|
||||
from modules.database import col_events, col_stages
|
||||
|
||||
|
||||
def hex_to_int(hex_color: str) -> int:
|
||||
@@ -16,19 +18,19 @@ def int_to_hex(integer_color: int) -> str:
|
||||
|
||||
|
||||
# TODO Maybe move to a separate module
|
||||
async def autofill_timezones(ctx: AutocompleteContext) -> List[str]:
|
||||
async def autocomplete_timezones(ctx: AutocompleteContext) -> List[str]:
|
||||
return sorted(list(available_timezones()))
|
||||
|
||||
|
||||
# TODO Maybe move to a separate module
|
||||
async def autofill_languages(ctx: AutocompleteContext) -> List[str]:
|
||||
async def autocomplete_languages(ctx: AutocompleteContext) -> List[str]:
|
||||
# TODO Discord normally uses a different set of locales.
|
||||
# For example, "en" being "en-US", etc. This will require changes to locale handling later.
|
||||
return ctx.bot.locales.keys()
|
||||
|
||||
|
||||
# TODO Maybe move to a separate module
|
||||
async def autofill_active_events(ctx: AutocompleteContext) -> List[OptionChoice]:
|
||||
async def autocomplete_active_events(ctx: AutocompleteContext) -> List[OptionChoice]:
|
||||
query: Dict[str, Any] = {
|
||||
"ended": None,
|
||||
"ends": {"$gt": datetime.now(tz=ZoneInfo("UTC"))},
|
||||
@@ -41,3 +43,24 @@ async def autofill_active_events(ctx: AutocompleteContext) -> List[OptionChoice]
|
||||
event_names.append(OptionChoice(result["name"], str(result["_id"])))
|
||||
|
||||
return event_names
|
||||
|
||||
|
||||
# TODO Maybe move to a separate module
|
||||
async def autocomplete_event_stages(ctx: AutocompleteContext) -> List[OptionChoice]:
|
||||
event_id: str | None = ctx.options["event"]
|
||||
|
||||
if event_id is None:
|
||||
return []
|
||||
|
||||
query: Dict[str, Any] = {
|
||||
"event_id": ObjectId(event_id),
|
||||
}
|
||||
|
||||
event_stages: List[OptionChoice] = []
|
||||
|
||||
async for result in col_stages.find(query).sort([("sequence", ASCENDING)]):
|
||||
event_stages.append(
|
||||
OptionChoice(f"{result['sequence']+1} ({result['question']})", str(result["_id"]))
|
||||
)
|
||||
|
||||
return event_stages
|
||||
|
Reference in New Issue
Block a user