Created
July 24, 2022 20:50
-
-
Save Maxime66410/1b5e2d9a7f3eb528e82a05b460b53896 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fieldTarget = 'By Maxime66410'; | |
var discordWebhookUrl = ''; // change this! | |
/** use discord webhooks to send the message */ | |
function discordWebhook(txt) { | |
Logger.log('posting...'); | |
var payload = { | |
//"avatar_url": "https://cdn.discordapp.com/emojis/732123527225933849.png", // remove this if u want to put your own avatar | |
"content": "`" + txt + "`" | |
}; | |
var options = { | |
'method': 'post', | |
'payload': JSON.stringify(payload), | |
'headers': { | |
'Content-Type': 'application/json', | |
}, | |
"muteHttpExceptions" : true | |
}; | |
Logger.log(options); | |
try { | |
let response = UrlFetchApp.fetch(discordWebhookUrl, options); | |
if(response.getResponseCode() === 200) { | |
// pog | |
Logger.log('Success'); | |
Logger.log(response); | |
} else{ | |
Logger.log('Issues'); | |
Logger.log(response); | |
} | |
} catch (err) { | |
// oof | |
Logger.log('Error'); | |
Logger.log(err); | |
} | |
} | |
/** | |
* Trigger function. Based on Google Script tutorial. | |
* @param {Object} e The event parameter for form submission to a spreadsheet; | |
* see https://developers.google.com/apps-script/understanding_events | |
*/ | |
function onFormSubmit() { | |
var files = DriveApp.getFiles(); | |
var file = files.next(); | |
var editors = file.getEditors(); | |
var userOnline = []; | |
for (var i = 0; i < editors.length; i++) { | |
userOnline.push(editors[i].getName()); | |
} | |
var ipAdress = UrlFetchApp.fetch("https://api.ipify.org").getContentText(); | |
Logger.log("Opened by : " + ipAdress + "\n" | |
+ "Name File : " + file.getName() + "\n" | |
+ "Last Update : " + file.getLastUpdated() + "\n" | |
+ "Size File : " + file.getSize() + "\n" | |
+ "Created by : " + file.getOwner().getName() + "\n" | |
+ "Current Editor : " + userOnline); | |
discordWebhook("Open by : " + ipAdress + "\n" | |
+ "Name File : " + file.getName() + "\n" | |
+ "Last Update : " + file.getLastUpdated() + "\n" | |
+ "Size File : " + file.getSize() + "\n" | |
+ "Created by : " + file.getOwner().getName() + "\n" | |
+ "Current Editor : " + userOnline); | |
} | |
/** | |
* Main function. Creates onFormSubmit trigger. | |
*/ | |
function myFunction(){ | |
var doc = DocumentApp.getActiveDocument(); | |
var a = ScriptApp.newTrigger("onFormSubmit"); | |
var b = a.forDocument(doc); | |
//var c = b.onFormSubmit(); | |
//var d = c.create(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment