forked from sorceress/rustcord
bottom text
This commit is contained in:
parent
aaf5ed8887
commit
a78e7a7d08
51
src/main.rs
51
src/main.rs
|
@ -10,6 +10,8 @@ use serenity::{
|
||||||
model::{channel::Message, gateway::Ready, id::UserId, user::OnlineStatus},
|
model::{channel::Message, gateway::Ready, id::UserId, user::OnlineStatus},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
use std::collections::hash_map::DefaultHasher;
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
use std::{env, process};
|
use std::{env, process};
|
||||||
|
|
||||||
struct Handler;
|
struct Handler;
|
||||||
|
@ -33,11 +35,18 @@ impl EventHandler for Handler {
|
||||||
|
|
||||||
#[group]
|
#[group]
|
||||||
#[commands(
|
#[commands(
|
||||||
init, ping, halt, list_srv, host, ship, headpat, uwu, gayculator, waffle, sausage, help, embed,
|
init, ping, halt, list_srv, host, ship, bottom_rng, headpat, uwu, gayculator, waffle, sausage,
|
||||||
what, owo, info
|
help, embed, what, owo, info
|
||||||
)]
|
)]
|
||||||
struct General;
|
struct General;
|
||||||
|
|
||||||
|
// Calculates hash of a type that implements Hash
|
||||||
|
fn calculate_hash<T: Hash>(t: &T) -> u64 {
|
||||||
|
let mut s = DefaultHasher::new();
|
||||||
|
t.hash(&mut s);
|
||||||
|
s.finish()
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut client = Client::new(&env::var("DISCORD_TOKEN").expect("Invalid token"), Handler)
|
let mut client = Client::new(&env::var("DISCORD_TOKEN").expect("Invalid token"), Handler)
|
||||||
.expect("Error creating client");
|
.expect("Error creating client");
|
||||||
|
@ -255,18 +264,38 @@ fn embed(ctx: &mut Context, message: &Message, args: Args) -> CommandResult {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
fn bottom_rng(ctx: &mut Context, message: &Message) -> CommandResult {
|
||||||
|
use rand::{rngs::StdRng, SeedableRng};
|
||||||
|
|
||||||
|
let messages = message
|
||||||
|
.channel_id
|
||||||
|
.messages(&ctx.http, |get| get.before(message.id).limit(20));
|
||||||
|
if let Err(e) = messages {
|
||||||
|
let _ = message.channel_id.say(&ctx.http, format!("Error: {}", e));
|
||||||
|
} else {
|
||||||
|
let mut messages = messages.unwrap();
|
||||||
|
messages.retain(|v| v.author != message.mentions[0]);
|
||||||
|
let mut input = String::new();
|
||||||
|
for msg in messages {
|
||||||
|
input.push_str(&format!("{} ", msg.content));
|
||||||
|
}
|
||||||
|
let result: u64 = StdRng::seed_from_u64(calculate_hash(&input)).gen_range(0, 100);
|
||||||
|
let _ = message.channel_id.send_message(&ctx.http, |m| {
|
||||||
|
m.embed(|e| {
|
||||||
|
e.title("Bottom RNG")
|
||||||
|
.description(format!("Result: {}", result))
|
||||||
|
.color(0x800869)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
fn ship(ctx: &mut Context, message: &Message, args: Args) -> CommandResult {
|
fn ship(ctx: &mut Context, message: &Message, args: Args) -> CommandResult {
|
||||||
use rand::{rngs::StdRng, SeedableRng};
|
use rand::{rngs::StdRng, SeedableRng};
|
||||||
use std::collections::hash_map::DefaultHasher;
|
|
||||||
use std::hash::{Hash, Hasher};
|
|
||||||
|
|
||||||
// Calculates hash of a type that implements Hash
|
|
||||||
fn calculate_hash<T: Hash>(t: &T) -> u64 {
|
|
||||||
let mut s = DefaultHasher::new();
|
|
||||||
t.hash(&mut s);
|
|
||||||
s.finish()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get input names
|
// Get input names
|
||||||
let names: String = args.rest().trim().to_string();
|
let names: String = args.rest().trim().to_string();
|
||||||
|
|
Loading…
Reference in New Issue