Skip to content

Use LinePaginator from bot-core #2682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed

Use LinePaginator from bot-core #2682

wants to merge 18 commits into from

Conversation

shtlrs
Copy link
Member

@shtlrs shtlrs commented Jul 14, 2023

This works in conjunction with bot-core#189

It serves as an example of how the new client code consuming bot-core's LinePaginator would look like.

bot/constants.py Outdated
@@ -702,3 +703,5 @@ class _Keys(EnvConfig):
"Noooooo!!",
"I can't believe you've done this",
]

PaginationEmojis = PaginationEmojisSettings()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is using defaults, wouldn't it be better for the paginator to use those settings by default? Meaning, you wouldn't need to explicitly send it settings for it to work, only when you want to use something custom. This will save another import and function arg every time you want to you the paginator.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire problem lies within the trashcan. It's the thing that causes problems for contribs, since that emoji is only available in our server.

So if you don't pass those to the paginator when you're running bot, the paginator will crash since you can't use that emoji.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case, it might be better to just use https://emojipedia.org/wastebasket/ instead, to avoid all those problems.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean use it in our server as well ?
Tbh, I didn't consider that as an option, as I thought it was put in place on purpose.

If we were to use that, then we wouldn't be needing the pydnatinc model, import & extra parameter indeed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, not sure why we decided on the custom emoji instead of this unicode one. We also have the option to use https://emojipedia.org/stop-sign/ too. Using a unicode emoji would remove a lot of hassle.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant class method *

Well, i don't remember what it does specifically now but I'll see what I can do about it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wookie184

Hey ! I'm trying to pick this up again and I was wondering what you meant exactly by

One simple way around this for now would be to just create a wrapper here that passes in the necessary constants and we can just use that instead. In the future we may want to think of other ways we can have configuration for bot-core.

Do you mean that we'd keep the pagination emojis as part of the parameters, and then make a decorator that will pass them for us ?
Something like

def pass_parameters(**kwargs_to_pass):
    def inner(func):
         def wrapper(*args, **kwargs):
              kwargs.update(kwargs_to_pass)
              return func(*args, **kwargs)
          retun wrapper
    return inner

Then we'd decorate the paginate method and pass the emojis using the previous deco ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we could replace bot/pagination.py with something like this

from pydis_core import LinePaginator as _LinePaginator
...

PaginationEmojis = PaginationEmojisModel(delete=Emojis.trashcan)

class LinePaginator(_LinePaginator):
    @classmethod
    async def paginate(cls, *args, **kwargs) -> discord.Message | None:
        return await super().paginate(PaginationEmojis, *args, **kwargs)

then we wouldn't need to update any imports either.

The main annoying thing there is by using "*args" and "**kwargs" you lose hints in the editor about what the arguments are and what types you can pass. Not sure if there's a nice way around that other than just copying the parameter list.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you meant that kind of wrapper.
Okay, I see.

Not sure if there's a nice way around that other than just copying the parameter list.
Don't think there is, even with PEP 692 it wouldn't be quite feasible.

I think just copying the parameter list is fine, this will be used by us only, and anyone who wishes to not used the default emojis we provide can fallback to _LinePaginator

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wookie184 Implemented in #2879

@shtlrs shtlrs marked this pull request as ready for review July 19, 2023 23:50
@shtlrs shtlrs force-pushed the use-bot-core-paginator branch from 4749e68 to 432e5e5 Compare July 19, 2023 23:51
@shtlrs shtlrs force-pushed the use-bot-core-paginator branch from 432e5e5 to 84c04e9 Compare July 20, 2023 00:12
@shtlrs shtlrs force-pushed the use-bot-core-paginator branch from 76505e4 to 43e3ce7 Compare July 21, 2023 16:56
@wookie184 wookie184 added the s: waiting for author Waiting for author to address a review or respond to a comment label Aug 31, 2023
@shtlrs
Copy link
Member Author

shtlrs commented Jan 4, 2024

Superseded by #2879

@shtlrs shtlrs closed this Jan 4, 2024
@hedyhli hedyhli deleted the use-bot-core-paginator branch March 11, 2024 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s: waiting for author Waiting for author to address a review or respond to a comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants