diff --git a/youmubot-osu/src/discord/announcer.rs b/youmubot-osu/src/discord/announcer.rs index fbb2eec..e88f2bd 100644 --- a/youmubot-osu/src/discord/announcer.rs +++ b/youmubot-osu/src/discord/announcer.rs @@ -9,15 +9,16 @@ use crate::{ Client as Osu, }; use announcer::MemberToChannels; +use serenity::builder::CreateMessage; use serenity::{ http::CacheHttp, model::{ channel::Message, id::{ChannelId, UserId}, }, - CacheAndHttp, }; use std::{convert::TryInto, sync::Arc}; +use youmubot_prelude::announcer::CacheAndHttp; use youmubot_prelude::*; /// osu! announcer's unique announcer key. @@ -38,7 +39,7 @@ impl Announcer { impl youmubot_prelude::Announcer for Announcer { async fn updates( &mut self, - c: Arc, + c: CacheAndHttp, d: AppData, channels: MemberToChannels, ) -> Result<()> { @@ -189,7 +190,7 @@ impl Announcer { #[derive(Clone)] struct Context { data: AppData, - c: Arc, + c: CacheAndHttp, } struct CollectedScore<'a> { @@ -291,31 +292,33 @@ impl<'a> CollectedScore<'a> { } }; let m = channel - .send_message(ctx.c.http(), |c| { - c.content(match self.kind { - ScoreType::TopRecord(_) => { - format!("New top record from {}!", self.discord_user.mention()) - } - ScoreType::WorldRecord(rank) => { - if rank <= 100 { - format!( - "New leaderboard record from {}!", - self.discord_user.mention() - ) - } else { - format!("New leaderboard record from **{}**!", member.distinct()) + .send_message( + ctx.c.http(), + CreateMessage::new() + .content(match self.kind { + ScoreType::TopRecord(_) => { + format!("New top record from {}!", self.discord_user.mention()) } - } - }) - .embed(|e| { - let mut b = score_embed(&self.score, bm, content, self.user); - match self.kind { - ScoreType::TopRecord(rank) => b.top_record(rank), - ScoreType::WorldRecord(rank) => b.world_record(rank), - } - .build(e) - }) - }) + ScoreType::WorldRecord(rank) => { + if rank <= 100 { + format!( + "New leaderboard record from {}!", + self.discord_user.mention() + ) + } else { + format!("New leaderboard record from **{}**!", member.distinct()) + } + } + }) + .embed({ + let mut b = score_embed(&self.score, bm, content, self.user); + match self.kind { + ScoreType::TopRecord(rank) => b.top_record(rank), + ScoreType::WorldRecord(rank) => b.world_record(rank), + } + .build() + }), + ) .await?; save_beatmap(&*ctx.data.read().await, channel, bm) .await diff --git a/youmubot-osu/src/discord/db.rs b/youmubot-osu/src/discord/db.rs index ddb2c21..9f8c2cf 100644 --- a/youmubot-osu/src/discord/db.rs +++ b/youmubot-osu/src/discord/db.rs @@ -37,7 +37,7 @@ impl OsuSavedUsers { /// Get an user by their user_id. pub async fn by_user_id(&self, user_id: UserId) -> Result> { let mut conn = self.pool.acquire().await?; - let u = model::OsuUser::by_user_id(user_id.0 as i64, &mut *conn) + let u = model::OsuUser::by_user_id(user_id.get() as i64, &mut *conn) .await? .map(OsuUser::from); Ok(u) @@ -52,7 +52,7 @@ impl OsuSavedUsers { /// Save the given user as a completely new user. pub async fn new_user(&self, u: OsuUser) -> Result<()> { let mut t = self.pool.begin().await?; - model::OsuUser::delete(u.user_id.0 as i64, &mut *t).await?; + model::OsuUser::delete(u.user_id.get() as i64, &mut *t).await?; model::OsuUser::from(u).store(&mut *t).await?; t.commit().await?; Ok(()) @@ -74,7 +74,8 @@ impl OsuLastBeatmap { impl OsuLastBeatmap { pub async fn by_channel(&self, id: impl Into) -> Result> { - let last_beatmap = models::LastBeatmap::by_channel_id(id.into().0 as i64, &self.0).await?; + let last_beatmap = + models::LastBeatmap::by_channel_id(id.into().get() as i64, &self.0).await?; Ok(match last_beatmap { Some(lb) => Some((bincode::deserialize(&lb.beatmap[..])?, lb.mode.into())), None => None, @@ -88,7 +89,7 @@ impl OsuLastBeatmap { mode: Mode, ) -> Result<()> { let b = models::LastBeatmap { - channel_id: channel.into().0 as i64, + channel_id: channel.into().get() as i64, beatmap: bincode::serialize(beatmap)?, mode: mode as u8, }; @@ -121,7 +122,7 @@ impl OsuUserBests { scores .into_iter() .map(|score| models::UserBestScore { - user_id: user.0 as i64, + user_id: user.get() as i64, beatmap_id: score.beatmap_id as i64, mode: mode as u8, mods: score.mods.bits() as i64, @@ -151,7 +152,7 @@ pub struct OsuUser { impl From for model::OsuUser { fn from(u: OsuUser) -> Self { Self { - user_id: u.user_id.0 as i64, + user_id: u.user_id.get() as i64, username: Some(u.username.into_owned()), id: u.id as i64, last_update: u.last_update, @@ -167,7 +168,7 @@ impl From for model::OsuUser { impl From for OsuUser { fn from(u: model::OsuUser) -> Self { Self { - user_id: UserId(u.user_id as u64), + user_id: UserId::new(u.user_id as u64), username: u.username.map(Cow::Owned).unwrap_or("unknown".into()), id: u.id as u64, last_update: u.last_update, diff --git a/youmubot-osu/src/discord/display.rs b/youmubot-osu/src/discord/display.rs index ef9491c..8efea59 100644 --- a/youmubot-osu/src/discord/display.rs +++ b/youmubot-osu/src/discord/display.rs @@ -51,6 +51,7 @@ mod scores { cache::save_beatmap, BeatmapCache, BeatmapMetaCache, BeatmapWithMode, }; use crate::models::{Mode, Score}; + use serenity::builder::EditMessage; use serenity::{framework::standard::CommandResult, model::channel::Message}; use youmubot_prelude::*; @@ -100,13 +101,14 @@ mod scores { .await? .ok_or_else(|| Error::msg("user not found"))?; - msg.edit(ctx, |e| { - e.embed(|e| { + msg.edit( + ctx, + EditMessage::new().embed({ crate::discord::embeds::score_embed(score, &bm, &content, &user) .footer(format!("Page {}/{}", page + 1, self.scores.len())) - .build(e) - }) - }) + .build() + }), + ) .await?; save_beatmap(&*ctx.data.read().await, msg.channel_id, &bm).await?; @@ -127,6 +129,7 @@ mod scores { use crate::discord::oppai_cache::Accuracy; use crate::discord::{Beatmap, BeatmapCache, BeatmapInfo, BeatmapMetaCache}; use crate::models::{Mode, Score}; + use serenity::builder::EditMessage; use serenity::{framework::standard::CommandResult, model::channel::Message}; use youmubot_prelude::*; @@ -327,7 +330,7 @@ mod scores { self.total_pages() )); m.push_line("[?] means pp was predicted by oppai-rs."); - msg.edit(ctx, |f| f.content(m.to_string())).await?; + msg.edit(ctx, EditMessage::new().content(m.to_string())).await?; hourglass.delete(ctx).await?; Ok(true) } @@ -347,7 +350,7 @@ mod beatmapset { models::{Beatmap, Mode, Mods}, }; use serenity::{ - collector::ReactionAction, model::channel::Message, model::channel::ReactionType, + model::channel::Message, model::channel::ReactionType, all::Reaction, builder::{EditMessage, CreateEmbedFooter}, }; use youmubot_prelude::*; @@ -418,11 +421,12 @@ mod beatmapset { ) -> Result { let page = page as usize; if page == self.maps.len() { - m.edit(ctx, |f| { - f.embed(|em| { - crate::discord::embeds::beatmapset_embed(&self.maps[..], self.mode, em) - }) - }) + m.edit(ctx, + EditMessage::new().embed(crate::discord::embeds::beatmapset_embed( + &self.maps[..], + self.mode, + )) + ) .await?; return Ok(true); } @@ -439,25 +443,24 @@ mod beatmapset { info } }; - m.edit(ctx, |e| { - e.content(self.message.as_str()).embed(|em| { + m.edit(ctx, + EditMessage::new().content(self.message.as_str()).embed( crate::discord::embeds::beatmap_embed( map, self.mode.unwrap_or(map.mode), self.mods, info, - em, ) - .footer(|f| { - f.text(format!( + .footer( { + CreateEmbedFooter::new(format!( "Difficulty {}/{}. To show all difficulties in a single embed (old style), react {}", page + 1, self.maps.len(), SHOW_ALL_EMOTE, )) }) - }) - }) + ) + ) .await?; save_beatmap( &*ctx.data.read().await, @@ -485,13 +488,10 @@ mod beatmapset { page: u8, ctx: &Context, message: &mut serenity::model::channel::Message, - reaction: &ReactionAction, + reaction: &Reaction, ) -> Result> { // Render the old style. - let v = match reaction { - ReactionAction::Added(v) | ReactionAction::Removed(v) => v, - }; - if let ReactionType::Unicode(s) = &v.emoji { + if let ReactionType::Unicode(s) = &reaction.emoji { if s == SHOW_ALL_EMOTE { self.render(self.maps.len() as u8, ctx, message).await?; return Ok(Some(self.maps.len() as u8)); diff --git a/youmubot-osu/src/discord/embeds.rs b/youmubot-osu/src/discord/embeds.rs index 2db8bdf..667a44c 100644 --- a/youmubot-osu/src/discord/embeds.rs +++ b/youmubot-osu/src/discord/embeds.rs @@ -3,12 +3,13 @@ use crate::{ discord::oppai_cache::{Accuracy, BeatmapContent, BeatmapInfo, BeatmapInfoWithPP}, models::{Beatmap, Difficulty, Mode, Mods, Rank, Score, User}, }; -use serenity::{builder::CreateEmbed, utils::MessageBuilder}; +use serenity::{ + builder::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter}, + utils::MessageBuilder, +}; use std::time::Duration; use youmubot_prelude::*; -type CreateEmbedFn = dyn FnOnce(&mut CreateEmbed) -> &mut CreateEmbed + Send + Sync; - /// Writes a number grouped in groups of 3. pub(crate) fn grouped_number(num: u64) -> String { let s = num.to_string(); @@ -24,7 +25,7 @@ pub(crate) fn grouped_number(num: u64) -> String { fn beatmap_description(b: &Beatmap) -> String { MessageBuilder::new() - .push_bold_line(b.approval) + .push_bold_line(b.approval.to_string()) .push({ let link = b.download_link(false); format!( @@ -36,9 +37,9 @@ fn beatmap_description(b: &Beatmap) -> String { }) .push_line(format!(" [[Beatmapset]]({})", b.beatmapset_link())) .push("Language: ") - .push_bold(b.language) + .push_bold(b.language.to_string()) .push(" | Genre: ") - .push_bold_line(b.genre) + .push_bold_line(b.genre.to_string()) .push( b.source .as_ref() @@ -62,7 +63,7 @@ pub fn beatmap_offline_embed( b: &'_ crate::discord::oppai_cache::BeatmapContent, m: Mode, mods: Mods, -) -> Result> { +) -> Result { let bm = b.content.clone(); let metadata = b.metadata.clone(); let (info, pp) = b.get_possible_pp_with(m, mods)?; @@ -93,29 +94,29 @@ pub fn beatmap_offline_embed( total_length, } .apply_mods(mods, info.stars); - Ok(Box::new(move |c: &mut CreateEmbed| { - c.title(beatmap_title( - &metadata.artist, - &metadata.title, - &metadata.version, - mods, - )) - .author(|a| { - a.name(&metadata.creator) - .url(format!("https://osu.ppy.sh/users/{}", metadata.creator)) - }) - .color(0xffb6c1) - .field( - "Calculated pp", - format!( - "95%: **{:.2}**pp, 98%: **{:.2}**pp, 99%: **{:.2}**pp, 100%: **{:.2}**pp", - pp[0], pp[1], pp[2], pp[3] - ), - false, - ) - .field("Information", diff.format_info(m, mods, None), false) - // .description(beatmap_description(b)) - })) + Ok( + CreateEmbed::new() + .title(beatmap_title( + &metadata.artist, + &metadata.title, + &metadata.version, + mods, + )) + .author({ + CreateEmbedAuthor::new(&metadata.creator) + .url(format!("https://osu.ppy.sh/users/{}", metadata.creator)) + }) + .color(0xffb6c1) + .field( + "Calculated pp", + format!( + "95%: **{:.2}**pp, 98%: **{:.2}**pp, 99%: **{:.2}**pp, 100%: **{:.2}**pp", + pp[0], pp[1], pp[2], pp[3] + ), + false, + ) + .field("Information", diff.format_info(m, mods, None), false), // .description(beatmap_description(b)) + ) } // Some helper functions here @@ -148,15 +149,15 @@ pub fn beatmap_embed<'a>( m: Mode, mods: Mods, info: BeatmapInfoWithPP, - c: &'a mut CreateEmbed, -) -> &'a mut CreateEmbed { +) -> CreateEmbed { let diff = b.difficulty.apply_mods(mods, info.0.stars); - c.title(beatmap_title(&b.artist, &b.title, &b.difficulty_name, mods)) - .author(|a| { - a.name(&b.creator) + CreateEmbed::new() + .title(beatmap_title(&b.artist, &b.title, &b.difficulty_name, mods)) + .author( + CreateEmbedAuthor::new(&b.creator) .url(format!("https://osu.ppy.sh/users/{}", b.creator_id)) - .icon_url(format!("https://a.ppy.sh/{}", b.creator_id)) - }) + .icon_url(format!("https://a.ppy.sh/{}", b.creator_id)), + ) .url(b.link()) .image(b.cover_url()) .color(0xffb6c1) @@ -177,54 +178,48 @@ pub fn beatmap_embed<'a>( const MAX_DIFFS: usize = 25 - 4; -pub fn beatmapset_embed<'a>( - bs: &'_ [Beatmap], - m: Option, - c: &'a mut CreateEmbed, -) -> &'a mut CreateEmbed { +pub fn beatmapset_embed<'a>(bs: &'_ [Beatmap], m: Option) -> CreateEmbed { let too_many_diffs = bs.len() > MAX_DIFFS; let b: &Beatmap = &bs[0]; - c.title( - MessageBuilder::new() - .push_bold_safe(&b.artist) - .push(" - ") - .push_bold_safe(&b.title) - .build(), - ) - .author(|a| { - a.name(&b.creator) - .url(format!("https://osu.ppy.sh/users/{}", b.creator_id)) - .icon_url(format!("https://a.ppy.sh/{}", b.creator_id)) - }) - .url(format!( - "https://osu.ppy.sh/beatmapsets/{}", - b.beatmapset_id, - )) - .image(format!( - "https://assets.ppy.sh/beatmaps/{}/covers/cover.jpg", - b.beatmapset_id - )) - .color(0xffb6c1) - .description(beatmap_description(b)) - .footer(|f| { - if too_many_diffs { - f.text(format!( - "This map has {} diffs, we are showing the last {}.", - bs.len(), - MAX_DIFFS - )) - } else { - f - } - }) - .fields(bs.iter().rev().take(MAX_DIFFS).rev().map(|b: &Beatmap| { - ( - format!("[{}]", b.difficulty_name), - b.difficulty - .format_info(m.unwrap_or(b.mode), Mods::NOMOD, b), - false, + let mut m = CreateEmbed::new() + .title( + MessageBuilder::new() + .push_bold_safe(&b.artist) + .push(" - ") + .push_bold_safe(&b.title) + .build(), ) - })) + .author( + CreateEmbedAuthor::new(&b.creator) + .url(format!("https://osu.ppy.sh/users/{}", b.creator_id)) + .icon_url(format!("https://a.ppy.sh/{}", b.creator_id)), + ) + .url(format!( + "https://osu.ppy.sh/beatmapsets/{}", + b.beatmapset_id, + )) + .image(format!( + "https://assets.ppy.sh/beatmaps/{}/covers/cover.jpg", + b.beatmapset_id + )) + .color(0xffb6c1) + .description(beatmap_description(b)) + .fields(bs.iter().rev().take(MAX_DIFFS).rev().map(|b: &Beatmap| { + ( + format!("[{}]", b.difficulty_name), + b.difficulty + .format_info(m.unwrap_or(b.mode), Mods::NOMOD, b), + false, + ) + })); + if too_many_diffs { + m = m.footer(CreateEmbedFooter::new(format!( + "This map has {} diffs, we are showing the last {}.", + bs.len(), + MAX_DIFFS + ))); + } + m } pub(crate) struct ScoreEmbedBuilder<'a> { @@ -271,7 +266,7 @@ pub(crate) fn score_embed<'a>( impl<'a> ScoreEmbedBuilder<'a> { #[allow(clippy::many_single_char_names)] - pub fn build<'b>(&mut self, m: &'b mut CreateEmbed) -> &'b mut CreateEmbed { + pub fn build<'b>(&mut self) -> CreateEmbed { let mode = self.bm.mode(); let b = &self.bm.0; let s = self.s; @@ -366,7 +361,12 @@ impl<'a> ScoreEmbedBuilder<'a> { } else { format!("by {} ", b.creator) }; - m.author(|f| f.name(&u.username).url(u.link()).icon_url(u.avatar_url())) + let mut m = CreateEmbed::new() + .author( + CreateEmbedAuthor::new(&u.username) + .url(u.link()) + .icon_url(u.avatar_url()), + ) .color(0xffb6c1) .title( MessageBuilder::new() @@ -378,7 +378,7 @@ impl<'a> ScoreEmbedBuilder<'a> { .push(" [") .push_safe(&b.difficulty_name) .push("] ") - .push(s.mods) + .push(s.mods.to_string()) .push(" ") .push(format!("({:.2}\\*)", stars)) .push(" ") @@ -420,7 +420,7 @@ impl<'a> ScoreEmbedBuilder<'a> { footer += " Star difficulty does not reflect game mods."; } if !footer.is_empty() { - m.footer(|f| f.text(footer)); + m = m.footer(CreateEmbedFooter::new(footer)); } m } @@ -429,9 +429,9 @@ impl<'a> ScoreEmbedBuilder<'a> { pub(crate) fn user_embed( u: User, best: Option<(Score, BeatmapWithMode, BeatmapInfo)>, - m: &mut CreateEmbed, -) -> &mut CreateEmbed { - m.title(MessageBuilder::new().push_safe(u.username).build()) +) -> CreateEmbed { + CreateEmbed::new() + .title(MessageBuilder::new().push_safe(u.username).build()) .url(format!("https://osu.ppy.sh/users/{}", u.id)) .color(0xffb6c1) .thumbnail(format!("https://a.ppy.sh/{}", u.id)) @@ -494,7 +494,7 @@ pub(crate) fn user_embed( v.pp.unwrap() /*Top record should have pp*/ )) .push(" - ") - .push_line(v.date.format("")) + .push_line(v.date.format("").to_string()) .push("on ") .push_line(format!( "[{} - {} [{}]]({})**{} **", diff --git a/youmubot-osu/src/discord/hook.rs b/youmubot-osu/src/discord/hook.rs index a579cc0..da33442 100644 --- a/youmubot-osu/src/discord/hook.rs +++ b/youmubot-osu/src/discord/hook.rs @@ -5,7 +5,7 @@ use crate::{ }; use lazy_static::lazy_static; use regex::Regex; -use serenity::{builder::CreateEmbed, model::channel::Message, utils::MessageBuilder}; +use serenity::{builder::CreateMessage, model::channel::Message, utils::MessageBuilder}; use std::str::FromStr; use youmubot_prelude::*; @@ -46,17 +46,12 @@ pub fn dot_osu_hook<'a>( let data = ctx.data.read().await; let oppai = data.get::().unwrap(); let (beatmap, _) = oppai.download_beatmap_from_url(&url).await.ok()?; - let embed_fn = crate::discord::embeds::beatmap_offline_embed( + crate::discord::embeds::beatmap_offline_embed( &beatmap, Mode::from(beatmap.content.mode as u8), /*For now*/ msg.content.trim().parse().unwrap_or(Mods::NOMOD), ) - .ok()?; - - let mut create_embed = CreateEmbed::default(); - embed_fn(&mut create_embed); - - Some(create_embed) + .pls_ok() } }) .collect::>() @@ -80,16 +75,12 @@ pub fn dot_osu_hook<'a>( beatmaps .into_iter() .filter_map(|beatmap| { - let embed_fn = crate::discord::embeds::beatmap_offline_embed( + crate::discord::embeds::beatmap_offline_embed( &beatmap, Mode::from(beatmap.content.mode as u8), /*For now*/ msg.content.trim().parse().unwrap_or(Mods::NOMOD), ) - .pls_ok()?; - - let mut create_embed = CreateEmbed::default(); - embed_fn(&mut create_embed); - Some(create_embed) + .pls_ok() }) .collect::>(), ) @@ -105,11 +96,13 @@ pub fn dot_osu_hook<'a>( if !osu_embeds.is_empty() { msg.channel_id - .send_message(ctx, |f| { - f.reference_message(msg) + .send_message( + ctx, + CreateMessage::new() + .reference_message(msg) .content(format!("{} attached beatmaps found", osu_embeds.len())) - .add_embeds(osu_embeds) - }) + .add_embeds(osu_embeds), + ) .await .ok(); } @@ -387,16 +380,23 @@ async fn handle_beatmap<'a, 'b>( ) -> Result<()> { reply_to .channel_id - .send_message(ctx, |m| { - m.content( - MessageBuilder::new() - .push("Beatmap information for ") - .push_mono_safe(link) - .build(), - ) - .embed(|b| beatmap_embed(beatmap, mode.unwrap_or(beatmap.mode), mods, info, b)) - .reference_message(reply_to) - }) + .send_message( + ctx, + CreateMessage::new() + .content( + MessageBuilder::new() + .push("Beatmap information for ") + .push_mono_safe(link) + .build(), + ) + .embed(beatmap_embed( + beatmap, + mode.unwrap_or(beatmap.mode), + mods, + info, + )) + .reference_message(reply_to), + ) .await?; Ok(()) } diff --git a/youmubot-osu/src/discord/mod.rs b/youmubot-osu/src/discord/mod.rs index ecacc4f..93c27df 100644 --- a/youmubot-osu/src/discord/mod.rs +++ b/youmubot-osu/src/discord/mod.rs @@ -8,7 +8,8 @@ use crate::{ }; use rand::seq::IteratorRandom; use serenity::{ - collector::{CollectReaction, ReactionAction}, + builder::{CreateMessage, EditMessage}, + collector, framework::standard::{ macros::{command, group}, Args, CommandResult, @@ -237,27 +238,26 @@ pub async fn save(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult .get_possible_pp_with(mode, Mods::NOMOD)?; let mut reply = reply.await?; reply - .edit(&ctx, |f| { - f.embed(|e| beatmap_embed(&beatmap, mode, Mods::NOMOD, info, e)) - }) + .edit( + &ctx, + EditMessage::new().embed(beatmap_embed(&beatmap, mode, Mods::NOMOD, info)), + ) .await?; let reaction = reply.react(&ctx, '👌').await?; let completed = loop { let emoji = reaction.emoji.clone(); - let user_reaction = CollectReaction::new(ctx) - .message_id(reply.id.0) - .author_id(msg.author.id.0) + let user_reaction = collector::ReactionCollector::new(&ctx) + .message_id(reply.id) + .author_id(msg.author.id) .filter(move |r| r.emoji == emoji) .timeout(std::time::Duration::from_secs(300)) - .collect_limit(1) + .next() .await; if let Some(ur) = user_reaction { if check(osu, &u, score.beatmap_id).await? { break true; } - if let ReactionAction::Added(ur) = &*ur { - ur.delete(&ctx).await?; - } + ur.delete(&ctx).await?; } else { break false; } @@ -423,13 +423,13 @@ pub async fn recent(ctx: &Context, msg: &Message, mut args: Args) -> CommandResu let beatmap_mode = BeatmapWithMode(beatmap, mode); msg.channel_id - .send_message(&ctx, |m| { - m.content("Here is the play that you requested".to_string()) - .embed(|m| { - score_embed(&recent_play, &beatmap_mode, &content, &user).build(m) - }) - .reference_message(msg) - }) + .send_message( + &ctx, + CreateMessage::new() + .content("Here is the play that you requested".to_string()) + .embed(score_embed(&recent_play, &beatmap_mode, &content, &user).build()) + .reference_message(msg), + ) .await?; // Save the beatmap... @@ -549,11 +549,13 @@ pub async fn last(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult .await? .get_possible_pp_with(m, mods)?; msg.channel_id - .send_message(&ctx, |f| { - f.content("Here is the beatmap you requested!") - .embed(|c| beatmap_embed(&b, m, mods, info, c)) - .reference_message(msg) - }) + .send_message( + &ctx, + CreateMessage::new() + .content("Here is the beatmap you requested!") + .embed(beatmap_embed(&b, m, mods, info)) + .reference_message(msg), + ) .await?; } None => { @@ -671,16 +673,17 @@ pub async fn top(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult let beatmap = BeatmapWithMode(beatmap, mode); msg.channel_id - .send_message(&ctx, |m| { - m.content(format!( - "{}: here is the play that you requested", - msg.author - )) - .embed(|m| { - score_embed(&top_play, &beatmap, &content, &user) - .top_record(rank) - .build(m) - }) + .send_message(&ctx, { + CreateMessage::new() + .content(format!( + "{}: here is the play that you requested", + msg.author + )) + .embed( + score_embed(&top_play, &beatmap, &content, &user) + .top_record(rank) + .build(), + ) }) .await?; @@ -740,13 +743,15 @@ async fn get_user(ctx: &Context, msg: &Message, mut args: Args, mode: Mode) -> C None => None, }; msg.channel_id - .send_message(&ctx, |m| { - m.content(format!( - "{}: here is the user that you requested", - msg.author - )) - .embed(|m| user_embed(u, best, m)) - }) + .send_message( + &ctx, + CreateMessage::new() + .content(format!( + "{}: here is the user that you requested", + msg.author + )) + .embed(user_embed(u, best)), + ) .await?; } None => { diff --git a/youmubot-osu/src/discord/server_rank.rs b/youmubot-osu/src/discord/server_rank.rs index de503b3..dd639db 100644 --- a/youmubot-osu/src/discord/server_rank.rs +++ b/youmubot-osu/src/discord/server_rank.rs @@ -11,6 +11,7 @@ use crate::{ }; use serenity::{ + builder::EditMessage, framework::standard::{macros::command, Args, CommandResult}, model::channel::Message, utils::MessageBuilder, @@ -141,7 +142,8 @@ pub async fn server_rank(ctx: &Context, m: &Message, mut args: Args) -> CommandR (total_len + ITEMS_PER_PAGE - 1) / ITEMS_PER_PAGE, last_update.format(""), )); - m.edit(ctx, |f| f.content(content.to_string())).await?; + m.edit(ctx, EditMessage::new().content(content.to_string())) + .await?; Ok(true) }) }, @@ -434,7 +436,7 @@ pub async fn show_leaderboard(ctx: &Context, m: &Message, mut args: Args) -> Com content.push_line("PP was calculated by `oppai-rs`, **not** official values."); } - m.edit(&ctx, |f| f.content(content.build())).await?; + m.edit(&ctx, EditMessage::new().content(content.build())).await?; Ok(true) }) },