mirror of
https://github.com/ethanrusz/echbot.git
synced 2024-11-24 04:47:47 -05:00
Code cleanup
This commit is contained in:
parent
e943135d2e
commit
832c78a603
4 changed files with 20 additions and 32 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -14,3 +14,4 @@ Cargo.lock
|
||||||
|
|
||||||
/target
|
/target
|
||||||
/.idea/
|
/.idea/
|
||||||
|
/quotes.txt
|
||||||
|
|
|
@ -19,9 +19,8 @@ pub struct God {
|
||||||
ret_msg: Option<String>,
|
ret_msg: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_utc_timestamp() -> Result<String, Error> {
|
async fn get_utc_timestamp() -> String {
|
||||||
let timestamp: String = chrono::Utc::now().format("%Y%m%d%H%M%S").to_string();
|
chrono::Utc::now().format("%Y%m%d%H%M%S").to_string()
|
||||||
Ok(timestamp)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_signature(
|
async fn get_signature(
|
||||||
|
@ -29,24 +28,20 @@ async fn get_signature(
|
||||||
method: &str,
|
method: &str,
|
||||||
auth_key: &String,
|
auth_key: &String,
|
||||||
timestamp: &String,
|
timestamp: &String,
|
||||||
) -> Result<String, Error> {
|
) -> String {
|
||||||
let hash: Digest = md5::compute(format!("{}{}{}{}", dev_id, method, auth_key, timestamp));
|
let hash: Digest = md5::compute(format!("{dev_id}{method}{auth_key}{timestamp}"));
|
||||||
let signature: String = format!("{:x}", hash);
|
format!("{:x}", hash)
|
||||||
Ok(signature)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_session() -> Result<Session, Error> {
|
async fn create_session() -> Result<Session, Error> {
|
||||||
let dev_id: String = std::env::var("DEV_ID").expect("Missing DEV_ID");
|
let dev_id: String = std::env::var("DEV_ID").expect("Missing DEV_ID");
|
||||||
let auth_key: String = std::env::var("AUTH_KEY").expect("Missing AUTH_KEY");
|
let auth_key: String = std::env::var("AUTH_KEY").expect("Missing AUTH_KEY");
|
||||||
|
|
||||||
let timestamp: String = get_utc_timestamp().await?;
|
let timestamp: String = get_utc_timestamp().await;
|
||||||
let signature: String = get_signature(&dev_id, "createsession", &auth_key, ×tamp).await?;
|
let signature: String = get_signature(&dev_id, "createsession", &auth_key, ×tamp).await;
|
||||||
|
|
||||||
let request: String = format!(
|
let request: String = format!(
|
||||||
"https://api.smitegame.com/smiteapi.svc/createsessionJson/{dev_id}/{signature}/{timestamp}",
|
"https://api.smitegame.com/smiteapi.svc/createsessionJson/{dev_id}/{signature}/{timestamp}"
|
||||||
dev_id = dev_id,
|
|
||||||
signature = signature,
|
|
||||||
timestamp = timestamp
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let response: Response = reqwest::get(&request).await?;
|
let response: Response = reqwest::get(&request).await?;
|
||||||
|
@ -60,15 +55,11 @@ async fn get_gods() -> Result<Vec<God>, Error> {
|
||||||
|
|
||||||
let session_id: String = create_session().await?.session_id;
|
let session_id: String = create_session().await?.session_id;
|
||||||
|
|
||||||
let timestamp: String = get_utc_timestamp().await?;
|
let timestamp: String = get_utc_timestamp().await;
|
||||||
let signature: String = get_signature(&dev_id, "getgods", &auth_key, ×tamp).await?;
|
let signature: String = get_signature(&dev_id, "getgods", &auth_key, ×tamp).await;
|
||||||
|
|
||||||
let request: String = format!(
|
let request: String = format!(
|
||||||
"https://api.smitegame.com/smiteapi.svc/getgodsJson/{id}/{signature}/{session}/{timestamp}/1",
|
"https://api.smitegame.com/smiteapi.svc/getgodsJson/{dev_id}/{signature}/{session_id}/{timestamp}/1"
|
||||||
id = dev_id,
|
|
||||||
signature = signature,
|
|
||||||
session = session_id,
|
|
||||||
timestamp = timestamp,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let response: Response = reqwest::get(&request).await?;
|
let response: Response = reqwest::get(&request).await?;
|
||||||
|
@ -78,9 +69,7 @@ async fn get_gods() -> Result<Vec<God>, Error> {
|
||||||
|
|
||||||
pub async fn get_random_god() -> Result<String, Error> {
|
pub async fn get_random_god() -> Result<String, Error> {
|
||||||
let gods: Vec<God> = get_gods().await?;
|
let gods: Vec<God> = get_gods().await?;
|
||||||
let god: &God = gods
|
let god: &God = gods.choose(&mut rand::thread_rng()).unwrap();
|
||||||
.choose(&mut rand::thread_rng())
|
|
||||||
.expect("Couldn't pick random god.");
|
|
||||||
let name: String = god.name.clone();
|
let name: String = god.name.clone();
|
||||||
Ok(name)
|
Ok(name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub async fn god(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
ctx.send(|f| {
|
ctx.send(|f| {
|
||||||
f.embed(|f| {
|
f.embed(|f| {
|
||||||
f.title("Random God")
|
f.title("Random God")
|
||||||
.description(format!("Try not to throw with **{}**, idiot.", god))
|
.description(format!("Try not to throw with **{god}**, idiot."))
|
||||||
.color(serenity::Colour::BLUE)
|
.color(serenity::Colour::BLUE)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,11 +9,10 @@ use crate::{Context, Error};
|
||||||
|
|
||||||
/// Return a string of pingable IDs from a slice of string UserIds
|
/// Return a string of pingable IDs from a slice of string UserIds
|
||||||
fn team_to_ping(team: &[&String]) -> String {
|
fn team_to_ping(team: &[&String]) -> String {
|
||||||
return team
|
team.iter()
|
||||||
.iter()
|
.map(|o| format!("<@{o}>"))
|
||||||
.map(|o| format!("<@{}>", o))
|
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(", ");
|
.join(", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Splits up players for custom matches
|
/// Splits up players for custom matches
|
||||||
|
@ -57,7 +56,7 @@ pub async fn team(
|
||||||
|
|
||||||
ctx.send(|f| {
|
ctx.send(|f| {
|
||||||
f.embed(|f| {
|
f.embed(|f| {
|
||||||
f.title(format!("Custom {}v{} Teams", size, size))
|
f.title(format!("Custom {size}v{size} Teams"))
|
||||||
.description("VER")
|
.description("VER")
|
||||||
.field("Order", team_to_ping(order), false)
|
.field("Order", team_to_ping(order), false)
|
||||||
.field("Chaos", team_to_ping(chaos), false)
|
.field("Chaos", team_to_ping(chaos), false)
|
||||||
|
@ -83,7 +82,7 @@ pub async fn team(
|
||||||
{
|
{
|
||||||
let guild: Guild = ctx.guild().unwrap(); // Grab guild from context
|
let guild: Guild = ctx.guild().unwrap(); // Grab guild from context
|
||||||
for user in chaos {
|
for user in chaos {
|
||||||
let member: Member = guild.member(ctx, UserId(user.parse().unwrap())).await?; // Get the member in the correct guild
|
let member: Member = guild.member(ctx, UserId(user.parse()?)).await?; // Get the member in the correct guild
|
||||||
member
|
member
|
||||||
.move_to_voice_channel(ctx, chaos_channel.id())
|
.move_to_voice_channel(ctx, chaos_channel.id())
|
||||||
.await?; // Move the member to the correct voice channel
|
.await?; // Move the member to the correct voice channel
|
||||||
|
@ -94,7 +93,7 @@ pub async fn team(
|
||||||
ir.kind(serenity::InteractionResponseType::UpdateMessage)
|
ir.kind(serenity::InteractionResponseType::UpdateMessage)
|
||||||
.interaction_response_data(|f| {
|
.interaction_response_data(|f| {
|
||||||
f.embed(|f| {
|
f.embed(|f| {
|
||||||
f.title(format!("Custom {}v{} Teams", size, size))
|
f.title(format!("Custom {size}v{size} Teams"))
|
||||||
.description("VVGO VVW VVX")
|
.description("VVGO VVW VVX")
|
||||||
.field("Order", team_to_ping(order), false)
|
.field("Order", team_to_ping(order), false)
|
||||||
.field("Chaos", team_to_ping(chaos), false)
|
.field("Chaos", team_to_ping(chaos), false)
|
||||||
|
@ -109,7 +108,6 @@ pub async fn team(
|
||||||
.disabled(true) // with disabled button
|
.disabled(true) // with disabled button
|
||||||
.style(serenity::ButtonStyle::Primary)
|
.style(serenity::ButtonStyle::Primary)
|
||||||
.label("Quit Sibelius") // and new text
|
.label("Quit Sibelius") // and new text
|
||||||
.custom_id(uuid_team)
|
|
||||||
}, // Use the context ID as button ID
|
}, // Use the context ID as button ID
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue