-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V2.10.1 started working on bot management command.
- Loading branch information
1 parent
507d8f5
commit 150dcef
Showing
32 changed files
with
580 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "kasuki" | ||
version = "2.10.0" | ||
version = "2.10.1" | ||
edition = "2021" | ||
authors = ["Valgul <[email protected]>"] | ||
description = "A discord bot written in rust that get info from anilist API" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{ | ||
"guild_id": 1117152661620408531, | ||
"name": "give_premium_sub", | ||
"desc": "Give a user a premium subscription", | ||
"nsfw": false, | ||
"permissions": [ | ||
{ | ||
"permission": "Administrator" | ||
} | ||
], | ||
"args": [ | ||
{ | ||
"name": "user", | ||
"desc": "The user you want to give a premium subscription to.", | ||
"required": true, | ||
"autocomplete": false, | ||
"arg_type": "User", | ||
"localised_args": [ | ||
{ | ||
"code": "en-US", | ||
"name": "user", | ||
"desc": "The user you want to give a premium subscription to." | ||
}, | ||
{ | ||
"code": "fr", | ||
"name": "utilisateur", | ||
"desc": "L'utilisateur dont vous voulez donner une souscription premium." | ||
}, | ||
{ | ||
"code": "de", | ||
"name": "Benutzer", | ||
"desc": "Der Benutzer, dem Sie eine Premium-Abonnement geben können." | ||
}, | ||
{ | ||
"code": "ja", | ||
"name": "ユーザー", | ||
"desc": "プレミアムサブスクリプションを与えるユーザー" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "subscription", | ||
"desc": "The subscription you want to give the user.", | ||
"required": true, | ||
"autocomplete": true, | ||
"arg_type": "String", | ||
"localised_args": [ | ||
{ | ||
"code": "en-US", | ||
"name": "subscription", | ||
"desc": "The subscription you want to give the user." | ||
}, | ||
{ | ||
"code": "fr", | ||
"name": "abonné", | ||
"desc": "La souscription que vous souhaitez donner à l'utilisateur." | ||
}, | ||
{ | ||
"code": "de", | ||
"name": "Abonnement", | ||
"desc": "Das Abonnement, das Sie dem Benutzer geben können." | ||
}, | ||
{ | ||
"code": "ja", | ||
"name": "サブスクリプション", | ||
"desc": "ユーザーに与えるサブスクリプション" | ||
} | ||
] | ||
} | ||
], | ||
"localised" : [ | ||
{ | ||
"code": "en-US", | ||
"name": "give_premium_sub", | ||
"desc": "Give a user a premium subscription" | ||
}, | ||
{ | ||
"code": "fr", | ||
"name": "give_premium_sub", | ||
"desc": "Donner un utilisateur une souscription premium" | ||
}, | ||
{ | ||
"code": "de", | ||
"name": "give_premium_sub", | ||
"desc": "Geben Sie einem Benutzer eine Premium-Abonnement" | ||
}, | ||
{ | ||
"code": "ja", | ||
"name": "give_premium_sub", | ||
"desc": "ユーザーにプレミアムサブスクリプションを与える" | ||
} | ||
] | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"en": { | ||
"success": "Successfully gave user {user} the subscription {subscription} \n {res}" | ||
}, | ||
"fr": { | ||
"success": "Vous avez bien donne l'utilisateur {user} la souscription {subscription} \n {res}" | ||
}, | ||
"de": { | ||
"success": "Die Benutzer {user} hat die Abonnement {subscription} gegeben \n {res}" | ||
}, | ||
"ja": { | ||
"success": "{user} ユーザーに {subscription} によって与えられたサブスクリプション \n {res}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"en": { | ||
"on": "The module has been activated for everyone.", | ||
"off": "The module has been deactivated for everyone." | ||
}, | ||
"fr": { | ||
"on": "Le module a été activé pour tout le monde.", | ||
"off": "Le module a été désactivé pour tout le monde." | ||
}, | ||
"jp": { | ||
"on": "モジュールが全員に有効化されました。", | ||
"off": "モジュールが全員に無効化されました。" | ||
}, | ||
"de": { | ||
"on": "Das Modul wurde für alle aktiviert.", | ||
"off": "Das Modul wurde für alle deaktiviert." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use crate::constant::DEFAULT_STRING; | ||
use crate::helper::get_option::command::{get_option_map_string, get_option_map_user}; | ||
use crate::helper::get_option::subcommand::get_option_map_string_autocomplete_subcommand; | ||
use serenity::all::{ | ||
AutocompleteChoice, CommandInteraction, Context, CreateAutocompleteResponse, | ||
CreateInteractionResponse, SkuFlags, SkuKind, | ||
}; | ||
use tracing::debug; | ||
|
||
pub async fn give_premium_sub_autocomplete( | ||
ctx: Context, | ||
autocomplete_interaction: CommandInteraction, | ||
) { | ||
let map = get_option_map_string(&autocomplete_interaction); | ||
let subscription = map | ||
.get(&String::from("subscription")) | ||
.unwrap_or(DEFAULT_STRING); | ||
let map = get_option_map_user(&autocomplete_interaction); | ||
let user = match map.get(&String::from("user")) { | ||
Some(user) => user, | ||
None => return, | ||
}; | ||
|
||
let sku_list = ctx.http.get_skus().await.unwrap(); | ||
let sku_list = sku_list | ||
.iter() | ||
.map(|sku| { | ||
( | ||
{ | ||
let kind = match sku.kind { | ||
SkuKind::Subscription => String::from("Subscription"), | ||
SkuKind::SubscriptionGroup => String::from("Subscription Group"), | ||
SkuKind::Unknown(2) => String::from("DURABLE"), | ||
SkuKind::Unknown(3) => String::from("CONSUMABLE"), | ||
_ => String::from("Unknown"), | ||
}; | ||
let available = 1 << 2; | ||
let guild_subscription = 1 << 7; | ||
let user_subscription = 1 << 8; | ||
let flags_bits = sku.flags.bits(); | ||
let mut flags = String::new(); | ||
let mut flags2 = String::new(); | ||
if (available & flags_bits) != 0 { | ||
flags2.push_str("is available "); | ||
} | ||
|
||
if (guild_subscription & flags_bits) != 0 { | ||
flags.push_str("guild subscription "); | ||
} | ||
|
||
if (user_subscription & flags_bits) != 0 { | ||
flags.push_str("user subscription "); | ||
} | ||
format!("{} {} for {} {}", sku.name, kind, flags, flags2) | ||
.chars() | ||
.take(100) | ||
.collect::<String>() | ||
}, | ||
sku.id.to_string(), | ||
) | ||
}) | ||
.filter(|sku| !sku.0.contains("Subscription Group")) | ||
.map(|sku| AutocompleteChoice::new(sku.0, sku.1)) | ||
.take(25) | ||
.collect::<Vec<AutocompleteChoice>>(); | ||
if sku_list.is_empty() { | ||
return; | ||
} | ||
let data = CreateAutocompleteResponse::new().set_choices(sku_list); | ||
let builder = CreateInteractionResponse::Autocomplete(data); | ||
if let Err(why) = autocomplete_interaction | ||
.create_response(ctx.http, builder) | ||
.await | ||
{ | ||
debug!("Error sending response: {:?}", why); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod give_premium_sub; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::config::Config; | ||
use crate::helper::create_default_embed::get_default_embed; | ||
use crate::helper::error_management::error_enum::ResponseError; | ||
use crate::helper::get_option::command::{get_option_map_string, get_option_map_user}; | ||
use serenity::all::{ | ||
CommandInteraction, Context, CreateInteractionResponse, CreateInteractionResponseMessage, | ||
EntitlementOwner, | ||
}; | ||
use std::error::Error; | ||
use std::sync::Arc; | ||
|
||
pub async fn run( | ||
ctx: &Context, | ||
command_interaction: &CommandInteraction, | ||
config: Arc<Config>, | ||
) -> Result<(), Box<dyn Error>> { | ||
let map = get_option_map_user(command_interaction); | ||
let user = map | ||
.get(&String::from("user")) | ||
.ok_or(ResponseError::Option(String::from("No option for user")))? | ||
.clone(); | ||
let map = get_option_map_string(command_interaction); | ||
let subscription = map | ||
.get(&String::from("subscription")) | ||
.ok_or(ResponseError::Option(String::from( | ||
"No option for subscription", | ||
)))? | ||
.clone(); | ||
|
||
let skus = ctx | ||
.http | ||
.get_skus() | ||
.await | ||
.map_err(|e| ResponseError::WebRequest(format!("{:#?}", e)))?; | ||
let skus_id: Vec<String> = skus.iter().map(|sku| sku.id.to_string()).collect(); | ||
if !skus_id.contains(&subscription) { | ||
Err(ResponseError::Option(String::from("Invalid sub id")))? | ||
} | ||
let mut sku_id = Default::default(); | ||
for sku in skus { | ||
if sku.id.to_string() == subscription { | ||
sku_id = sku.id; | ||
} | ||
} | ||
|
||
let res = ctx | ||
.http | ||
.create_test_entitlement(sku_id, EntitlementOwner::User(user)) | ||
.await | ||
.map_err(|e| ResponseError::WebRequest(format!("{:#?}", e)))?; | ||
|
||
let embed = get_default_embed(None).description(format!( | ||
"Successfully gave user {} the subscription {} \n {:#?}", | ||
user, subscription, res | ||
)); | ||
let builder_message = CreateInteractionResponseMessage::new().embed(embed); | ||
|
||
let builder = CreateInteractionResponse::Message(builder_message); | ||
command_interaction | ||
.create_response(&ctx.http, builder) | ||
.await | ||
.map_err(|e| ResponseError::Sending(format!("{:#?}", e)))?; | ||
Ok(()) | ||
} |
Oops, something went wrong.