initial crap
This commit is contained in:
parent
f3f9b24d26
commit
8390a26c48
3 changed files with 2457 additions and 8 deletions
2414
Cargo.lock
generated
Normal file
2414
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -4,4 +4,6 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
rand = "0.9.1"
|
||||
serenity = "0.12"
|
||||
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
||||
|
|
45
src/main.rs
45
src/main.rs
|
@ -4,19 +4,51 @@ use serenity::async_trait;
|
|||
use serenity::model::channel::Message;
|
||||
use serenity::model::gateway::Ready;
|
||||
use serenity::prelude::*;
|
||||
use tokio::fs::{read_to_string, File};
|
||||
|
||||
use std::fs::File as fsFile;
|
||||
use std::io::prelude::*;
|
||||
use std::fs::OpenOptions;
|
||||
use rand::Rng;
|
||||
|
||||
struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
async fn message(&self, ctx: Context, msg: Message) {
|
||||
if msg.content == "!ping" {
|
||||
// Sending a message can fail, due to a network error, an authentication error, or lack
|
||||
// of permissions to post in the channel, so log to stdout when some error happens,
|
||||
// with a description of it.
|
||||
if let Err(why) = msg.channel_id.say(&ctx.http, "Pong!").await {
|
||||
println!("Error sending message: {why:?}");
|
||||
if msg.content.starts_with("-addquote") {
|
||||
let quote = msg.content.strip_prefix("-addquote ").expect("asdf").to_string().replace("@", "\\@");
|
||||
let quote_to_write = format!("{}", quote).clone();
|
||||
let mut quote_file = OpenOptions::new().write(true).append(true).open("quotes.txt").unwrap();
|
||||
let write_result = writeln!(quote_file, "{}", quote_to_write);
|
||||
|
||||
match write_result {
|
||||
Ok(_) => {
|
||||
if let Err(_) = msg.channel_id.say(&ctx.http, "Successfully added your quote!").await {
|
||||
println!("THIS IS BROKJEN.");
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
if let Err(_) = msg.channel_id.say(&ctx.http, "fuck.").await {
|
||||
println!("EVERYTHING IS BREAKING.");
|
||||
}
|
||||
println!("STUPID FUCKING FILE: {}", e);
|
||||
}
|
||||
}
|
||||
} else if msg.content.starts_with("-quote") {
|
||||
let mut result = Vec::new();
|
||||
|
||||
for line in read_to_string("quotes.txt").await.unwrap().lines() {
|
||||
result.push(line.to_string())
|
||||
}
|
||||
|
||||
let rando = rand::rng().random_range(0..result.len());
|
||||
|
||||
if let Err(_) = msg.channel_id.say(&ctx.http, result[rando].to_string()).await {
|
||||
println!("mfw");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +59,7 @@ impl EventHandler for Handler {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
fsFile::create_new("quotes.txt");
|
||||
let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
|
||||
let intents = GatewayIntents::GUILD_MESSAGES
|
||||
| GatewayIntents::DIRECT_MESSAGES
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue