diff --git a/.github/workflows/docker-image-dev.yml b/.github/workflows/docker-image-dev.yml index 6002217b..2b173978 100644 --- a/.github/workflows/docker-image-dev.yml +++ b/.github/workflows/docker-image-dev.yml @@ -11,7 +11,7 @@ concurrency: cancel-in-progress: false jobs: - docker_amd64: + docker: runs-on: ubuntu-latest steps: - name: Set up Docker Buildx @@ -28,32 +28,7 @@ jobs: uses: docker/build-push-action@v5 with: push: true - platforms: linux/amd64 - tags: ${{ secrets.DOCKER_HUB_USERNAME }}/kasuki:dev - cache-from: type=gha - cache-to: type=gha,mode=max - build-args: | - BUILDKIT_INLINE_CACHE=1 - - docker_arm64: - needs: docker_amd64 - runs-on: ubuntu-latest - steps: - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - name: Build and push arm64 - id: docker_build_arm64 - uses: docker/build-push-action@v5 - with: - push: true - platforms: linux/arm64/v8 + platforms: linux/amd64,linux/arm64/v8 tags: ${{ secrets.DOCKER_HUB_USERNAME }}/kasuki:dev cache-from: type=gha cache-to: type=gha,mode=max diff --git a/.github/workflows/docker-image-release.yml b/.github/workflows/docker-image-release.yml index 7b32eb4a..be0da496 100644 --- a/.github/workflows/docker-image-release.yml +++ b/.github/workflows/docker-image-release.yml @@ -11,7 +11,7 @@ concurrency: cancel-in-progress: false jobs: - docker_amd64: + docker: runs-on: ubuntu-latest steps: - name: Set up Docker Buildx @@ -28,32 +28,7 @@ jobs: uses: docker/build-push-action@v5 with: push: true - platforms: linux/amd64 - tags: ${{ secrets.DOCKER_HUB_USERNAME }}/kasuki:latest - cache-from: type=gha - cache-to: type=gha,mode=max - build-args: | - BUILDKIT_INLINE_CACHE=1 - - docker_arm64: - needs: docker_amd64 - runs-on: ubuntu-latest - steps: - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - name: Build and push arm64 - id: docker_build_arm64 - uses: docker/build-push-action@v5 - with: - push: true - platforms: linux/arm64/v8 + platforms: linux/amd64,linux/arm64/v8 tags: ${{ secrets.DOCKER_HUB_USERNAME }}/kasuki:latest cache-from: type=gha cache-to: type=gha,mode=max diff --git a/Cargo.toml b/Cargo.toml index 3af9a570..b8f9e989 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kasuki" -version = "2.5.1" +version = "2.5.2" edition = "2021" authors = ["Valgul "] description = "A discord bot written in rust that get info from anilist API" diff --git a/json/message/general/info.json b/json/message/general/info.json index 585a4499..5b7058d5 100644 --- a/json/message/general/info.json +++ b/json/message/general/info.json @@ -1,7 +1,15 @@ { "en": { "title": "Info", - "desc": "This bot uses the AniList API to provide information on a show or a user. \n The bot is on $number$ server. \n The bot version is: $version$", + "desc": "This bot uses the AniList API to provide information on a show or a user.", + "bot_name": "Bot name:", + "bot_id": "Bot ID:", + "server_count": "Server count:", + "user_count": "User count", + "creation_date": "Creation date", + "shard": "You are on shard:", + "shard_count": "Shard count:", + "version": "The version of the bot is:", "footer": "Creator: valgul.", "button_see_on_github": "See on GitHub", "button_official_website": "Official website", @@ -10,31 +18,55 @@ "button_add_the_beta_bot": "Add the beta bot" }, "fr": { - "title": "Informations", - "desc": "Ce bot utilise l'API AniList pour fournir des informations sur une série ou un utilisateur. \n Le bot est sur $number$ serveur. \n La version du bot est : $version$", + "title": "Info", + "desc": "Ce bot utilise l'API AniList pour fournir des informations sur un spectacle ou un utilisateur.", + "bot_name": "Nom du bot :", + "bot_id": "ID du bot :", + "server_count": "Nombre de serveurs :", + "user_count": "Nombre d'utilisateurs", + "creation_date": "Date de création", + "shard": "Vous êtes sur le fragment :", + "shard_count": "Nombre de fragments :", + "version": "La version du bot est :", "footer": "Créateur : valgul.", "button_see_on_github": "Voir sur GitHub", "button_official_website": "Site officiel", "button_official_discord": "Discord officiel", "button_add_the_bot": "Ajouter le bot", - "button_add_the_beta_bot": "Ajouter le bot beta" + "button_add_the_beta_bot": "Ajouter le bot bêta" }, "jp": { "title": "情報", - "desc": "このボットはAniList APIを使用して番組やユーザーの情報を提供します。 \n ボットは$number$サーバーにいます。 \n ボットのバージョンは:$version$", - "footer": "作成者:valgul。", + "desc": "このボットは、AniList APIを使用して番組またはユーザーに関する情報を提供します。", + "bot_name": "ボット名:", + "bot_id": "ボットID:", + "server_count": "サーバー数:", + "user_count": "ユーザー数", + "creation_date": "作成日", + "shard": "あなたはシャードにいます:", + "shard_count": "シャードの数:", + "version": "ボットのバージョンは:", + "footer": "クリエイター:valgul。", "button_see_on_github": "GitHubで見る", "button_official_website": "公式ウェブサイト", "button_official_discord": "公式Discord", - "button_add_the_bot": "ボットを追加", - "button_add_the_beta_bot": "ベータ版ボットを追加" + "button_add_the_bot": "ボットを追加する", + "button_add_the_beta_bot": "ベータ版ボットを追加する" }, "de": { "title": "Info", - "desc": "Dieser Bot verwendet die AniList API, um Informationen zu einer Show oder einem Benutzer bereitzustellen. \n Der Bot ist auf $number$ Server. \n Die Bot-Version ist: $version$", - "footer": "Schöpfer: valgul.", + "desc": "Dieser Bot verwendet die AniList API, um Informationen zu einer Show oder einem Benutzer bereitzustellen.", + "bot_name": "Bot-Name:", + "bot_id": "Bot-ID:", + "server_count": "Serveranzahl:", + "user_count": "Benutzeranzahl", + "creation_date": "Erstellungsdatum", + "shard": "Du bist auf Shard:", + "shard_count": "Shard-Anzahl:", + "version": "Die Version des Bots lautet:", + "footer": "Ersteller: valgul.", "button_see_on_github": "Auf GitHub ansehen", - "button_official_website": "Offizielle Website", + "button_official_website": "Offizielle Webseite", "button_official_discord": "Offizieller Discord", "button_add_the_bot": "Bot hinzufügen", "button_add_the_beta_bot": "Beta-Bot hinzufügen" diff --git a/src/command_run/bot_info/info.rs b/src/command_run/bot_info/info.rs index 442cd3ce..64d5cf6b 100644 --- a/src/command_run/bot_info/info.rs +++ b/src/command_run/bot_info/info.rs @@ -13,16 +13,50 @@ pub async fn run(ctx: &Context, command_interaction: &CommandInteraction) -> Res None => String::from("0"), }; let info_localised = load_localization_info(guild_id).await?; + let shard_count = ctx.cache.shard_count(); + let shard = ctx.shard_id.to_string(); + let user_count = ctx.cache.user_count(); + let server_count = ctx.cache.guild_count(); + let bot = ctx.http.get_current_application_info().await.map_err(|e| { + AppError::new( + format!("Error while getting the bot info {}", e), + ErrorType::Option, + ErrorResponseType::Message, + ) + })?; + let bot_name = bot.name; + let bot_id = bot.id.to_string(); + let creation_date = bot.id.created_at().to_rfc3339().unwrap_or_default(); + let bot_icon = bot.icon.ok_or(AppError::new( + String::from("The bot has no avatar"), + ErrorType::Option, + ErrorResponseType::Message, + ))?; + let avatar = if bot_icon.is_animated() { + format!( + "https://cdn.discordapp.com/icons/{}/{}.gif?size=1024", + bot_id, bot_icon + ) + } else { + format!( + "https://cdn.discordapp.com/icons/{}/{}.webp?size=1024", + bot_id, bot_icon + ) + }; let builder_embed = CreateEmbed::new() .timestamp(Timestamp::now()) .color(COLOR) - .description( - info_localised - .desc - .replace("$number$", ctx.cache.guilds().len().to_string().as_str()) - .replace("$version$", APP_VERSION), - ) + .description(info_localised.desc) + .field(info_localised.bot_name, bot_name, true) + .field(info_localised.bot_id, bot_id, true) + .field(info_localised.version, APP_VERSION, true) + .field(info_localised.shard_count, shard_count.to_string(), true) + .field(info_localised.shard, shard, true) + .field(info_localised.user_count, user_count.to_string(), true) + .field(info_localised.server_count, server_count.to_string(), true) + .field(info_localised.creation_date, creation_date, true) + .thumbnail(avatar) .title(&info_localised.title) .footer(CreateEmbedFooter::new(&info_localised.footer)); let mut buttons = Vec::new(); diff --git a/src/error_management/error_dispatch.rs b/src/error_management/error_dispatch.rs index bc7c1dc8..617bf7c6 100644 --- a/src/error_management/error_dispatch.rs +++ b/src/error_management/error_dispatch.rs @@ -12,20 +12,20 @@ pub async fn command_dispatching( command_interaction: &CommandInteraction, ctx: &Context, ) { - error!("{:?}", error); + error!("{}", error); let response_type = error.error_response_type.clone(); match response_type { ErrorResponseType::Message => match send_error(error, command_interaction, ctx).await { Ok(_) => {} Err(e) => { - error!("{:?}", e); + error!("{}", e); } }, ErrorResponseType::Followup => { match send_differed_error(error, command_interaction, ctx).await { Ok(_) => {} Err(e) => { - error!("{:?}", e); + error!("{}", e); } } } @@ -35,7 +35,7 @@ pub async fn command_dispatching( Err(_) => match send_differed_error(error, command_interaction, ctx).await { Ok(_) => {} Err(e) => { - error!("{:?}", e); + error!("{}", e); } }, } @@ -51,7 +51,7 @@ async fn send_error( ) -> Result<(), AppError> { let error_message = format!("**This error is most likely an error on your part. \ like you asking the bot to find unknown stuff or other. but in some case it's an error on my part juts check the \ - error and report it to me and I will try to fix it the fastest I can** \n{:?}", e); + error and report it to me and I will try to fix it the fastest I can** \n{}", e); let builder_embed = CreateEmbed::new() .timestamp(Timestamp::now()) .color(COLOR) @@ -81,7 +81,7 @@ async fn send_differed_error( ) -> Result<(), AppError> { let error_message = format!("**This error is most likely an error on your part. \ like you asking the bot to find unknown stuff or other. but in some case it's an error on my part juts check the \ - error and report it to me and I will try to fix it the fastest I can** \n{:?}", e); + error and report it to me and I will try to fix it the fastest I can** \n{}", e); let builder_embed = CreateEmbed::new() .timestamp(Timestamp::now()) .color(COLOR) diff --git a/src/error_management/error_enum.rs b/src/error_management/error_enum.rs index e980100d..566e4033 100644 --- a/src/error_management/error_enum.rs +++ b/src/error_management/error_enum.rs @@ -25,8 +25,8 @@ impl fmt::Display for AppError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "Error type: {}. Error message: {}, Error response type: {}", - self.error_type, self.message, self.error_response_type + "Error type: {}. Error message: {}", + self.error_type, self.message ) } } diff --git a/src/lang_struct/general/info.rs b/src/lang_struct/general/info.rs index 5c1b8e04..3a23ade1 100644 --- a/src/lang_struct/general/info.rs +++ b/src/lang_struct/general/info.rs @@ -13,6 +13,14 @@ use crate::error_management::error_enum::{AppError, ErrorResponseType, ErrorType pub struct InfoLocalised { pub title: String, pub desc: String, + pub bot_name: String, + pub bot_id: String, + pub server_count: String, + pub user_count: String, + pub creation_date: String, + pub shard: String, + pub shard_count: String, + pub version: String, pub footer: String, pub button_see_on_github: String, pub button_official_website: String,