mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-24 01:00:49 +00:00
Implement Flags parser and handle choose --everyone
- A generic Flags parser that could handle any `--flag` argument. - `choose --everyone` overrides the Offline/DnD check.
This commit is contained in:
parent
2449b09cb2
commit
2c2092eb91
3 changed files with 46 additions and 0 deletions
|
@ -51,6 +51,7 @@ Note that only online/idle users in the channel are chosen from."]
|
|||
#[bucket = "community"]
|
||||
#[max_args(2)]
|
||||
pub async fn choose(ctx: &Context, m: &Message, mut args: Args) -> CommandResult {
|
||||
let flags = Flags::collect_from(&mut args);
|
||||
let role = args.find::<RoleId>().ok();
|
||||
let title = if args.is_empty() {
|
||||
"the chosen one".to_owned()
|
||||
|
@ -58,6 +59,8 @@ pub async fn choose(ctx: &Context, m: &Message, mut args: Args) -> CommandResult
|
|||
args.single::<String>()?
|
||||
};
|
||||
|
||||
let online_only = !flags.contains("everyone");
|
||||
|
||||
let users: Result<Vec<_>, Error> = {
|
||||
let guild = m.guild(&ctx).await.unwrap();
|
||||
let presences = &guild.presences;
|
||||
|
@ -69,6 +72,9 @@ pub async fn choose(ctx: &Context, m: &Message, mut args: Args) -> CommandResult
|
|||
.into_iter()
|
||||
.filter(|v| !v.user.bot) // Filter out bots
|
||||
.filter(|v| {
|
||||
if !online_only {
|
||||
return true;
|
||||
}
|
||||
// Filter out only online people
|
||||
presences
|
||||
.get(&v.user.id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue