Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- client.on("ready", () => {
- console.log("ready")
- console.log(date().format('YY MMM DD'))
- if (!fs.existsSync("logs")){
- fs.mkdirSync("logs");
- }
- });
- //_____________________________________________________
- client.on("message",async message =>{
- //check so the channel is a text channel
- if(message.channel.type == "text"){
- //check if the message has an attachment
- if(message.attachments.size != 0){
- let Url = message.attachments.first().url
- //creates the direcotries as necesserly for storeing the attachments
- var dir = config.folder + "/" + message.guild.name + "/" + message.channel.name + "/"
- mkdirp.sync(dir, function (err) {
- if (err) console.error(err)
- });
- //makes the filename a timestamp while preserveing the extention.
- var extention = message.attachments.first().filename.split(".")
- var NewFilename = date().format("LTS") + "." + extention[1]
- //creates the downlaod function then calls it and pipe the attachment into designated folder/direcotry
- var download = function(uri, filename, callback){
- request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);}
- download(Url, dir + NewFilename, function(err){
- if (err)
- throw err
- })
- }
- //creates the datastring in .CSV format then passes it into the log function
- logData = date().format("h a") + ";" + message.guild.name + ";" + message.channel.name + ";" + message.author.username + ";" + message.content + "\r\n"
- log(logData,message.guild.name)
- }
- });
- //function to write the datastring into .CSV file
- function log(data,guild){
- if (!fs.existsSync("logs/" + date().format('YYYY MMM DD'))){
- fs.mkdirSync("logs/" + date().format('YYYY MMM DD'));
- }
- fs.appendFile("logs/" + date().format('YYYY MMM DD') + "/"+ guild + ".csv", data, function (err) {
- if (err) {
- console.log(err)
- } else {
- // done
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement