Skip to content

Instantly share code, notes, and snippets.

@anthonybaldwin
Last active October 28, 2024 02:12
Show Gist options
  • Save anthonybaldwin/1ade79b8b8fd45a96f5c9fe4fc263240 to your computer and use it in GitHub Desktop.
Save anthonybaldwin/1ade79b8b8fd45a96f5c9fe4fc263240 to your computer and use it in GitHub Desktop.
IFTTT Filter for Discord Twitter Webhook
const t12To24 = (time: string): string => { // time=12:30PM
time = time.replace(/[AP]/, " $&"); // time=12:30 PM
let [t, p] = time.split(" "); // t=12:30, p=PM
let [h, m] = t.split(":"); // h=12, m=30
if (h === "12") h = "00"; // h=00
if (p === "PM") h = (parseInt(h, 10) + 12).toString(); // h=12
return `${h}:${m}`; // 12:30
};
const date = Trigger.CreatedAt; // date="April 20, 2021 at 04:20PM"
let [d, t] = date.split(" at "); // d="April 20, 2021", t=04:20PM
t = t12To24(t); // t=16:20
const url = Trigger.LinkToTweet.replace(/^http:\/\//i, "https://");
const body = {
username: "@" + Trigger.UserName,
avatar_url: Trigger.UserImageUrl,
content: `tweeted on ${d} at ${t} PST: ${url}`
};
// Filter
/*if (Trigger.Text.indexOf('word') > 0) {
MakerWebhooks.makeWebRequest.skip('Skipped because...');
}*/
MakerWebhooks.makeWebRequest.setBody(JSON.stringify(body));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment