mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-24 17:20:49 +00:00
Update to Tokio 1 and Serenity 0.10 (#9)
This commit is contained in:
parent
40f6c6e553
commit
901d55814d
19 changed files with 238 additions and 281 deletions
|
@ -96,11 +96,7 @@ async fn update_user(
|
|||
e.content(format!("Rating change for {}!", user_id.mention()))
|
||||
.embed(|c| {
|
||||
crate::embed::rating_change_embed(
|
||||
&rc,
|
||||
&info,
|
||||
&contest,
|
||||
&user_id.mention(),
|
||||
c,
|
||||
&rc, &info, &contest, user_id, c,
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -2,6 +2,7 @@ use codeforces::{Contest, RatingChange, User};
|
|||
use inflector::Inflector;
|
||||
use serenity::{builder::CreateEmbed, utils::MessageBuilder};
|
||||
use std::borrow::Borrow;
|
||||
use youmubot_prelude::*;
|
||||
|
||||
fn unwrap_or_ref<'a, T: ?Sized, B: Borrow<T>>(opt: &'a Option<B>, default: &'a T) -> &'a T {
|
||||
opt.as_ref().map(|v| v.borrow()).unwrap_or(default)
|
||||
|
@ -59,14 +60,14 @@ pub fn rating_change_embed<'a>(
|
|||
rating_change: &RatingChange,
|
||||
user: &User,
|
||||
contest: &Contest,
|
||||
tag: &str,
|
||||
user_id: serenity::model::id::UserId,
|
||||
e: &'a mut CreateEmbed,
|
||||
) -> &'a mut CreateEmbed {
|
||||
let delta = (rating_change.new_rating as i64) - (rating_change.old_rating as i64);
|
||||
let color = if delta < 0 { 0xff0000 } else { 0x00ff00 };
|
||||
let message = if delta > 0 {
|
||||
MessageBuilder::new()
|
||||
.push(tag)
|
||||
.push(user_id.mention())
|
||||
.push(" competed in ")
|
||||
.push_bold_safe(&contest.name)
|
||||
.push(", gaining ")
|
||||
|
@ -77,7 +78,7 @@ pub fn rating_change_embed<'a>(
|
|||
.build()
|
||||
} else {
|
||||
MessageBuilder::new()
|
||||
.push(tag)
|
||||
.push(user_id.mention())
|
||||
.push(" competed in ")
|
||||
.push_bold_safe(&contest.name)
|
||||
.push(", but lost ")
|
||||
|
|
|
@ -33,8 +33,7 @@ pub use hook::InfoHook;
|
|||
pub async fn setup(path: &std::path::Path, data: &mut TypeMap, announcers: &mut AnnouncerHandler) {
|
||||
CfSavedUsers::insert_into(data, path.join("cf_saved_users.yaml"))
|
||||
.expect("Must be able to set up DB");
|
||||
let http = data.get::<HTTPClient>().unwrap();
|
||||
let client = Arc::new(codeforces::Client::new(http.clone()));
|
||||
let client = Arc::new(codeforces::Client::new());
|
||||
data.insert::<hook::ContestCache>(hook::ContestCache::new(client.clone()).await.unwrap());
|
||||
data.insert::<CFClient>(client);
|
||||
announcers.add("codeforces", announcer::Announcer);
|
||||
|
|
|
@ -84,7 +84,7 @@ pub async fn watch_contest(
|
|||
break;
|
||||
}
|
||||
// Sleep for a minute
|
||||
tokio::time::delay_for(std::time::Duration::from_secs(60)).await;
|
||||
tokio::time::sleep(std::time::Duration::from_secs(60)).await;
|
||||
}
|
||||
|
||||
// Announce the final results
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue