initial commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/target
|
||||
.env
|
||||
1937
Cargo.lock
generated
Normal file
1937
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
13
Cargo.toml
Normal file
13
Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "beboucord"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serenity = "0.12"
|
||||
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
||||
dotenv = "0.15"
|
||||
regex = "1.10"
|
||||
once_cell = "1.19"
|
||||
60
src/main.rs
Normal file
60
src/main.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
use std::env;
|
||||
|
||||
use dotenv::dotenv;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use serenity::async_trait;
|
||||
use serenity::model::channel::Message;
|
||||
use serenity::model::gateway::Ready;
|
||||
use serenity::prelude::*;
|
||||
|
||||
struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
async fn message(&self, ctx: Context, msg: Message) {
|
||||
if msg.author.bot {
|
||||
return;
|
||||
}
|
||||
static RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"https://(?:www\.)?((reddit\.com)|(twitter\.com|x\.com)|(instagram\.com))").unwrap());
|
||||
|
||||
if let Some(capture) = RE.captures(&msg.content) {
|
||||
let mut new_msg = "Oups".to_string();
|
||||
|
||||
if let Some(reddit) = capture.get(2) {
|
||||
new_msg = msg.content.replace(reddit.as_str(), "rxddit.com");
|
||||
} else if let Some(twitter) = capture.get(3) {
|
||||
new_msg = msg.content.replace(twitter.as_str(), "fxtwitter.com");
|
||||
} else if let Some(instagram) = capture.get(4) {
|
||||
new_msg = msg.content.replace(instagram.as_str(), "ddinstagram.com");
|
||||
}
|
||||
|
||||
if let Err(why) = msg.channel_id.say(&ctx.http, new_msg).await {
|
||||
println!("Error sending message: {why:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn ready(&self, _: Context, ready: Ready) {
|
||||
println!("{} is connected!", ready.user.name);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
dotenv().ok();
|
||||
let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
|
||||
let intents = GatewayIntents::GUILD_MESSAGES
|
||||
| GatewayIntents::DIRECT_MESSAGES
|
||||
| GatewayIntents::MESSAGE_CONTENT;
|
||||
|
||||
let mut client = Client::builder(&token, intents)
|
||||
.event_handler(Handler)
|
||||
.await
|
||||
.expect("Err creating client");
|
||||
|
||||
if let Err(why) = client.start().await {
|
||||
println!("Client error: {why:?}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user