Update serenity
This commit is contained in:
parent
7e8a5fc410
commit
d558b9aa7c
File diff suppressed because it is too large
Load Diff
|
@ -2,9 +2,11 @@
|
|||
name = "basedbot"
|
||||
version = "0.1.0"
|
||||
authors = ["kageru <kageru@encode.moe>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
serenity = "0.8.7"
|
||||
serenity = "0.10"
|
||||
lazy_static = "1.4.0"
|
||||
regex = { version = "1.5.6", default_features = false, features = ["std", "unicode"] }
|
||||
async-trait = "0.1.53"
|
||||
tokio = { version = "1.18.2", features = ["rt-multi-thread"] }
|
||||
|
|
70
src/main.rs
70
src/main.rs
|
@ -1,3 +1,4 @@
|
|||
use async_trait::async_trait;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::{Captures, Regex};
|
||||
use serenity::model::channel::ReactionType;
|
||||
|
@ -15,28 +16,34 @@ lazy_static! {
|
|||
static ref RETARD_REGEX: Regex = Regex::new("([^j])a( |$)").unwrap();
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
fn message(&self, ctx: Context, message: Message) {
|
||||
async fn message(&self, ctx: Context, message: Message) {
|
||||
if message.guild_id != Some(*SERVER_ID) {
|
||||
return;
|
||||
}
|
||||
// That other idiot who ends words with “a” instead of “er”
|
||||
if message.author.id == 261246789942902794 && RETARD_REGEX.is_match(&message.content) {
|
||||
if let Err(e) = message.delete(&ctx) {
|
||||
if let Err(e) = message.delete(&ctx).await {
|
||||
eprintln!("Could not delete retarded message: {e}");
|
||||
}
|
||||
if let Err(e) = message
|
||||
.channel_id
|
||||
.say(&ctx, &format!("{} wollte sagen:", message.author.mention()))
|
||||
.await
|
||||
{
|
||||
eprint!("Could not send sanitized message intro: {e}");
|
||||
}
|
||||
if let Err(e) = message.channel_id.say(
|
||||
&ctx,
|
||||
RETARD_REGEX.replace_all(&message.content_safe(&ctx), |caps: &Captures| {
|
||||
format!("{}**er**{}", &caps[1], &caps[2])
|
||||
}),
|
||||
) {
|
||||
if let Err(e) = message
|
||||
.channel_id
|
||||
.say(
|
||||
&ctx,
|
||||
RETARD_REGEX.replace_all(&message.content_safe(&ctx).await, |caps: &Captures| {
|
||||
format!("{}**er**{}", &caps[1], &caps[2])
|
||||
}),
|
||||
)
|
||||
.await
|
||||
{
|
||||
eprint!("Could not send sanitized message: {e}");
|
||||
}
|
||||
}
|
||||
|
@ -46,45 +53,49 @@ impl EventHandler for Handler {
|
|||
|| message.content.contains(".webm")
|
||||
|| message.content.contains(".mov"))
|
||||
{
|
||||
if let Err(e) = message.channel_id.say(&ctx, "Working link:") {
|
||||
if let Err(e) = message.channel_id.say(&ctx, "Working link:").await {
|
||||
eprint!("Could not send fixed link: {e}");
|
||||
}
|
||||
if let Err(e) = message.channel_id.say(
|
||||
&ctx,
|
||||
message.content_safe(&ctx).replace(
|
||||
"https://media.discordapp.net/",
|
||||
"https://cdn.discordapp.com/",
|
||||
),
|
||||
) {
|
||||
if let Err(e) = message
|
||||
.channel_id
|
||||
.say(
|
||||
&ctx,
|
||||
message.content_safe(&ctx).await.replace(
|
||||
"https://media.discordapp.net/",
|
||||
"https://cdn.discordapp.com/",
|
||||
),
|
||||
)
|
||||
.await
|
||||
{
|
||||
eprint!("Could not send fixed link: {e}");
|
||||
};
|
||||
}
|
||||
if message.channel_id == *MEME_CHANNEL && is_meme(&message) {
|
||||
react(&ctx, &message, 748564944449962017, "based");
|
||||
react(&ctx, &message, 748564944819060856, "cringe");
|
||||
react(&ctx, &message, 748564944449962017, "based").await;
|
||||
react(&ctx, &message, 748564944819060856, "cringe").await;
|
||||
}
|
||||
let content = message.content.to_lowercase();
|
||||
if content.contains("everyone") && content.contains("nitro") && content.contains("http") {
|
||||
if let Err(e) = message.delete(&ctx) {
|
||||
if let Err(e) = message.delete(&ctx).await {
|
||||
eprint!("Could not delete spam: {e}");
|
||||
}
|
||||
if let Err(e) = message.channel_id.say(
|
||||
&ctx,
|
||||
&format!("{}: your message has been deleted because it triggered my spam filter. If you believe this to be in error, please contact the mods.", message.author.mention())
|
||||
) {
|
||||
).await {
|
||||
eprint!("Could not respond to spam: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn react(ctx: &Context, msg: &Message, emoji: u64, name: &str) {
|
||||
async fn react(ctx: &Context, msg: &Message, emoji: u64, name: &str) {
|
||||
let reaction = ReactionType::Custom {
|
||||
animated: false,
|
||||
id: EmojiId(emoji),
|
||||
name: Some(name.to_string()),
|
||||
};
|
||||
if let Err(e) = msg.react(ctx, reaction) {
|
||||
if let Err(e) = msg.react(ctx, reaction).await {
|
||||
println!("Could not react, error was: {e}");
|
||||
}
|
||||
}
|
||||
|
@ -93,11 +104,12 @@ fn is_meme(msg: &Message) -> bool {
|
|||
!msg.attachments.is_empty() || msg.content.to_lowercase().contains("http")
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let mut client = Client::new(
|
||||
std::env::var("DISCORD_TOKEN").expect("no token in environment"),
|
||||
Handler,
|
||||
)
|
||||
.expect("Could not create client");
|
||||
client.start().expect("could not start");
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let mut client =
|
||||
Client::builder(std::env::var("DISCORD_TOKEN").expect("no token in environment"))
|
||||
.event_handler(Handler)
|
||||
.await
|
||||
.expect("Could not create client");
|
||||
client.start().await.expect("could not start");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user