Skip to content

discord_lfg.utils.general

Utilities for Group Builder.

datetime_now_utc() #

Gets the current time using the UTC timezone.

Source code in src\discord_lfg\utils\general.py
def datetime_now_utc():
    """Gets the current time using the UTC timezone."""
    return datetime.now(tz=timezone.utc)

end_of_month(start_date) #

Creates a date for the last day of the month of a given date.

Source code in src\discord_lfg\utils\general.py
def end_of_month(start_date: date):
    """Creates a date for the last day of the month of a given date."""
    if start_date.month == 12:
        return start_date.replace(year=start_date.year + 1, month=1) - timedelta(days=1)
    else:
        return start_date.replace(month=start_date.month + 1) - timedelta(days=1)

extract_numbers(text) #

Gets any numbers from a string and returns them as a list of integers.

Source code in src\discord_lfg\utils\general.py
7
8
9
def extract_numbers(text: str) -> list[int]:
    """Gets any numbers from a string and returns them as a list of integers."""
    return [int(num) for num in re.findall(r"\d+", text)]

get_numbers_from_channel_name(channel_name) #

Generates a set of numbers from a channel name.

Assumes that at most there are 2 numbers in the channel name. If this is the bot-control channel, generates a list of 1-10. Otherwise, generates a list with just -1 as a difficulty.

Source code in src\discord_lfg\utils\general.py
def get_numbers_from_channel_name(channel_name: str) -> None | list:
    """Generates a set of numbers from a channel name.

    Assumes that at most there are 2 numbers in the channel name.
    If this is the bot-control channel, generates a list of 1-10.
    Otherwise, generates a list with just -1 as a difficulty.
    """
    numbers = extract_numbers(channel_name)
    if len(numbers) == 1:
        return [str(numbers[0])]
    elif len(numbers) == 2:
        return [str(num) for num in range(numbers[0], numbers[1] + 1)]
    elif channel_name == "bot-control":
        return [str(num) for num in range(1, 11)]
    else:
        return [str(-1)]

next_month(start_date) #

Creates a date for the first day of the next month of a given date.

Source code in src\discord_lfg\utils\general.py
def next_month(start_date: date):
    """Creates a date for the first day of the next month of a given date."""
    if start_date.month == 12:
        return start_date.replace(year=start_date.year + 1, month=1, day=1)
    else:
        return start_date.replace(month=start_date.month + 1)