Add multiple group broadcast support
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Signed-off-by: adithyagenie <adithyagenie@gmail.com>
This commit is contained in:
adithyagenie 2024-06-16 00:52:00 +05:30
parent 5c1ffd5fd5
commit 80c923bf1c
Signed by: adithyagenie
GPG key ID: C66E41599E458D96
3 changed files with 20 additions and 10 deletions

View file

@ -29,7 +29,7 @@ variables.
WEBHOOK_URL="your_webhook_url" WEBHOOK_URL="your_webhook_url"
WEBHOOK_SECRET="your_webhook_secret" WEBHOOK_SECRET="your_webhook_secret"
PORT=your_port_number PORT=your_port_number
CHAT_ID="your_chat_id" CHAT_ID="your_chat_ids seperated by commas"
``` ```
4. Run the bot: 4. Run the bot:
@ -44,7 +44,7 @@ variables.
- **WEBHOOK_URL**: The URL for the webhook (required if using webhook mode). - **WEBHOOK_URL**: The URL for the webhook (required if using webhook mode).
- **WEBHOOK_SECRET**: The secret for the webhook (required if using webhook mode). - **WEBHOOK_SECRET**: The secret for the webhook (required if using webhook mode).
- **PORT**: The port number to run the webhook server on (required if using webhook mode). - **PORT**: The port number to run the webhook server on (required if using webhook mode).
- **CHAT_ID**: The chat ID of the group or person where the bot will send notifications. - **CHAT_ID**: The chat IDs of the group or person where the bot will send notifications, seperated by commas.
## Usage ## Usage

View file

@ -1,15 +1,21 @@
import { bot } from "../bot"; import { bot } from "../bot";
export async function reminderContestLC(contestName: string, contestKey: string): Promise<void> { export async function reminderContestLC(contestName: string, contestKey: string): Promise<void> {
await bot.api.sendMessage(parseInt(process.env.CHAT_ID as string), const chatids = (process.env.CHAT_ID as string).split(",").map(i => parseInt(i));
for (const id of chatids) {
await bot.api.sendMessage(id,
`LeetCode ${contestName} is in ~10 minutes.\n `LeetCode ${contestName} is in ~10 minutes.\n
Attend the contest here: https://leetcode.com/contest/${contestKey}/`); Attend the contest here: https://leetcode.com/contest/${contestKey}/`);
}
} }
export async function reminderContestCodeChef(): Promise<void> { export async function reminderContestCodeChef(): Promise<void> {
await bot.api.sendMessage(parseInt(process.env.CHAT_ID as string), const chatids = (process.env.CHAT_ID as string).split(",").map(i => parseInt(i));
for (const id of chatids) {
await bot.api.sendMessage(id,
`CodeChef contest is in ~10 minutes.\n `CodeChef contest is in ~10 minutes.\n
Attend the contest here: https://www.codechef.com/contests/`); Attend the contest here: https://www.codechef.com/contests/`);
}
} }
export async function reminderContestCF(contestName: string, contestID: number, contestTime: Date) { export async function reminderContestCF(contestName: string, contestID: number, contestTime: Date) {
@ -17,7 +23,10 @@ export async function reminderContestCF(contestName: string, contestID: number,
timeZone: 'Asia/Calcutta', timeZone: 'Asia/Calcutta',
timeStyle: "short" timeStyle: "short"
}; };
await bot.api.sendMessage(parseInt(process.env.CHAT_ID as string), const chatids = (process.env.CHAT_ID as string).split(",").map(i => parseInt(i));
for (const id of chatids) {
await bot.api.sendMessage(id,
`${contestName} at ${new Date(contestTime).toLocaleTimeString('en-US', options)} IST starts in ~10 minutes. `${contestName} at ${new Date(contestTime).toLocaleTimeString('en-US', options)} IST starts in ~10 minutes.
Attend the contest here: https://codeforces.com/contests/${contestID}`); Attend the contest here: https://codeforces.com/contests/${contestID}`);
}
} }

View file

@ -1,11 +1,12 @@
import { config } from "dotenv"; import { config } from "dotenv";
config();
import { FastifyInstance } from "fastify"; import { FastifyInstance } from "fastify";
import { startserver } from "./api/server"; import { startserver } from "./api/server";
import { botInit } from "./bot/bot"; import { botInit } from "./bot/bot";
import { contestScheduler } from "./helpers/scheduler"; import { contestScheduler } from "./helpers/scheduler";
config();
if (process.env.BOT_TOKEN === undefined || if (process.env.BOT_TOKEN === undefined ||
process.env.RUN_METHOD === undefined || process.env.RUN_METHOD === undefined ||
(process.env.RUN_METHOD !== "POLLING" && process.env.RUN_METHOD !== "WEBHOOK") || (process.env.RUN_METHOD !== "POLLING" && process.env.RUN_METHOD !== "WEBHOOK") ||