Removed code and phrases that Discord didn't like

This commit is contained in:
Em (Ethan) Ruszanowski 2023-03-08 13:25:50 -05:00
parent 832c78a603
commit 205c806369
No known key found for this signature in database
GPG key ID: B4B3EFE1F35DF9D6
7 changed files with 93 additions and 36 deletions

View file

@ -19,6 +19,23 @@ pub struct God {
ret_msg: Option<String>, ret_msg: Option<String>,
} }
#[derive(Deserialize, Debug)]
#[allow(dead_code)]
pub struct Profile {
#[serde(rename = "Name")]
pub name: Option<String>,
#[serde(rename = "Personal_Status_Message")]
pub personal_status_message: Option<String>,
pub hz_player_name: Option<String>,
#[serde(rename = "HoursPlayed")]
pub hours_played: i32,
#[serde(rename = "Losses")]
pub losses: i32,
#[serde(rename = "Wins")]
pub wins: i32,
pub ret_msg: Option<String>,
}
async fn get_utc_timestamp() -> String { async fn get_utc_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()
} }
@ -73,3 +90,21 @@ pub async fn get_random_god() -> Result<String, Error> {
let name: String = god.name.clone(); let name: String = god.name.clone();
Ok(name) Ok(name)
} }
pub async fn get_player(player: String) -> Result<Vec<Profile>, Error> {
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 session_id: String = create_session().await?.session_id;
let timestamp: String = get_utc_timestamp().await;
let signature: String = get_signature(&dev_id, "getplayer", &auth_key, &timestamp).await;
let request: String = format!(
"https://api.smitegame.com/smiteapi.svc/getplayerJson/{dev_id}/{signature}/{session_id}/{timestamp}/{player}"
);
let response: Response = reqwest::get(&request).await?;
let profiles: Vec<Profile> = response.json().await?;
Ok(profiles)
}

View file

@ -1,6 +1,7 @@
// Group all commands for registration // Group all commands for registration
mod api; mod api;
pub mod ping;
pub mod profile;
pub mod random; pub mod random;
pub mod register; pub mod register;
pub mod slur;
pub mod team; pub mod team;

48
src/commands/profile.rs Normal file
View file

@ -0,0 +1,48 @@
use crate::commands::api::get_player;
use crate::serenity;
use crate::{Context, Error};
/// Looks up a player's profile
#[poise::command(slash_command)]
pub async fn profile(
ctx: Context<'_>,
#[rename = "player"] player_name: String,
) -> Result<(), Error> {
let profiles = get_player(player_name).await?;
let profile = profiles.first().unwrap();
if profile.name.is_none() {
ctx.send(|f| {
f.embed(|f| {
f.title("Hidden")
.description("This profile is hidden.")
.color(serenity::Colour::RED)
})
})
.await?;
return Ok(());
}
let winrate =
(profile.wins as f32 / (profile.wins as f32 + profile.losses as f32)) * 100 as f32;
ctx.send(|f| {
f.embed(|f| {
f.title(format!("{}", profile.name.as_ref().unwrap()))
.description(format!(
"{}'s statistics.",
profile.hz_player_name.as_ref().unwrap()
))
.field(
"Status",
format!("{}", profile.personal_status_message.as_ref().unwrap()),
false,
)
.field("Hours played", format!("{}", profile.hours_played), false)
.field("Wins", format!("{}", profile.wins), true)
.field("Losses", format!("{}", profile.losses), true)
.field("Winrate", format!("{:.2}%", winrate), true)
.color(serenity::Colour::BLURPLE)
})
})
.await?;
Ok(())
}

View file

@ -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 **{god}**, idiot.")) .description(format!("Your random god is **{god}**!"))
.color(serenity::Colour::BLUE) .color(serenity::Colour::BLUE)
}) })
}) })

View file

@ -1,28 +0,0 @@
use crate::serenity;
use crate::{Context, Error};
use rand::seq::IteratorRandom;
use std::{
fs::File,
io::{BufRead, BufReader},
};
/// Basically a ping command
#[poise::command(slash_command, prefix_command)]
pub async fn slur(ctx: Context<'_>) -> Result<(), Error> {
let file: File = File::open("quotes.txt").unwrap_or_else(|_e| panic!("Quote file missing.")); // Open the quotes file
let file: BufReader<File> = BufReader::new(file); // Read the quotes file
let quotes = file.lines().map(|res| res.expect("Failed to read line."));
let quote: String = quotes
.choose(&mut rand::thread_rng())
.expect("No lines in file."); // Pick a random quote
ctx.send(|f| {
f.embed(|f| {
f.title("DMBrandon Sez")
.description(format!("\"{}\"", quote))
.color(serenity::Colour::GOLD)
})
})
.await?; // Send embed with team picks
Ok(())
}

View file

@ -38,12 +38,12 @@ pub async fn team(
// Make sure there are enough members in the voice channel // Make sure there are enough members in the voice channel
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("You don't have enough friends for that, idiot.") .description("There are not enough members in the call!")
.color(serenity::Colour::RED) .color(serenity::Colour::RED)
}) })
}) })
.await?; // Insult the user for not having enough friends .await?;
return Ok(()); // Break out early if there are not enough members return Ok(()); // Break out early if there are not enough members
} }
@ -57,7 +57,7 @@ pub async fn team(
ctx.send(|f| { ctx.send(|f| {
f.embed(|f| { f.embed(|f| {
f.title(format!("Custom {size}v{size} Teams")) f.title(format!("Custom {size}v{size} Teams"))
.description("VER") .description("Click the button below to move the Chaos players.")
.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)
.color(serenity::Colour::DARK_GREEN) .color(serenity::Colour::DARK_GREEN)
@ -94,7 +94,7 @@ pub async fn team(
.interaction_response_data(|f| { .interaction_response_data(|f| {
f.embed(|f| { f.embed(|f| {
f.title(format!("Custom {size}v{size} Teams")) f.title(format!("Custom {size}v{size} Teams"))
.description("VVGO VVW VVX") .description("Good luck! Have fun!")
.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)
.color(serenity::Colour::DARK_GREEN) .color(serenity::Colour::DARK_GREEN)

View file

@ -12,10 +12,11 @@ async fn main() {
let framework = poise::Framework::builder() let framework = poise::Framework::builder()
.options(poise::FrameworkOptions { .options(poise::FrameworkOptions {
commands: vec![ commands: vec![
commands::slur::slur(), commands::ping::ping(),
commands::team::team(), commands::team::team(),
commands::random::random(), commands::random::random(),
commands::register::register(), commands::register::register(),
commands::profile::profile(),
], // IntelliJ doesn't like this, but it's fine. ], // IntelliJ doesn't like this, but it's fine.
..Default::default() ..Default::default()
}) })