Skip to content

Commit

Permalink
"bot checks if the channel exists before sending a message"
Browse files Browse the repository at this point in the history
  • Loading branch information
Josee9988 committed Jun 23, 2021
1 parent 9ade227 commit 993c878
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

---

## [**1.3.4**] - 2021-06-23

### Fixed

* The bot now checks if the channel exists before sending a message.

## [**1.3.2**] - 2021-06-22

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "daily-image-discord-bot",
"displayName": "Daily Image Bot",
"version": "1.3.3",
"version": "1.3.4",
"description": "A discord bot that sends a daily image from a Google photos album, right to your selected discord channel",
"main": "out/index.js",
"scripts": {
Expand Down
12 changes: 4 additions & 8 deletions src/commands/commands-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ export default class CommandsController {

constructor(private PREFIX: string, private client: any, private databaseController: DatabaseController) {
// 30 */12 * * * (at minute 30 past every 12th hour) * * * * * for every minute (testing purposes)
this.cronJob = new CronJob('* * * * *', async () => { // TODO: REMOVE COMMENTS
this.cronJob = new CronJob('30 */12 * * *', async () => {
await this.sendRandomPhoto(false).catch((e: any) => console.error(e));
});

// Start cron job
if (!this.cronJob.running) {
this.cronJob.start();
}
if (!this.cronJob.running) this.cronJob.start();
}

/**
Expand Down Expand Up @@ -164,14 +162,12 @@ export default class CommandsController {
* @param dimg the dimg object to be searched in the database.
*/
private async fetchAndSendPhoto(dimg: IDimg): Promise<void> {
if (dimg.serverId !== "856855520311771176") return; // TODO: IF NOT TEST SERVER JUST LEAVE
await this.client.channels.cache.get(dimg.channelId)
.send("โš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš  ๏ธThe bot is under maintenance, it might post more photos than the expected or work unexpectedly for a while, please be patient ;) โš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธโš ๏ธ"); // TODO: remove
if (dimg.channelId || this.client.channels.cache.get(dimg.channelId) == null) return; // channel not defined
let isDetectedAFetchFail: boolean = false;
let msg1Detected = dimg.sendMsg ? dimg.sendMsg : sendRandomPhotoMessage.msg1;
const photos: ImageInfo[] | any = await GooglePhotosAlbum.fetchImageUrls(dimg.albumLink).catch(() => isDetectedAFetchFail = true);
if (!photos || isDetectedAFetchFail || Object.keys(photos).length < 1) {
console.debug("Photos object broken for serverId:: " + dimg.serverId)
console.error("Photos object broken for serverId: " + dimg.serverId)
return;
}
const randomPhoto = Math.floor((Math.random() * Object.keys(photos).length) + 1);
Expand Down

0 comments on commit 993c878

Please sign in to comment.