예제 #1
0
async def play_wordle(ctx, *message):
    if message:
        if message[0] == "stats":
            response = embed_wordle(
                {"Wordle Stats": get_wordle_stats(message, WORD_SET)})
            await ctx.send(embed=response)
            return
        try:
            word_len = int(message[0])
        except:
            word_len = 5
    else:
        word_len = 5
    try:
        word = get_word(BRITISH_WORDS, WORD_SET, word_len).upper()
        response = embed_wordle({
            'Wordle!':
            f'Guessing a {word_len} character word in {word_len+1} guesses...'
        })
        await ctx.send(embed=response)
        await wait_for_answer(ctx, word, word_len, WORD_SET,
                              REGIONAL_INDICATOR_LETTERS, ALPHABET)
    except Exception as error:
        if DEBUG == '1':
            response_text = ' Debug mode error details:\n```' + str(e) + '```'
        response_text = wordle_exception(error, DEBUG)
        response = embed_wordle({'A wordley error!': response_text})
        await ctx.send(embed=response)
예제 #2
0
async def play_wordle(ctx, *message):
    if message:
        if message[0] == "stats":
            response = embed_wordle(
                {"Wordle Stats": get_wordle_stats(message, WORD_SET)})
            await ctx.send(embed=response)
            return
        try:
            word_len = int(message[0])
        except:
            word_len = 5
    else:
        word_len = 5
    try:
        word = get_word(BRITISH_WORDS, WORD_SET, word_len).upper()
        response = embed_wordle({
            'Wordle!':
            f'Guessing a {word_len} character word in {word_len+1} guesses...'
        })
        await ctx.send(embed=response)
        await wait_for_answer(ctx, word, word_len)
    except Exception as e:
        if DEBUG == '1':
            response_text = ' Debug mode error details:\n```' + str(e) + '```'
        else:
            response_text = ' Sorry your current game is lost forever, please start a new one!'
        response = embed_wordle({'A wordley error!': response_text})
        print('\nException in play_wordle():', e, '', sep='\n')
        await ctx.send(embed=response)
예제 #3
0
async def musi_nimi(ctx, *message):
    if message:
        try:
            word_len = int(message[0])
        except:
            word_len = 4
    else:
        word_len = 4
    try:
        toki_pona_words = [*TOKI_PONA_DICT.keys()]
        toki_pona_length_words = [
            word for word in toki_pona_words if len(word) == word_len
        ]
        word = get_random(toki_pona_length_words).upper()
        response = embed_wordle({
            'Wordle!':
            f'Guessing a {word_len} character toki pona word in {word_len+1} guesses...'
        })
        await ctx.send(embed=response)
        await wait_for_answer(ctx, word, word_len, toki_pona_words,
                              REGIONAL_INDICATOR_LETTERS, TOKI_ALPHABET)
    except Exception as error:
        response_text = wordle_exception(error, DEBUG)
        response = embed_wordle({'A wordley error!': response_text})
        await ctx.send(embed=response)
예제 #4
0
async def wait_for_answer(ctx, word, word_len):
    emoji_correct_word = get_emoji_word(word, REGIONAL_INDICATOR_LETTERS)
    tag_user = ctx.author.mention

    def check(m):
        '''
        Checks message is by original command user and in the same channel
        '''
        if m.channel != ctx.channel:
            return False
        if m.author != ctx.author:
            return False
        return True

    try:
        correct = False
        fail_count = 0
        leftover_alphabet = ALPHABET
        past_guesses = []
        while not correct:
            msg = await ctx.bot.wait_for('message', timeout=500, check=check)
            player = f'{msg.author}'
            player_title = f'{player.split("#")[0]}\'s Wordle!'
            guess = msg.content.lower()
            emoji_guess_word = get_emoji_word(msg.content.lower(),
                                              REGIONAL_INDICATOR_LETTERS)
            if msg:
                if guess[0] == '$':
                    # Skip bot commands
                    pass
                elif not valid_word(guess, WORD_SET):
                    wordle_invalid_word = {
                        player_title:
                        f'{emoji_guess_word} is not in the dictionary. Please guess again.'
                    }
                    await ctx.send(content=tag_user,
                                   embed=embed_wordle(wordle_invalid_word))
                else:
                    correct, wrong_len, leftover_alphabet, squares_response = check_answer(
                        guess, word, leftover_alphabet)
                    # Setup only for valid guesses
                    if not wrong_len:
                        fail_count += 1
                        emoji_alphabet = get_emoji_word(
                            ''.join(leftover_alphabet),
                            REGIONAL_INDICATOR_LETTERS)
                        past_guesses += [
                            f'{emoji_guess_word} | {squares_response}'
                        ]
                        past_guesses_string = '\n'.join(past_guesses)
                        common_response_text = f'{past_guesses_string} - {fail_count}/{word_len+1}'
                    # Respond
                    if correct:
                        wordle_success = {
                            player_title: f'{common_response_text}',
                            'Correct!': f'The word was {emoji_correct_word}'
                        }
                        await ctx.send(content=tag_user,
                                       embed=embed_wordle(wordle_success))
                        return
                    elif wrong_len:
                        wordle_bad_word = {
                            player_title:
                            f'Your guesses must be {word_len} letters long! Try again!'
                        }
                        await ctx.send(content=tag_user,
                                       embed=embed_wordle(wordle_bad_word))
                    elif (fail_count == word_len + 1):
                        wordle_fail = {
                            player_title:
                            f'{common_response_text}',
                            'Incorrect!':
                            f'The correct word was {emoji_correct_word}'
                        }
                        await ctx.send(content=tag_user,
                                       embed=embed_wordle(wordle_fail))
                        break
                    else:
                        wordle_guess_again = {
                            player_title: f'{common_response_text}',
                            'Unused Letters': emoji_alphabet
                        }
                        await ctx.send(content=tag_user,
                                       embed=embed_wordle(wordle_guess_again))
    except asyncio.TimeoutError:
        wordle_timeout_error = {
            'A wordley timeout':
            f'Guess quicker next time!\nThe word was {emoji_correct_word}'
        }
        await ctx.send(content=tag_user,
                       embed=embed_wordle(wordle_timeout_error))