From eba657a24dda70fa6d93c877e2695710cd61842c Mon Sep 17 00:00:00 2001 From: SrIzan10 <66965250+SrIzan10@users.noreply.github.com> Date: Mon, 12 Dec 2022 16:47:48 +0100 Subject: [PATCH] fix: twitter just crashing oh my god i hate it --- util/twitternotifications.ts | 52 +++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/util/twitternotifications.ts b/util/twitternotifications.ts index 9737b13..9f15bae 100644 --- a/util/twitternotifications.ts +++ b/util/twitternotifications.ts @@ -3,29 +3,31 @@ import axios from 'axios'; import schema from '../schemas/twitter.js'; export default async function twitternotifications(client: Client) { - const db = await schema.findOne({ user: 'elpady' }); - const request = ( - await axios - .get( - 'https://api.twitter.com/2/tweets/search/recent?query=from%3AMaraTuring', - { - headers: { - Authorization: `Bearer ${process.env.TWITTER}`, - }, - } - ) - .then((res) => res.data) - ).data[0].id; - const fetchTextChannel = (await ( - await client.guilds.fetch(process.env.GUILDID!) - ).channels.fetch(process.env.SOCIALS_CHANNEL!)) as TextChannel; - if (request === db?.id) return; - else { - db!.id = request; - await db?.save(); - const message = await fetchTextChannel.send({ - content: `Nuevo tweet de Mara Turing, corre a verlo! https://twitter.com/MaraTuring/status/${request}`, - }); - message.react('<:Pog:1030169609178976346>'); - } + try { + const db = await schema.findOne({ user: 'elpady' }); + const request = ( + await axios + .get( + 'https://api.twitter.com/2/tweets/search/recent?query=from%3AMaraTuring', + { + headers: { + Authorization: `Bearer ${process.env.TWITTER}`, + }, + } + ) + .then((res) => res.data) + ).data[0].id; + const fetchTextChannel = (await ( + await client.guilds.fetch(process.env.GUILDID!) + ).channels.fetch(process.env.SOCIALS_CHANNEL!)) as TextChannel; + if (request === db?.id) return; + else { + db!.id = request; + await db?.save(); + const message = await fetchTextChannel.send({ + content: `Nuevo tweet de Mara Turing, corre a verlo! https://twitter.com/MaraTuring/status/${request}`, + }); + message.react('<:Pog:1030169609178976346>'); + } + } catch (err) {} }