示例#1
0
 def get_formatted_message(self, message):
     edit_ts = message.edited_at
     if not edit_ts:
         edit_ts = None
     else:
         edit_ts = self.format_datetime(edit_ts)
     msg = {
         "id": str(message.id),
         "channel_id": str(message.channel.id),
         "content": message.content,
         "author": get_message_author(message),
         "timestamp": self.format_datetime(message.created_at),
         "edited_timestamp": edit_ts,
     }
     if hasattr(message, "mentions"):
         msg["mentions"] = get_message_mentions(message.mentions)
     if hasattr(message, "attachments"):
         msg["attachments"] = get_attachments_list(message.attachments)
     if hasattr(message, "embeds"):
         msg["embeds"] = get_embeds_list(message.embeds)
     if hasattr(message, "author"):
         nickname = None
         if hasattr(message.author, 'nick') and message.author.nick:
             nickname = message.author.nick
         msg["author"]["nickname"] = nickname
     if hasattr(message, "mentions"):
         for mention in msg["mentions"]:
             mention["nickname"] = None
             member = message.guild.get_member(mention["id"])
             if member:
                 mention["nickname"] = member.nick
     return msg
示例#2
0
 def get_formatted_message(self, message):
     edit_ts = message.edited_timestamp
     if not edit_ts:
         edit_ts = None
     else:
         edit_ts = self.format_datetime(edit_ts)
     msg = {
         "id": message.id,
         "channel_id": message.channel.id,
         "content": message.content,
         "author": get_message_author(message),
         "timestamp": self.format_datetime(message.timestamp),
         "edited_timestamp": edit_ts,
         "mentions": get_message_mentions(message.mentions),
         "attachments": message.attachments,
         "embeds": message.embeds,
     }
     nickname = None
     if hasattr(message.author, 'nick') and message.author.nick:
         nickname = message.author.nick
     msg["author"]["nickname"] = nickname
     for mention in msg["mentions"]:
         mention["nickname"] = None
         member = message.server.get_member(mention["id"])
         if member:
             mention["nickname"] = member.nick
     return msg
示例#3
0
文件: __init__.py 项目: Ryonez/Titan
 async def update_message(self, message):
     if message.guild:
         await Messages.update.values(
             content=message.content,
             timestamp=message.created_at,
             edited_timestamp=message.edited_at,
             mentions=json.dumps(get_message_mentions(message.mentions)),
             attachments=json.dumps(
                 get_attachments_list(message.attachments)),
             embeds=json.dumps(get_embeds_list(message.embeds)),
             author=json.dumps(get_message_author(message))).where(
                 Messages.message_id == int(message.id)).gino.status()
示例#4
0
文件: __init__.py 项目: Ryonez/Titan
 async def push_message(self, message):
     if message.guild:
         await Messages.create(
             message_id=int(message.id),
             guild_id=int(message.guild.id),
             channel_id=int(message.channel.id),
             content=message.content,
             author=json.dumps(get_message_author(message)),
             timestamp=message.created_at,
             edited_timestamp=message.edited_at,
             mentions=json.dumps(get_message_mentions(message.mentions)),
             attachments=json.dumps(
                 get_attachments_list(message.attachments)),
             embeds=json.dumps(get_embeds_list(message.embeds)))
示例#5
0
 async def update_message(self, message):
     if message.server:
         async with threadpool():
             with self.get_session() as session:
                 msg = session.query(Messages) \
                     .filter(Messages.guild_id == message.server.id) \
                     .filter(Messages.channel_id == message.channel.id) \
                     .filter(Messages.message_id == message.id).first()
                 if msg:
                     msg.content = message.content
                     msg.timestamp = message.timestamp
                     msg.edited_timestamp = message.edited_timestamp
                     msg.mentions = json.dumps(
                         get_message_mentions(message.mentions))
                     msg.attachments = json.dumps(message.attachments)
                     msg.author = json.dumps(get_message_author(message))
                     session.commit()
示例#6
0
 def _update_message(self, message):
     if message.guild:
         with self.get_session() as session:
             msg = session.query(Messages) \
                 .filter(Messages.guild_id == message.guild.id) \
                 .filter(Messages.channel_id == message.channel.id) \
                 .filter(Messages.message_id == message.id).first()
             if msg:
                 msg.content = message.content
                 msg.timestamp = message.created_at
                 msg.edited_timestamp = message.edited_at
                 msg.mentions = json.dumps(
                     get_message_mentions(message.mentions))
                 msg.attachments = json.dumps(
                     get_attachments_list(message.attachments))
                 msg.embeds = json.dumps(get_embeds_list(message.embeds))
                 msg.author = json.dumps(get_message_author(message))
                 session.commit()
示例#7
0
    async def push_message(self, message):
        if message.server:
            async with threadpool():
                with self.get_session() as session:
                    edit_ts = message.edited_timestamp
                    if not edit_ts:
                        edit_ts = None
                    else:
                        edit_ts = str(edit_ts)

                    msg = Messages(
                        message.server.id, message.channel.id,
                        message.id, message.content,
                        json.dumps(get_message_author(message)),
                        str(message.timestamp), edit_ts,
                        json.dumps(get_message_mentions(message.mentions)),
                        json.dumps(message.attachments))
                    session.add(msg)
                    session.commit()
示例#8
0
    def _push_message(self, message):
        if message.guild:
            with self.get_session() as session:
                edit_ts = message.edited_at
                if not edit_ts:
                    edit_ts = None
                else:
                    edit_ts = str(edit_ts)

                msg = Messages(
                    int(message.guild.id), int(message.channel.id),
                    int(message.id), message.content,
                    json.dumps(get_message_author(message)),
                    str(message.created_at), edit_ts,
                    json.dumps(get_message_mentions(message.mentions)),
                    json.dumps(get_attachments_list(message.attachments)),
                    json.dumps(get_embeds_list(message.embeds)))
                session.add(msg)
                session.commit()