Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

clxrityy/hbd

Repository files navigation

hbd

ARCHIVED!!!

This is the old version of the hbd bot running on Node.js runtime. To view the new and improved (yet work in progress) version of this bot that is on edge runtime, click here.


a discord bot for user's birthdays, horoscopes, and wishing user's a happy birthday.

📖 WIKI

banner


how it works

  • data is stored in mongoose models

    • guild settings (channels, roles)
    • user's birthdays
    • birthday wishes
  • when the bot logs in, the time event is emitted:

client.login(process.env.BOT_TOKEN!).then(() => client.emit("time"));
  • which checks the time, if it is midnight, the interval is emitted
    • this returns an interval that runs every 24 hrs and checks for birthdays
    • if there's a birthday present, the birthday event is emitted with the designated user & guild ID
module.exports = (client: Client) => {
  const handleInterval = async (client: Client) => {
    let date = new Date();
    let filter = {};
    const birthdays = await Birthday.find(filter);

    const dateString = date.toLocaleDateString();
    const dateArray = dateString.split("/");
    const dateParsed = dateArray[0] + `/` + dateArray[1];

    for (const birthday of birthdays) {
      if (birthday.Birthday === dateParsed) {
        client.emit("birthday", [birthday.UserID, birthday.GuildID]);
      } else {
        //
      }
    }
  };

  return setInterval(
    async () => await handleInterval(client),
    1000 * 60 * 60 * 24
  ); // 1000 * 60 * 60 = 1 hr
};
//...
const announceChannelId = guildData.AnnouncementChannel!;

channel = await(
  await(await client.guilds.fetch(guildId)).channels.fetch(announceChannelId)
).fetch() as TextChannel;

return await channel.send(/* ... */);
let birthdayRole: Role;

targetGuild.roles.cache.forEach((role) => {
  if (role.id === guildData.BirthdayRole) {
    birthdayRole = role;
  }
  return;
});

try {
    return await user.roles.add(birthdayRole);
} catch (err) {
    //...
}