Initial commit

This commit is contained in:
sirmangler 2023-09-24 18:54:32 +01:00
commit f56eafe2c2
4 changed files with 1598 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

1498
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

11
Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "dolphinbot"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
regex = "1.9.5"
serenity = { version = "0.11.6", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "cache"] }
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }

88
src/main.rs Normal file
View File

@ -0,0 +1,88 @@
use std::env;
use std::thread;
use std::sync::Arc;
use std::time::Duration;
use regex::Regex;
use serenity::async_trait;
use serenity::futures::TryFutureExt;
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 || msg.channel_id != 1000215517673554012 {
return;
}
let ctx = Arc::new(ctx);
let gateway_raw: &'static str = "Piracy is illegal, so I will not talk about downloading games or copyrighted content even if I have owned another copy in the past, as that is still illegal under US law.";
let pattern = Regex::new(r"[*,.-` ><!]").unwrap();
let clean = pattern.replace_all(&msg.content, "").to_lowercase();
let gateway = pattern.replace_all(gateway_raw, "").to_lowercase();
if let Err(why) = msg.delete(&ctx.http).await {
println!("Couldn't delete message! {:?}", why);
}
if String::eq(&clean, &gateway) {
if let Some(guild_id) = msg.guild_id {
if let Some(guild) = guild_id.to_guild_cached(&ctx) {
let mut member =
guild.member(&ctx, msg.author.id).await.unwrap();
if let Err(why) = member.add_role(&ctx, 1000167241465209024).await {
println!("Couldn't add role! {:?}", why);
}
} else {
println!("Couldn't get guild");
}
}
return;
}
let incorrect_msg = format!("<@{:?}> To enter the server, please enter: `{}`", msg.author.id.as_u64(), gateway_raw);
let future = msg.channel_id.say(&ctx.http, incorrect_msg);
let ctx1 = Arc::clone(&ctx);
let then = future.and_then(|msg| async move {
thread::sleep(Duration::from_millis(3000));
_ = msg.delete(&ctx1.http).await;
return Ok(());
});
if let Err(why) = then.await {
println!("Error sending message: {:?}", why);
}
}
async fn ready(&self, _: Context, ready: Ready) {
println!("{} is connected!", ready.user.name);
}
}
#[tokio::main]
async fn main() {
let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
let intents = GatewayIntents::GUILD_MESSAGES
| GatewayIntents::DIRECT_MESSAGES
| GatewayIntents::MESSAGE_CONTENT
| GatewayIntents::GUILDS;
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);
}
}