juniorguru / chick

A real-time, synchronous Junior Guru Discord bot
https://juniorguru-chick.fly.dev/
GNU Affero General Public License v3.0
2 stars 0 forks source link

Suggest a GitHub Connection #32

Closed dariagrudzien closed 1 year ago

dariagrudzien commented 1 year ago

I broke the event loop 💔

When running the new test I get:

tests/test_lib_intro.py:49:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
juniorguru_chick/lib/intro.py:105: in generate_intro_message
    view = ui.View(ui.Button(emoji='📖',
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <View timeout=180.0 children=2>, timeout = 180.0, disable_on_timeout = False
items = (<Button style=<ButtonStyle.link: 5> url='https://junior.guru/handbook/' disabled=False label='Příručka' emoji=<Partia...nior.guru/courses/' disabled=False label='Kurzy' emoji=<PartialEmoji animated=False name='🧑\u200d🏫' id=None> row=None>)

    def __init__(
        self,
        *items: Item,
        timeout: float | None = 180.0,
        disable_on_timeout: bool = False,
    ):
        self.timeout = timeout
        self.disable_on_timeout = disable_on_timeout
        self.children: list[Item] = []
        for func in self.__view_children_items__:
            item: Item = func.__discord_ui_model_type__(
                **func.__discord_ui_model_kwargs__
            )
            item.callback = partial(func, self, item)
            item._view = self
            setattr(self, func.__name__, item)
            self.children.append(item)

        self.__weights = _ViewWeights(self.children)
        for item in items:
            self.add_item(item)

>       loop = asyncio.get_running_loop()
E       RuntimeError: no running event loop

../../../Library/Caches/pypoetry/virtualenvs/juniorguru-chick-woDL3_j3-py3.11/lib/python3.11/site-packages/discord/ui/view.py:183: RuntimeError

I have a feeling this is the line that causes it: https://github.com/juniorguru/juniorguru-chick/blob/daria/github-connections/juniorguru_chick/bot.py#L85 but not really sure why?

honzajavorek commented 1 year ago

I can't see anything wrong in the code. I'll have to try it out.

honzajavorek commented 1 year ago

So it seems just instantiating ui.View() touches the asyncio event loop 🤯 That means one cannot instantiate the object outside of event loop, which is what happens when you test the function. This would bite me too! I'm quite surprised they do this. It's quite annoying as that means the generate_intro_message() isn't really that pure and testable as I thought 😢

dariagrudzien commented 1 year ago

Ah ha! Interesting. I'll refactor tomorrow and try to fix it.

dariagrudzien commented 1 year ago

@honzajavorek Would you mind writing a correct text snippet when you have a moment? No rush.

honzajavorek commented 1 year ago

Hotfix here https://github.com/juniorguru/juniorguru-chick/pull/33

Would you mind writing a correct text snippet when you have a moment? No rush.

Sure, putting to my todo.

dariagrudzien commented 1 year ago

@honzajavorek This feature is ready to deploy, needs correct copy.

honzajavorek commented 1 year ago

Message:

Vidím, že máš **profil na GitHubu**. Když si GitHub propojíš s Discordem, bude tvůj profil viditelnější. Do budoucna navíc chystáme pro lidi s propojeným GitHub profilem spoustu vychytávek <a:yayfrog:976193164471853097>

1. Jdi do [nastavení](https://discord.com/channels/@me)
2. Klikni na Propojení (_Connections_).
3. Přidej GitHub.
honzajavorek commented 1 year ago

For start, I'd do it like this. If there's no mention of GitHub in the intro, then the message looks like this:

Screenshot 2023-10-04 at 12 21 03

If there's a link to GitHub in the intro, then the message should be:

Dík, že se představuješ! Když o tobě víme víc, můžeme ti líp radit <:meowthumbsup:842730599906279494> 

+ Vidím, že máš **profil na GitHubu**. Když si GitHub propojíš s Discordem, bude tvůj profil viditelnější. Do budoucna navíc chystáme pro lidi s propojeným GitHub profilem spoustu vychytávek <a:yayfrog:976193164471853097>
+ 
+ 1. Jdi do [nastavení](https://discord.com/channels/@me)
+ 2. Klikni na Propojení (_Connections_).
+ 3. Přidej GitHub.

Představení můžeš kdyžtak doplnit či změnit přes tři tečky a „Upravit zprávu“ 📝
...

I may fiddle with it later for better structuring or readability, but I wouldn't bother you with this now.

dariagrudzien commented 1 year ago

@honzajavorek I think that I've got it. Is this how you imagined it? Or should the GH version skip the tips at the end to make the message shorter?

image image

honzajavorek commented 1 year ago

I think this is awesome. It is indeed rather long message, but let's not fiddle with that. I'll merge this so that we have the feature in place. I'm curious how many people will trigger it, how they'll react to it, and then we can make changes based on observations.

honzajavorek commented 1 year ago

Ouch 😂 So the dedent wasn't unused 😂

ackward-look-monkey

honzajavorek commented 1 year ago

🎉 Shipping! Unrelated Garfield attached.

garfield-coffee