Skip to content

Commit

Permalink
Merge pull request #140 from ValgulNecron/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ValgulNecron committed Jul 11, 2024
2 parents 1387c4f + f5418db commit 155ad02
Show file tree
Hide file tree
Showing 22 changed files with 235 additions and 522 deletions.
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ license-file = "LICENSE"
[dependencies]
regex = "1.10.5"
reqwest = { version = "0.12.5", features = ["json", "multipart", "blocking"] }
serde = "1.0.203"
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"] }
tokio = { version = "1.38.0", features = ["full"] }
sqlx = { version = "0.7.4", features = ["sqlite", "runtime-tokio-native-tls", "postgres"] }
rand = "0.9.0-alpha.1"
chrono = "0.4.38"
uuid = { version = "1.9.1", features = ["v4"] }
uuid = { version = "1.10.0", features = ["v4"] }
image = "0.25.1"
base64 = "0.22.1"
tracing = { version = "0.1.40" }
Expand All @@ -32,24 +32,24 @@ serde_with = { version = "3.8.3", features = ["macros"] }
rust-fuzzy-search = "0.1.1"
palette = "0.7.6"
tracing-appender = "0.2.3"
tonic = { version = "0.11.0", features = ["tls"] }
prost = "0.12.6"
tonic-reflection = "0.11.0"
sysinfo = "0.30.12"
tonic = { version = "0.12.0", features = ["tls"] }
prost = "0.13.1"
tonic-reflection = "0.12.0"
sysinfo = "0.30.13"
rayon = "1.10.0"
os_info = "3.8.2"
rcgen = "0.13.1"
markdown_converter = "0.3.4"
futures = "0.3.30"
rapidfuzz = "0.5.0"
cynic = { version = "3.7.3", features = ["reqwest", "http-reqwest", "serde_json"] }
moka = { version = "0.12.7", features = ["future"] }
moka = { version = "0.12.8", features = ["future"] }
toml = "0.8.14"
num-bigint = "0.4.6"
text-to-png = "0.2.0"

[build-dependencies]
tonic-build = "0.11.0"
tonic-build = "0.12.0"
cynic-codegen = { version = "3.7.3" }

[profile.dev]
Expand Down
37 changes: 22 additions & 15 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@
- [X] Command for a random anime image NSFW.

- Games module:
- [X] Search for a steam game.
- [ ] 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
- [ ] get player stat
- [ ] get free promotion notification
- [ ] Steam
- [ ] Epic
- [ ] get game release notification
- [ ] get game update notification

Expand All @@ -44,15 +52,15 @@
- [X] Video translation.
- [X] Ask a question and reply the response.

- Music module: (Not sure if I will do this one.)
- [ ] Play music from youtube.
- Music module: (Not sure if I will do this one. since it broke tos)
- [ ] Play music from YouTube.
- [ ] Play music from file upload.
- [ ] Play music from a link.
- [ ] Play music from a playlist.
- [ ] Play music from a search.

- General module:
- [X] Command to change the bot response langage.
- [X] Command to change the bot response language.
- [X] Command to turn on and off module.
- [X] Credit command.
- [X] Bot info command.
Expand All @@ -72,22 +80,23 @@
- [X] Localisation for response.
- [X] Localisation for command.
- [X] Find a name for the bot.
- [ ] Database
- [X] Database
- [x] Add a sqlite database.
- [X] Add postgres database choices.
- [ ] Add redis for cache.
- [ ] In memory cache.
- [ ] Rework the database to be more efficient.
- [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
supported
- [X] Figure out the necessary deps to work. Once found, change the dockerfile to use a debian base image to reduce
size.
- [X] Better error handling.
- [ ] Better error handling.
- [X] Doing something with error else than logging it.
- [ ] Rename function and variable for better clarity.
- [X] Add docs to every public function.
- [ ] Add docs to every public function.
(Run, Register and Autocomplete don’t need this.).
- [X] Logging
- [X] Updating to serenity 0.12.
Expand All @@ -99,12 +108,10 @@
- [X] Subcommand group
- [X] User command
- [ ] Message command
- [ ] User installed app (waiting on serenity to support it).
- [ ] Federation
- [ ] Add a federation system to share data between bot.
- Should be able to share data between bot.
- Should be P2P.
- Should work with a "token" system to allow different "federation" to share different data.
- [X] User installed app.

- Optimisation needed:
- [ ] anilist_server list_user

- Fix needed:
- [ ] steam game search
5 changes: 0 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ fn main() -> Result<(), Box<dyn Error>> {
.file_descriptor_set_path(out_dir.join("command_descriptor.bin"))
.compile(&["proto/command.proto"], &["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"])?;

cynic_codegen::register_schema("anilist")
.from_sdl_file("schemas/anilist.graphql")?
.as_default()?;
Expand Down
16 changes: 0 additions & 16 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,3 @@ use_tls = false
tls_cert_path = ""
tls_key_path = ""

# Additional federation settings for the gRPC server
[grpc.federation]
# Whether federation is enabled.
federation_is_on = false

# The name of the bot in the federation.
federation_name = ""

# The address of the current node in the federation.
self_address = ""

# Indicates whether to join a new federation.
new_federation = false

# The address of the federation to join.
federation_address = ""
28 changes: 24 additions & 4 deletions json/message/game/steam_game_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
"field7": "Categories",
"free": "Free",
"coming_soon": "Coming soon",
"tba": "TBA"
"tba": "TBA",
"win": "Windows",
"mac": "Mac",
"linux": "Linux",
"website": "Website",
"required_age": "Required age"
},
"fr": {
"field1": "Prix",
Expand All @@ -22,7 +27,12 @@
"field8": "Avis",
"free": "Gratuit",
"coming_soon": "Bientôt disponible",
"tba": "À annoncer"
"tba": "À annoncer",
"win": "Windows",
"mac": "Mac",
"linux": "Linux",
"website": "Site web",
"required_age": "Âge requis"
},
"de": {
"field1": "Preis",
Expand All @@ -35,7 +45,12 @@
"field8": "Bewertungen",
"free": "Kostenlos",
"coming_soon": "Demnächst verfügbar",
"tba": "TBA"
"tba": "TBA",
"win": "Windows",
"mac": "Mac",
"linux": "Linux",
"website": "Webseite",
"required_age": "Erforderliches Alter"
},
"jp": {
"field1": "価格",
Expand All @@ -48,6 +63,11 @@
"field8": "レビュー",
"free": "無料",
"coming_soon": "近日公開",
"tba": "TBA"
"tba": "TBA",
"win": "Windows",
"mac": "Mac",
"linux": "Linux",
"website": "ウェブサイト",
"required_age": "必要年齢"
}
}
84 changes: 0 additions & 84 deletions proto/federation.proto

This file was deleted.

12 changes: 9 additions & 3 deletions src/background_task/background_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::background_task::activity::anime_activity::manage_activity;
use crate::background_task::server_image::calculate_user_color::color_management;
use crate::background_task::server_image::generate_server_image::server_image_management;
use crate::background_task::update_random_stats::update_random_stats_launcher;
use crate::config::Config;
use crate::config::{Config, ImageConfig};
use crate::constant::{
TIME_BEFORE_SERVER_IMAGE, TIME_BETWEEN_ACTIVITY_CHECK, TIME_BETWEEN_BLACKLISTED_USER_UPDATE,
TIME_BETWEEN_BOT_INFO, TIME_BETWEEN_GAME_UPDATE, TIME_BETWEEN_PING_UPDATE,
Expand Down Expand Up @@ -74,9 +74,11 @@ pub async fn thread_management_launcher(ctx: Context, bot_data: Arc<BotData>) {
));
// Sleep for a specified duration before spawning the server image management thread
sleep(Duration::from_secs(TIME_BEFORE_SERVER_IMAGE)).await;
let image_config = bot_data.config.image.clone();
tokio::spawn(launch_server_image_management_thread(
ctx.clone(),
db_type.clone(),
image_config,
));

info!("Done spawning thread manager.");
Expand Down Expand Up @@ -219,12 +221,16 @@ async fn launch_activity_management_thread(
///
/// * `ctx` - A `Context` instance which is used in the server image management function.
///
async fn launch_server_image_management_thread(ctx: Context, db_type: String) {
async fn launch_server_image_management_thread(
ctx: Context,
db_type: String,
image_config: ImageConfig,
) {
info!("Launching the server image management thread!");
let mut interval = interval(Duration::from_secs(TIME_BETWEEN_SERVER_IMAGE_UPDATE));
loop {
interval.tick().await;
server_image_management(&ctx, db_type.clone()).await;
server_image_management(&ctx, db_type.clone(), image_config.clone()).await;
}
}

Expand Down
28 changes: 17 additions & 11 deletions src/background_task/server_image/calculate_user_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,23 @@ pub async fn return_average_user_color(
let color = user_color.color.clone();
let pfp_url_old = user_color.pfp_url.clone();
let image_old = user_color.image;
if color.is_none()
|| pfp_url_old.is_none()
|| image_old.is_none()
|| pfp_url != pfp_url_old.clone().unwrap_or_default()
{
let (average_color, image): (String, String) = calculate_user_color(member).await?;
set_user_approximated_color(&id, &average_color, &pfp_url, &image, db_type.clone())
.await?;
average_colors.push((average_color, pfp_url, image))
} else {
average_colors.push((color.unwrap(), pfp_url_old.unwrap(), image_old.unwrap()))
match (
color,
pfp_url_old.clone(),
image_old,
pfp_url == pfp_url_old.unwrap_or_default(),
) {
(Some(color), Some(pfp_url_old), Some(image_old), true) => {
average_colors.push((color, pfp_url_old, image_old));
continue;
}
_ => {
let (average_color, image): (String, String) = calculate_user_color(member).await?;
set_user_approximated_color(&id, &average_color, &pfp_url, &image, db_type.clone())
.await?;
average_colors.push((average_color, pfp_url, image));
continue;
}
}
}

Expand Down
Loading

0 comments on commit 155ad02

Please sign in to comment.