Skip to content

Commit

Permalink
Merge pull request #91 from ValgulNecron/dev
Browse files Browse the repository at this point in the history
Small update
  • Loading branch information
ValgulNecron committed Nov 8, 2023
2 parents 7daeb94 + 498d8ef commit c811726
Show file tree
Hide file tree
Showing 217 changed files with 3,211 additions and 2,699 deletions.
3 changes: 2 additions & 1 deletion .env-default
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ DISCORD_TOKEN="Your token here"
AI_API_TOKEN="Your token here for the ai part"
AI_API_BASE_URL="The url for the request open ai or any openai proxy one do not forget to end with a / the url"
IMAGE_GENERATION_MODELS_ON=True
IMAGE_GENERATION_MODELS=""
IMAGE_GENERATION_MODELS=""
LOG="info" # trace, debug, info, warn or error
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Feature request
name: Feature requests
about: Suggest an idea for this project
title: ''
labels: 'enhancement'
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/translation_request.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Translation request
name: Translation requests
about: Ask for a translation in a specific langage
title: ''
labels: 'translation'
Expand Down
13 changes: 0 additions & 13 deletions .github/workflows/security_audit.yml

This file was deleted.

14 changes: 4 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
### Code style


please use sonarlint and respect it as much as possible.
always add comment on why you did this or that (I know I'm the first not doing it, but it helps everyone)
Please use clippy and do not add new warning (or as little as possible, so it can be easily fixed.)
Always add docstring to public function except for autocomplete, run and register.
also add comment to "hard" thing so people know why you did this.


### Naming convention
Expand All @@ -14,15 +15,8 @@ always add comment on why you did this or that (I know I'm the first not doing i
please respect <https://github.com/rust-lang/rfcs/blob/master/text/0430-finalizing-naming-conventions.md> \


### When adding new functionality to the bot


first, focus on a working version and after do it more properly and clean (except if you want to do it from the start)
since all new functionality will not be accepted or added having a "prototype" is best.


### When editing an already existing functionality


please tell what has changed and the impact better performance,
more readable, using a new api version.
more readable, using a new api version, etc...
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dotenv = "0.15.0"
tide = "0.16.0"
image = "0.24.7"
base64 = "0.21.2"
log = { version = "0.4.20" }


[profile.release]
lto = true
lto = true
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ RUN cargo build --release

FROM debian:buster-slim AS bot

LABEL maintainer="valgul"
LABEL author="valgul"
LABEL "com.docker.compose.hide"="true"
LABEL hidden="true"

RUN apt-get update && apt-get install -y --no-install-recommends \
libssl-dev libsqlite3-dev \
libpng-dev libjpeg-dev \
Expand Down
Binary file modified cache.db
Binary file not shown.
3 changes: 2 additions & 1 deletion compose-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ services:
- AI_API_TOKEN=your_token_here_for_the_ai_part
- AI_API_BASE_URL=the_url_for_the_request_open_ai_or_any_openai_proxy_one_do_not_forget_to_end_with_a_/_the_url
- IMAGE_GENERATION_MODELS_ON=True # true if you use have a proxy server on which you added another model
- IMAGE_GENERATION_MODELS="" # the name of the model you want only used if IMAGE_GENERATION_MODELS_ON is True
- IMAGE_GENERATION_MODELS=model_name # the name of the model you want only used if IMAGE_GENERATION_MODELS_ON is True
- LOG="info" # trace, debug, info, warn or error
volumes:
- ./db/data.db:/kasuki/data.db
- ./db/cache.db:/kasuki/cache.db
4 changes: 2 additions & 2 deletions lang_file/command_register/anilist/compare.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"code": "fr",
"name": "comparer",
"desc": "comparer les statistiques de deux utilisateurs",
"option1": "nom d'utilisateur",
"option1": "nom_d_utilisateur",
"option1_desc": "Nom d'utilisateur du 1er utilisateur AniList à comparer",
"option2": "nom d'utilisateur2",
"option2": "nom_d_utilisateur2",
"option2_desc": "Nom d'utilisateur du 2e utilisateur AniList à comparer"
},
"De": {
Expand Down
22 changes: 22 additions & 0 deletions lang_file/embed/general/avatar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"En": {
"title": "Here's the avatar of ",
"no_banner_title": "No avatar",
"error_no_user": "Error getting user"
},
"Fr": {
"title": "Voici l'avatar de ",
"no_banner_title": "Pas d'avatar",
"error_no_user": "Erreur lors de l'obtention de l'utilisateur"
},
"De": {
"title": "Hier ist das Avatar von ",
"no_banner_title": "Kein Avatar",
"error_no_user": "Fehler beim Abrufen des Benutzers"
},
"Jp": {
"title": "こちらがのアバターです ",
"no_banner_title": "アバターなし",
"error_no_user": "ユーザーの取得エラー"
}
}
20 changes: 16 additions & 4 deletions lang_file/embed/general/credit.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,43 @@
"title": "credit",
"list": [
{
"text": "Valgul: Main dev / original creator / french and english translation"
"text": "Valgul: Main dev / original creator / french and english translation \n"
},
{
"text": "Sionnakh: Dev of the website. \n"
}
]
},
"Fr": {
"title": "crédits",
"list": [
{
"text": "Valgul : Développeur principal / Créateur original / Traduction française et anglaise"
"text": "Valgul : Développeur principal / Créateur original / Traduction française et anglaise \n"
},
{
"text": "Sionnakh : Développeur du site web. \n"
}
]
},
"Jp": {
"title": "クレジット",
"list": [
{
"text": "バルガル:メインデベロッパー/オリジナルクリエイター/フランス語と英語の翻訳"
"text": "バルガル:メインデベロッパー/オリジナルクリエイター/フランス語と英語の翻訳 \n"
},
{
"text": "Sionnakh:ウェブサイトの開発者。 \n"
}
]
},
"De": {
"title": "Credits",
"list": [
{
"text": "Valgul: Hauptentwickler / Urheber / Französische und englische Übersetzung"
"text": "Valgul: Hauptentwickler / Originaler Schöpfer / Französische und englische Übersetzung \n"
},
{
"text": "Sionnakh: Entwickler der Website. \n"
}
]
}
Expand Down
15 changes: 12 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[![Build & Publish Release Docker Image](https://github.com/ValgulNecron/kasuki/actions/workflows/docker-image-release.yml/badge.svg?branch=master)](https://github.com/ValgulNecron/kasuki/actions/workflows/docker-image-release.yml)
[![Build & Publish Release Dev Image](https://github.com/ValgulNecron/kasuki/actions/workflows/docker-image-dev.yml/badge.svg?branch=dev)](https://github.com/ValgulNecron/kasuki/actions/workflows/docker-image-dev.yml)
[![Rust Clippy](https://github.com/ValgulNecron/kasuki/actions/workflows/linting.yml/badge.svg?branch=master)](https://github.com/ValgulNecron/kasuki/actions/workflows/linting.yml)
[![Rust Testing](https://github.com/ValgulNecron/kasuki/actions/workflows/testing.yml/badge.svg)](https://github.com/ValgulNecron/kasuki/actions/workflows/testing.yml)
![Code Activity](https://img.shields.io/github/commit-activity/w/valgulnecron/kasuki/master?style=plastic)

# TODO


Expand All @@ -10,6 +14,8 @@
- [ ] Clean the code. — It will never be done.
- [X] Find a name for the bot. — Found one kasuki. if you have any better, don't hesitate to recommend.
- [x] Add a bdd for some stuff prob sqlite but not sure. — Added sqlite db. (change to PostgreSQL)
— will add a var variable that will either be "sqlite" or "postgresql" with a url var for PostgreSQL
— will need to do some change and move db logic to it's own funtion.
- [X] Banner. Show your or a specified user banner. — Done.
- [X] Profil. Show a user profile and some info. — Done.
- [ ] Avatar. show you the profile picture of a user. — In progress
Expand Down Expand Up @@ -80,6 +86,11 @@
- Moderation submodule:
- [ ] General moderation stuff

- Games module:
- [ ] get game price from different platform (ubi, steam, epic, ea, etc....)
- [ ] get player stat
- [ ] get free promotion notification

## Website

for those of you who prefer web dev.\
Expand Down Expand Up @@ -205,7 +216,7 @@ cargo run --release
- Thanks Srayeals for the badge I use as the bot
pfp. ([https://anilist.co/forum/thread/20292](https://anilist.co/forum/thread/20292), [https://anilist.co/user/Srayeals](https://anilist.co/user/Srayeals))
- Annie May for the idea of having a discord bot linked to anilist (not the only one but the one I used and do not work
anymore.)
anymore. (and now it seems to work again.))
- [https://anilist.co/forum/thread/64835](https://anilist.co/forum/thread/64835) For seiyuu and va role image generation
idea.
- [https://github.com/Skittyblock/AniBot](https://github.com/Skittyblock/AniBot) For auto-complete on command, did not
Expand All @@ -215,5 +226,3 @@ cargo run --release


![kasuki](https://counter.valgul.moe/get/@kasuki?theme=gelbooru)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/987dc84319a24235a346a662ca9045c1)](https://app.codacy.com/gh/ValgulNecron/kasuki/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
![Code Activity](https://img.shields.io/github/commit-activity/w/valgulnecron/kasuki/master?style=plastic)
18 changes: 7 additions & 11 deletions src/cmd/api_module/main.rs → src/api/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ struct Ping {
ping: String,
}


async fn handle(req: tide::Request<()>) -> tide::Result<String> {
let shard_id = req.param("shardid").unwrap_or("0");
let database_url = "./data.db";
let pool = get_pool(database_url).await;
let row: (Option<String>, Option<String>) = sqlx::query_as(
"SELECT anilist_username, user_id FROM registered_user WHERE user_id = ?",
)
.bind(shard_id)
.fetch_one(&pool)
.await
.unwrap_or((None, None));

let row: (Option<String>, Option<String>) =
sqlx::query_as("SELECT anilist_username, user_id FROM registered_user WHERE user_id = ?")
.bind(shard_id)
.fetch_one(&pool)
.await
.unwrap_or((None, None));

let ping = Ping {
id: shard_id,
Expand All @@ -35,7 +32,6 @@ pub async fn create_server() -> tide::Result<()> {
let mut app = tide::new();
app.at("/api/ping/:shardid").get(handle);


app.listen("0.0.0.0:5783").await?;
Ok(())
}
}
1 change: 1 addition & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod main;
66 changes: 66 additions & 0 deletions src/available_lang.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use std::collections::HashMap;
use std::fs::File;
use std::io::Read;

use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct AvailableLang {
pub lang: String,
}

type AvailableLangList = HashMap<String, AvailableLang>;

impl AvailableLang {
/// Reads and returns a list of available languages from a JSON file.
///
/// This function opens a file named `available_lang.json` in the `lang_file` directory.
/// After opening the file, it reads the JSON content into a `String`.
/// Finally, it tries to deserialize the JSON content into an `AvailableLangList` object.
///
/// # Errors
///
/// If any error occurs while performing these operations, such as:
///
/// * Error while opening the file.
/// * Error while reading the file.
/// * Error while parsing the JSON content.
///
/// This function will return a static string describing the error.
///
/// # Returns
///
/// A `Result` which is:
///
/// * `Ok(AvailableLangList)` if all operations completed successfully.
/// * `Err(&'static str)` if any error occurred.
///
/// # Example
///
/// ```
/// use crate::your_module::get_available_lang;
///
/// match get_available_lang() {
/// Ok(lang_list) => println!("Available languages: {:?}", lang_list),
/// Err(err) => println!("Error: {}", err),
/// }
/// ```
pub fn get_available_lang() -> Result<AvailableLangList, &'static str> {
let mut file = match File::open("./lang_file/available_lang.json") {
Ok(file) => file,
Err(_) => return Err("Failed to open file"),
};

let mut json = String::new();

match file.read_to_string(&mut json) {
Ok(_) => {}
Err(_) => return Err("Failed to read file"),
};

match serde_json::from_str(&json) {
Ok(data) => Ok(data),
Err(_) => Err("Failed to parse json."),
}
}
}
3 changes: 0 additions & 3 deletions src/cmd/ai_module/cmd/mod.rs

This file was deleted.

Loading

0 comments on commit c811726

Please sign in to comment.