Skip to content

Commit

Permalink
🚨 Fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pvillaverde committed May 16, 2024
1 parent 81db992 commit 08df6df
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 53 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![GitHub license][license-shield]][license-url]

Esta aplicación encárgase de obter a información das canles rexistradas na [Asociación Cultural Obradoiro Dixital Galego](https://obradoirodixitalgalego.gal) e difundir o novo contido que xeran estes proxectos en galego pola rede, a través das canlees da asociación (Twitter, Mastodon e Discord).
Esta aplicación encárgase de obter a información das canles rexistradas na [Asociación Cultural Obradoiro Dixital Galego](https://obradoirodixitalgalego.gal) e difundir o novo contido que xeran estes proxectos en galego pola rede, a través das canles da asociación (Twitter, Mastodon e Discord).

# 🗂️ Índice

Expand Down Expand Up @@ -31,9 +31,9 @@ Esta aplicación encárgase de obter a información das canles rexistradas na [A
- [ ] RefreshTwitch
- [ ] RefreshTwitchClips
- [ ] RefreshTwitchStreams
- [ ] PublishTwitter
- [ ] PublishMastodon
- [ ] PublishDiscord
- [x] PublishTwitter
- [x] PublishMastodon
- [x] PublishDiscord

## 🧩 Requerimentos

Expand Down
20 changes: 3 additions & 17 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ logger.info(`
`);
let keepRuning = false;
switch (task) {
// One-time tasks
case "refreshBlogs":
await refreshBlogs();
break;
Expand All @@ -28,6 +29,7 @@ switch (task) {
case "refreshYoutube":
await refreshYoutube();
break;
// Service Tasks
case "publishTwitter":
keepRuning = true;
await publishTwitter();
Expand All @@ -44,24 +46,8 @@ switch (task) {
logger.fatal("Especifica unha subtarefa para executar a RADIO Dixital.");
break;
}

if (!keepRuning) {
connection.end();
mqttService.end();
}

// const food = Deno.args[1];
// console.log(`Hello ${name}, I like ${food}!`);

// import { parseArgs } from "jsr:@std/cli/parse-args";

// const flags = parseArgs(Deno.args, {
// boolean: ["help", "color"],
// string: ["version"],
// default: { color: true },
// negatable: ["color"],
// });
// console.log("Wants help?", flags.help);
// console.log("Version:", flags.version);
// console.log("Wants color?:", flags.color);

// console.log("Other:", flags._);
2 changes: 1 addition & 1 deletion src/services/mqtt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export default connect(`mqtt://${mqttConfig.MQTT_HOST}`, {
username: mqttConfig.MQTT_USER,
password: mqttConfig.MQTT_PASS,
manualConnect: true,
});
});
15 changes: 6 additions & 9 deletions src/tasks/publishDiscord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export default function publishDiscord() {
if (err) {
logger.error(err.toString());
} else {
logger.info("Listening MQTT Topic")
logger.info("Listening MQTT Topic");
}
});
})
mqttService.on("message", async (topic, message) => {
});
mqttService.on("message", async (_topic, message) => {
try {
const decodedMessage: PubSubMessage = JSON.parse(message.toString());
logger.debug(decodedMessage);
Expand All @@ -25,7 +25,7 @@ export default function publishDiscord() {
.replace(/{channelName}/g, decodedMessage.title)
.replace(/{mentionUser}/g, ``)
.replace(/{title}/g, decodedMessage.entryTitle)
.replace(/{url}/g, decodedMessage.entryLink)
.replace(/{url}/g, decodedMessage.entryLink);

const webhook = new Webhook(discordConfig[decodedMessage.type].webhook);
const result = await webhook.send(messageStatus);
Expand All @@ -34,10 +34,7 @@ export default function publishDiscord() {
logger.error(error);
logger.error(message.toString());
}
})



});

// // const hook = new Webhook("YOUR WEBHOOK URL");

Expand Down Expand Up @@ -86,4 +83,4 @@ export default function publishDiscord() {
// // window.sessionStorage.getItem('K2'); //{"a":1,"b":"2"}window.sessionStorage.length; //1
// // window.sessionStorage.clear();
// // window.sessionStorage.length; //0
}
}
16 changes: 8 additions & 8 deletions src/tasks/publishMastodon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createRestAPIClient } from 'npm:[email protected]';
import { createRestAPIClient } from "npm:[email protected]";
import mastodonConfig from "../config/mastodon.config.ts";
import logger from "../services/logger.service.ts";
import mqttService from "../services/mqtt.service.ts";
Expand All @@ -12,11 +12,11 @@ export default function publishMastodon() {
if (err) {
logger.error(err.toString());
} else {
logger.info("Listening MQTT Topic")
logger.info("Listening MQTT Topic");
}
});
})
mqttService.on("message", async (topic, message) => {
});
mqttService.on("message", async (_topic, message) => {
try {
const decodedMessage: PubSubMessage = JSON.parse(message.toString());
logger.debug(decodedMessage);
Expand All @@ -25,14 +25,14 @@ export default function publishMastodon() {
.replace(/{channelName}/g, decodedMessage.title)
.replace(/{mentionUser}/g, decodedMessage.mastodon ? ` (${decodedMessage.mastodon})` : ``)
.replace(/{title}/g, decodedMessage.entryTitle)
.replace(/{url}/g, decodedMessage.entryLink)
.replace(/{url}/g, decodedMessage.entryLink);

const mastodon = await createRestAPIClient(mastodonConfig[decodedMessage.type]);
const status = await mastodon.v1.statuses.create({ status: messageStatus, visibility: 'public', });
const status = await mastodon.v1.statuses.create({ status: messageStatus, visibility: "public" });
logger.info(messageStatus, status.url);
} catch (error) {
logger.error(error);
logger.error(message.toString());
}
})
}
});
}
14 changes: 7 additions & 7 deletions src/tasks/publishTwitter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TwitterApi } from 'npm:[email protected]';
import { TwitterApi } from "npm:[email protected]";
import twitterConfig from "../config/twitter.config.ts";
import logger from "../services/logger.service.ts";
import mqttService from "../services/mqtt.service.ts";
Expand All @@ -12,11 +12,11 @@ export default function publishTwitter() {
if (err) {
logger.error(err.toString());
} else {
logger.info("Listening MQTT Topic")
logger.info("Listening MQTT Topic");
}
});
})
mqttService.on("message", async (topic, message) => {
});
mqttService.on("message", async (_topic, message) => {
try {
const decodedMessage: PubSubMessage = JSON.parse(message.toString());
logger.debug(decodedMessage);
Expand All @@ -25,7 +25,7 @@ export default function publishTwitter() {
.replace(/{channelName}/g, decodedMessage.title)
.replace(/{mentionUser}/g, decodedMessage.twitter ? ` (${decodedMessage.twitter})` : ``)
.replace(/{title}/g, decodedMessage.entryTitle)
.replace(/{url}/g, decodedMessage.entryLink)
.replace(/{url}/g, decodedMessage.entryLink);

const twitter = new TwitterApi(twitterConfig[decodedMessage.type]);
const status = await twitter.v2.tweet(messageStatus);
Expand All @@ -34,5 +34,5 @@ export default function publishTwitter() {
logger.error(error);
logger.error(message.toString());
}
})
}
});
}
4 changes: 2 additions & 2 deletions src/tasks/refreshBlogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ export default async function refreshBlogs() {
twitter: item.twitter,
entryTitle: entry.title,
entryLink: entry.link,
}
};
logger.debug(`Publishing to MQTT topic "${mqttConfig.MQTT_TOPIC}"`, JSON.stringify(message));
mqttService.publish(mqttConfig.MQTT_TOPIC, JSON.stringify(message));
})
});
}
}
logger.info(`${index + 1}/${blogs.length}`, `Recuperadas ${entries.length} entradas de ${item.title}.`);
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/refreshPodcasts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ export default async function refreshPodcasts() {
twitter: item.twitter,
entryTitle: entry.title,
entryLink: entry.link,
}
};
logger.debug(`Publishing to MQTT topic "${mqttConfig.MQTT_TOPIC}"`, JSON.stringify(message));
mqttService.publish(mqttConfig.MQTT_TOPIC, JSON.stringify(message));
})
});
}
}
logger.info(`${index + 1}/${podcasts.length}`, `Recuperados ${entries.length} episodios de ${item.title}.`);
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/refreshYoutube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ export default async function refreshYoutube() {
twitter: item.twitter,
entryTitle: entry.title,
entryLink: entry.link,
}
};
logger.debug(`Publishing to MQTT topic "${mqttConfig.MQTT_TOPIC}"`, JSON.stringify(message));
mqttService.publish(mqttConfig.MQTT_TOPIC, JSON.stringify(message));
})
});
}
}
logger.info(
Expand Down
2 changes: 1 addition & 1 deletion src/types/pubsub.message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export default interface PubSubMessage {
entryLink: string;
twitter?: string;
mastodon?: string;
}
}

0 comments on commit 08df6df

Please sign in to comment.