Don't allow here and everyone pings

This commit is contained in:
Yash Karandikar 2022-07-16 16:20:50 -04:00
parent 36c6488fa0
commit c9bb6843d1
2 changed files with 18 additions and 2 deletions

View file

@ -7,6 +7,7 @@ use tokio::sync::{mpsc::unbounded_channel, Mutex};
use tokio_stream::wrappers::UnboundedReceiverStream;
use serenity::{
cache::Cache,
futures::StreamExt,
http::Http,
model::{
@ -14,6 +15,7 @@ use serenity::{
webhook::Webhook,
},
prelude::*,
utils::{content_safe, ContentSafeOptions},
};
use crate::{regex, OptionReplacer};
@ -33,6 +35,7 @@ macro_rules! unwrap_or_continue {
pub async fn irc_loop(
mut client: IrcClient,
http: Arc<Http>,
cache: Arc<Cache>,
mapping: Arc<HashMap<String, u64>>,
webhooks: HashMap<String, Webhook>,
members: Arc<Mutex<Vec<Member>>>,
@ -101,9 +104,21 @@ pub async fn irc_loop(
let members_lock = members.lock().await;
let computed =
let mut computed =
irc_to_discord_processing(message, &*members_lock, &mut id_cache, channels);
computed = {
let opts = ContentSafeOptions::new()
.clean_role(false)
.clean_user(false)
.clean_channel(false)
.show_discriminator(false)
.clean_here(true) // setting these to true explicitly isn't needed,
.clean_everyone(true); // but i did it anyway for readability
content_safe(&cache, computed, &opts).await
};
if let Some(webhook) = webhooks.get(channel) {
let avatar = &*avatar_cache.entry(nickname.to_owned()).or_insert_with(|| {
members_lock.iter().find_map(|member| {

View file

@ -107,6 +107,7 @@ async fn main() -> anyhow::Result<()> {
let irc_client = IrcClient::from_config(config).await?;
let http = discord_client.cache_and_http.http.clone();
let cache = discord_client.cache_and_http.cache.clone();
let members = Arc::new(Mutex::new({
let channel_id = ChannelId::from(*conf.channels.iter().next().unwrap().1);
@ -144,7 +145,7 @@ async fn main() -> anyhow::Result<()> {
}
select! {
r = irc_loop(irc_client, http.clone(), channels.clone(), webhooks_transformed, members) => r.unwrap(),
r = irc_loop(irc_client, http.clone(), cache.clone(), channels.clone(), webhooks_transformed, members) => r.unwrap(),
r = discord_client.start() => r.unwrap(),
_ = terminate_signal() => {
for (_, &v) in channels.iter() {