def log_message(message: discord.Message): user, _ = User.get_or_create(id=message.author.id, defaults={ "username": message.author.name, "discriminator": message.author.discriminator, "nickname": message.author.display_name }) text_channel, _ = TextChannel.get_or_create( id=message.channel.id, defaults={"name": message.channel.name}) msg, _ = Message.get_or_create(id=message.id, defaults={ "author": user, "channel": text_channel, "timestamp": message.created_at, "jump_url": message.jump_url, "was_deleted": False }) embed_json = "" try: for embed in message.embeds: embed_json += f" | Embed: {json.dumps(embed.to_dict())}" except: # todo better handling pass attachment = "" try: attachment = message.attachments[0].proxy_url except IndexError: pass # Ignore, just means we don't have an attachment todo better handling :) # todo Embeds show as an empty message - this needs better handling MessageContent.create( message_id=msg, timestamp=message.edited_at or message.created_at, text=message.clean_content + embed_json, attachment_url=attachment, )
def operate(self, telnetinput): message = '{}' useridentifier = telnetinput[0:11] useridentifier = useridentifier.strip() validator = UserValidator() valid = validator.validate({'username': useridentifier}) if not valid: message = 'Invalid username at {}' return message user, created = User.get_or_create(useridentifier=useridentifier) entry = Entry(date=self.start_time, useridentifier=useridentifier, username=user.username, extra=telnetinput) if "Abre" in telnetinput: # ex. C64BFCC4B5 Abre message = "Open at {}" entry.operation = 'Abre' entry.save() elif "Maestra" in telnetinput: # ex. 1E02420759 Abre 1E02420759 Maestra message = "Master at {}" entry.operation = 'Maestra' entry.save() elif "Negra" in telnetinput: # ex. 3B4BFCD05C Negra message = "Banned at {}" entry.operation = 'Negra' entry.save() elif "Cerrado" in telnetinput: # ex. 6A4BFCE439 Cerrado message = "Not Allowed at {}" entry.operation = 'Cerrado' entry.save() return message