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_SECRET="your_webhook_secret"
PORT=your_port_number
CHAT_ID="your_chat_id"
CHAT_ID="your_chat_ids seperated by commas"
```
4. Run the bot:
@ -44,7 +44,7 @@ variables.
- **WEBHOOK_URL**: The URL 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).
- **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

View file

@ -1,15 +1,21 @@
import { bot } from "../bot";
export async function reminderContestLC(contestName: string, contestKey: string): Promise<void> {
await bot.api.sendMessage(parseInt(process.env.CHAT_ID as string),
`LeetCode ${contestName} is in ~10 minutes.\n
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
Attend the contest here: https://leetcode.com/contest/${contestKey}/`);
}
}
export async function reminderContestCodeChef(): Promise<void> {
await bot.api.sendMessage(parseInt(process.env.CHAT_ID as string),
`CodeChef contest is in ~10 minutes.\n
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
Attend the contest here: https://www.codechef.com/contests/`);
}
}
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',
timeStyle: "short"
};
await bot.api.sendMessage(parseInt(process.env.CHAT_ID as string),
`${contestName} at ${new Date(contestTime).toLocaleTimeString('en-US', options)} IST starts in ~10 minutes.
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.
Attend the contest here: https://codeforces.com/contests/${contestID}`);
}
}

View file

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