Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
A simple view-based paginator library for discord.py 2.0. Works with Python 3.8+.
discord-ext-pager is available on PyPI, and as such can be installed using pip.
Users of Danny's discord-ext-menus will find some familiarity in this library. Provided are the following classes:
discord.SelectOption
used for presenting navigation options.The PaginatorView
can be instantiated and used by itself, but page formatting
is handled by subclassing one of the PageSource
base classes.
from typing import List
from discord.ext.pager import ListPageSource, PageSource, PaginatorView
class EmbedListPageSource(ListPageSource[object, PageSource, PaginatorView]):
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# These type parameters denote the page item type,
# source type for page options (demonstrated later),
# and view type. Only needed for static typing.
"""Takes a list of items and formats it in an embed."""
def format_page(self, view: PaginatorView, page: List[object]):
index = self.current_index * self.page_size
description = "\n".join(
f"{i}. {x}"
for i, x in enumerate(page, start=index + 1)
)
return discord.Embed(description=description)
# Anywhere a channel or interaction is available:
fruits = ["🍎 Apple", "🍊 Orange", "🍋 Lemon"]
source = EmbedListPageSource(fruits, page_size=2)
view = PaginatorView(sources=source, timeout=180)
await view.start(interaction)
If the navigation select menu is desired, the get_page_options()
method
should be overridden to return a list of PageOption
objects for the user
to select from:
from typing import List
from discord.ext.pager import ListPageSource, PageOption, PageSource, PaginatorView
class MessageSource(PageSource[str, PageSource, PaginatorView]):
"""A single page for displaying a string."""
def __init__(self, message: str):
super().__init__(current_index=0)
self.message = message
def get_page(self, index: int):
return self.message
def format_page(self, view: PaginatorView, page: str):
# If we don't specify both content and embed, either will
# persist as the user clicks between options
return {"content": page, "embed": None}
class MessageNavigator(ListPageSource[MessageSource, MessageSource, PaginatorView]):
"""A list of messages for the user to select from."""
def get_page_options(self, view: PaginatorView, page: List[MessageSource]):
# PageOption() takes the same arguments as discord.SelectOption,
# except that source= is also required
return [PageOption(source=source, label=source.message) for source in page]
def format_page(self, view: PaginatorView, page: List[MessageSource]):
description = "\n".join(source.message for source in page)
embed = discord.Embed(description=description)
return {"content": None, "embed": embed}
hands = "👈👉👆👇🫵🤞🫰🤘🤙🤛🤜✊👊👋👏🙌"
source = MessageNavigator([MessageSource(s) for s in hands], page_size=5)
view = PaginatorView(sources=source)
await view.start(ctx)
When an option is selected, the PageSource
contained within that option
is appended to PaginatorView.sources
, causing that source to be displayed.
Another button is automatically provided for users to back out to the last
page source. This can be manually triggered by passing a list of page sources
to the PaginatorView(sources=)
argument.
Click on an example below to see its source code:
FAQs
A view-based paginator library for discord.py 2.0
We found that discord-ext-pager demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.