remove attachement logger

This commit is contained in:
oupson 2022-03-11 10:37:49 +01:00
parent fdd88db34c
commit dd33bc8f81
2 changed files with 1 additions and 30 deletions

View File

@ -9,6 +9,5 @@ pub(crate) struct Conf {
pub(crate) struct Bot {
pub(crate) token: String,
pub(crate) application_id: u64,
pub(crate) log_attachments: Option<bool>,
pub(crate) invite_url: Option<String>,
}

View File

@ -21,14 +21,13 @@ use serenity::{
};
use std::{
collections::{HashMap, HashSet},
fs::{self},
fs,
io::Result as IoResult,
path::Path,
sync::Arc,
time::Duration,
time::Instant,
};
use tokio::{fs::File, io::AsyncWriteExt};
#[cfg(feature = "music")]
use songbird::SerenityInit;
@ -46,7 +45,6 @@ mod utils;
const MINIMUM_MENTIONS: usize = 20;
const PREFIX: &str = "?";
static mut LOG_ATTACHMENTS: bool = false;
pub(crate) static mut INVITE_URL: Option<String> = None;
// TODO CLAP FOR CLI
@ -60,20 +58,12 @@ async fn main() -> IoResult<()> {
let token = conf.bot.token;
if conf.bot.log_attachments.unwrap_or(false) {
unsafe {
LOG_ATTACHMENTS = true;
}
}
if let Some(url) = conf.bot.invite_url {
unsafe {
INVITE_URL = Some(url);
}
}
debug!("Log attachments : {}", unsafe { LOG_ATTACHMENTS });
let dir = Path::new("logging");
if !dir.exists() {
fs::create_dir(dir)?;
@ -211,14 +201,6 @@ impl EventHandler for Messages {
}
async fn message(&self, ctx: Context, new_message: Message) {
if unsafe { LOG_ATTACHMENTS } && !new_message.attachments.is_empty() {
for att in &new_message.attachments {
if let Err(e) = download_to_log(att).await {
error!("Error while downloading to log : {:?}", e);
}
}
}
if let Err(e) = log_mentions(ctx, &new_message).await {
error!("Error while logging mentions: {}", e);
}
@ -239,7 +221,6 @@ impl EventHandler for Messages {
log::error!("Failed to join thread : {}", e);
}
}
}
async fn log_mentions(ctx: Context, new_message: &Message) -> CommandResult {
@ -345,15 +326,6 @@ async fn log_mentions(ctx: Context, new_message: &Message) -> CommandResult {
Ok(())
}
async fn download_to_log(attachment: &Attachment) -> commands::Result<()> {
debug!("Download_to_log : {:?}", attachment);
let path = Path::new("logging").join(format!("{}-{}", attachment.id, attachment.filename));
let content = reqwest::get(&attachment.url).await?.bytes().await?;
let mut file = File::create(path).await?;
file.write_all(&content).await?;
Ok(())
}
#[hook]
async fn unknown_command(_ctx: &Context, _msg: &Message, unknown_command_name: &str) {
debug!("Could not find command named '{}'", unknown_command_name);