osu updatelb command (#8)

* Make `paginate` take a Paginate trait impl, while `paginate_fn` takes a function

* Add `updatelb` command

* Implement a member cache

* Update member queries to use member cache

* Allow everyone to updatelb
This commit is contained in:
Natsu Kagami 2020-11-23 02:26:18 -05:00 committed by GitHub
parent b8471152d3
commit 6bf2779d61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 241 additions and 47 deletions

View file

@ -14,7 +14,7 @@ const ARROW_RIGHT: &'static str = "➡️";
const ARROW_LEFT: &'static str = "⬅️";
#[async_trait::async_trait]
pub trait Paginate {
pub trait Paginate: Send {
async fn render(&mut self, page: u8, ctx: &Context, m: &mut Message) -> Result<bool>;
}
@ -36,12 +36,7 @@ where
// Paginate! with a pager function.
/// If awaited, will block until everything is done.
pub async fn paginate(
mut pager: impl for<'m> FnMut(
u8,
&'m Context,
&'m mut Message,
) -> std::pin::Pin<Box<dyn Future<Output = Result<bool>> + Send + 'm>>
+ Send,
mut pager: impl Paginate,
ctx: &Context,
channel: ChannelId,
timeout: std::time::Duration,
@ -56,7 +51,7 @@ pub async fn paginate(
message
.react(&ctx, ReactionType::try_from(ARROW_RIGHT)?)
.await?;
pager(0, ctx, &mut message).await?;
pager.render(0, ctx, &mut message).await?;
// Build a reaction collector
let mut reaction_collector = message.await_reactions(&ctx).removed(true).await;
let mut page = 0;
@ -80,6 +75,21 @@ pub async fn paginate(
res
}
/// Same as `paginate`, but for function inputs, especially anonymous functions.
pub async fn paginate_fn(
pager: impl for<'m> FnMut(
u8,
&'m Context,
&'m mut Message,
) -> std::pin::Pin<Box<dyn Future<Output = Result<bool>> + Send + 'm>>
+ Send,
ctx: &Context,
channel: ChannelId,
timeout: std::time::Duration,
) -> Result<()> {
paginate(pager, ctx, channel, timeout).await
}
// Handle the reaction and return a new page number.
async fn handle_reaction(
page: u8,