Redo ship command, minor text edits

This commit is contained in:
Agatha 2020-03-10 20:57:04 +02:00
parent 6f9790bda5
commit 55b6fff568
1 changed files with 30 additions and 5 deletions

View File

@ -24,7 +24,7 @@ impl EventHandler for Handler {
); );
use serenity::model::gateway::Activity; use serenity::model::gateway::Activity;
let activity = Activity::listening("uwu noises"); let activity = Activity::listening("catgirls nyaaing");
let status = OnlineStatus::Online; let status = OnlineStatus::Online;
ctx.set_presence(Some(activity), status); ctx.set_presence(Some(activity), status);
@ -155,8 +155,8 @@ fn host(ctx: &mut Context, message: &Message) -> CommandResult {
} }
#[command] #[command]
fn ship(ctx: &mut Context, message: &Message, mut args: Args) -> CommandResult { fn ship(ctx: &mut Context, message: &Message, args: Args) -> CommandResult {
use std::collections::hash_map::DefaultHasher; /*use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
let first = calculate_hash( let first = calculate_hash(
@ -195,7 +195,32 @@ fn ship(ctx: &mut Context, message: &Message, mut args: Args) -> CommandResult {
let mut s = DefaultHasher::new(); let mut s = DefaultHasher::new();
t.hash(&mut s); t.hash(&mut s);
s.finish() s.finish()
} } */
let names: String = args.rest().trim().to_string();
let names = names.split_whitespace().map(|x| x.to_owned()).collect::<Vec<String>>();
let shipname: Result<String, ()> = 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(()) Ok(())
} }
@ -360,7 +385,7 @@ fn info(ctx: &mut Context, message: &Message) -> CommandResult {
.embed(|e| e .embed(|e| e
.title("Discordinator9000's info:") .title("Discordinator9000's info:")
.description("h") .description("h")
.field("Author:", "#9000 (Agatha)", false) .field("Author:", "#9000 / Agatha", false)
.field("Server count:", num , false) .field("Server count:", num , false)
.field("Invite:", "[Invite link](https://discordapp.com/api/oauth2/authorize?client_id=470350233419907129&permissions=2048&scope=bot)", false ) .field("Invite:", "[Invite link](https://discordapp.com/api/oauth2/authorize?client_id=470350233419907129&permissions=2048&scope=bot)", false )
.footer(|f| f .footer(|f| f