Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const axios = require('axios');
- const fs = require('fs');
- module.exports = {
- config: {
- name: "bc",
- aliases: ["bdcalendar", "calendar"],
- version: "1.0",
- author: "Samir Œ",
- shortDescription: "Get the calendar for a specific month and year",
- longDescription: "Fetches and sends an image of the calendar for the specified month and year.",
- category: "Utility",
- guide: {
- en: "{pn} [month | year]"
- }
- },
- onStart: async function ({ api, event, args }) {
- try {
- let month, year;
- if (args.length > 0) {
- [month, year] = args.join(" ").split("|").map(item => item.trim());
- } else {
- month = new Date().getMonth() + 1;
- year = new Date().getFullYear();
- }
- let apiUrl = `https://apis-samir.onrender.com/calendar/${year}/${month}`;
- const response = await axios.get(apiUrl, { responseType: 'stream' });
- const path = `calendar-${month}-${year}.jpg`;
- const writer = fs.createWriteStream(path);
- response.data.pipe(writer);
- await new Promise((resolve, reject) => {
- writer.on('finish', resolve);
- writer.on('error', reject);
- });
- await api.sendMessage({
- body: `Here is the calendar for ${month}/${year}:`,
- attachment: fs.createReadStream(path)
- }, event.threadID);
- fs.unlinkSync(path);
- } catch (error) {
- console.error("Error retrieving calendar:", error.message);
- api.sendMessage({ body: "Failed to retrieve calendar." }, event.threadID);
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement