Exemplo n.º 1
0
 def check(message):
     if message.channel != channel:
         return False
     if not playerlist:
         return message.author not in neg_list and (
             message.content.lower() in ["buzz", "bz", "skip"])
     return tournament.get_player(message.author, message.guild) in playerlist and message.author not in neg_list \
            and message.content.lower() == "buzz"
Exemplo n.º 2
0
 def check(message):
     if not playerlist:
         return message.author not in neg_list and (
             "buzz" in message.content.lower()
             or "skip" in message.content.lower())
     return tournament.get_player(
         message.author, message.server
     ) in playerlist and message.author not in neg_list and "buzz" in message.content.lower(
     )
Exemplo n.º 3
0
async def tossup(bot,
                 channel,
                 is_bonus=False,
                 playerlist=None,
                 ms=False,
                 category=None):
    correct = False
    if not ms:
        question_obj = await bot.db.get_tossups(category)
    else:
        question_obj = await bot.db.get_ms()
    print(
        f'question from {question_obj.packet}, answer {question_obj.formatted_answer}'
    )
    neg_list = []
    print(f'theme: {question_obj.category}, power={question_obj.power}')
    event = asyncio.Event()
    event.set()
    event.negged = False
    event.over = False
    loop = asyncio.get_event_loop()

    def check(message):
        if message.channel != channel:
            return False
        if not playerlist:
            return message.author not in neg_list and (
                message.content.lower() == "buzz"
                or message.content.lower() == "skip")
        return tournament.get_player(message.author, message.guild) in playerlist and message.author not in neg_list \
               and message.content.lower() == "buzz"

    buzz = loop.create_task(wait_for_buzz(bot, event, channel, check))
    reading = loop.create_task(read_tossup(question_obj, channel, event))

    while not reading.done():
        loop.create_task(timeout(buzz, reading))
        answer = await buzz
        if not answer:
            break
        if isinstance(answer, discord.Member):
            buzz = loop.create_task(wait_for_buzz(bot, event, channel, check))
            await channel.send("No answer!")
            neg_list.append(answer)
            event.set()
            continue

        if "skip" == answer.content:
            if not reading.done():
                reading.cancel()
                buzz.cancel()
            break

        matched = match(answer.content, question_obj.formatted_answer,
                        "</strong" in question_obj.formatted_answer)
        if matched == "p":
            await channel.send("prompt")
            try:
                answer = await bot.wait_for(
                    'message',
                    timeout=10,
                    check=lambda x: x.author == answer.author)
                matched = match(answer.content,
                                question_obj.formatted_answer,
                                "</strong" in question_obj.formatted_answer,
                                is_prompt=True)
            except asyncio.TimeoutError:
                matched = "n"

        if matched == "y":
            reading.cancel()
            power = await reading
            if power:
                await channel.send("correct - power!")
            else:
                await channel.send("correct!")
            await print_answer(channel, question_obj.formatted_answer, True)
            correct = True
            if playerlist:
                team = tournament.get_team(answer.author, answer.guild)
                player = tournament.get_player(answer.author, answer.guild)
                if power:
                    team.score += 15
                    player.score += 15
                else:
                    team.score += 10
                    player.score += 10
        else:
            buzz = loop.create_task(wait_for_buzz(bot, event, channel, check))
            await channel.send("incorrect!")
            neg_list.append(answer.author)
            event.set()
            event.negged = True
            if not event.over and playerlist:
                team = tournament.get_team(answer.author, answer.guild)
                player = tournament.get_player(answer.author, answer.guild)
                team.score -= 5
                player.score -= 5
            await asyncio.sleep(0.75)

    if not correct:
        await channel.send("Time's up!")
        await print_answer(channel, question_obj.formatted_answer, True)

    if correct and is_bonus:
        ctx = await bot.get_context(answer)
        await bonus(bot, ctx, team)
    neg_list.clear()
    if not playerlist:
        try:
            await bot.wait_for(
                'message',
                timeout=20,
                check=lambda x: x.content == 'n' and x.channel == channel)
            await tossup(bot, channel, ms=ms, category=category)
        except asyncio.TimeoutError:
            pass
Exemplo n.º 4
0
 def check(message):
     if not team:
         return message.author == ctx.author
     return tournament.get_player(message.author,
                                  message.guild) in team.members
Exemplo n.º 5
0
async def bonus(bot, ctx, team=None):
    bonus_obj = quizdb.get_bonuses()
    print(bonus_obj.formatted_answers[0])
    if team:
        await ctx.send(f"Bonus for {team.name}:")
        await asyncio.sleep(1)
    if bonus_obj.leadin == "[missing]":
        bonus_obj.leadin = "For 10 points each:"
    question_arr = bonus_obj.leadin.split(" ")
    sent_question = await ctx.send(" ".join(question_arr[:5]))
    await asyncio.sleep(1)
    for i in range(1, len(question_arr) // 5 + 1):
        sent_question_content = sent_question.content
        await sent_question.edit(content=sent_question_content + " " +
                                 " ".join(question_arr[i * 5:i * 5 + 5]))
        print(sent_question.content)
        await asyncio.sleep(1)

    # leadin done
    def check(message):
        if not team:
            return message.author == ctx.author
        return tournament.get_player(message.author,
                                     message.guild) in team.members

    for j in range(0, 3):
        correct = False
        question_arr = bonus_obj.texts[j].split(" ")
        formatted = bonus_obj.formatted_answers[j]
        sent_question = await ctx.send(" ".join(question_arr[:5]))
        await asyncio.sleep(1)
        for i in range(1, len(question_arr) // 5 + 1):
            sent_question_content = sent_question.content
            await sent_question.edit(content=sent_question_content + " " +
                                     " ".join(question_arr[i * 5:i * 5 + 5]))
            await asyncio.sleep(1)

        msg = None
        try:
            msg = await bot.wait_for('message', timeout=10, check=check)
            matched = match(msg.content, formatted, "</" in formatted)
            if matched == "p":
                await ctx.send("prompt")
                try:
                    answer = await bot.wait_for(
                        'message',
                        timeout=10,
                        check=lambda x: x.author == msg.author)
                    matched = match(answer.content,
                                    formatted,
                                    "</" in formatted,
                                    is_prompt=True)
                except asyncio.TimeoutError:
                    await ctx.send("Time's up!")

            if matched == "y":
                await ctx.send("correct!")
                await print_answer(ctx, formatted, "</" in formatted)
                correct = True
                if team:
                    team = tournament.get_team(msg.author, msg.guild)
                    player = tournament.get_player(msg.author, msg.guild)
                    team.score += 10
                    player.score += 10
            elif matched == "n":
                await ctx.send("incorrect!")
                print("incorrect")
        except asyncio.TimeoutError:
            await ctx.send("Time's up!")
            await asyncio.sleep(1)
        if not correct:
            await print_answer(ctx, bonus_obj.formatted_answers[j], "</"
                               in formatted)
Exemplo n.º 6
0
async def tossup(bot,
                 channel,
                 is_bonus=False,
                 playerlist=None,
                 ms=False,
                 category=None):
    correct = False
    if not ms:
        question_obj = quizdb.get_tossups(category)
    else:
        question_obj = quizdb.get_ms()
    print(
        f'question from {question_obj.packet}, answer {question_obj.formatted_answer}'
    )
    neg_list = []
    print(question_obj.category, question_obj.power)
    event = asyncio.Event()
    event.set()
    event.negged = False
    event.over = False
    loop = asyncio.get_event_loop()

    def check(message):
        if not playerlist:
            return message.author not in neg_list and (
                "buzz" in message.content.lower()
                or "skip" in message.content.lower())
        return tournament.get_player(
            message.author, message.server
        ) in playerlist and message.author not in neg_list and "buzz" in message.content.lower(
        )

    buzz = loop.create_task(wait_for_buzz(bot, event, channel, check))
    reading = loop.create_task(read_tossup(bot, question_obj, channel, event))

    while not reading.done():
        loop.create_task(timeout(buzz, reading))
        answer = await buzz
        if not answer:
            break
        if isinstance(answer, discord.Member):
            buzz = loop.create_task(wait_for_buzz(bot, event, channel, check))
            await bot.say("No answer!")
            neg_list.append(answer)
            event.set()
            continue

        if "skip" in answer.content:
            if not reading.done():
                reading.cancel()
                buzz.cancel()
            break
        matched = match(answer.content, question_obj.formatted_answer,
                        "</strong" in question_obj.formatted_answer)
        if matched == "p":
            await bot.say("prompt")
            answer = await bot.wait_for_message(timeout=10,
                                                author=answer.author)
            if answer is None:
                matched = "n"
            else:
                matched = match(answer.content,
                                question_obj.formatted_answer,
                                "</strong" in question_obj.formatted_answer,
                                is_prompt=True)
        if matched == "y":
            reading.cancel()
            power = await reading
            if power:
                await bot.say("correct - power!")
            else:
                await bot.say("correct!")
            await print_answer(bot, question_obj.formatted_answer, True)
            correct = True
            if playerlist:
                team = tournament.get_team(answer.author, answer.author.server)
                player = tournament.get_player(answer.author,
                                               answer.author.server)
                if power:
                    team.score += 15
                    player.score += 15
                else:
                    team.score += 10
                    player.score += 10
        else:
            buzz = loop.create_task(wait_for_buzz(bot, event, channel, check))
            await bot.say("incorrect!")
            neg_list.append(answer.author)
            event.set()
            event.negged = True
            if not event.over and playerlist:
                team = tournament.get_team(answer.author, answer.author.server)
                player = tournament.get_player(answer.author,
                                               answer.author.server)
                team.score -= 5
                player.score -= 5
            await asyncio.sleep(0.75)

    if not correct:
        await bot.say("Time's up!")
        await print_answer(bot, question_obj.formatted_answer, True)

    if correct and is_bonus:
        await bonus(bot, answer.author, team)
    neg_list.clear()
    if not playerlist:
        msg = await bot.wait_for_message(timeout=20, content="n")
        if msg is not None:
            await tossup(bot, channel, ms=ms, category=category)
Exemplo n.º 7
0
 def check(message):
     if not team:
         return message.author == author
     return tournament.get_player(message.author,
                                  message.server) in team.members
Exemplo n.º 8
0
async def bonus(bot, author, team=None):
    print(author)
    print(author.name)

    bonus_obj = quizdb.get_bonuses()
    print(bonus_obj.formatted_answers[0])
    if team:
        await bot.say(f"Bonus for {team.name}:")
        await asyncio.sleep(1)
    if bonus_obj.leadin == "[missing]":
        bonus_obj.leadin = "For 10 points each:"
    question_arr = bonus_obj.leadin.split(" ")
    sent_question = await bot.say(" ".join(question_arr[:5]))
    await asyncio.sleep(1)
    for i in range(1, len(question_arr) // 5 + 1):
        sent_question_content = sent_question.content
        sent_question = await bot.edit_message(
            sent_question, sent_question_content + " " +
            " ".join(question_arr[i * 5:i * 5 + 5]))
        print(sent_question.content)
        await asyncio.sleep(1)

    # leadin done
    def check(message):
        if not team:
            return message.author == author
        return tournament.get_player(message.author,
                                     message.server) in team.members

    for j in range(0, 3):
        correct = False
        question_arr = bonus_obj.texts[j].split(" ")
        formatted = bonus_obj.formatted_answers[j]
        sent_question = await bot.say(" ".join(question_arr[:5]))
        await asyncio.sleep(1)
        for i in range(1, len(question_arr) // 5 + 1):
            sent_question_content = sent_question.content
            sent_question = await bot.edit_message(
                sent_question, sent_question_content + " " +
                " ".join(question_arr[i * 5:i * 5 + 5]))
            await asyncio.sleep(1)

        msg = None
        msg = await bot.wait_for_message(timeout=10, check=check)
        if msg is not None:
            matched = match(msg.content, formatted, "</" in formatted)
            if matched == "p":
                await bot.say("prompt")
                answer = await bot.wait_for_message(timeout=10,
                                                    author=msg.author)
                if answer is None:
                    await bot.say("Time's up!")
                else:
                    matched = match(answer.content,
                                    formatted,
                                    "</" in formatted,
                                    is_prompt=True)
            if matched == "y":
                await bot.say("correct!")
                await print_answer(bot, formatted, "</" in formatted)
                correct = True
                if team:
                    team = tournament.get_team(msg.author, msg.author.server)
                    player = tournament.get_player(msg.author,
                                                   msg.author.server)
                    team.score += 10
                    player.score += 10
            elif matched == "n":
                await bot.say("incorrect!")
                print("incorrect")
        else:
            await bot.say("Time's up!")
            await asyncio.sleep(1)
        if not correct:
            await print_answer(bot, bonus_obj.formatted_answers[j], "</"
                               in formatted)
Exemplo n.º 9
0
async def tossup(bot,
                 ctx,
                 is_bonus=False,
                 playerlist=None,
                 category=None,
                 in_tournament=False,
                 difficulties=[2, 3, 4, 5]):
    channel = ctx.channel
    correct = False
    question_obj = await bot.db.get_tossups(category=category,
                                            difficulties=difficulties)
    print(
        f'question from {question_obj.packet}, answer {question_obj.formatted_answer}'
    )
    neg_list = []
    print(f'theme: {question_obj.category}, power={question_obj.power}')
    pk_id = await bot.db.log_tossup(question_obj, ctx, in_tournament)
    event = asyncio.Event()
    event.set()
    event.negged = False
    event.over = False
    event.power_passed = False
    event.progress = 0
    loop = asyncio.get_event_loop()

    def check(message):
        if message.channel != channel:
            return False
        if not playerlist:
            return message.author not in neg_list and (
                message.content.lower() in ["buzz", "bz", "skip"])
        return tournament.get_player(message.author, message.guild) in playerlist and message.author not in neg_list \
               and message.content.lower() == "buzz"

    buzz = loop.create_task(wait_for_buzz(bot, event, channel, check))
    reading = loop.create_task(read_tossup(bot, question_obj, channel, event))

    while not reading.done():
        loop.create_task(timeout(buzz, reading))
        action = await buzz
        if not action:
            break
        if "skip" == action.content:
            if not reading.done():
                reading.cancel()
            buzz.cancel()
            break
        # if we get here the action was a buzz
        buzz_id = await bot.db.log_buzz(pk_id, action,
                                        int(event.progress * 100))
        print(pk_id)
        try:
            answer = await bot.wait_for(
                'message',
                timeout=10.0,
                check=lambda x: x.author == action.author)
        except asyncio.TimeoutError:
            buzz = loop.create_task(wait_for_buzz(bot, event, channel, check))
            await channel.send("No answer!")
            neg_list.append(action.author)
            event.set()
            await bot.db.update_buzz(buzz_id, False)
            continue

        matched = match(answer.content, question_obj.formatted_answer,
                        "</strong" in question_obj.formatted_answer)
        if matched == "p":
            await channel.send("prompt")
            try:
                answer = await bot.wait_for(
                    'message',
                    timeout=10,
                    check=lambda x: x.author == answer.author)
                matched = match(answer.content,
                                question_obj.formatted_answer,
                                "</strong" in question_obj.formatted_answer,
                                is_prompt=True)
            except asyncio.TimeoutError:
                matched = "n"

        if matched == "y":
            reading.cancel()
            power = await reading
            if power:
                await channel.send("correct - power!")
            else:
                await channel.send("correct!")
            await print_answer(channel, question_obj.formatted_answer, True)
            correct = True
            points = 15 if power else 10
            if playerlist:
                team = tournament.get_team(answer.author, answer.guild)
                player = tournament.get_player(answer.author, answer.guild)
                team.score += points
                player.score += points
            await bot.db.update_buzz(buzz_id, True, points)
        else:
            buzz = loop.create_task(wait_for_buzz(bot, event, channel, check))
            await channel.send("incorrect!")
            neg_list.append(answer.author)
            event.set()
            await bot.db.update_buzz(buzz_id, False)
            event.negged = True
            if not event.over and playerlist:
                team = tournament.get_team(answer.author, answer.guild)
                player = tournament.get_player(answer.author, answer.guild)
                team.score -= 5
                player.score -= 5
            await asyncio.sleep(0.75)

    if not correct:
        await channel.send("Time's up!")
        await print_answer(channel, question_obj.formatted_answer, True)

    if correct and is_bonus:
        ctx = await bot.get_context(answer)
        await bonus(bot, ctx, team)
    neg_list.clear()