Exemple #1
0
def test_github_repo_exclude_words(tmp_pathplus,
                                   image_regression: ImageRegressionFixture):
    w = Wordle(random_state=5678)

    w.generate_from_git("https://github.com/domdfcoding/domdf_python_tools",
                        outfile=tmp_pathplus / "git_wordcloud.svg",
                        sha="de815f593718e16c031bc70e9c24b5635c3144dc",
                        exclude_words=["assert", "def", "self"])
    export_wordcloud(w, outfile=tmp_pathplus / "git_wordcloud.png")

    image_regression.check((tmp_pathplus / "git_wordcloud.png").read_bytes(),
                           diff_threshold=3.5)
Exemple #2
0
def test_c_source_file(
    tmp_pathplus,
    image_regression: ImageRegressionFixture,
    counter_regression: CounterRegressionFixture,
):
    w = Wordle(random_state=5678)

    src_file = examples_dir / "example.c"
    outfile = tmp_pathplus / "c_wordcloud.png"

    w.generate_from_file(src_file, outfile=tmp_pathplus / "c_wordcloud.svg")
    export_wordcloud(w, outfile=outfile)

    image_regression.check(outfile.read_bytes())
    counter_regression.check(frequency_from_file(src_file))
Exemple #3
0
    async def wordle_guess_cmd(self, ctx, word):
        """
    Callback for the /wordle guess command
    --
    input:
      ctx: interactions.CommandContext
      word: str
    """
        await ctx.defer(ephemeral=True)
        await utils.custom_assert("current_event" in db.keys(),
                                  "No current event registered", ctx)

        current_event = eval(db["current_event"])
        await utils.custom_assert(
            isinstance(current_event, events.Wordle_event),
            "The current event is not a wordle", ctx)

        wordle = Wordle(db["word_of_the_day"])

        user_id = str(int(ctx.author.id))
        if user_id not in db["wordle_guesses"].keys():
            db["wordle_guesses"][user_id] = []

        guesses = list(db["wordle_guesses"][user_id])
        word = word.lower()
        await utils.custom_assert(
            len(guesses) < wordle.nb_trials,
            "The maximum amount of trials has been reached!", ctx)
        await utils.custom_assert(wordle.is_valid(word),
                                  "This is not a valid word!", ctx)
        await utils.custom_assert(
            guesses == [] or wordle.solution != guesses[-1],
            "You already won!", ctx)

        guesses.append(word)
        db["wordle_guesses"][user_id] = guesses

        header_str = "\n".join(wordle.guess(w) for w in guesses)

        if guesses[-1] == wordle.solution:
            header_str += f"\n\nCongratulations, you found the word of the day with {len(guesses)}/{wordle.nb_trials} trials!\nYou earnt {current_event.reward}{Constants.PIFLOUZ_EMOJI}"
            piflouz_handlers.update_piflouz(user_id,
                                            current_event.reward,
                                            check_cooldown=False)
        elif len(guesses) == wordle.nb_trials:
            header_str += f"\n\nOuch, you failed :(\nThe answer was: **{wordle.solution}**"

        await self.send_wordle_embed(ctx, wordle, guesses, header_str)
Exemple #4
0
def display_result(wordle: Wordle):
    print(f"\n {Fore.LIGHTBLUE_EX} Your result so far.. .{Fore.RESET}\n")

    for word in wordle.attempts:
        result = wordle.guess(word)
        converted_result = convert_result_to_color(result)
        print(converted_result)
    for _ in range(wordle.remaining_attempts):
        print("_ " * wordle.word_length)
Exemple #5
0
def test_python_source_file(
    tmp_pathplus,
    image_regression: ImageRegressionFixture,
    counter_regression: CounterRegressionFixture,
):
    w = Wordle(random_state=5678)

    outfile = tmp_pathplus / "python_wordcloud.png"

    source_url = RequestsURL(
        "https://raw.githubusercontent.com/domdfcoding/wordle")
    source_url = source_url / "76797ba8b641b38fe1bed0801f0af248b793b59e/wordle/__init__.py"
    (tmp_pathplus / "source.py").write_bytes(source_url.get().content)

    w.generate_from_file(tmp_pathplus / "source.py",
                         outfile=tmp_pathplus / "python_wordcloud.svg")
    export_wordcloud(w, outfile=outfile)

    image_regression.check(outfile.read_bytes())
    counter_regression.check(frequency_from_file(tmp_pathplus / "source.py"))
Exemple #6
0
def test_github_repo(tmp_pathplus, image_regression: ImageRegressionFixture):
    w = Wordle(random_state=5678)

    w.generate_from_git(
        "https://github.com/domdfcoding/domdf_python_tools",
        outfile=tmp_pathplus / "git_wordcloud.svg",
        sha="de815f593718e16c031bc70e9c24b5635c3144dc",
    )
    export_wordcloud(w, outfile=tmp_pathplus / "git_wordcloud.png")

    image_regression.check((tmp_pathplus / "git_wordcloud.png").read_bytes(),
                           diff_threshold=3.5)

    # The results should be different for a different commit
    w.generate_from_git(
        "https://github.com/domdfcoding/domdf_python_tools",
        outfile=tmp_pathplus / "git_wordcloud.svg",
        sha="c30106567a27a17a5bd1339409ca22b6d425a25f",
    )
    export_wordcloud(w, outfile=tmp_pathplus / "git_wordcloud.png")

    with pytest.raises(AssertionError,
                       match="Difference between images too high"):
        image_regression.check(
            (tmp_pathplus / "git_wordcloud.png").read_bytes(),
            diff_threshold=3.5)
Exemple #7
0
def main():
    print(Fore.GREEN + "... HELLO WORDLE ..." + Fore.RESET)
    # reading the words from a text file
    wordle_words = load_word_set("data\wordle_words.txt")
    secret = random.choice(list(wordle_words))

    wordle = Wordle(secret)

    # checking the correct input
    while wordle.can_attempt:
        w = input("\nEnter your word:  ").upper()
        if len(w) != wordle.word_length:
            print(
                Fore.RED +
                f"\nWord length must be {wordle.word_length} charcters long!" +
                Fore.RESET)
            continue
        if w.isdigit():
            print(Fore.RED + f"\nNot a word. Enter a string!" + Fore.RESET)
            continue
        if not w in wordle_words:
            print(Fore.RED + f"\nNot a correct word in the list!" + Fore.RESET)
            continue

        wordle.attempt(w)
        # result= wordle.guess(w)
        # print(*result, sep='\n')
        display_result(wordle)

    if wordle.is_solved:
        print(
            Fore.LIGHTBLUE_EX +
            f"\nYou solved the puzzle.. in {len(wordle.attempts)} attempts! " +
            Fore.RESET)
    else:
        print(Fore.RED + "\nYou failed to solved the puzzle!" + Fore.RESET)
        print(
            f"\nThe Secret word was {Fore.LIGHTMAGENTA_EX}{wordle.secret}{Fore.RESET}"
        )
Exemple #8
0
    async def wordle_status_cmd(self, ctx):
        """
    Callback for the /wordle status command
    --
    input:
      ctx: interactions.CommandContext
    """
        await ctx.defer(ephemeral=True)
        await utils.custom_assert("current_event" in db.keys(),
                                  "No current event registered", ctx)

        current_event = eval(db["current_event"])
        await utils.custom_assert(
            isinstance(current_event, events.Wordle_event),
            "The current event is not a wordle", ctx)

        wordle = Wordle(db["word_of_the_day"])

        user_id = str(int(ctx.author.id))
        await utils.custom_assert(
            user_id in db["wordle_guesses"].keys(),
            "You haven't participated to today's wordle yet!", ctx)

        guesses = list(db["wordle_guesses"][user_id])

        await utils.custom_assert(
            len(guesses) > 0,
            "You haven't participated to today's wordle yet!", ctx)

        header_str = "\n".join(wordle.guess(w) for w in guesses)
        header_str += f"\n{len(guesses)}/{wordle.nb_trials}"

        if guesses != [] and guesses[-1] == wordle.solution:
            header_str += "\nYou won!"
        elif len(guesses) == wordle.nb_trials:
            header_str += f"You lost :( The correct word was {wordle.solution}"

        await self.send_wordle_embed(ctx, wordle, guesses, header_str)
Exemple #9
0
"""
Create a wordcloud from a single Python source file
"""

# stdlib
import pathlib

# this package
from wordle import Wordle, export_wordcloud

filename = pathlib.Path('.').absolute().parent / "wordle/__init__.py"

w = Wordle(random_state=5678)
w.generate_from_file(filename, outfile="python_wordcloud.svg")
export_wordcloud(w, outfile="python_wordcloud.png")
Exemple #10
0
"""
Create a wordcloud from a single C source file
"""

# this package
from wordle import Wordle, export_wordcloud

w = Wordle(random_state=5678)
w.generate_from_file("example.c", outfile="c_wordcloud.svg")
export_wordcloud(w, outfile="c_wordcloud.png")
Exemple #11
0
"""
Create a wordcloud from the Folium git repository.

https://github.com/python-visualization/folium
"""

# this package
from wordle import Wordle, export_wordcloud

w = Wordle(random_state=5678)
w.generate_from_git("https://github.com/python-visualization/folium",
                    outfile="folium_wordcloud.svg")
export_wordcloud(w, outfile="folium_wordcloud.png")
import discord
from discord.ext import commands
from utils import load_paywalls, load_token
from librarian import Librarian
from rando import Creeper, Utes, RateLimiter
from wordle import Wordle
from collector import Collector

if __name__ == "__main__":
    """local resource loads"""
    # load paywalled sites
    paywalled_sites = load_paywalls()
    # load bot token
    token = load_token()
    """bot instantiation"""
    # creates discord bot object (with member intents enabled to grab members)
    intents = discord.Intents.default()
    intents.members = True
    bot = commands.Bot(intents=intents,
                       command_prefix="!",
                       case_insensitive=True)
    # add command cogs to bot
    bot.add_cog(Librarian(paywalled_sites))  # archive is commands and listener
    bot.add_cog(RateLimiter())  # gripe at sal and aj when they fight
    bot.add_cog(Utes())  # calc and gif
    bot.add_cog(Creeper(bot))  # listen to say weird things
    bot.add_cog(Wordle(bot))  # calculate wordle stats
    bot.add_cog(Collector(bot))  # aggregate yee data
    # run the bot
    bot.run(token)