Skip to content

Commit

Permalink
Merge pull request #121 from ValgulNecron/dev
Browse files Browse the repository at this point in the history
V2.8.11
  • Loading branch information
ValgulNecron committed May 11, 2024
2 parents 039bad9 + 8751330 commit 6351d19
Show file tree
Hide file tree
Showing 223 changed files with 1,543 additions and 2,010 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Install rustup and common components
## Install rustup and helper components
curl https://sh.rustup.rs -sSf | sh -s -- -y
rustup install stable
rustup component add rustfmt
Expand Down
9 changes: 6 additions & 3 deletions .env-default
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ DB_TYPE="sqlite" # Database type (sqlite or postgres)
REMOVE_OLD_COMMAND="false" # Remove old commands on startup
MAX_LOG_RETENTION_DAYS=30 # Maximum number of days to retain logs

# web server configuration
GRPC_IS_ON="true" # Enable web server
GRPC_SERVER_PORT="8080" # Port for web server
# gRPC server configuration
GRPC_IS_ON="true" # Enable gRPC server
GRPC_SERVER_PORT="443" # Port for gRPC server
USE_SSL="true" # Use SSL for gRPC server
SSL_CERT_PATH="cert/cert.pem" # Path to SSL certificate
SSL_KEY_PATH="cert/key.pem" # Path to SSL key

# Media Saving Configuration
SAVE_IMAGE="local" # Where to save images (local, remote, false)
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ target/

images
images/**
cert
cert/**


# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kasuki"
version = "2.8.8"
version = "2.8.11"
edition = "2021"
authors = ["Valgul <contact@valgul.moe>"]
description = "A discord bot written in rust that get info from anilist API"
Expand Down Expand Up @@ -34,15 +34,16 @@ palette = "0.7.6"
catbox = "0.8.2"
imgurs = "0.11.2"
tracing-appender = "0.2.3"
tonic = "0.11.0"
tonic = { version = "0.11.0", features = ["tls"] }
prost = "0.12.4"
tonic-reflection = "0.11.0"
ratatui = "0.27.0-alpha.5"
crossterm = "0.27.0"
sysinfo = "0.30.11"
sysinfo = "0.30.12"
tui-logger = "0.11.1"
rayon = "1.10.0"
os_info = "3.8.2"
rcgen = "0.13.1"

[build-dependencies]
tonic-build = "0.11.0"
Expand Down
5 changes: 3 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
- [X] Get guild info.
- [X] Profile command.
- [X] Upgrade get guild info to show more info.
- [ ] Make the user profile better.
- [X] Make the user profile better.


- General part:
Expand All @@ -75,7 +75,8 @@
- [ ] Database
- [x] Add a sqlite database.
- [X] Add postgres database choices.
- [X] Add redis for cache.
- [ ] Add redis for cache.
- [ ] In memory cache.
- [ ] Rework the database to be more efficient.
- [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
Expand Down
6 changes: 6 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ fn main() -> Result<(), Box<dyn Error>> {
.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()
.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()
.file_descriptor_set_path(out_dir.join("command_descriptor.bin"))
.compile(&["proto/command.proto"], &["proto"])?;
tonic_build::compile_protos("proto/command.proto")?;
Ok(())
}
56 changes: 30 additions & 26 deletions compose-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,59 @@ services:
tty: true
environment:
# Discord Bot Configuration
- DISCORD_TOKEN="YourDiscordTokenHere" # Discord bot token used for authentication [0][2]
- BOT_ACTIVITY="Let you get info from anilist_user." # Status message displayed when the bot is active
- DISCORD_TOKEN=YourDiscordTokenHere # Discord bot token used for authentication [0][2]
- BOT_ACTIVITY=Let you get info from anilist_user. # Status message displayed when the bot is active

# OpenAI API Tokens and Base URLs
- AI_API_TOKEN="YourOpenAITokenHere" # Token for making requests to the OpenAI API [12]
- AI_API_BASE_URL="https://api.openai.com/v1/" # Base URL for API requests; must end with a slash [12]
- AI_API_TOKEN=YourOpenAITokenHere # Token for making requests to the OpenAI API [12]
- AI_API_BASE_URL=https://api.openai.com/v1/ # Base URL for API requests; must end with a slash [12]

# Image Generation Settings
- AI_IMAGE_API_TOKEN="${AI_API_TOKEN}" # Token specifically for image-related AI requests; defaults to AI_API_TOKEN if unset
- AI_IMAGE_API_BASE_URL="${AI_API_BASE_URL}" # Base URL for image-related API requests; defaults to AI_API_BASE_URL if unset
- AI_IMAGE_GENERATION_MODELS="dall-e-3" # AI model(s) used for generating images; default is 'dall-e-3' [12]
- AI_IMAGE_QUALITY="hd" # Quality level for generated images; typical options are 'ld', 'sd', 'hd', etc.
- AI_IMAGE_STYLE="vivid" # Style preference for generated images; can vary depending on the model used
- AI_IMAGE_SIZE="1024x1024" # Dimensions of generated images; default is '1024x1024'
- AI_IMAGE_API_TOKEN=${AI_API_TOKEN} # Token specifically for image-related AI requests; defaults to AI_API_TOKEN if unset
- AI_IMAGE_API_BASE_URL=${AI_API_BASE_URL} # Base URL for image-related API requests; defaults to AI_API_BASE_URL if unset
- AI_IMAGE_GENERATION_MODELS=dall-e-3 # AI model(s) used for generating images; default is 'dall-e-3' [12]
- AI_IMAGE_QUALITY=hd # Quality level for generated images; typical options are 'ld', 'sd', 'hd', etc.
- AI_IMAGE_STYLE=vivid # Style preference for generated images; can vary depending on the model used
- AI_IMAGE_SIZE=1024x1024 # Dimensions of generated images; default is '1024x1024'

# Chatbot Configuration
- AI_CHAT_API_TOKEN="${AI_API_TOKEN}" # Token for chat-related AI requests; defaults to AI_API_TOKEN if unset
- AI_CHAT_API_BASE_URL="${AI_API_BASE_URL}" # Base URL for chat-related API requests; defaults to AI_API_BASE_URL if unset
- AI_CHAT_MODEL="gpt-3.5-turbo" # AI model used for chat generation; default is 'gpt-3.5-turbo' [12]
- AI_CHAT_API_TOKEN=${AI_API_TOKEN} # Token for chat-related AI requests; defaults to AI_API_TOKEN if unset
- AI_CHAT_API_BASE_URL=${AI_API_BASE_URL} # Base URL for chat-related API requests; defaults to AI_API_BASE_URL if unset
- AI_CHAT_MODEL=gpt-3.5-turbo # AI model used for chat generation; default is 'gpt-3.5-turbo' [12]

# Transcription Configuration
- AI_TRANSCRIPT_API_TOKEN="${AI_API_TOKEN}" # Token for transcription-related AI requests; defaults to AI_API_TOKEN if unset
- AI_TRANSCRIPT_BASE_URL="${AI_API_BASE_URL}" # Base URL for transcription-related API requests; defaults to AI_API_BASE_URL if unset
- AI_TRANSCRIPT_MODELS="whisper-1" # AI model used for transcription generation; default is 'whisper-1' [12]
- AI_TRANSCRIPT_API_TOKEN=${AI_API_TOKEN} # Token for transcription-related AI requests; defaults to AI_API_TOKEN if unset
- AI_TRANSCRIPT_BASE_URL=${AI_API_BASE_URL} # Base URL for transcription-related API requests; defaults to AI_API_BASE_URL if unset
- AI_TRANSCRIPT_MODELS=whisper-1 # AI model used for transcription generation; default is 'whisper-1' [12]

# Logging and Debugging Configuration
- RUST_LOG="info" # Logging level for the application; can be 'trace', 'debug', 'info', 'warn', or 'error'
- RUST_LOG=info # Logging level for the application; can be 'trace', 'debug', 'info', 'warn', or 'error'
- MAX_LOG_RETENTION_DAYS=30 # Maximum number of days to retain logs

# Bot configuration
- REMOVE_OLD_COMMAND=false # Whether to remove old commands when the bot starts up
- DB_TYPE="sqlite" # Type of database to use; either 'sqlite' or 'postgres'
- DB_TYPE=sqlite # Type of database to use; either 'sqlite' or 'postgres'

# Web Server Configuration
- GRPC_IS_ON="true" # Whether to enable the web server for serving images and other content
- GRPC_PORT=8080 # Port to use for the web server (if enabled) (don't change this unless you know what you're doing)
# gRPC server configuration
- GRPC_IS_ON=true # Whether to enable the gRPC server for serving images and other content
- GRPC_PORT=443 # Port to use for the gRPC server (if enabled) (don't change this unless you know what you're doing)
- USE_SSL=true # Use SSL for gRPC server (don't change this unless you know what you're doing)
- SSL_CERT_PATH=cert/cert.pem # Path to SSL certificate (don't change this unless you know what you're doing)
- SSL_KEY_PATH=cert/key.pem # Path to SSL key (don't change this unless you know what you're doing)

# Media Saving Configuration
- SAVE_IMAGE="local" # Location to save images; can be 'local', 'remote', or 'false' to disable
- SAVE_SERVER="imgur" # Server to save media to; either 'imgur' or 'catbox'
- TOKEN="ImgurClientIDOrCatboxUserHash" # Authentication token for the chosen media saving server
- SAVE_IMAGE=local # Location to save images; can be 'local', 'remote', or 'false' to disable
- SAVE_SERVER=imgur # Server to save media to; either 'imgur' or 'catbox'
- TOKEN=ImgurClientIDOrCatboxUserHash # Authentication token for the chosen media saving server

# application configuration
- TUI="false" # Enable the TUI interface
- TUI=false # Enable the TUI interface
ports:
- "8080:8080"
- "443:443"
volumes:
- ./db/data.db:/kasuki/data.db
- ./db/cache.db:/kasuki/cache.db
- ./logs/:/kasuki/logs/
- ./server_image:/kasuki/server_image/
- ./cert:/kasuki/cert/
- /etc/localtime:/etc/localtime:ro
8 changes: 4 additions & 4 deletions json/subcommand_group/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -570,22 +570,22 @@
"localised": [
{
"code": "en-US",
"name": "admin",
"name": "general",
"desc": "Bot configuration configuration for admin only."
},
{
"code": "fr",
"name": "admin",
"name": "general",
"desc": "Configuration du bot pour les administrateurs uniquement."
},
{
"code": "de",
"name": "admin",
"name": "general",
"desc": "Allgemeine Bot-Konfiguration nur für Admins."
},
{
"code": "ja",
"name": "admin",
"name": "general",
"desc": "管理者専用の一般的なボット構成設定。"
}
]
Expand Down
43 changes: 43 additions & 0 deletions proto/command.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
syntax = "proto3";

package command;

service CommandService {
rpc CommandList (CommandListRequest) returns (CommandListResponse) {}
}

message CommandListRequest {
}

message CommandListResponse {
int64 command_count = 1;
repeated Command commands = 2;
repeated SubCommand sub_commands = 3;
repeated SubCommandGroup sub_command_groups = 4;
}

message Command {
string name = 1;
string description = 2;
repeated Arg args = 3;
}

message Arg {
string name = 1;
string description = 2;
bool required = 3;
repeated string choices = 4;
}

message SubCommand {
string name = 1;
string description = 2;
repeated Command commands = 3;
}

message SubCommandGroup {
string name = 1;
string description = 2;
repeated SubCommand sub_commands = 3;
repeated Command commands = 4;
}
31 changes: 18 additions & 13 deletions proto/info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,32 @@ syntax = "proto3";
package info;

service Info {
rpc GetInfo (InfoRequest) returns (InfoResponse);
rpc GetInfo (InfoRequest) returns (InfoResponse);
}

message InfoRequest {
}

message InfoResponse {
InfoData info = 1;
BotInfoData bot_info = 1;
SystemInfoData sys_info = 2;
}

message InfoData {
message BotInfoData {
string bot_name = 1;
string version = 2;
string cpu = 3;
string memory = 4;
string os = 5;
string uptime = 6;
string bot_id = 7;
string bot_owner = 8;
string bot_activity = 9;
string system_total_memory = 10;
string system_used_memory = 11;
string system_cpu_usage = 12;
string bot_uptime = 3;
string bot_id = 4;
string bot_owner = 5;
string bot_activity = 6;
string description = 7;
}

message SystemInfoData {
string app_cpu = 1;
string app_memory = 2;
string os = 3;
string system_total_memory = 4;
string system_used_memory = 5;
string system_cpu_usage = 6;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use chrono::Utc;
use serenity::all::{Context, CreateAttachment, EditWebhook, ExecuteWebhook, Webhook};
use tracing::{error, trace};

use crate::anilist_struct::run::minimal_anime::{ActivityData, MinimalAnimeWrapper};
use crate::common::default_embed::get_default_embed;
use crate::database::dispatcher::data_dispatch::{
use crate::database::data_struct::server_activity::ServerActivityFull;
use crate::database::manage::dispatcher::data_dispatch::{
get_data_activity, remove_data_activity_status, set_data_activity,
};
use crate::database_struct::server_activity::ServerActivityFull;
use crate::error_management::error_enum::{AppError, ErrorResponseType, ErrorType};
use crate::lang_struct::anilist_user::send_activity::load_localization_send_activity;
use crate::helper::create_normalise_embed::get_default_embed;
use crate::helper::error_management::error_enum::{AppError, ErrorResponseType, ErrorType};
use crate::structure::message::anilist_user::send_activity::load_localization_send_activity;
use crate::structure::run::anilist::minimal_anime::{ActivityData, MinimalAnimeWrapper};

/// `manage_activity` is an asynchronous function that manages activities.
/// It takes a `ctx` as a parameter.
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/background_task/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod activity;
pub mod server_image;
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use tokio::time::sleep;
use tracing::{debug, error};

use crate::constant::USER_BLACKLIST_SERVER_IMAGE;
use crate::database::dispatcher::data_dispatch::{
use crate::database::data_struct::user_color::UserColor;
use crate::database::manage::dispatcher::data_dispatch::{
get_user_approximated_color, set_user_approximated_color,
};
use crate::database_struct::user_color::UserColor;
use crate::error_management::error_enum::{AppError, ErrorResponseType, ErrorType};
use crate::helper::error_management::error_enum::{AppError, ErrorResponseType, ErrorType};

/// Calculates the color for each user in a list of members.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use image::DynamicImage;
use palette::color_difference::ImprovedDeltaE;
use palette::{IntoColor, Lab, Srgb};

use crate::database_struct::user_color::UserColor;
use crate::database::data_struct::user_color::UserColor;

/// `Color` is a struct that represents a color in the CIELAB color space.
/// It contains a single field, `cielab`, which is a `Lab` object from the `palette` crate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ use tokio::task;
use tracing::{error, info};
use uuid::Uuid;

use crate::database::dispatcher::data_dispatch::{
get_all_user_approximated_color, set_server_image,
};
use crate::error_management::error_enum::{AppError, ErrorResponseType, ErrorType};
use crate::image_saver::general_image_saver::image_saver;
use crate::server_image::calculate_user_color::{
use crate::background_task::server_image::calculate_user_color::{
get_image_from_url, get_member, return_average_user_color,
};
use crate::server_image::common::{
use crate::background_task::server_image::common::{
create_color_vector_from_tuple, create_color_vector_from_user_color, find_closest_color, Color,
ColorWithUrl,
};
use crate::database::manage::dispatcher::data_dispatch::{
get_all_user_approximated_color, set_server_image,
};
use crate::helper::error_management::error_enum::{AppError, ErrorResponseType, ErrorType};
use crate::helper::image_saver::general_image_saver::image_saver;

/// This function generates a local server image.
///
Expand Down
File renamed without changes.
Loading

0 comments on commit 6351d19

Please sign in to comment.