mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-24 09:10:49 +00:00
Improvements for voting
- Voting no longer tries to react all at once, creating unneeded congestion. This also has the added benefits of having the options laid out in order. - Include relative timestamps in the embed and the result.
This commit is contained in:
parent
68da7c3f4d
commit
9ac8683c5d
1 changed files with 11 additions and 12 deletions
|
@ -84,13 +84,15 @@ pub async fn vote(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult
|
||||||
// Ok... now we post up a nice voting panel.
|
// Ok... now we post up a nice voting panel.
|
||||||
let channel = msg.channel_id;
|
let channel = msg.channel_id;
|
||||||
let author = msg.author.clone();
|
let author = msg.author.clone();
|
||||||
|
let asked = msg.timestamp;
|
||||||
|
let until = asked + (chrono::Duration::from_std(*duration).unwrap());
|
||||||
let panel = channel.send_message(&ctx, |c| {
|
let panel = channel.send_message(&ctx, |c| {
|
||||||
c.content("@here").embed(|e| {
|
c.content("@here").embed(|e| {
|
||||||
e.author(|au| {
|
e.author(|au| {
|
||||||
au.icon_url(author.avatar_url().unwrap_or_else(|| "".to_owned()))
|
au.icon_url(author.avatar_url().unwrap_or_else(|| "".to_owned()))
|
||||||
.name(&author.name)
|
.name(&author.name)
|
||||||
})
|
})
|
||||||
.title(format!("You have {} to vote!", _duration))
|
.title(format!("Please vote! Poll ends {}", until.format("<t:%s:R>")))
|
||||||
.thumbnail("https://images-ext-2.discordapp.net/external/BK7injOyt4XT8yNfbCDV4mAkwoRy49YPfq-3IwCc_9M/http/cdn.i.ntere.st/p/9197498/image")
|
.thumbnail("https://images-ext-2.discordapp.net/external/BK7injOyt4XT8yNfbCDV4mAkwoRy49YPfq-3IwCc_9M/http/cdn.i.ntere.st/p/9197498/image")
|
||||||
.description(MessageBuilder::new().push_bold_line_safe(&question).push("\nThis question was asked by ").push(author.mention()))
|
.description(MessageBuilder::new().push_bold_line_safe(&question).push("\nThis question was asked by ").push(author.mention()))
|
||||||
.fields(fields.into_iter())
|
.fields(fields.into_iter())
|
||||||
|
@ -99,16 +101,12 @@ pub async fn vote(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult
|
||||||
msg.delete(&ctx).await?;
|
msg.delete(&ctx).await?;
|
||||||
|
|
||||||
// React on all the choices
|
// React on all the choices
|
||||||
choices
|
for (emote, _) in &choices {
|
||||||
.iter()
|
|
||||||
.map(|(emote, _)| {
|
|
||||||
panel
|
panel
|
||||||
.react(&ctx, ReactionType::try_from(&emote[..]).unwrap())
|
.react(&ctx, ReactionType::try_from(&emote[..]).unwrap())
|
||||||
.map_ok(|_| ())
|
.map_ok(|_| ())
|
||||||
})
|
|
||||||
.collect::<stream::FuturesUnordered<_>>()
|
|
||||||
.try_collect::<()>()
|
|
||||||
.await?;
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
// A handler for votes.
|
// A handler for votes.
|
||||||
let user_reactions: Map<String, Set<UserId>> = choices
|
let user_reactions: Map<String, Set<UserId>> = choices
|
||||||
|
@ -178,8 +176,9 @@ pub async fn vote(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult
|
||||||
let mut content = MessageBuilder::new();
|
let mut content = MessageBuilder::new();
|
||||||
content
|
content
|
||||||
.push("@here, ")
|
.push("@here, ")
|
||||||
|
.push(asked.format("<t:%s:R>, "))
|
||||||
.push(author.mention())
|
.push(author.mention())
|
||||||
.push(" previously asked ")
|
.push(" asked ")
|
||||||
.push_bold_safe(&question)
|
.push_bold_safe(&question)
|
||||||
.push(", and here are the results!");
|
.push(", and here are the results!");
|
||||||
result.into_iter().for_each(|(emote, votes)| {
|
result.into_iter().for_each(|(emote, votes)| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue