Versions

  • v0

    1/10/2025
    Open: Version
    +42
    -0

    import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";
    import { socialDataSearch, Tweet } from "https://esm.town/v/stevekrouse/socialDataSearch";

    // Customize your keywords and exclusions
    const 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 display
    const isProd = true;

    export async function twitterAlert({ lastRunAt }: Interval) {
    // Scrapes data from past 48 hours time frame if testing
    const timeFrame = isProd
    ? lastRunAt ? Math.floor(lastRunAt.getTime() / 1000) : 0
    : Math.floor((Date.now() - 2 * 24 * 60 * 60 * 1000) / 1000);

    // Fetch and log tweets
    const response = await socialDataSearch(`${query} since_time:${timeFrame}`);
    console.log("Response from socialDataSearch:", response);
    if ("message" in response) throw new Error(response.message);

    // Format notification content
    const 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) {
1
Next
Updated: January 10, 2025