예제 #1
0
    async def checkBirthdays(self):
        """
        Task that wishes people a happy birthday
        """
        # Don't do it multiple times a day if bot dc's, ...
        with open("files/lastTasks.json", "r") as fp:
            lastTasks = json.load(fp)
        if int(self.getCurrentHour()) == 6 and int(time.time()) - int(
                lastTasks["birthdays"]) > 10000:
            dt = timeFormatters.dateTimeNow()
            res = birthdays.get_users_on_date(dt.day, dt.month)

            COC = self.client.get_guild(int(constants.CallOfCode))
            people = [COC.get_member(int(user[0])) for user in res]
            general = COC.get_channel(int(constants.CoCGeneral))

            lastTasks["birthdays"] = round(time.time())
            with open("files/lastTasks.json", "w") as fp:
                json.dump(lastTasks, fp)

            if not people:
                return

            if len(people) == 1:
                return await general.send("Gelukkige verjaardag {}!".format(
                    people[0].mention))
            return await general.send("Gelukkige verjaardag {} en {}!".format(
                ", ".join(user.mention for user in people[:-1]),
                people[-1].mention))
예제 #2
0
    async def week(self, ctx):
        """
        Command that lists all birthdays for the coming week.
        :param ctx: Discord Context
        """
        # Dict of all birthdays this week
        this_week = {}

        # Create a datetime object starting yesterday so the first line
        # of the loop can add a day every time,
        # as premature returning would prevent this from happening
        # & get the day stuck
        dt = timeFormatters.dateTimeNow() - datetime.timedelta(days=1)

        # Create an embed
        embed = discord.Embed(colour=discord.Colour.blue())
        embed.set_author(name="Verjaardagen deze week")

        # Add all people of the coming week
        for dayCounter in range(7):
            dt += datetime.timedelta(days=1)
            res = birthdays.get_users_on_date(dt.day, dt.month)

            # No birthdays on this day
            if not res:
                continue

            # Add everyone from this day into the dict
            this_week[str(dayCounter)] = {
                "day": dt.day,
                "month": dt.month,
                "users": []
            }

            for user in res:
                this_week[str(dayCounter)]["users"].append(user[0])

        # No one found
        if not this_week:
            embed.description = "Deze week is er niemand jarig."
            return await ctx.send(embed=embed)

        COC = self.client.get_guild(int(constants.CallOfCode))

        # For every day, add the list of users into the embed
        for day, value in this_week.items():

            dayDatetime, timeString = self.dmToDatetime(
                int(value["day"]), int(value["month"]))
            weekday = timeFormatters.intToWeekday(dayDatetime.weekday())

            embed.add_field(name="{} {}".format(weekday, timeString),
                            value=", ".join(
                                COC.get_member(user).mention
                                for user in value["users"]),
                            inline=False)

        await ctx.send(embed=embed)
예제 #3
0
    def getBirthdayOnDate(self, dt):
        """
        Function to get all birthdays on a certain date.
        Returns a string right away to avoid more code duplication.
        :param dt: the date (Python datetime instance)
        :return: A formatted string containing all birthdays on [dt]
        """
        res = birthdays.get_users_on_date(dt.day, dt.month)

        # Nobody's birthday
        if not res:
            return "Vandaag is er niemand jarig."

        COC = self.client.get_guild(int(constants.CallOfCode))

        # Create a list of member objects of the people that have a birthday on this date
        people = [COC.get_member(int(user[0])) for user in res]

        if len(people) == 1:
            return "Vandaag is **{}** jarig.".format(people[0].display_name)
        return "Vandaag zijn {} en {} jarig.".format(
            ", ".join("**" + user.display_name + "**" for user in people[:-1]),
            people[-1].display_name)