示例#1
0
    async def on_one_hour(self):
        current_time = datetime.utcnow()
        hour = current_time.hour

        self.CHANNEL = discord.utils.get(self.SERVER["MAIN"].channels,
                                         name=self.param["CHANNEL"])

        day_change_tz = []
        for timezone in range(-12, 15):  # For each timezone
            if (hour + timezone
                ) % 24 == 0:  # If the day just changed in this timezone
                tz_info = [timezone
                           ]  # Timezone is the first element of the list

                tz_time = current_time + timedelta(hours=timezone)
                tz_info.append(f"{tz_time.day}/{tz_time.month}")
                tz_info.append(
                    tz_time)  # The day is the second element of the list

                day_change_tz.append(tz_info)

        for tz in day_change_tz:
            l_d = tz[2] + timedelta(
                days=-1
            )  # Get the last day in the timezone that just switched days
            n_d = tz[2] + timedelta(days=1)

            n_d = f"{n_d.day}/{n_d.month}"
            l_d = f"{l_d.day}/{l_d.month}"

            found = self.db.get_entries("birthday",
                                        columns=["id", "timezone"],
                                        conditions={"birthday": l_d})
            for person in found:
                if person[1] < tz[0] and self.BIRTHDAY_ROLE not in self.SERVER[
                        "MAIN"].get_member(int(member[0])).roles:
                    f_tz = ("+" if person[1] > 0 else "") + str(person[1])
                    await self.CHANNEL.send(
                        f"🎉 It is no longer **{l_d} UTC {f_tz}**, but happy birthday to <@{person[0]}> regardless! 🎉"
                    )
                    await self.SERVER["MAIN"].get_member(int(
                        person[0])).add_roles(self.BIRTHDAY_ROLE)

            found = self.db.get_entries("birthday",
                                        columns=["id", "timezone"],
                                        conditions={"birthday": tz[1]})
            for person in found:
                if person[1] > tz[
                        0] and self.BIRTHDAY_ROLE not in SERVER.get_member(
                            int(member[0])).roles:
                    f_tz = ("+" if person[1] > 0 else "") + str(person[1])
                    await self.CHANNEL.send(
                        f"🎉 It is no longer **{tz[1]} UTC {f_tz}**, but happy birthday to <@{person[0]}> regardless! 🎉"
                    )
                    await self.SERVER["MAIN"].get_member(int(
                        person[0])).add_roles(self.BIRTHDAY_ROLE)

            found = self.db.get_entries("birthday",
                                        columns=["id", "timezone"],
                                        conditions={"birthday": n_d})
            for person in found:
                if person[1] - 24 > tz[
                        0] and self.BIRTHDAY_ROLE not in self.SERVER[
                            "MAIN"].get_member(int(member[0])).roles:
                    f_tz = ("+" if person[1] > 0 else "") + str(person[1])
                    await self.CHANNEL.send(
                        f"🎉 It is no longer **{n_d} UTC {f_tz}**, but happy birthday to <@{person[0]}> regardless! 🎉"
                    )
                    await self.SERVER["MAIN"].get_member(int(
                        person[0])).add_roles(self.BIRTHDAY_ROLE)

            # Find members whose birthdays just ended in that timezone
            found = self.db.get_entries("birthday",
                                        columns=["id"],
                                        conditions={
                                            "birthday": l_d,
                                            "timezone": tz[0]
                                        })
            for member in found:  # Remove their birthday role
                await self.SERVER["MAIN"].get_member(int(
                    member[0])).remove_roles(self.BIRTHDAY_ROLE)

            # Now, search for members whose birthday just started
            found = self.db.get_entries("birthday",
                                        columns=["id"],
                                        conditions={
                                            "birthday": tz[1],
                                            "timezone": tz[0]
                                        })

            if len(found) == 0:  # If there are none, return
                return

            # If there are members, cycle through each of them.
            for member in found:
                if self.BIRTHDAY_ROLE in self.SERVER["MAIN"].get_member(
                        int(member[0])).roles:
                    found[found.index(
                        member
                    )] = 0  # If they already have the birthday role, they're being counted
                    continue  # again, and this is a mistake. Change their id in found to 0 and continue

                # If they don't have the birthday role, give it to them
                await self.SERVER["MAIN"].get_member(int(member[0])).add_roles(
                    self.BIRTHDAY_ROLE)

            found = [
                x for x in found if x != 0
            ]  # Remove those who already had their birthday counted to avoid
            # birthday ping repeats.

            if len(found) == 0:
                return  # If nobody's birthday is supposed to be announced now, return

            # Specify the timezone the bot is covering in this message
            f_tz = ("+" if tz[0] > 0 else "") + str(tz[0])

            # Prepare pings for everyone having their birthday
            birthday_mentions = grammar_list([f"<@{x[0]}>" for x in found])

            await self.CHANNEL.send(
                f"🎉 It's now **{tz[1]} UTC {f_tz}**! Happy birthday to {birthday_mentions}! 🎉"
            )
        return
示例#2
0
    async def on_one_hour(self):
        current_time = datetime.utcnow()
        hour = current_time.hour

        self.CHANNEL = discord.utils.get(self.SERVER["MAIN"].channels,
                                         name=self.param["CHANNEL"])

        day_change_tz = []
        for timezone in range(-12, 15):  # For each timezone
            if (hour + timezone
                ) % 24 == 0:  # If the day just changed in this timezone
                tz_info = [timezone
                           ]  # Timezone is the first element of the list

                tz_time = current_time + timedelta(hours=timezone)
                tz_info.append(f"{tz_time.day}/{tz_time.month}")
                tz_info.append(
                    tz_time)  # The day is the second element of the list

                day_change_tz.append(tz_info)

        print(day_change_tz)
        for tz in day_change_tz:
            l_d = tz[2] + timedelta(
                days=-1
            )  # Get the last day in the timezone that just switched days
            n_d = tz[2] + timedelta(days=1)

            n_d = f"{n_d.day}/{n_d.month}"
            l_d = f"{l_d.day}/{l_d.month}"
            '''
			# All people whose birthdays were yesterday
			found = self.db.get_entries("birthday", columns=["id", "timezone"], conditions={"birthday": l_d})
			for person in found: # Cycle through all
				# person[1] < tz[0] checks if the timezone whose day just changed is greater than the person's timezone
				# since the day flips over in greater timezones first and then gradually smaller values, this checks
				# to see if the day has flipped over to the current day (tz[1]) in the person's timezone yet.
				# If person[1] < tz[0], it hasn't, and it's still l_d ("yesterday", tz[1] - 1 day) in their timezone,
				# so it's still their birthday.
				# the second boolean just checks if the person already has the birthday role. If they don't and the
				# first boolean is true, that means this person's birthday was missed, so correct that
				if person[1] < tz[0] and (self.BIRTHDAY_ROLE not in self.SERVER["MAIN"].get_member(int(person[0])).roles):
					f_tz = ("+" if person[1] > 0 else "") + str(person[1])
					await self.CHANNEL.send(
					f"""🎉 It's no longer midnight on **{l_d} UTC {f_tz}**, 
					but happy birthday to <@{person[0]}> regardless! 🎉""".replace("\n", "").replace("\t", "")
					)
					await self.SERVER["MAIN"].get_member(int(person[0])).add_roles(self.BIRTHDAY_ROLE)
			
			# All people whose birthdays are today
			found = self.db.get_entries("birthday", columns=["id", "timezone"], conditions={"birthday": tz[1]})
			for person in found: # Cycle through all
				# person[1] > tz[0] checks if the timezone whose day just changed is smaller than the person's timezone
				# since the day flips over in greater timezones first and then gradually smaller values, this checks
				# to see if the day has flipped over to the next day (tz[1] + 1 day) in the person's timezone yet.
				# If person[1] > tz[0], it hasn't, and it's still tz[1] (today) in their timezone, so it's still their
				# birthday. If person[1] == tz[0], that means it just became their birthday, and that's covered later.
				# the second boolean just checks if the person already has the birthday role. If they don't and the
				# first boolean is true, that means this person's birthday was missed, so correct that
				if person[1] > tz[0] and (self.BIRTHDAY_ROLE not in self.SERVER["MAIN"].get_member(int(person[0])).roles):
					f_tz = ("+" if person[1] > 0 else "") + str(person[1])
					await self.CHANNEL.send(
					f"""🎉 It's no longer midnight on **{tz[1]} UTC {f_tz}**, 
					but happy birthday to <@{person[0]}> regardless! 🎉""".replace("\n", "").replace("\t", "")
					)
					await self.SERVER["MAIN"].get_member(int(person[0])).add_roles(self.BIRTHDAY_ROLE)
			
			found = self.db.get_entries("birthday", columns=["id", "timezone"], conditions={"birthday": n_d})
			for person in found:
				# person[1] - 24 > tz[0] checks if the timezone whose day just changed is smaller enough than the
				# person's timezone such that there's a difference of two days between the timezone that just changed
				# and the person's. This checks to see if it's already n_d ("tomorrow", tz[1] + 1 day) somewhere and if
				# it's also at least 1 AM, so that it's possible we missed someone there.
				# If person[1] - 24 > tz[0], it is, and it's already n_d in their timezone, so it's already their
				# birthday. If person[1] == tz[0], that means it just became their birthday, and that's covered later.
				# the second boolean just checks if the person already has the birthday role. If they don't and the
				# first boolean is true, that means this person's birthday was missed, so correct that
				if person[1] - 24 > tz[0] and (self.BIRTHDAY_ROLE not in self.SERVER["MAIN"].get_member(int(person[0])).roles):
					f_tz = ("+" if person[1] > 0 else "") + str(person[1])
					await self.CHANNEL.send(
					f"""🎉 It's no longer midnight on **{n_d} UTC {f_tz}**, 
					but happy birthday to <@{person[0]}> regardless! 🎉""".replace("\n", "").replace("\t", "")
					)
					await self.SERVER["MAIN"].get_member(int(person[0])).add_roles(self.BIRTHDAY_ROLE)
			'''

            # Find members whose birthdays just ended in that timezone (one day ago, same timezone = exactly 24h ago)
            found = self.db.get_entries("birthday",
                                        columns=["id"],
                                        conditions={
                                            "birthday": l_d,
                                            "timezone": tz[0]
                                        })
            print("No more birthday:", found)
            for member in found:  # Remove their birthday role, as their birthday just ended
                await self.SERVER["MAIN"].get_member(int(
                    member[0])).remove_roles(self.BIRTHDAY_ROLE)

            # Now, search for members whose birthday just started (today, in the day-changing timezone = it's midnight)
            found = self.db.get_entries("birthday",
                                        columns=["id"],
                                        conditions={
                                            "birthday": tz[1],
                                            "timezone": tz[0]
                                        })
            print("More birthday:", found)
            if len(found) == 0:  # If there are none, return
                return

            # If there are members, cycle through each of them.
            for member in found:
                if self.BIRTHDAY_ROLE in self.SERVER["MAIN"].get_member(
                        int(member[0])).roles:
                    found[found.index(
                        member
                    )] = 0  # If they already have the birthday role, they're being counted
                    continue  # again, and this is a mistake. Change their id in found to 0 and continue

                # If they don't have the birthday role, give it to them
                await self.SERVER["MAIN"].get_member(int(member[0])).add_roles(
                    self.BIRTHDAY_ROLE)

            found = [
                x for x in found if x != 0
            ]  # Remove those who already had their birthday counted to avoid
            # birthday ping repeats.

            print("Actual birthday announcements:", found)

            if len(found) == 0:
                return  # If nobody's birthday is supposed to be announced now, return

            # Specify the timezone the bot is covering in this message
            f_tz = ("+" if tz[0] > 0 else "") + str(tz[0])

            # Prepare pings for everyone having their birthday
            birthday_mentions = grammar_list([f"<@{x[0]}>" for x in found])

            await self.CHANNEL.send(
                f"🎉 It's now **{tz[1]} UTC {f_tz}**! Happy birthday to {birthday_mentions}! 🎉"
            )
        return
示例#3
0
async def MAIN(message, args, level, perms, SERVER):
    if level != 1:
        if args[1].lower() == "queue" and perms == 2:
            await message.channel.send(
                open("Config/_image_gen.txt", "r").read())
            return

    tr_gen = open("Config/_image_gen.txt", "r").read()
    tr_gen += f" {message.id}"
    open("Config/_image_gen.txt", "w").write(tr_gen.strip())

    while not open("Config/_image_gen.txt", "r").read().startswith(
            str(message.id)):
        await asyncio.sleep(1)

    pixel_count = 250 * np.power(10,
                                 np.power(np.e, random.uniform(0, 2.5)) - 1)

    image_pixels = 490 + 115 + pixel_count
    height = (0.2 / 860) * image_pixels

    if height > 10:
        image_pixels = 10 / (0.2 / 860)
        pixel_count = image_pixels - 115 - 490

    top = Image.open("Images/tr_ top.png").convert("RGBA")
    face = Image.open("Images/tr_ face.png").convert("RGBA")
    grad = Image.open("Images/tr_ gradient.png").convert("RGBA")
    bottom = Image.open("Images/tr_ bottom.png").convert("RGBA")

    tr_base = Image.new("RGBA", (1440, int(image_pixels)), (0, 0, 0, 0))
    tr_base.paste(top, (0, 0))
    grad = grad.resize((1440, int(pixel_count)))
    tr_base.paste(grad, (0, 115))
    tr_base.paste(bottom, (0, int(image_pixels) - 609), mask=bottom)

    face_position = min(309, int(image_pixels / 2) - 312)

    tr_base.paste(face, (0, face_position), mask=face)

    ratio = 250 / image_pixels

    tr_base = tr_base.resize((int(1440 * ratio), int(image_pixels * ratio)),
                             Image.ANTIALIAS)
    w = 1440 * ratio
    h = int(image_pixels * ratio)

    center_w = max(min(150, 150 / np.sqrt(height)), 35)

    to_post = Image.open("Images/tr_ background.png").convert("RGBA")
    to_post.paste(tr_base, (int(center_w - w / 2), 290 - h), mask=tr_base)

    scale_objects = {
        "Tesla Cybertruck": 1.9,
        "Elephant": 3.2,
        "Basketball": 0.23,
        "Human Hand": 0.19,
        "Apple Pro Stand": 0.45,
        "Hummingbird": 0.1,
        "Robert Wadlow": 2.72,
        "Blue Whale": 4.5,
        "Bonsai Tree": 0.8,
        "Four Year Old Child": 1.1,
        "Aegislash": 1.7,
        "Purplegaze": 1.78,
        "Medium Dog House": 0.65,
        "Hedgehog": 0.12,
        "Pine Tree": 15,
        "All Diary of a Wimpy Kid Books Stacked on Top of Each Other": 0.27,
        "Brazil": 4292000,
        "Earth": 12742000,
        "Empire State Building": 441,
        "Neutron Star": 10000,
        "The Three Pyramids of Giza Stacked on Top of Each Other": 348.1,
        "Giratina Origin Form": 6.9,
        "Eiffel Tower": 324,
        "Christ the Redeemer": 38,
        "Jupiter": 139822000,
        "Saturn's Rings": 357864000,
        "Mount Everest": 8848,
        "Hiroshima Mushroom Cloud": 18288,
        "Shimizu Mega-City Pyramid": 2000,
        "Kármán Line": 100000,
        "Birthday Cake": 0.11,
        "Regular Book": 0.3043
    }

    current_w = center_w * 1.65

    pixels_per_height = 250 / height

    references = []
    for scale in scale_objects.keys():
        if 0.2 * height < scale_objects[scale] < 1.15 * height:
            img = Image.open(f"Images/{scale}.png").convert("RGBA")
            ratio = (pixels_per_height * scale_objects[scale]) / img.height
            img = img.resize((int(img.width * ratio), int(img.height * ratio)))

            references.append([scale, img, img.width, img.height])

    to_scale = []

    while True:
        possible_ref = []

        for ref in references:
            if ref[2] + current_w <= 790:
                possible_ref.append(ref)

        if len(possible_ref) == 0:
            break

        ref = random.choice(possible_ref)

        to_post.paste(ref[1], (int(current_w), 290 - ref[3]), mask=ref[1])
        current_w += ref[2] + 35

        prefix = ""
        if scale_objects[ref[0]] > 1000:
            scale_objects[ref[0]] = scale_objects[ref[0]] / 1000
            prefix = "k"

        to_scale.append(
            f"**`{ref[0]}`** ({scale_objects[ref[0]]}{prefix}m tall)")
        references.remove(ref)

    if len(to_scale) != 0:
        to_scale = "To scale: " + grammar_list(to_scale)
    else:
        to_scale = ""

    to_post.save("Images/generated tr_.png")

    width_note = ""
    if height >= 10:
        width_note = "*(tr_ width not to scale)*"

    prefix = ""
    if height > 1000:
        height = height / 1000
        prefix = "k"
    await message.channel.send(
        f"""**<@{message.author.id}>, your generated tr_ is {round(height, 4)}{prefix}m tall!**
	{width_note}
	{to_scale}""".replace("\t", ""),
        file=discord.File("Images/generated tr_.png"))

    os.remove("Images/generated tr_.png")

    try:
        tr_gen = open("Config/_image_gen.txt", "r").read().split(" ")
        tr_gen.remove(str(message.id))
        open("Config/_image_gen.txt", "w").write(" ".join(tr_gen).strip())
    except ValueError:
        pass
    return