mirror of
https://github.com/dolphin-emu/discord-bot.git
synced 2024-10-06 23:23:22 +00:00
Initial commit
This commit is contained in:
commit
f56eafe2c2
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/target
|
1498
Cargo.lock
generated
Normal file
1498
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
11
Cargo.toml
Normal file
11
Cargo.toml
Normal 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
88
src/main.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user