remove attachement logger
This commit is contained in:
parent
fdd88db34c
commit
dd33bc8f81
|
@ -9,6 +9,5 @@ pub(crate) struct Conf {
|
||||||
pub(crate) struct Bot {
|
pub(crate) struct Bot {
|
||||||
pub(crate) token: String,
|
pub(crate) token: String,
|
||||||
pub(crate) application_id: u64,
|
pub(crate) application_id: u64,
|
||||||
pub(crate) log_attachments: Option<bool>,
|
|
||||||
pub(crate) invite_url: Option<String>,
|
pub(crate) invite_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,14 +21,13 @@ use serenity::{
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
fs::{self},
|
fs,
|
||||||
io::Result as IoResult,
|
io::Result as IoResult,
|
||||||
path::Path,
|
path::Path,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
use tokio::{fs::File, io::AsyncWriteExt};
|
|
||||||
|
|
||||||
#[cfg(feature = "music")]
|
#[cfg(feature = "music")]
|
||||||
use songbird::SerenityInit;
|
use songbird::SerenityInit;
|
||||||
|
@ -46,7 +45,6 @@ mod utils;
|
||||||
const MINIMUM_MENTIONS: usize = 20;
|
const MINIMUM_MENTIONS: usize = 20;
|
||||||
|
|
||||||
const PREFIX: &str = "?";
|
const PREFIX: &str = "?";
|
||||||
static mut LOG_ATTACHMENTS: bool = false;
|
|
||||||
pub(crate) static mut INVITE_URL: Option<String> = None;
|
pub(crate) static mut INVITE_URL: Option<String> = None;
|
||||||
|
|
||||||
// TODO CLAP FOR CLI
|
// TODO CLAP FOR CLI
|
||||||
|
@ -60,20 +58,12 @@ async fn main() -> IoResult<()> {
|
||||||
|
|
||||||
let token = conf.bot.token;
|
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 {
|
if let Some(url) = conf.bot.invite_url {
|
||||||
unsafe {
|
unsafe {
|
||||||
INVITE_URL = Some(url);
|
INVITE_URL = Some(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Log attachments : {}", unsafe { LOG_ATTACHMENTS });
|
|
||||||
|
|
||||||
let dir = Path::new("logging");
|
let dir = Path::new("logging");
|
||||||
if !dir.exists() {
|
if !dir.exists() {
|
||||||
fs::create_dir(dir)?;
|
fs::create_dir(dir)?;
|
||||||
|
@ -211,14 +201,6 @@ impl EventHandler for Messages {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn message(&self, ctx: Context, new_message: Message) {
|
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 {
|
if let Err(e) = log_mentions(ctx, &new_message).await {
|
||||||
error!("Error while logging mentions: {}", e);
|
error!("Error while logging mentions: {}", e);
|
||||||
}
|
}
|
||||||
|
@ -239,7 +221,6 @@ impl EventHandler for Messages {
|
||||||
log::error!("Failed to join thread : {}", e);
|
log::error!("Failed to join thread : {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn log_mentions(ctx: Context, new_message: &Message) -> CommandResult {
|
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(())
|
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]
|
#[hook]
|
||||||
async fn unknown_command(_ctx: &Context, _msg: &Message, unknown_command_name: &str) {
|
async fn unknown_command(_ctx: &Context, _msg: &Message, unknown_command_name: &str) {
|
||||||
debug!("Could not find command named '{}'", unknown_command_name);
|
debug!("Could not find command named '{}'", unknown_command_name);
|
||||||
|
|
Loading…
Reference in New Issue