async def on_member_join(self, member): if not member.bot: UserProfiles(member) server_settings = ServerSettings(member.guild).getServerSettings() log_channel = self.bot.get_channel( server_settings["log_channel"] ) if server_settings["log_channel"] else None enabled = server_settings["events"]["guild_member_join"] if log_channel is not None and enabled: created_at_unix = utc_to_epoch(member.created_at) created_date = datetime.fromtimestamp(created_at_unix) embed = discord.Embed(title="User joined the server!", description=None, color=discord.Color.green(), timestamp=datetime.utcnow()) embed.add_field(name=f"Username", value=f"{member.name}#{member.discriminator}", inline=False) embed.add_field(name=f"User ID", value=member.id, inline=False) embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.avatar_url) embed.add_field(name="Account created", value=f"{created_date}", inline=False) embed.set_thumbnail(url=member.avatar_url) embed.set_footer(text=self.bot.user.name, icon_url=self.bot.user.avatar_url) await log_channel.send(content=None, embed=embed) stats = ServerStats(self.bot, member.guild) if stats.isEnabled(): await stats.update()
async def on_member_remove(self, member): if not member.bot: UserProfiles(member).reset() try: banned_users = await member.guild.bans() except: # TODO: add exceptions here and handle them return is_banned = [x for x in banned_users if x.user.id == member.id] if is_banned: return server_settings = ServerSettings(member.guild).getServerSettings() log_channel = self.bot.get_channel( server_settings["log_channel"] ) if server_settings["log_channel"] else None enabled = server_settings["events"]["guild_member_leave"] if log_channel is not None and enabled: created_at_unix = utc_to_epoch(member.created_at) created_date = datetime.fromtimestamp(created_at_unix) joined_at_unix = utc_to_epoch(member.joined_at) joined_date = datetime.fromtimestamp(joined_at_unix) embed = discord.Embed(title="User left the server!", description=None, color=discord.Color.red(), timestamp=datetime.utcnow()) embed.add_field(name=f"Username", value=f"{member.mention} ({member.id})", inline=False) embed.add_field(name="Account created", value=f"{created_date}", inline=False) embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.avatar_url) embed.add_field(name="Joined", value=f"{joined_date}", inline=False) embed.set_thumbnail(url=member.avatar_url) embed.set_footer(text=self.bot.user.name, icon_url=self.bot.user.avatar_url) await log_channel.send(content=None, embed=embed) stats = ServerStats(self.bot, member.guild) if stats.isEnabled(): await stats.update()
def parse_entry(self, entry): """Parse a single feed entry into an IFTTT trigger item.""" # Not sure why, but sometimes we get http entry IDs. If we # don't have consistency between https/http, we get mutliple # unique UUIDs for the same entry. meta_id = url_to_uuid5(entry.id.replace('http:', 'https:')) date = entry.published_parsed created_at = utc_to_iso8601(date) ts = utc_to_epoch(date) return {'created_at': created_at, 'entry_id': meta_id, 'url': entry.id, 'meta': {'id': meta_id, 'timestamp': ts}}