weathergeocode.ts2 matches
9596try {
97// Simulating fetch here - in a real implementation this would be:
98// const response = await fetch(`${this.baseUrl}/search?${params}`);
99console.log(`Making request to: ${this.baseUrl}/search?${params}`);
100
29});
3031// HTTP vals expect an exported "fetch handler"
32// This is how you "run the server" in Val Town with Hono
33export default app.fetch;
2import { withErrorHandling } from "https://esm.town/v/ktodaz/Discord_Bot_Services/error-handling.tsx";
3import { blob } from "https://esm.town/v/std/blob";
4import { fetch } from "https://esm.town/v/std/fetch";
56// Hardcoded list of role IDs that are allowed to be toggled
31// Get role information using error handling wrapper
32const roles = await withErrorHandling(
33"fetchGuildRoles",
34async () => {
35const token = Deno.env.get("DISCORD_BOT_TOKEN");
36const roleResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/roles`, {
37headers: {
38Authorization: `Bot ${token}`,
40});
41if (!roleResponse.ok) {
42throw new Error(`Failed to fetch role data: ${roleResponse.status}`);
43}
44return roleResponse.json();
52// Get member info using error handling wrapper
53const member = await withErrorHandling(
54"fetchGuildMember",
55async () => {
56const token = Deno.env.get("DISCORD_BOT_TOKEN");
57const memberResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/members/${userId}`, {
58headers: {
59Authorization: `Bot ${token}`,
61});
62if (!memberResponse.ok) {
63throw new Error(`Failed to fetch member data: ${memberResponse.status}`);
64}
65return memberResponse.json();
78async () => {
79const token = Deno.env.get("DISCORD_BOT_TOKEN");
80const toggleResponse = await fetch(
81`https://discord.com/api/v10/guilds/${guildId}/members/${userId}/roles/${roleId}`,
82{
158}
159160// Fetch all roles from the guild with error handling
161const allRoles = await withErrorHandling(
162"fetchGuildRolesForAlerts",
163async () => {
164const roleResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/roles`, {
165headers: {
166Authorization: `Bot ${token}`,
169170if (!roleResponse.ok) {
171throw new Error(`Failed to fetch role data: ${roleResponse.status}`);
172}
173212const focusedValue = interaction.data.options[0].value?.toLowerCase() || "";
213214// Fetch toggleable roles
215const { success, roles, error } = await getSignupAlertsRoles(guildId);
216219type: 8, // Autocomplete result
220data: {
221choices: [{ name: "Error: " + (error || "Could not fetch roles"), value: "error" }],
222},
223});
257type: 8,
258data: {
259choices: [{ name: "Error fetching roles", value: "error" }],
260},
261});
1// toggle-server-helper-pings-service.ts - Service for handling server helper ping toggle functionality
2import { fetch } from "https://esm.town/v/std/fetch";
34// Hardcoded role IDs
2627// First, get the member to check if they have any of the server helper roles
28const memberResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/members/${userId}`, {
29headers: {
30Authorization: `Bot ${token}`,
3334if (!memberResponse.ok) {
35throw new Error(`Failed to fetch member data: ${memberResponse.status}`);
36}
375051// Get the role information to include in the response
52const roleResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/roles`, {
53headers: {
54Authorization: `Bot ${token}`,
5758if (!roleResponse.ok) {
59throw new Error(`Failed to fetch role data: ${roleResponse.status}`);
60}
6171const action = hasRole ? "removed" : "added";
7273const toggleResponse = await fetch(
74`https://discord.com/api/v10/guilds/${guildId}/members/${userId}/roles/${SERVER_HELPER_PINGS_ROLE_ID}`,
75{
1// toggle-role-service.ts - Service for handling role toggle functionality
2import { withErrorHandling } from "https://esm.town/v/ktodaz/Discord_Bot_Services/error-handling.tsx";
3import { fetch } from "https://esm.town/v/std/fetch";
45// Hardcoded list of role IDs that are allowed to be toggled
2223// Get guild information to check for owner
24const guildResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}`, {
25headers: {
26Authorization: `Bot ${token}`,
2930if (!guildResponse.ok) {
31throw new Error(`Failed to fetch guild data: ${guildResponse.status}`);
32}
333637// Get member to check for administrator permissions
38const memberResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/members/${userId}`, {
39headers: {
40Authorization: `Bot ${token}`,
4344if (!memberResponse.ok) {
45throw new Error(`Failed to fetch member data: ${memberResponse.status}`);
46}
4748const member = await memberResponse.json();
4950// Fetch all roles in the guild
51const rolesResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/roles`, {
52headers: {
53Authorization: `Bot ${token}`,
5657if (!rolesResponse.ok) {
58throw new Error(`Failed to fetch roles data: ${rolesResponse.status}`);
59}
60122const token = Deno.env.get("DISCORD_BOT_TOKEN");
123// First, get the role information to include in the response
124const roleResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/roles`, {
125headers: {
126Authorization: `Bot ${token}`,
128});
129if (!roleResponse.ok) {
130throw new Error(`Failed to fetch role data: ${roleResponse.status}`);
131}
132const roles = await roleResponse.json();
135136// Get the member to check if they have the role
137const memberResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/members/${userId}`, {
138headers: {
139Authorization: `Bot ${token}`,
141});
142if (!memberResponse.ok) {
143throw new Error(`Failed to fetch member data: ${memberResponse.status}`);
144}
145const member = await memberResponse.json();
149const method = hasRole ? "DELETE" : "PUT";
150const action = hasRole ? "removed" : "added";
151const toggleResponse = await fetch(
152`https://discord.com/api/v10/guilds/${guildId}/members/${userId}/roles/${roleId}`,
153{
209// Use the error handling wrapper for the API call
210const allRoles = await withErrorHandling(
211"fetchGuildRoles",
212async () => {
213const token = Deno.env.get("DISCORD_BOT_TOKEN");
214const roleResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/roles`, {
215headers: {
216Authorization: `Bot ${token}`,
219220if (!roleResponse.ok) {
221throw new Error(`Failed to fetch role data: ${roleResponse.status}`);
222}
223254const focusedValue = interaction.data.options[0].value?.toLowerCase() || "";
255256// Fetch toggleable roles
257const { success, roles, error } = await getToggleableRoles(guildId);
258261type: 8, // Autocomplete result
262data: {
263choices: [{ name: "Error: " + (error || "Could not fetch roles"), value: "error" }],
264},
265});
290type: 8,
291data: {
292choices: [{ name: "Error fetching roles", value: "error" }],
293},
294});
217// -------------------------------
218219app.function("fetch_user_details", async ({ payload, context: { client, functionExecutionId } }) => {
220try {
221// Requires users:read scope
241await client.functions.completeError({
242function_execution_id: functionExecutionId!,
243error: `Failed to respond to fetch_user_details function event (${e})`,
244});
245}
2import { XMLParser } from "https://esm.sh/fast-xml-parser@4.2.5"; // For parsing RSS/Atom feeds
3import { AgentContext, AgentInput, AgentOutput } from "https://esm.town/v/salon/mandate/interfaces.ts";
4import { fetch } from "https://esm.town/v/std/fetch";
5import { OpenAI } from "https://esm.town/v/std/openai";
651}
5253// Fetch Agent (Now fetches and parses RSS feeds for headlines)
54export async function fetchAgent(
55input: AgentInput<{ url_from_input?: string; maxHeadlines?: number }>, // Added maxHeadlines
56context: AgentContext,
7172const DEFAULT_RSS_URL = "https://feeds.npr.org/1001/rss.xml"; // NPR Top Stories as default
73const urlToFetch = payload?.url_from_input ?? config?.rssFeedUrl ?? DEFAULT_RSS_URL;
74const maxHeadlines = Number(payload?.maxHeadlines ?? config?.maxHeadlines ?? 5);
7576log("INFO", "FetchAgent", `Workspaceing headlines from ${urlToFetch}, max: ${maxHeadlines}`);
7778try {
79const resp = await fetch(urlToFetch);
80const fetchedContentType = resp.headers.get("content-type")?.toLowerCase() || "";
81const rawResponseText = await resp.text();
8284let errorBody = rawResponseText;
85if (errorBody.length > 500) errorBody = errorBody.substring(0, 500) + "...";
86throw new Error(`Workspace failed: ${resp.status} ${resp.statusText}. URL: ${urlToFetch}. Body: ${errorBody}`);
87}
8894// Attempt to parse as RSS/Atom if content type suggests XML, or if it's a known RSS URL pattern/default
95if (
96fetchedContentType.includes("xml") || fetchedContentType.includes("rss") || urlToFetch.endsWith(".xml")
97|| urlToFetch.endsWith(".rss") || urlToFetch === DEFAULT_RSS_URL
98) {
99try {
154155if (parsedSuccessfully) {
156log("INFO", "FetchAgent", `Successfully parsed ${headlines.length} headlines from "${feedTitle}".`);
157} else {
158parsingMessage = "RSS/Atom structure not as expected or no items found.";
159log("WARN", "FetchAgent", parsingMessage);
160}
161} catch (parseError: any) {
162parsingMessage = `Failed to parse XML/RSS content. Error: ${parseError.message}`;
163log("WARN", "FetchAgent", `${parsingMessage} from URL: ${urlToFetch}`);
164}
165} else {
166parsingMessage =
167`Content type "${fetchedContentType}" is not XML/RSS. Not attempting RSS parse. Raw text will be available.`;
168log("INFO", "FetchAgent", parsingMessage);
169}
170172headlines,
173feedTitle,
174sourceUrl: urlToFetch,
175...(parsingMessage && !parsedSuccessfully ? { message: parsingMessage } : {}),
176};
182data: outputData,
183rawText: rawResponseText,
184contentType: fetchedContentType,
185},
186};
187} catch (e: any) {
188log("ERROR", "FetchAgent", `Workspace or processing failed: ${e.message}`, e);
189return {
190mandateId,
194headlines: [],
195feedTitle: "Error",
196sourceUrl: urlToFetch,
197message: `Workspace or processing failed: ${e.message}`,
198},
205}
206207// Combiner Agent (Adapted to handle new headline structure from FetchAgent)
208export async function combinerAgent(
209input: AgentInput<{
210summary?: string;
211// Expecting externalData to potentially contain the output of fetchAgent
212externalData?: {
213headlines?: Array<{ title: string; link: string; summary: string; publishedDate: string }>;
227try {
228const summaryText = payload.summary ?? "N/A";
229let externalDataDescription = "External Data: Not Fetched/Available or not in expected format.";
230231if (
247}
248});
249} else if (payload.externalData?.message) { // If fetchAgent had a message (e.g. parsing error but still some info)
250externalDataDescription = `External Data Information: ${payload.externalData.message} (Source: ${
251payload.externalData.sourceUrl || "Unknown"
untitled-3323new-file-8432.tsx7 matches
20if (/^https?:\/\/(?:[^/]+\.)?reddit\.com\/.*\/comments\/[a-z0-9]+/i.test(feedUrl)) {
21try {
22return json(await fetchRedditPost(feedUrl, limit));
23}
24catch (err) {
25console.error(err);
26return json({ error: "Reddit fetch failed", details: String(err) }, 500);
27}
28}
37feedUrl = u.toString();
38}
39const xml = await fetch(feedUrl, { headers: { "User-Agent": "val-town-rss2json" } }).then(r => r.text());
40const raw = await parseStringPromise(xml, { explicitArray: false });
41const feed = raw.feed ?? raw.rss?.channel;
6061// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
62// FULL-DATA fetch for a single Reddit submission
63// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
64async function fetchRedditPost(postUrl: string, limit: number) {
65const pathname = new URL(postUrl).pathname.replace(/\/$/, "");
66const headers = {
7172// 1๏ธโฃ try api.reddit.com (no Cloudflare)
73let txt = await fetch(`https://api.reddit.com${pathname}?limit=${limit}&raw_json=1`, { headers })
74.then(r => r.text());
75if (txt.trim().startsWith("<")) { // got HTML โ fallback
76// 2๏ธโฃ try old.reddit.com
77txt = await fetch(`https://old.reddit.com${pathname}.json?limit=${limit}&raw_json=1`, {
78headers: { "User-Agent": "val-town-faceless-video/1.0" },
79}).then(r => r.text());
pollinaterpbldemo.tsx4 matches
910useEffect(() => {
11async function fetchSensorData() {
12try {
13// Simulated sensor data with realistic bee habitat conditions
19setLastUpdated(new Date());
20} catch (error) {
21console.error("Error fetching sensor data", error);
22}
23}
2425fetchSensorData();
26const intervalId = setInterval(fetchSensorData, 5000);
27return () => clearInterval(intervalId);
28}, []);
rdo-dailies-webhookmain.ts4 matches
1import { discordWebhook } from "https://esm.town/v/mmorihara/coherentVioletFinch";
23const strings = await fetch("https://esm.town/v/mmorihara/rdo-dailies-webhook@8-dev/data.json").then(r => r.json());
45const templates: { [key: string]: (goalText: string, goalNum: number) => string } = {
82}
8384async function fetchDailies() {
85const response = await fetch("https://api.rdo.gg/challenges/index.json");
86return response.json();
87}
141142export async function main() {
143const dailies = await fetchDailies();
144const formatted = formatDailies(dailies);
145