From 55b6fff5680e7a99b4c8f0977735acf029a80624 Mon Sep 17 00:00:00 2001 From: Agatha Date: Tue, 10 Mar 2020 20:57:04 +0200 Subject: [PATCH] Redo ship command, minor text edits --- src/main.rs | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index a0445ce..fe638f5 100755 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ impl EventHandler for Handler { ); use serenity::model::gateway::Activity; - let activity = Activity::listening("uwu noises"); + let activity = Activity::listening("catgirls nyaaing"); let status = OnlineStatus::Online; ctx.set_presence(Some(activity), status); @@ -155,8 +155,8 @@ fn host(ctx: &mut Context, message: &Message) -> CommandResult { } #[command] -fn ship(ctx: &mut Context, message: &Message, mut args: Args) -> CommandResult { - use std::collections::hash_map::DefaultHasher; +fn ship(ctx: &mut Context, message: &Message, args: Args) -> CommandResult { + /*use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; let first = calculate_hash( @@ -195,7 +195,32 @@ fn ship(ctx: &mut Context, message: &Message, mut args: Args) -> CommandResult { let mut s = DefaultHasher::new(); t.hash(&mut s); s.finish() - } + } */ + + let names: String = args.rest().trim().to_string(); + let names = names.split_whitespace().map(|x| x.to_owned()).collect::>(); + let shipname: Result = match names.len() { + 0 => Err(()), + 1 => Ok(names[0].clone()), + _ => { + let mut first_halves = String::new(); + for name in &names[0..names.len()-1] { + first_halves.push_str(&name[0..name.len() / 2]); + } + let first_halves = first_halves.as_str(); + let last_half = &names[names.len()-1][(names.len() / 2)+1..]; + + Ok(format!("{}{}", first_halves, last_half)) + } + }; + + let _ = message.channel_id.send_message(&ctx.http, |m| { + m.embed(|e| { + e.title("Ship name:".to_string()) + .description(shipname.unwrap_or_else(|_| "Invalid input!".to_string())) + .color(0xffd1dc) + }) + }); Ok(()) } @@ -360,7 +385,7 @@ fn info(ctx: &mut Context, message: &Message) -> CommandResult { .embed(|e| e .title("Discordinator9000's info:") .description("h") - .field("Author:", "#9000 (Agatha)", false) + .field("Author:", "#9000 / Agatha", false) .field("Server count:", num , false) .field("Invite:", "[Invite link](https://discordapp.com/api/oauth2/authorize?client_id=470350233419907129&permissions=2048&scope=bot)", false ) .footer(|f| f