Last active
October 28, 2018 04:36
-
-
Save nzws/828e86e2a34179c90578bc87ab4a125e to your computer and use it in GitHub Desktop.
This file contains 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
function main() { | |
const data = GmailApp.search('label:to_radtech is:unread', 0, 100); //to_radtechを設定したラベル名に | |
var i = 0; | |
while (data[i]) { | |
var message = data[i].getMessages(); | |
var p = 0; | |
while (message[p]) { | |
if (message[p].isUnread()) { | |
var content = "件名: " + message[p].getSubject() + "\n\n" + message[p].getBody(); | |
if (content.length > 2000) { | |
content = content.substring(1900, -1); | |
content += "\n\n-- 文字数制限突破しそうなので切りますた --"; | |
} | |
var name = message[p].getFrom(); | |
if (name.length > 32) { | |
name = name.substring(30, -1); | |
name += "…"; | |
} | |
var option = { | |
"method": "post", | |
"payload": { | |
"username": name, | |
"content": content | |
} | |
}; | |
UrlFetchApp.fetch("https://discordapp.com/api/webhooks/00000000/xxxxxxxxxxx", option); //DiscordのWebHook URL | |
} | |
p++; | |
} | |
data[i].markRead(); | |
i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment