Ejemplo n.º 1
0
def giveaway_done(giveaway):
    giveaway.set_status("archived")
    giveaway.draw_winners(giveaway.get_number_of_winners())
    giveaway.replace_winners = 1
    store_giveaway(giveaway)
    reloaded = retrieve_giveaway(giveaway.get_id())
    winners = ()
    for x in reloaded.get_winners():
        winners = winners + (x[0], )
    donelist.append(reloaded)
    return
Ejemplo n.º 2
0
async def preview_giveaway(message, listmode=0):
    if listmode != 0:
        giveaway_id = listmode
    else:
        giveaway_id = (message.content.split(sep=" "))[1]
    giveaway = retrieve_giveaway(giveaway_id)
    if giveaway == "NA":
        await client.send_message(message.channel, "Invalid ID!")
        return
    winning_users = []
    for x in giveaway.get_winners():
        winning_users.append(x)

    if giveaway.get_status() == "active":
        liveswitch = "\** LIVE \**"
    else:
        liveswitch = "\** COMPLETE \**"
    line1_1 = str("**Giveaway #" + giveaway.get_id() + " |** start-" +
                  giveaway.timeframe.start)
    line1_2 = str(" end-" + giveaway.timeframe.end + " --" +
                  giveaway.get_status() + "--" + " **|\n" +
                  giveaway.get_header() + "**\n" + liveswitch + "\n")
    line1 = line1_1 + line1_2
    line2 = giveaway.get_description() + "\n"
    line3 = "**Winners(" + giveaway.get_number_of_winners() + "):**"
    line4 = "Number of entrants: **" + str(len(giveaway.entrants)) + "** \n"
    if len(winning_users) == 0:
        line3 = line3 + " Not Drawn \n"
    else:
        for i in winning_users:
            user = await client.get_user_info(i[0])
            userstring = user.mention
            line3 = line3 + userstring + " "
        line3 = line3 + "**|** Congratulations!\n"

    msg = line2 + line4 + line3
    em = discord.Embed(colour=EM_COLOUR, title=line1, description=msg)
    image = (giveaway.get_image())
    em.set_image(url=image)
    em.set_footer(text=EM_FOOTER)

    message_to_cache = await client.send_message(message.channel, embed=em)
    sql = "INSERT INTO message_cache VALUES (%s,%s, %s)"
    values = (giveaway_id, message_to_cache.id, message_to_cache.channel.id)
    cursor.execute(sql, values)
    database.commit()
    # for x in client.get_all_emojis():
    #     print(str(x))
    emoji = discord.utils.get(client.get_all_emojis(), name=ENTRY_TOKEN)
    # print(str(emoji))
    await client.add_reaction(message_to_cache, emoji)
    return
Ejemplo n.º 3
0
async def set_winners(message):
    text = message.content.split(sep=" ")
    giveaway = retrieve_giveaway(text[1])
    if giveaway == "NA" or len(
            text) < 4:  # means there was an error in the read function
        await client.send_message(
            message.channel,
            "Invalid giveaway id, or not enough parameters passed!!")
        return
    giveaway.set_number_of_winners(text[3])
    store_giveaway(giveaway)
    msg = ("There are now " + giveaway.get_number_of_winners() +
           " winners for giveway '" + giveaway.get_id() + "'")
    await client.send_message(message.channel, msg)
Ejemplo n.º 4
0
async def redraw_winners(message):
    text = message.content.split(sep=" ")
    giveaway = retrieve_giveaway(text[1])
    if giveaway == "NA":
        client.send_message(message.channel, "Invalid ID")
        return
    if giveaway.get_status() != "archived":
        await client.send_message(
            message.channel,
            "This giveaway is not complete! Unable to redraw!")
        return
    giveaway.draw_winners(giveaway.get_number_of_winners())
    giveaway.replace_winners = 1
    store_giveaway(giveaway)

    msg = "Winners have been picked randomly for giveaway '" + giveaway.get_id(
    ) + "'"
    await client.send_message(message.channel, msg)
    return
Ejemplo n.º 5
0
async def update_giveaways():
    sql = "SELECT * FROM message_cache "
    cursor.execute(sql)
    messages = cursor.fetchall()
    message_list = []
    for i in range(len(messages)):
        message_list.append(messages[i])
    for x in message_list:
        giveaway_id = x[0]
        try:
            message = await client.get_message(client.get_channel(x[2]), x[1])
        except:
            donothing = 1
        giveaway = retrieve_giveaway(giveaway_id)
        if giveaway == "NA":
            return
        winning_users = []
        for x in giveaway.get_winners():
            winning_users.append(x)
        if giveaway.get_status() == "active":
            liveswitch = "\** LIVE \**"
        else:
            liveswitch = "\** COMPLETE \**"
        line1_1 = str("**Giveaway #" + giveaway.get_id() + " |** start-" +
                      giveaway.timeframe.start)
        line1_2 = str(" end-" + giveaway.timeframe.end + " --" +
                      giveaway.get_status() + "--" + " **\n" +
                      giveaway.get_header() + "**\n" + liveswitch + "\n")
        line1 = line1_1 + line1_2
        line2 = giveaway.get_description() + "\n"
        line3 = "**Winners(" + giveaway.get_number_of_winners() + "):**"
        line4 = "Number of entrants: **" + str(len(
            giveaway.entrants)) + "** \n"
        if len(winning_users) == 0 and giveaway.timeframe.end != "3000/01/01":
            current_date = datetime.datetime.utcnow()
            end_time_array = date_parser(giveaway.timeframe.end,
                                         giveaway.timeframe.endtime)
            end_time = datetime.datetime(end_time_array[0], end_time_array[1],
                                         end_time_array[2], end_time_array[3],
                                         end_time_array[4], 0)
            difference = (end_time - current_date)
            line3 = "Time till drawing: " + str(
                difference.days) + " days " + str(
                    int(difference.seconds / (60 * 60))) + " hours " + str(
                        int((difference.seconds / (60)) % 60)) + " minutes"
        elif giveaway.status == "archived":
            for i in winning_users:
                user = await client.get_user_info(i[0])
                userstring = user.mention
                line3 = line3 + userstring + " "
            line3 = line3 + "**|** Congratulations!\n"

        msg = line2 + line4 + line3
        em = discord.Embed(colour=EM_COLOUR, title=line1, description=msg)
        image = (giveaway.get_image())
        em.set_image(url=image)
        em.set_footer(text=EM_FOOTER)
        try:
            await client.edit_message(message, new_content=None, embed=em)
        except:
            donothing = 1
            # yeah sorry this hurts me too
        database.commit()
    return