Recreate webhooks when they go missing, reuse older webhooks, and initiate connections to Redis cluster

This commit is contained in:
2025-08-20 23:20:21 -03:00
parent ee49b0a984
commit aba11cb2da
15 changed files with 553 additions and 34 deletions
+34 -9
View File
@@ -2,6 +2,7 @@ use std::{error::Error, sync::Arc};
use async_trait::async_trait;
use itertools::Itertools;
use twilight_http::{api_error::ApiError, error::ErrorType};
use twilight_model::{
gateway::payload::incoming::{MessageCreate, MessageDelete, MessageUpdate},
id::Id,
@@ -151,7 +152,7 @@ impl OnMessageHandler<State> for CallMessageHandler {
return Ok(());
}
let Some(opposite_channel) = Channel::get_by_id(
let Some(mut opposite_channel) = Channel::get_by_id(
call.other_party_channel_id(event.channel_id.get()),
&rt.state.db,
)
@@ -167,7 +168,7 @@ impl OnMessageHandler<State> for CallMessageHandler {
let Some((webhook_id, webhook_token)) = opposite_channel
.webhook_id
.zip(opposite_channel.webhook_token)
.zip(opposite_channel.webhook_token.clone())
else {
// Handle DM calls in the future.
return Ok(());
@@ -202,14 +203,14 @@ impl OnMessageHandler<State> for CallMessageHandler {
rt.http
.create_message(event.channel_id)
.content(
"❌ Your message has been blocked because it broke Payphone's code of conduct. Check your DMs for more information.",
"🚩 Your message has been blocked because it broke Payphone's code of conduct. Check your DMs for more information.",
)
.await?;
rt.http
.create_message(Id::new(opposite_channel.id))
.content(&format!(
"❌ **{}** Sent a message that was blocked.\n-# If you see an inappropiate message, please report it using `Message > Apps > Report Message`.",
"🚩 **{}** Sent a message that was blocked.\n-# If you see an inappropiate message, please report it using `Message > Apps > Report Message`.",
profile.name.sanitize(false)
))
.await?;
@@ -241,7 +242,7 @@ impl OnMessageHandler<State> for CallMessageHandler {
);
}
let message_sent = rt
let message_sent = match rt
.http
.execute_webhook(Id::new(webhook_id), &webhook_token)
.allowed_mentions(None)
@@ -257,9 +258,26 @@ impl OnMessageHandler<State> for CallMessageHandler {
call.id,
opposite_channel.id
);
})?
.model()
.await?;
}) {
Ok(message) => message,
Err(e) => {
if let ErrorType::Response {
error: ApiError::General(error),
..
} = e.kind()
{
if error.code == 10015 {
log::debug!("Webhook not found, updating...");
log::trace!("Webhook ID before the update: {}", opposite_channel.webhook_id.unwrap_or(0));
opposite_channel.update_webhook(&rt.state.db, &rt.http).await?;
log::trace!("Webhook ID after the update: {}", opposite_channel.webhook_id.unwrap_or(0));
}
}
return Ok(());
}
}
.model()
.await?;
message = Message::build()
.call_id(call.id)
@@ -306,6 +324,13 @@ pub struct CallMessageEditHandler;
#[async_trait]
impl OnMessageEditHandler<State> for CallMessageEditHandler {
async fn on_message_edit(&self, event: &MessageUpdate, rt: Arc<Runtime<State>>) -> EventResult {
log::trace!(
"Edited message was '{}' sent by {} (bot? {:?})",
event.content,
event.author.id.get(),
event.author.bot
);
let Some(channel) = Channel::get_by_id(event.channel_id.get(), &rt.state.db).await? else {
return Ok(());
};
@@ -346,7 +371,7 @@ impl OnMessageEditHandler<State> for CallMessageEditHandler {
rt.http
.create_message(event.channel_id)
.content(
"❌ Your message's edit has been blocked because it broke Payphone's code of conduct. Check your DMs for more information.",
"🚩 Your message's edit has been blocked because it broke Payphone's code of conduct. Check your DMs for more information.",
)
.reply(event.id)
.await?;
@@ -1,5 +1,7 @@
sex
segs
esex
esegs
give head
gave head
give me head
@@ -35,7 +37,11 @@ stick it in yr pussy
cock
dick
dih
pussy
pusy
posay
vagina
vgina
vgna
dck
psy
pu-c
@@ -92,6 +98,7 @@ masturbate
masturbating
masterbating
masterbaiting
masturbatigng
horny
hrny
whore
@@ -8,6 +8,7 @@ qiga
niqa
nqa
nlger
ngiga
digga
fag
fagot
@@ -45,4 +46,5 @@ get the fvck out
get the fck out
get tfo
blackie
motherfucker
motherfucker
chinese ape
@@ -12,6 +12,3 @@ rape u
slit
grape
graped
throat slit
slit your throat
slit ur throat