Guest User

Untitled

a guest
Jan 23rd, 2023
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { ActivityType, Client } from "discord.js";
  2. import addPoints from "../utils/addPoints.js"; // util used to add points to the numbers
  3. import cron from "node-cron";
  4. import { getBotd } from "../utils/getBOTD.js"; // Bestemmia of the day, basically it's "blasphemy of the day" but in italian
  5.  
  6. export const name = 'ready';
  7. export const once = true;
  8.  
  9. export async function execute(client: Client<true>) {
  10.     console.log('ready');
  11.    
  12.     await client.database.connect();
  13.    
  14.     let bestemmieDocs = await client.dbCollections.bestemmie.find({ globalbestemmie: undefined }).toArray();
  15.     let numeroBestemmie = 0;
  16.    
  17.     for (let bestemmieDoc of bestemmieDocs) {
  18.         numeroBestemmie += bestemmieDoc.bestemmieGlobal;
  19.     }
  20.    
  21.     if (client.user.username.endsWith('Staging')) {
  22.         client.prefix = '..';
  23.     }
  24.    
  25.     if (client.manutenzione) {
  26.         client.user.setActivity(`🔴🛠️ MANUTENZIONE IN CORSO`, { type: ActivityType.Watching }); // maintenance mode
  27.         return;
  28.     }
  29.    
  30.     client.user.setActivity(`${addPoints(numeroBestemmie)} bestemmie totali.`, { type: ActivityType.Watching });
  31.     // we disabled this to check if it was the issue, but it still dies after a while
  32. /*    setInterval(async () => {
  33.         bestemmieDocs = await client.dbCollections.bestemmie.find({ globalbestemmie: undefined }).toArray();
  34.         numeroBestemmie = 0;
  35.        
  36.         for (let bestemmieDoc of bestemmieDocs) {
  37.             numeroBestemmie += bestemmieDoc.bestemmieGlobal;
  38.         }
  39.        
  40.         client.user.setActivity(`${addPoints(numeroBestemmie)} bestemmie totali.`, { type: ActivityType.Watching });
  41.     }, 1 * 60 * 60 * 1000);
  42. */
  43.     cron.schedule('0 0 23 * * *', async () => { //botd
  44.         const botd = await getBotd(client);
  45.         let embed = {
  46.             title: 'Bestemmia del giorno',
  47.             description: botd
  48.         }
  49.         // @ts-ignore
  50.         await (await client.channels.fetch("1059884162909212765")).send({ embeds: [embed] }) // sends botd to the channel in our server
  51.     });
  52. }
Advertisement
Add Comment
Please, Sign In to add comment