Public
Versions
- Open: Version+42-0import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";import { socialDataSearch, Tweet } from "https://esm.town/v/stevekrouse/socialDataSearch";// Customize your keywords and exclusionsconst keywords = ["val.town", "val.run", "val town"];const excludes = "-_ValTown_ -is:retweet -from:valenzuelacity -from:val__run";const query = keywords.map(k => `"${k}"`).join(" OR ") + " " + excludes;// Set isProd = false if testing, to ensure there are enough tweets to displayconst isProd = true;export async function twitterAlert({ lastRunAt }: Interval) {// Scrapes data from past 48 hours time frame if testingconst timeFrame = isProd? lastRunAt ? Math.floor(lastRunAt.getTime() / 1000) : 0: Math.floor((Date.now() - 2 * 24 * 60 * 60 * 1000) / 1000);// Fetch and log tweetsconst response = await socialDataSearch(`${query} since_time:${timeFrame}`);console.log("Response from socialDataSearch:", response);if ("message" in response) throw new Error(response.message);// Format notification contentconst content = response.tweets?.map(({ user: { screen_name }, id_str }) =>`https://fxtwitter.com/${screen_name}/status/${id_str}`);if (content?.length) {console.log("Relevant Tweet URLs:");content.forEach((url) => console.log(url));} else {console.log("No relevant tweets found.");}// Send notifications to Discord (only if isProd is set to true)if (isProd && content?.length) {
Updated: January 10, 2025