Skip to content

Commit

Permalink
Merge pull request #105 from ValgulNecron/dev
Browse files Browse the repository at this point in the history
Fixed command.
  • Loading branch information
ValgulNecron committed Mar 8, 2024
2 parents 3d8fa3a + 505b22c commit 8bf5bf3
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 54 deletions.
30 changes: 30 additions & 0 deletions json/command/anilist.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,36 @@
"desc": "最高のワイフを提供します。"
}
]
},
{
"name": "user",
"desc": "Info of an anilist user.",
"command_type": "SubCommand",
"required": true,
"autocomplete": false,
"file": "anilist/user.json",
"localised_args": [
{
"code": "en-US",
"name": "user",
"desc": "Info of an anilist user."
},
{
"code": "fr",
"name": "utilisateur",
"desc": "Informations sur un utilisateur d'Anilist."
},
{
"code": "de",
"name": "benutzer",
"desc": "Informationen zu einem Anilist-Benutzer."
},
{
"code": "ja",
"name": "ユーザー",
"desc": "アニリストユーザーの情報。"
}
]
}
],
"localised": [
Expand Down
File renamed without changes.
30 changes: 0 additions & 30 deletions json/command/general.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,36 +185,6 @@
"desc": "ユーザーのプロフィールを表示します。"
}
]
},
{
"name": "user",
"desc": "Info of an anilist user.",
"command_type": "SubCommand",
"required": true,
"autocomplete": false,
"file": "general/user.json",
"localised_args": [
{
"code": "en-US",
"name": "user",
"desc": "Info of an anilist user."
},
{
"code": "fr",
"name": "utilisateur",
"desc": "Informations sur un utilisateur d'Anilist."
},
{
"code": "de",
"name": "benutzer",
"desc": "Informationen zu einem Anilist-Benutzer."
},
{
"code": "ja",
"name": "ユーザー",
"desc": "アニリストユーザーの情報。"
}
]
}
],
"localised": [
Expand Down
21 changes: 5 additions & 16 deletions src/command_run/admin/lang.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
use serenity::all::{
CommandDataOption, CommandDataOptionValue, CommandInteraction, Context, CreateEmbed,
CommandInteraction, Context, CreateEmbed,
CreateInteractionResponse, CreateInteractionResponseMessage, Timestamp,
};
use crate::command_run::get_option::get_option_map_string_subcommand;

use crate::constant::COLOR;
use crate::database::dispatcher::data_dispatch::set_data_guild_language;
use crate::error_management::error_enum::{AppError, ErrorResponseType, ErrorType};
use crate::lang_struct::general::lang::load_localization_lang;

pub async fn run(
options: &[CommandDataOption],
ctx: &Context,
command_interaction: &CommandInteraction,
) -> Result<(), AppError> {
let lang = options.first().ok_or(AppError::new(
let map = get_option_map_string_subcommand(command_interaction);
let lang = map.get(&String::from("lang_choice")).ok_or(AppError::new(
String::from("There is no option"),
ErrorType::Option,
ErrorResponseType::Message,
ErrorResponseType::Followup,
))?;
let lang = lang.value.clone();

let lang = match lang {
CommandDataOptionValue::String(lang) => lang,
_ => {
return Err(AppError::new(
String::from("The option is not a string."),
ErrorType::Option,
ErrorResponseType::Message,
));
}
};

let guild_id = match command_interaction.guild_id {
Some(id) => id.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/command_run/command_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async fn admin(ctx: &Context, command_interaction: &CommandInteraction) -> Resul
.name
.as_str()
{
"lang" => lang::run(&command_interaction.data.options, ctx, command_interaction).await,
"lang" => lang::run(ctx, command_interaction).await,
"module" => module::run(ctx, command_interaction).await,
_ => Err(AppError::new(
String::from("Command does not exist."),
Expand Down
10 changes: 5 additions & 5 deletions src/database/sqlite/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub async fn set_data_ping_history_sqlite(
) -> Result<(), AppError> {
let pool = get_sqlite_pool(DATA_SQLITE_DB).await?;
let now = Utc::now().timestamp().to_string();
sqlx::query("INSERT OR REPLACE INTO ping_history (shard_id, timestamp, ping) VALUES (?, ?, ?)")
let _ = sqlx::query("INSERT OR REPLACE INTO ping_history (shard_id, timestamp, ping) VALUES (?, ?, ?)")
.bind(shard_id)
.bind(now)
.bind(latency)
Expand Down Expand Up @@ -83,7 +83,7 @@ pub async fn set_data_guild_language_sqlite(
lang: &String,
) -> Result<(), AppError> {
let pool = get_sqlite_pool(DATA_SQLITE_DB).await?;
sqlx::query("INSERT OR REPLACE INTO guild_lang (guild, lang) VALUES (?, ?)")
let _ = sqlx::query("INSERT OR REPLACE INTO guild_lang (guild, lang) VALUES (?, ?)")
.bind(guild_id)
.bind(lang)
.execute(&pool)
Expand Down Expand Up @@ -133,7 +133,7 @@ pub async fn set_data_activity_sqlite(
server_activity_full: ServerActivityFull,
) -> Result<(), AppError> {
let pool = get_sqlite_pool(DATA_SQLITE_DB).await?;
sqlx::query(
let _ = sqlx::query(
"INSERT OR REPLACE INTO activity_data (anime_id, timestamp, server_id, webhook, episode, name, delays, image) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
)
.bind(server_activity_full.anime_id)
Expand Down Expand Up @@ -289,10 +289,10 @@ pub async fn set_registered_user_sqlite(
username: &String,
) -> Result<(), AppError> {
let pool = get_sqlite_pool(DATA_SQLITE_DB).await?;
sqlx::query_as("INSERT OR REPLACE INTO registered_user (user_id, anilist_id) VALUES (?, ?)")
let _ = sqlx::query("INSERT OR REPLACE INTO registered_user (user_id, anilist_id) VALUES (?, ?)")
.bind(user_id)
.bind(username)
.fetch_one(&pool)
.execute(&pool)
.await
.map_err(|e| {
AppError::new(
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,11 @@ impl EventHandler for Handler {
if let Interaction::Command(command_interaction) = interaction.clone() {
// Log the details of the command interaction
info!(
"Received {} from {} in {}",
"Received {} from {} in {} with option {:?}",
command_interaction.data.name,
command_interaction.user.name,
command_interaction.guild_id.unwrap().to_string()
command_interaction.guild_id.unwrap().to_string(),
command_interaction.data.options
);
// Dispatch the command
if let Err(e) = command_dispatching(&ctx, &command_interaction).await {
Expand Down

0 comments on commit 8bf5bf3

Please sign in to comment.