class Image9000(data.Base, data.MemberRelated, data.ChannelRelated): HASH_SIZE = 10 attachment_id = data.Column(data.BigInteger, primary_key=True) message_id = data.Column(data.BigInteger, nullable=False) hash = data.Column(data.String(25), nullable=False) sent_at = data.Column(data.DateTime, nullable=False) def calculate_similarity_to(self, other) -> float: return (self.HASH_SIZE**2 - bin(int(self.hash, 16) ^ int(other.hash, 16)).count('1')) / self.HASH_SIZE**2 async def get_presentation(self, bot: commands.Bot) -> str: parts = [self.sent_at.strftime('%-d %B %Y o %-H:%M')] discord_channel = self.discord_channel(bot) parts.append('na usuniętym kanale' if discord_channel is None else f'na #{discord_channel}') discord_user = self.discord_user(bot) if discord_user is None: discord_user = await bot.fetch_user(self.user_id) parts.append( f'przez {"przez usuniętego użytkownika" if discord_user is None else discord_user}' ) return ' '.join(parts)
class Reminder(data.Base, data.ChannelRelated, data.UserRelated): MAX_CONTENT_LENGTH = 100 confirmation_message_id = data.Column(data.BigInteger, primary_key=True) content = data.Column(data.String(MAX_CONTENT_LENGTH), nullable=False) requested_at = data.Column(data.DateTime, nullable=False) execute_at = data.Column(data.DateTime, nullable=False) has_been_executed = data.Column(data.Boolean, nullable=False, default=False)
class Burning(data.Base, data.ChannelRelated, data.UserRelated): confirmation_message_id = data.Column(data.BigInteger, primary_key=True) target_message_id = data.Column(data.BigInteger, nullable=False) requested_at = data.Column(data.DateTime, nullable=False) execute_at = data.Column(data.DateTime, nullable=False) has_been_executed = data.Column(data.Boolean, nullable=False, default=False)
class Invocation(data.MemberRelated, data.ChannelRelated, data.Base): MAX_ERROR_LENGTH = 300 message_id = data.Column(data.BigInteger, primary_key=True) prefix = data.Column(data.String( max(23, data.Server.COMMAND_PREFIX_MAX_LENGTH)), nullable=False) full_command = data.Column(data.String(100), nullable=False, index=True) root_command = data.Column(data.String(100), nullable=False, index=True) created_at = data.Column(data.DateTime, nullable=False) exited_at = data.Column(data.DateTime) error = data.Column(data.String(MAX_ERROR_LENGTH))
class MessageMetadata(data.Base, data.MemberRelated, data.ChannelRelated): __tablename__ = 'message_metadata_cache' id = data.Column(data.BigInteger, primary_key=True) word_count = data.Column(data.Integer, nullable=False) character_count = data.Column(data.Integer, nullable=False) hour = data.Column(data.SmallInteger, nullable=False) weekday = data.Column(data.SmallInteger, nullable=False) datetime = data.Column(data.DateTime, nullable=False)
class Ballot(data.Base, data.ChannelRelated, data.UserRelated): MAX_MATTER_LENGTH = 200 urn_message_id = data.Column(data.BigInteger, primary_key=True) matter = data.Column(data.String(MAX_MATTER_LENGTH), nullable=False) letters = data.Column(data.String(26)) commenced_at = data.Column(data.DateTime, nullable=False) conclude_at = data.Column(data.DateTime, nullable=False) has_been_concluded = data.Column(data.Boolean, nullable=False, default=False)
class BornPerson(data.Base, data.UserSpecific): EDGE_YEAR = 1900 birthday = data.Column(data.Date) birthday_public_servers = data.relationship( 'Server', secondary='birthday_publicness_links', backref='birthday_public_born_persons') def age(self) -> int: return None if self.birthday is None or self.birthday.year == self.EDGE_YEAR else calculate_age( self.birthday) def is_birthday_today(self) -> bool: today = dt.date.today() return (self.birthday.day, self.birthday.month) == (today.day, today.month) def is_birthday_public(self, session: data.RawSession, server: Optional[discord.Guild]) -> bool: return server is None or session.query(data.Server).get( server.id) in self.birthday_public_servers
class BirthdayPublicnessLink(data.Base, data.ServerSpecific): born_person_user_id = data.Column(data.BigInteger, data.ForeignKey('born_persons.user_id'), primary_key=True)
class Oofer(data.Base, data.MemberSpecific): oofs = data.Column(data.Integer, nullable=False, default=1)
class Event(data.Base, data.MemberRelated, data.ChannelRelated): MAX_DETAILS_LENGTH = 1000 id = data.Column(data.BigInteger, primary_key=True) type = data.Column(data.String(50), nullable=False) executing_user_id = data.Column(data.BigInteger, index=True) details = data.Column(data.String(MAX_DETAILS_LENGTH)) occurred_at = data.Column(data.DateTime, nullable=False, default=dt.datetime.now) async def get_presentation(self, bot: commands.Bot) -> str: type_presentation = '???' if self.type == 'warned': type_presentation = 'Ostrzeżenie' elif self.type == 'kicked': type_presentation = 'Wyrzucenie' elif self.type == 'banned': type_presentation = 'Ban' elif self.type == 'unbanned': type_presentation = 'Unban' elif self.type == 'pardoned': type_presentation = 'Przebaczenie' elif self.type == 'joined': type_presentation = 'Dołączenie' elif self.type == 'left': type_presentation = 'Opuszczenie' parts = [ type_presentation, self.occurred_at.strftime('%-d %B %Y o %-H:%M') ] if self.channel_id is not None: discord_channel = self.discord_channel(bot) parts.append(f'na #{discord_channel}' if discord_channel is not None else 'na usuniętym kanale') if self.executing_user_id is not None: discord_executing_user = bot.get_user(self.executing_user_id) if discord_executing_user is None: discord_executing_user = await bot.fetch_user( self.executing_user_id) parts.append( f'przez {discord_executing_user}' if discord_executing_user is not None else 'przez usuniętego użytkownika') return ' '.join(parts) @staticmethod def comprehend_types(input_string: str) -> List[str]: types = [] if 'warn' in input_string or 'ostrzeż' in input_string or 'ostrzez' in input_string: types.append('warned') if 'kick' in input_string or 'wyrzuć' in input_string or 'wyrzuc' in input_string: types.append('kicked') if 'unban' in input_string or 'odban' in input_string: types.append('unbanned') if 'ban' in input_string or 'wygnan' in input_string: types.append('banned') if 'pardon' in input_string or 'przebacz' in input_string: types.append('pardoned') if 'join' in input_string or 'dołącz' in input_string or 'dolacz' in input_string: types.append('joined') if ('leave' in input_string or 'left' in input_string or 'odejście' in input_string or 'odejscie' in input_string or 'odszed' in input_string or 'odesz' in input_string): types.append('left') if not types: raise ValueError return types