Exemple #1
0
async def addReminder(parameters, channel):
    """Adds a reminder in the database

    Args:
        parameters (list): The list of parameters required for the command to work
        channel (discord.channel): The channel in which the command has been done
    """
    try:
        start_time = datetime.strptime(
            "{} {}".format(parameters[0], parameters[1]), "%d/%m/%Y %H:%M"
        )
        name = parameters[2].lower()

        hours, minutes = parameters[3].split(":")
        duration = dt.timedelta(hours=int(hours), minutes=int(minutes))
    except ValueError as e:
        await channel.send("Valeur pas valide :", e)
        return

    people_to_remind = " ".join(parameters[4:])

    start_time = timezone.make_aware(start_time)

    await sync_to_async(createReminder)(
        name=name,
        start_time=start_time,
        duration=duration,
        people_to_remind=people_to_remind,
        channel_id=_(channel).id,
        server_id=_(channel).guild.id,
    )
    message = "Bert a ajouté l'évenement **{}** le **{}** (pour {})".format(
        name, start_time.strftime("%d/%m/%Y à %H:%M"), people_to_remind
    )
    await channel.send(message)
Exemple #2
0
async def getFuture(parameters, channel):
    """Returns the future events occuring in the given period of time

    Args:
        parameters (list): The list of parameters required for the command to work
        channel (discord.channel): The channel in which the command has been done
    """
    if len(parameters) == 0:
        field = "days"
        value = "7"
    else:
        field = parameters[0]
        value = parameters[1]
    if not value.isdigit():
        await channel.send(f"La valeur {value} doit être chiffre")
        return
    value = int(value)
    future_events = await sync_to_async(getFutureEvents)(
        name=field, value=value, guild=_(channel).guild.id
    )
    for event in future_events:
        await channel.send(
            f"```Événement : {event['name']}\n  Début : {event['start_time']}\n  Durée : {event['duration']}\n\n```"
        )
    if len(future_events) == 0:
        await channel.send("Bert a pas trouvé événements dans période donnée")
Exemple #3
0
async def stopping(parameters, channel):
    """Stops the deathping on the selected user

    Args:
        parameters (list): The list of parameters required for the command to work
        channel (discord.channel): The channel in which the command has been done
    """
    uids = parameters
    cog = ReminderCog.getInstance()
    for uid in uids:
        uid = uid.replace("!", "")
        if uid.startswith("<") and uid.endswith(">"):
            if (uid, _(channel).id) in cog.toBePinged:
                del cog.toBePinged[cog.toBePinged.index((uid, _(channel).id))]
                await channel.send(f"Stopping to ping the shit out of {uid}")
            else:
                await channel.send(
                    f"{uid} is not in the list of person to deathing in this channel"
                )
Exemple #4
0
async def delReminder(parameters, channel):
    """Deletes a reminder

    Args:
        parameters (list): The list of parameters required for the command to work
        channel (discord.channel): The channel in which the command has been done
    """
    name = parameters[0]

    guild_id = _(channel).guild.id
    result = await sync_to_async(deleteReminder)(name, guild_id)
    await displayResult(channel, result)
Exemple #5
0
async def deathping(parameters, channel):
    """Launches a deathping on the given user (The bot will ping the user every two seconds)

    Args:
        parameters (list): The list of parameters required for the command to work
        channel (discord.channel): The channel in which the command has been done
    """
    uids = parameters
    for uid in uids:
        if uid.startswith("<") and uid.endswith(">"):
            ReminderCog.getInstance().toBePinged.append((uid, _(channel).id))
            await channel.send(f"Gonna ping the shit out of {uid}\n{constants.deathping_gif}")
Exemple #6
0
async def modReminder(parameters, channel):
    """Modifies the selected field from a reminder

    Args:
        parameters (list): The list of parameters required for the command to work
        channel (discord.channel): The channel in which the command has been done
    """
    name = parameters[0]
    guild_id = _(channel).guild.id
    field = parameters[1]
    value = " ".join(parameters[2:])

    result = await sync_to_async(modifyReminder)(
        name=name, server_id=guild_id, field=field, value=value
    )
    await displayResult(channel, result)