Exemplo n.º 1
0
async def queue(ctx, user: User = None):
    try:
        if user:
            name = db.get_name_from_discriminator(user.name +
                                                  user.discriminator)[0]
            queue = db.get_user_queue(name)
        else:
            name = db.get_name_from_discriminator(ctx.author.name +
                                                  ctx.author.discriminator)[0]
            queue = db.get_user_queue(name)
    except TypeError:
        return await ctx.send("User not registered.")

    await ctx.send(embed=handle_queue(queue, f"{name}' queue"))
Exemplo n.º 2
0
def handle_discord_request(ctx, command, args):
    request = " ".join(args)
    user_disc = ctx.author.name + ctx.author.discriminator
    username = db.get_name_from_discriminator(user_disc)

    try:
        request_dict = dissect_comment(f"!{command} {request}")
    except (MovieNotFound, EpisodeNotFound, OffensiveWord,
            InvalidRequest) as kino_exc:
        return f"Nope: {type(kino_exc).__name__}."

    request_id = str(randint(2000000, 5000000))

    if not request_dict:
        return "Invalid syntax."
    elif not username:
        return "You are not registered. Use `!register <YOUR NAME>`."

    try:
        db.insert_request((
            username[0],
            request_dict["comment"],
            request_dict["command"],
            request_dict["title"],
            "|".join(request_dict["content"]),
            request_id,
            1,
        ))
        return f"Added. ID: {request_id}; user: {username[0]}."
    except sqlite3.IntegrityError:
        return "Duplicate request."
Exemplo n.º 3
0
async def request(ctx, *args):
    request = " ".join(args)
    user_disc = ctx.author.name + ctx.author.discriminator
    username = db.get_name_from_discriminator(user_disc)

    try:
        request_dict = dissect_comment("!req " + request)
    except (MovieNotFound, EpisodeNotFound, OffensiveWord) as kino_exc:
        return await ctx.send(f"Nope: {type(kino_exc).__name__}.")

    request_id = str(randint(2000000, 5000000))

    if not request_dict:
        message = "Invalid syntax. Usage: `!req TITLE [{quote,timestamp}]...`"
    elif not username:
        message = "You are not registered. Use `!register <YOUR NAME>`."
    else:
        try:
            db.insert_request(
                (
                    username[0],
                    request_dict["comment"],
                    request_dict["command"],
                    request_dict["title"],
                    "|".join(request_dict["content"]),
                    request_id,
                    1,
                )
            )
            message = f"Added. (User: `{username[0]}`; ID: `{request_id}`)."
        except sqlite3.IntegrityError:
            message = "Duplicate request."

    await ctx.send(message)
Exemplo n.º 4
0
async def purge(ctx, user: User):
    try:
        user = db.get_name_from_discriminator(user.name + user.discriminator)[0]
    except TypeError:
        return await ctx.send("No requests found for given user")

    db.purge_user_requests(user)
    await ctx.send(f"Purged: {user}.")
Exemplo n.º 5
0
async def queue(ctx, user: User = None):
    try:
        if user:
            name = db.get_name_from_discriminator(user.name + user.discriminator)[0]
            queue = db.get_user_queue(name)
        else:
            name = db.get_name_from_discriminator(
                ctx.author.name + ctx.author.discriminator
            )[0]
            queue = db.get_user_queue(name)
    except TypeError:
        return await ctx.send("User not registered.")

    if queue:
        shuffle(queue)
        embed = Embed(title=f"{name}'s queue", description="\n".join(queue[:10]))
        return await ctx.send(embed=embed)

    await ctx.send("No requests found.")
Exemplo n.º 6
0
async def register(ctx, *args):
    name = " ".join(args).title()
    discriminator = ctx.author.name + ctx.author.discriminator
    if not name:
        message = "Usage: `!register <YOUR NAME>`"
    elif not "".join(args).isalpha():
        message = "Invalid name."
    else:
        try:
            db.register_discord_user(name, discriminator)
            message = f"You were registered as '{name}'."
        except sqlite3.IntegrityError:
            old_name = db.get_name_from_discriminator(discriminator)[0]
            try:
                db.update_discord_name(name, discriminator)
                db.update_name_from_requests(old_name, name)
                message = f"Your name was updated: '{name}'."
            except sqlite3.IntegrityError:
                message = "Duplicate name."

    await ctx.send(message)