Guest User

Untitled

a guest
Jan 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. import pytz
  2.  
  3. def toJSON(message, realtime=True):
  4. message_obj = {
  5. 'timestamp': pytz.utc.localize(message.timestamp),
  6. 'tts': message.tts,
  7. 'author': {
  8. 'name': message.author.name,
  9. 'id': message.author.id,
  10. 'discriminator': message.author.discriminator,
  11. 'avatar': message.author.avatar,
  12. 'bot': message.author.bot,
  13. 'avatar_url': message.author.avatar_url,
  14. 'mention': message.author.mention,
  15. 'display_name': message.author.display_name,
  16. 'created_at': pytz.utc.localize(message.author.created_at), # "Returns the user’s creation time in UTC."
  17. 'voice': {
  18. 'deaf': message.author.voice.deaf,
  19. 'mute': message.author.voice.mute,
  20. 'self_mute': message.author.voice.self_mute,
  21. 'self_deaf': message.author.voice.self_deaf
  22. },
  23. 'joined_at': pytz.utc.localize(message.author.joined_at),
  24. 'nick': message.author.nick,
  25. 'top_role': {
  26. 'id': message.author.top_role.id,
  27. 'name': message.author.top_role.name,
  28. 'position': message.author.top_role.position,
  29. 'mentionable': message.author.top_role.mentionable,
  30. 'created_at': pytz.utc.localize(message.author.top_role.created_at),
  31. 'mention': message.author.top_role.mention
  32. },
  33.  
  34. },
  35. 'content': message.content,
  36. 'channel': {
  37. 'name': message.channel.name,
  38. 'id': message.channel.id,
  39. 'topic': message.channel.topic,
  40. 'position': message.channel.position,
  41. 'mention': message.channel.mention,
  42. 'created_at': pytz.utc.localize(message.channel.created_at) # "Returns the channel’s creation time in UTC."
  43. },
  44. 'server': {
  45. 'name': message.server.name,
  46. 'icon': message.server.icon,
  47. 'id': message.server.id,
  48. 'icon_url': message.server.icon_url,
  49. 'member_count': message.server.member_count,
  50. 'created_at': pytz.utc.localize(message.server.created_at) # "Returns the server’s creation time in UTC."
  51. },
  52. 'mention_everyone': message.mention_everyone,
  53. 'id': message.id,
  54. 'attachments': message.attachments,
  55. 'raw_mentions': message.raw_mentions,
  56. 'raw_channel_mentions': message.raw_channel_mentions,
  57. 'raw_role_mentions': message.raw_role_mentions
  58. }
  59. if realtime == False:
  60. message_obj['pinned'] = message.pinned
  61. message.reactions = [{'id':x.emoji.id,'count':x.count} for x in message.reactions]
  62. return message_obj
Add Comment
Please, Sign In to add comment