|
1 | 1 | with |
2 | 2 | messages := <array <json>>$messages, |
3 | 3 | for data in array_unpack(messages) union ( |
4 | | - insert discord::Message { |
5 | | - client := global client, |
6 | | - data := data, |
7 | | - guild_id := <str>json_get(data, 'guild_id'), |
8 | | - channel_id := <str>json_get(data, 'channel_id'), |
9 | | - message_id := <str>json_get(data, 'id'), |
10 | | - author_id := <str>json_get(data, 'author', 'id'), |
11 | | - content := <str>json_get(data, 'content'), |
12 | | - timestamp := <datetime>json_get(data, 'timestamp'), |
13 | | - edited_timestamp := <datetime>json_get(data, 'edited_timestamp'), |
14 | | - } |
15 | | - unless conflict on ((.client, .message_id)) |
| 4 | + with |
| 5 | + message_data := <json>json_get(data, 'message'), |
| 6 | + reactions_data := <array <json>>json_get(data, 'reactions'), |
| 7 | + message_id := <str>json_get(message_data, 'id'), |
| 8 | + inserted := ( |
| 9 | + insert discord::Message { |
| 10 | + client := global client, |
| 11 | + data := message_data, |
| 12 | + guild_id := <str>json_get(message_data, 'guild_id'), |
| 13 | + channel_id := <str>json_get(message_data, 'channel_id'), |
| 14 | + message_id := message_id, |
| 15 | + author_id := <str>json_get(message_data, 'author', 'id'), |
| 16 | + content := <str>json_get(message_data, 'content'), |
| 17 | + timestamp := <datetime>json_get(message_data, 'timestamp'), |
| 18 | + edited_timestamp := <datetime>json_get(message_data, 'edited_timestamp'), |
| 19 | + } |
| 20 | + unless conflict on ((.client, .message_id)) |
| 21 | + else (select discord::Message) |
| 22 | + ), |
| 23 | + for item in array_unpack(reactions_data) union ( |
| 24 | + with |
| 25 | + reaction_data := <json>json_get(item, 'reaction'), |
| 26 | + users_data := <array <json>>json_get(item, 'users'), |
| 27 | + emoji := <json>json_get(reaction_data, 'emoji'), |
| 28 | + name := <str>json_get(emoji, 'name'), |
| 29 | + emoji_id := <str>json_get(emoji, 'id'), |
| 30 | + animated := <bool>json_get(emoji, 'animated') ?? false, |
| 31 | + burst := <int32>json_get(reaction_data, 'count_details', 'burst') > 0, |
| 32 | + for user_data in array_unpack(users_data) union ( |
| 33 | + with |
| 34 | + user_id := <str>json_get(user_data, 'id'), |
| 35 | + user := ( |
| 36 | + insert user::User { |
| 37 | + discord_id := user_id, |
| 38 | + discord_username := <str>json_get(user_data, 'username'), |
| 39 | + } |
| 40 | + unless conflict on .discord_id |
| 41 | + else (select user::User) |
| 42 | + ), |
| 43 | + insert discord::Reaction { |
| 44 | + client := global client, |
| 45 | + message := inserted, |
| 46 | + user := user, |
| 47 | + name := name, |
| 48 | + emoji_id := emoji_id, |
| 49 | + animated := animated, |
| 50 | + burst := burst, |
| 51 | + } |
| 52 | + unless conflict |
| 53 | + ) |
| 54 | + ) |
16 | 55 | ) |
0 commit comments