Skip to content

Commit

Permalink
Merge pull request #129 from ValgulNecron/dev
Browse files Browse the repository at this point in the history
V2.9.2 Fixed action
  • Loading branch information
ValgulNecron committed Jun 19, 2024
2 parents ebaf0c3 + fa21a5f commit d7f0a17
Show file tree
Hide file tree
Showing 45 changed files with 618 additions and 254 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/cleanup-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
jobs:
cleanup:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Cleanup
run: |
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/test-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ jobs:
sudo apt-get update
sudo apt-get install -y protobuf-compiler
- name: Configure protoc for proto3 optional fields
run: echo "syntax = \"proto3\"; option allow_proto3_optional = true;" >.protoconfig

- name: Set environment variable for protoc
run: export PROTO_CONFIG_PATH=.protoconfig
- name: Check protoc version
run: protoc --version

- name: Cache
uses: Swatinem/rust-cache@v2
Expand Down
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kasuki"
version = "2.9.2"
version = "2.9.3"
edition = "2021"
authors = ["Valgul <contact@valgul.moe>"]
description = "A discord bot written in rust that get info from anilist API"
Expand Down Expand Up @@ -37,7 +37,7 @@ tracing-appender = "0.2.3"
tonic = { version = "0.11.0", features = ["tls"] }
prost = "0.12.6"
tonic-reflection = "0.11.0"
ratatui = "0.27.0-alpha.5"
ratatui = "0.27.0-alpha.7"
crossterm = "0.27.0"
sysinfo = "0.30.12"
tui-logger = "0.11.1"
Expand All @@ -54,7 +54,6 @@ toml = "0.8.14"
[build-dependencies]
tonic-build = "0.11.0"
cynic-codegen = { version = "3.7.3" }
insta = "1.39.0"

[profile.dev]
codegen-units = 512
Expand Down
11 changes: 11 additions & 0 deletions ERROR_CODE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## List of error code and their description

| Error Code | Description |
|------------|----------------------------------------------------------------------------------------|
| 0 | No error. normal exit of the app. |
| 1 | Error with the config. either formating error, or missing file. |
| 2 | Failed to init the logger. either permission error, or some internal error. |
| 3 | Failed to init the TUI. (specific when TUI is on in the config file. |
| 4 | Failed to init the database. either permission error, or some internal error. |
| 5 | Failed to init the discord client. error with the token, internet or some other stuff. |
| 6 | Failed to start the bot. |
8 changes: 4 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ use std::{env, path::PathBuf};
fn main() -> Result<(), Box<dyn Error>> {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional")
.file_descriptor_set_path(out_dir.join("shard_descriptor.bin"))
.compile(&["proto/shard.proto"], &["proto"])?;
tonic_build::compile_protos("proto/shard.proto")?;

tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional")
.file_descriptor_set_path(out_dir.join("info_descriptor.bin"))
.compile(&["proto/info.proto"], &["proto"])?;
tonic_build::compile_protos("proto/info.proto")?;

tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional")
.file_descriptor_set_path(out_dir.join("command_descriptor.bin"))
.compile(&["proto/command.proto"], &["proto"])?;
tonic_build::compile_protos("proto/command.proto")?;

tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional")
.file_descriptor_set_path(out_dir.join("federation_descriptor.bin"))
.compile(&["proto/federation.proto"], &["proto"])?;
tonic_build::compile_protos("proto/federation.proto")?;

cynic_codegen::register_schema("anilist")
.from_sdl_file("schemas/anilist.graphql")?
Expand Down
3 changes: 2 additions & 1 deletion compose-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ services:
ports:
- "443:443"
volumes:
- ./db/data.db:/kasuki/db
- ./db/:/kasuki/db
- ./logs/:/kasuki/logs/
- ./server_image:/kasuki/server_image/
- ./cert:/kasuki/cert/
- ./config.toml:/kasuki/config.toml
- /etc/localtime:/etc/localtime:ro

26 changes: 26 additions & 0 deletions json/message/vn/staff.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"en": {
"main": "Main",
"aid": "AID",
"gender": "Gender",
"lang": "Language"
},
"de": {
"main": "Haupt",
"aid": "AID",
"gender": "Geschlecht",
"lang": "Sprache"
},
"fr": {
"main": "Principal",
"aid": "AID",
"gender": "Sexe",
"lang": "Langue"
},
"ja": {
"main": "メイン",
"aid": "AID",
"gender": "性別",
"lang": "言語"
}
}
2 changes: 2 additions & 0 deletions src/command/autocomplete/anilist_server/add_anime_activity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serenity::all::{CommandInteraction, Context};
use tracing::trace;

use crate::command::autocomplete::anilist_user::anime::get_autocomplete_media_variables;
use crate::constant::DEFAULT_STRING;
Expand Down Expand Up @@ -26,6 +27,7 @@ use crate::structure::autocomplete::anilist::media::send_auto_complete;
/// This function is asynchronous. It awaits the creation of the `MediaPageWrapper` and the sending of the autocomplete response.
pub async fn autocomplete(ctx: Context, autocomplete_interaction: CommandInteraction) {
let map = get_option_map_string_autocomplete_subcommand_group(&autocomplete_interaction);
trace!("{:?}", map);
let anime_search = map
.get(&String::from("anime_name"))
.unwrap_or(DEFAULT_STRING);
Expand Down
42 changes: 20 additions & 22 deletions src/command/run/admin/anilist/add_activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use crate::helper::make_graphql_cached::make_request_anilist;
use crate::helper::trimer::trim_webhook;
use crate::structure::message::admin::anilist::add_activity::load_localization_add_activity;
use crate::structure::run::anilist::minimal_anime::{
Media, MediaTitle, MinimalAnime, MinimalAnimeVariables,
Media, MediaTitle, MinimalAnimeId, MinimalAnimeIdVariables, MinimalAnimeSearch,
MinimalAnimeSearchVariables,
};

/// This asynchronous function gets or creates a webhook for a given channel.
Expand Down Expand Up @@ -209,9 +210,17 @@ pub async fn run(ctx: &Context, command_interaction: &CommandInteraction) -> Res
///
/// A boolean indicating whether the activity exists.
async fn check_if_activity_exist(anime_id: i32, server_id: String) -> bool {
let row: Option<SmallServerActivity> =
get_one_activity(anime_id, server_id).await.unwrap_or(None);
row.is_some()
let row: SmallServerActivity = get_one_activity(anime_id, server_id.clone())
.await
.unwrap_or(SmallServerActivity {
anime_id: None,
timestamp: None,
guild_id: None,
});
if row.anime_id.is_none() || row.timestamp.is_none() || row.guild_id.is_none() {
return false;
};
true
}

/// This function gets the name of an anime from a `Title` struct.
Expand Down Expand Up @@ -387,28 +396,17 @@ async fn get_webhook(
}

pub async fn get_minimal_anime_by_id(id: i32) -> Result<Media, AppError> {
let query = MinimalAnimeVariables {
id: Some(id),
search: None,
};
get_minimal_anime(query, id.to_string()).await
let query = MinimalAnimeIdVariables { id: Some(id) };
let operation = MinimalAnimeId::build(query);
let data: GraphQlResponse<MinimalAnimeId> = make_request_anilist(operation, false).await?;
Ok(data.data.unwrap().media.unwrap())
}

pub async fn get_minimal_anime_by_search(value: &str) -> Result<Media, AppError> {
let query = MinimalAnimeVariables {
id: None,
let query = MinimalAnimeSearchVariables {
search: Some(value),
};
get_minimal_anime(query, value.to_string()).await
}

pub async fn get_minimal_anime<'a>(
query: MinimalAnimeVariables<'a>,
value: String,
) -> Result<Media, AppError> {
let operation = MinimalAnime::build(query);
let data: Result<GraphQlResponse<MinimalAnime>, AppError> =
make_request_anilist(operation, false).await;
let data = data?;
let operation = MinimalAnimeSearch::build(query);
let data: GraphQlResponse<MinimalAnimeSearch> = make_request_anilist(operation, false).await?;
Ok(data.data.unwrap().media.unwrap())
}
20 changes: 13 additions & 7 deletions src/command/run/anilist_user/anime.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use cynic::{GraphQlResponse, QueryBuilder};
use serenity::all::{CommandInteraction, Context};

use crate::helper::error_management::error_enum::AppError;
use crate::helper::get_option::subcommand::get_option_map_string_subcommand;
use crate::helper::make_graphql_cached::make_request_anilist;
use crate::structure::run::anilist::media::{
get_media, send_embed, Media, MediaFormat, MediaQuerryVariables, MediaType,
send_embed, Media, MediaFormat, MediaQuerryId, MediaQuerryIdVariables, MediaQuerrySearch,
MediaQuerrySearchVariables, MediaType,
};

/// This asynchronous function runs the command interaction for retrieving information about an anime.
Expand Down Expand Up @@ -35,7 +38,7 @@ pub async fn run(ctx: &Context, command_interaction: &CommandInteraction) -> Res
// If the value is not an integer, treat it as a name and retrieve the anime with that name
let data: Media = if value.parse::<i32>().is_ok() {
let id = value.parse::<i32>().unwrap();
let var = MediaQuerryVariables {
let var = MediaQuerryIdVariables {
format_in: Some(vec![
Some(MediaFormat::Tv),
Some(MediaFormat::TvShort),
Expand All @@ -47,11 +50,12 @@ pub async fn run(ctx: &Context, command_interaction: &CommandInteraction) -> Res
]),
id: Some(id),
media_type: Some(MediaType::Anime),
search: None,
};
get_media(var).await?
let operation = MediaQuerryId::build(var);
let data: GraphQlResponse<MediaQuerryId> = make_request_anilist(operation, false).await?;
data.data.unwrap().media.unwrap()
} else {
let var = MediaQuerryVariables {
let var = MediaQuerrySearchVariables {
format_in: Some(vec![
Some(MediaFormat::Tv),
Some(MediaFormat::TvShort),
Expand All @@ -63,9 +67,11 @@ pub async fn run(ctx: &Context, command_interaction: &CommandInteraction) -> Res
]),
search: Some(&*value),
media_type: Some(MediaType::Anime),
id: None,
};
get_media(var).await?
let operation = MediaQuerrySearch::build(var);
let data: GraphQlResponse<MediaQuerrySearch> =
make_request_anilist(operation, false).await?;
data.data.unwrap().media.unwrap()
};

// Send an embed with the anime information as a response to the command interaction
Expand Down
26 changes: 10 additions & 16 deletions src/command/run/anilist_user/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::helper::error_management::error_enum::AppError;
use crate::helper::get_option::subcommand::get_option_map_string_subcommand;
use crate::helper::make_graphql_cached::make_request_anilist;
use crate::structure::run::anilist::character::{
send_embed, Character, CharacterQuerry, CharacterQuerryVariables,
send_embed, Character, CharacterQuerryId, CharacterQuerryIdVariables, CharacterQuerrySearch,
CharacterQuerrySearchVariables,
};

/// This asynchronous function runs the command interaction for retrieving information about a character.
Expand Down Expand Up @@ -38,29 +39,22 @@ pub async fn run(ctx: &Context, command_interaction: &CommandInteraction) -> Res
let data: Character = if value.parse::<i32>().is_ok() {
get_character_by_id(value.parse::<i32>().unwrap()).await?
} else {
let var = CharacterQuerryVariables {
id: None,
let var = CharacterQuerrySearchVariables {
search: Some(&*value),
};
get_character(var).await?
let operation = CharacterQuerrySearch::build(var);
let data: GraphQlResponse<CharacterQuerrySearch> =
make_request_anilist(operation, false).await?;
data.data.unwrap().character.unwrap()
};

// Send an embed with the character information as a response to the command interaction
send_embed(ctx, command_interaction, data).await
}

pub async fn get_character_by_id(value: i32) -> Result<Character, AppError> {
let var = CharacterQuerryVariables {
id: Some(value),
search: None,
};
get_character(var).await
}

pub async fn get_character<'a>(var: CharacterQuerryVariables<'a>) -> Result<Character, AppError> {
let operation = CharacterQuerry::build(var);
let data: Result<GraphQlResponse<CharacterQuerry>, AppError> =
make_request_anilist(operation, false).await;
let data = data?;
let var = CharacterQuerryIdVariables { id: Some(value) };
let operation = CharacterQuerryId::build(var);
let data: GraphQlResponse<CharacterQuerryId> = make_request_anilist(operation, false).await?;
Ok(data.data.unwrap().character.unwrap())
}
21 changes: 14 additions & 7 deletions src/command/run/anilist_user/ln.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use cynic::{GraphQlResponse, QueryBuilder};
use serenity::all::{CommandInteraction, Context};

use crate::helper::error_management::error_enum::AppError;
use crate::helper::get_option::subcommand::get_option_map_string_subcommand;
use crate::helper::make_graphql_cached::make_request_anilist;
use crate::structure::run::anilist::media::{
get_media, send_embed, Media, MediaFormat, MediaQuerryVariables, MediaType,
send_embed, Media, MediaFormat, MediaQuerryId, MediaQuerryIdVariables, MediaQuerrySearch,
MediaQuerrySearchVariables, MediaType,
};

/// Executes the command to fetch and display information about a light novel (LN) based on its name or ID.
Expand Down Expand Up @@ -31,21 +34,25 @@ pub async fn run(ctx: &Context, command_interaction: &CommandInteraction) -> Res
// Fetch the LN data by ID if the value can be parsed as an `i32`, or by search otherwise
let data: Media = if value.parse::<i32>().is_ok() {
let id = value.parse::<i32>().unwrap();
let var = MediaQuerryVariables {
let var = MediaQuerryIdVariables {
format_in: Some(vec![Some(MediaFormat::Novel)]),
id: Some(id),
media_type: Some(MediaType::Manga),
search: None,
};
get_media(var).await?
let operation = MediaQuerryId::build(var);
let data: GraphQlResponse<MediaQuerryId> = make_request_anilist(operation, false).await?;
data.data.unwrap().media.unwrap()
} else {
let var = MediaQuerryVariables {
let var = MediaQuerrySearchVariables {
format_in: Some(vec![Some(MediaFormat::Novel)]),
search: Some(&*value),
media_type: Some(MediaType::Manga),
id: None,
};
get_media(var).await?

let operation = MediaQuerrySearch::build(var);
let data: GraphQlResponse<MediaQuerrySearch> =
make_request_anilist(operation, false).await?;
data.data.unwrap().media.unwrap()
};

// Send an embed containing the LN data as a response to the command interaction
Expand Down
Loading

0 comments on commit d7f0a17

Please sign in to comment.