Skip to content

Commit

Permalink
V2.10.0 WIP
Browse files Browse the repository at this point in the history
doing refactor and changing error handling to this error

need to do after list_all_activity.rs
  • Loading branch information
ValgulNecron committed Jul 15, 2024
1 parent 3102cfb commit ff6f5c0
Show file tree
Hide file tree
Showing 26 changed files with 939 additions and 1,004 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ regex = "1.10.5"
reqwest = { version = "0.12.5", features = ["json", "multipart", "blocking"] }
serde = "1.0.204"
serde_json = "1.0.120"
serenity = { git = "https://github.com/serenity-rs/serenity.git", branch = "current", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "utils", "full", "unstable_discord_api"] }
#serenity = { path = "serenity", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "utils", "full", "unstable_discord_api"] }
#serenity = { git = "https://github.com/serenity-rs/serenity.git", branch = "current", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "utils", "full", "unstable_discord_api"] }
serenity = { path = "../serenity", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "utils", "full", "unstable_discord_api"] }
tokio = { version = "1.38.0", features = ["full"] }
sqlx = { version = "0.7.4", features = ["sqlite", "runtime-tokio-native-tls", "postgres"] }
rand = "0.8.5"
Expand Down
26 changes: 13 additions & 13 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
- [ ] get game info from different platform (ubi (api not found), steam, epic(api not found), ea(api not found),
etc…)
Get the currency and language from the server language setting.
- [X] Steam
- [ ] Epic
- [ ] Ubisoft
- [ ] EA
- [ ] GOG
- [ ] Xbox
- [ ] Playstation
- [X] Steam
- [ ] Epic
- [ ] Ubisoft
- [ ] EA
- [ ] GOG
- [ ] Xbox
- [ ] Playstation
- [ ] get player stat
- [ ] get free promotion notification
- [ ] Steam
- [ ] Epic
- [ ] Steam
- [ ] Epic
- [ ] get game release notification
- [ ] get game update notification

Expand Down Expand Up @@ -84,9 +84,9 @@
- [x] Add a sqlite database.
- [X] Add postgres database choices.
- [ ] Rework the database to be more efficient.
- [X] Cache
- [ ] Add redis for cache.
- [X] In memory cache.
- [X] Cache
- [ ] Add redis for cache.
- [X] In memory cache.
- [X] Create a parser because some description uses html and not markdown.
- [ ] Check [https://anilist.co/forum/thread/6125](https://anilist.co/forum/thread/6125) to be sure all cases
are
Expand Down Expand Up @@ -114,4 +114,4 @@
- [ ] anilist_server list_user

- Fix needed:
- [ ] steam game search
- [ ] steam game search
8 changes: 4 additions & 4 deletions json/message/admin/server/new_member_setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"title": "Neues Mitglied Einstellung",
"description": "Die Einstellung wurde erfolgreich aktualisiert."
},
"fr": {
"title": "Nouveau membre Réglage",
"description": "Le réglage a été mis à jour avec succès."
}
"fr": {
"title": "Nouveau membre Réglage",
"description": "Le réglage a été mis à jour avec succès."
}
}
148 changes: 74 additions & 74 deletions json/subcommand_group/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -596,79 +596,80 @@
{
"name": "member_info_setting",
"desc": "Change the member info setting (new and removed member).",
"args": [{
"name": "show_username",
"desc": "Show the username in the member info.",
"required": true,
"autocomplete": false,
"arg_type": "Boolean",
"choices": [
{
"option_choice": "True",
"option_choice_localised": [
{
"code": "en-US",
"name": "True"
},
{
"code": "fr",
"name": "Vrai"
},
{
"code": "de",
"name": "Wahr"
},
{
"code": "ja",
"name": ""
}
]
},
{
"option_choice": "False",
"option_choice_localised": [
{
"code": "en-US",
"name": "False"
},
{
"code": "fr",
"name": "Faux"
},
{
"code": "de",
"name": "Falsch"
},
{
"code": "ja",
"name": ""
}
]
}
],
"localised": [
{
"code": "en-US",
"name": "show_username",
"desc": "Show the username in the member info."
},
{
"code": "fr",
"name": "afficher_nom_utilisateur",
"desc": "Afficher le nom d'utilisateur dans les informations sur les membres."
},
{
"code": "de",
"name": "benutzernamen_anzeigen",
"desc": "Zeigen Sie den Benutzernamen in den Mitgliederinformationen an."
},
{
"code": "ja",
"name": "yuza_nemuo_shimesu",
"desc": "メンバー情報にユーザー名を表示します。"
}
]
},
"args": [
{
"name": "show_username",
"desc": "Show the username in the member info.",
"required": true,
"autocomplete": false,
"arg_type": "Boolean",
"choices": [
{
"option_choice": "True",
"option_choice_localised": [
{
"code": "en-US",
"name": "True"
},
{
"code": "fr",
"name": "Vrai"
},
{
"code": "de",
"name": "Wahr"
},
{
"code": "ja",
"name": ""
}
]
},
{
"option_choice": "False",
"option_choice_localised": [
{
"code": "en-US",
"name": "False"
},
{
"code": "fr",
"name": "Faux"
},
{
"code": "de",
"name": "Falsch"
},
{
"code": "ja",
"name": ""
}
]
}
],
"localised": [
{
"code": "en-US",
"name": "show_username",
"desc": "Show the username in the member info."
},
{
"code": "fr",
"name": "afficher_nom_utilisateur",
"desc": "Afficher le nom d'utilisateur dans les informations sur les membres."
},
{
"code": "de",
"name": "benutzernamen_anzeigen",
"desc": "Zeigen Sie den Benutzernamen in den Mitgliederinformationen an."
},
{
"code": "ja",
"name": "yuza_nemuo_shimesu",
"desc": "メンバー情報にユーザー名を表示します。"
}
]
},
{
"name": "show_time",
"desc": "Show the time when he joined or left.",
Expand Down Expand Up @@ -873,7 +874,6 @@
}
]
}

],
"localised": [
{
Expand Down
61 changes: 23 additions & 38 deletions src/background_task/activity/anime_activity.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::error::Error;
use std::io::{Cursor, Read};
use std::sync::Arc;
use std::time::Duration;
Expand All @@ -16,7 +17,7 @@ use crate::database::manage::dispatcher::data_dispatch::{
get_data_activity, remove_data_activity_status, set_data_activity,
};
use crate::helper::create_default_embed::get_default_embed;
use crate::helper::error_management::error_enum::{AppError, ErrorResponseType, ErrorType};
use crate::helper::error_management::error_enum;
use crate::structure::message::anilist_user::send_activity::load_localization_send_activity;

/// `manage_activity` is an asynchronous function that manages activities.
Expand Down Expand Up @@ -130,18 +131,12 @@ async fn send_specific_activity(
ctx: &Context,
db_type: String,
anilist_cache: Arc<RwLock<Cache<String, String>>>,
) -> Result<(), AppError> {
) -> Result<(), Box<dyn Error>> {
let localised_text = load_localization_send_activity(guild_id.clone(), db_type.clone()).await?;
let webhook_url = row.webhook.clone();
let mut webhook = Webhook::from_url(&ctx.http, webhook_url.as_str())
.await
.map_err(|e| {
AppError::new(
format!("There was an error getting the webhook from the url {}", e),
ErrorType::Webhook,
ErrorResponseType::None,
)
})?;
.map_err(|e| error_enum::Error::Webhook(format!("{:#?}", e)))?;

let image = row.image;
trace!(image);
Expand All @@ -151,13 +146,9 @@ async fn send_specific_activity(

// Read the decoded bytes into a Vec
let mut decoded_bytes = Vec::new();
decoder.read_to_end(&mut decoded_bytes).map_err(|e| {
AppError::new(
format!("There was an error reading the decoded bytes {}", e),
ErrorType::File,
ErrorResponseType::None,
)
})?;
decoder
.read_to_end(&mut decoded_bytes)
.map_err(|e| error_enum::Error::Byte(format!("{:#?}", e)))?;
let name = row.name.clone();
let trimmed_name = if name.len() > 100 {
name[..100].to_string()
Expand All @@ -166,13 +157,10 @@ async fn send_specific_activity(
};
let attachment = CreateAttachment::bytes(decoded_bytes, "avatar");
let edit_webhook = EditWebhook::new().name(trimmed_name).avatar(&attachment);
webhook.edit(&ctx.http, edit_webhook).await.map_err(|e| {
AppError::new(
format!("There was an error editing the webhook {}", e),
ErrorType::Webhook,
ErrorResponseType::None,
)
})?;
webhook
.edit(&ctx.http, edit_webhook)
.await
.map_err(|e| error_enum::Error::Webhook(format!("{:#?}", e)))?;

let embed = get_default_embed(None)
.description(
Expand All @@ -190,15 +178,14 @@ async fn send_specific_activity(
webhook
.execute(&ctx.http, false, builder_message)
.await
.map_err(|e| {
AppError::new(
format!("There was an error sending the webhook {}", e),
ErrorType::Webhook,
ErrorResponseType::None,
)
})?;
.map_err(|e| error_enum::Error::Webhook(format!("{:#?}", e)))?;

tokio::spawn(async move { update_info(row2, guild_id, anilist_cache.clone(), db_type).await });
tokio::spawn(async move {
match update_info(row2, guild_id, anilist_cache.clone(), db_type).await {
Err(e) => error!("{}", e),
_ => {}
}
});
Ok(())
}

Expand Down Expand Up @@ -227,17 +214,15 @@ async fn update_info(
guild_id: String,
anilist_cache: Arc<RwLock<Cache<String, String>>>,
db_type: String,
) -> Result<(), AppError> {
) -> Result<(), Box<dyn Error>> {
let media = get_minimal_anime_by_id(row.anime_id, anilist_cache).await?;
let next_airing = match media.next_airing_episode {
Some(na) => na,
None => return remove_activity(row, guild_id, db_type).await,
};
let title = media.title.ok_or(AppError::new(
"Failed to get the title.".to_string(),
ErrorType::Option,
ErrorResponseType::None,
))?;
let title = media
.title
.ok_or(error_enum::Error::Option(String::from("no title")))?;
let rj = title.romaji;
let en = title.english;
let name = en.unwrap_or(rj.unwrap_or(String::from("nothing")));
Expand Down Expand Up @@ -276,7 +261,7 @@ async fn remove_activity(
row: ServerActivityFull,
guild_id: String,
db_type: String,
) -> Result<(), AppError> {
) -> Result<(), Box<dyn Error>> {
trace!("removing {:#?} for {}", row, guild_id);
remove_data_activity_status(guild_id, row.anime_id.to_string(), db_type).await?;
Ok(())
Expand Down
Loading

0 comments on commit ff6f5c0

Please sign in to comment.