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 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 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)
def xor(*args): if len(args) != 2: errors.error(f'xor needs exactly 2 arguments, got {len(args)}') val = str(args[0].val) key = str(args[1].val) out = '' for i in range(len(val)): out += chr(ord(val[i]) ^ ord(key[i % len(key)])) return data.String(out)
def rot13(*args): if len(args) != 1: errors.error(f'rot13 needs exactly 1 argument, got {len(args)}') val = str(args[0].val) out = '' for char in val: if char.isalpha(): add = 65 if char.isupper() else 97 new = ord(char) - add out += chr(((new + 13) % 26) + add) else: out += char return data.String(out)
def decode_wav(carrier): song = wave.open(carrier.val, mode='rb') frame_bytes = bytearray(list(song.readframes(song.getnframes()))) extracted = [frame_bytes[i] & 1 for i in range(len(frame_bytes))] string = "".join(chr(int("".join(map(str,extracted[i:i+8])),2)) for i in range(0,len(extracted),8)) decoded = string.split("###")[0] song.close() return data.String(decoded)
def decode(carrier): img = carrier.val image = Image.open(img, 'r') out = '' imgdata = iter(image.getdata()) while (True): pixels = [value for value in imgdata.__next__()[:3] + imgdata.__next__()[:3] + imgdata.__next__()[:3]] binstr = '' for i in pixels[:8]: if (i % 2 == 0): binstr += '0' else: binstr += '1' out += chr(int(binstr, 2)) if (pixels[-1] % 2 != 0): return data.String(out)
def sha256(*args): if len(args) != 1: errors.error(f'sha256 needs exactly 1 argument, got {len(args)}') val = str(args[0].val) return data.String(hashlib.sha256(bytes(val, 'utf-8')).hexdigest())
def evaluate(self): return Push(data.String(self))
def expr(val, scope): if val.type == 'string': return data.String(val.val[0]) elif val.type == 'number': return data.Number(val.val[0]) elif val.type == 'decl': t = data.call(data.get_name(scope, val.val[0])) if t == data.Number: default = data.Number(0) elif t == data.String: default = data.String('') elif t == data.Func: default = data.Func(scope, data.Block(Program(parse.Node('program')))) default.val.val.globals = scope elif t == data.Class: default = data.Class(data.Block(Program(parse.Node('program')))) elif t == data.List: default = data.List(data.Type) elif t == data.PyType: default = data.PyType(None) else: try: default = data.call(t) except: default = t if len(val.val) == 3: func = data.get(scope, val.val[0]).to args = [] for arg in val.val[2].val: if arg.type == 'decl': args.append(arg) else: args.append(expr(arg, scope)) scope.set(data.Symbol(val.val[1]), data.call(func, *args)) else: scope.set(data.Symbol(val.val[1]), default) elif val.type == 'name': return data.get_name(scope, val.val[0]) elif val.type == 'call': func = expr(val.val[0], scope) args = [] for arg in val.val[1].val: if arg.type == 'decl' or isinstance(data.ref(func), data.LazyMethod): args.append(arg) else: args.append(expr(arg, scope)) return data.call(func, *args) elif val.type == 'op': a = expr(val.val[0], scope) func = data.op(a, data.Symbol(val.val[1])) return data.call(func, expr(val.val[2], scope)) elif val.type == 'block': program = Program(val.val[0]) return data.Block(program, scope) elif val.type == 'array': array = [] for item in val.val[0].val: array.append(expr(item, scope)) if val.val[0].val: return data.List(type(array[0]), *array) else: return data.List(data.Type) elif val.type == 'index': index = data.op(expr(val.val[0], scope), data.Symbol('index')) return data.call(index, expr(val.val[1], scope)) elif val.type == 'child': return data.get(expr(val.val[0], scope), val.val[1]) elif val.type == 'bool': if val.val[0] == 'true': return data.Bool(True) else: return data.Bool(False)
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