async def _send_verification_email(self, member: discord.Member, email: str, code: str) -> bool: cleartext = self.text.get("plaintext mail").format( guild_name=self.getGuild().name, code=code, bot_name=self.bot.user.name, git_hash=utils.git_get_hash()[:7], prefix=config.prefix, ) richtext = self.text.get( "html mail", # styling color_bg="#54355F", color_fg="white", font_family="Arial,Verdana,sans-serif", # names guild_name=self.getGuild().name, bot_name=self.bot.user.name, user_name=member.name, # codes code=code, git_hash=utils.git_get_hash()[:7], prefix=config.prefix, # images bot_avatar=self.bot.user.avatar_url_as(static_format="png", size=128), bot_avatar_size="120px", user_avatar=member.avatar_url_as(static_format="png", size=32), user_avatar_size="20px", ) msg = MIMEMultipart("alternative") msg["Subject"] = self.text.get("mail subject", guild_name=self.getGuild().name, user_name=member.name) msg["From"] = self.config.get("email", "address") msg["To"] = email msg["Bcc"] = self.config.get("email", "address") msg.attach(MIMEText(cleartext, "plain")) msg.attach(MIMEText(richtext, "html")) with smtplib.SMTP(self.config.get("email", "server"), self.config.get("email", "port")) as server: server.starttls() server.ehlo() server.login(self.config.get("email", "address"), self.config.get("email", "password")) server.send_message(msg)
async def on_ready(): global started if started: message = "Reconnected: {timestamp}".format( timestamp=datetime.today().strftime("%Y-%m-%d %H:%M:%S")) else: message = "Logged in [{level}]: {timestamp} ({hash} on branch {branch})".format( level=config.get("bot", "logging"), timestamp=datetime.today().strftime("%Y-%m-%d %H:%M:%S"), hash=utils.git_get_hash()[:7], branch=utils.git_get_branch(), ) started = True print(message) channel = bot.get_channel(config.get("channels", "stdout")) await channel.send(f"```{message}```") await utils.set_presence(bot)
def get_pet_frames(avatar: Image.Image, hue: bool = False) -> List[Image.Image]: """Get frames for the pet avatar: Image hue: boolean; if set to True, avatar's hue is randomly offset """ frames = [] deform_width = (-1, -2, 1, 2, 1) defom_height = (4, 3, 2, 2, -4) width, height = 80, 80 if hue: git_hash = int(utils.git_get_hash(), 16) avatar_pixels = np.array(avatar) else: git_hash = None avatar_pixels = None for i in range(5): if hue: # get random values based on current hash -- last ten decimal digits deform_hue = git_hash % 100**(i + 1) // 100**i / 100 avatar = Image.fromarray( image_utils.shift_hue(avatar_pixels, deform_hue)) frame = Image.new("RGBA", (112, 112), (255, 255, 255, 1)) hand = Image.open(f"data/meme/pet_{i}.png") width -= deform_width[i] height -= defom_height[i] frame_avatar = avatar.resize((width, height)) frame_mask = Image.new("1", frame_avatar.size, 0) draw = ImageDraw.Draw(frame_mask) draw.ellipse((0, 0) + frame_avatar.size, fill=255) frame_avatar.putalpha(frame_mask) frame.paste(frame_avatar, (112 - width, 112 - height), frame_avatar) frame.paste(hand, (0, 0), hand) frames.append(frame) return frames
def get_hyperpet_frames(avatar: Image.Image) -> List[Image.Image]: """Get frames for the hyperpet""" frames = [] width, height = 148, 148 vertical_offset = (0, 1, 2, 3, 1, 0) avatar = image_utils.round_image(avatar.resize((100, 100))) avatar_pixels = np.array(avatar) git_hash = int(utils.git_get_hash(), 16) for i in range(6): deform_hue = git_hash % 100**(i + 1) // 100**i / 100 frame_avatar = Image.fromarray( image_utils.shift_hue(avatar_pixels, deform_hue)) img = "%02d" % (i + 1) frame = Image.new("RGBA", (width, height), (54, 57, 63, 1)) hand = Image.open(f"data/meme/hyperpet/{img}.png") frame.paste(frame_avatar, (35, 25 + vertical_offset[i]), frame_avatar) frame.paste(hand, (10, 5), hand) frames.append(frame) return frames