Pixel-Composer/objects/o_dialog_splash/Other_62.gml

127 lines
3.4 KiB
Plaintext
Raw Normal View History

2023-06-01 10:32:21 +02:00
/// @description
2023-06-25 20:12:17 +02:00
if(async_load[? "id"] == contest_req) { //get contests
2023-06-01 10:32:21 +02:00
var r_str = async_load[? "result"];
if(is_undefined(r_str)) exit;
2023-06-01 10:32:21 +02:00
var thr_str = json_try_parse(r_str, noone);
if(thr_str == noone) exit;
2023-06-01 10:32:21 +02:00
if(struct_has(thr_str, "threads")) {
var thrs = thr_str.threads;
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(thrs); i < n; i++ ) {
2023-06-01 10:32:21 +02:00
var thr = thrs[i];
2023-06-25 20:12:17 +02:00
if(thr.parent_id != "1113080578351312906") continue; //not in contest channel
if(struct_has(thr, "flags") && thr.flags & 2) continue;
if(struct_has(thr, "applied_tags") && array_exists(thr.applied_tags, "1113145223938326658")) continue; //has announcement tag
2023-06-01 10:32:21 +02:00
thr.messages = [];
array_push(contests, thr);
var url = $"https://discord.com/api/v10/channels/{thr.id}/messages";
array_push(contest_message_req, [ http_request(url, "GET", discord_map, ""), array_length(contests) - 1 ]);
}
array_insert(pages, 0, "Contests");
project_page++;
}
exit;
2023-06-01 10:32:21 +02:00
}
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(contest_message_req); i < n; i++ ) {
2023-06-01 10:32:21 +02:00
if(async_load[? "id"] != contest_message_req[i][0]) continue;
var r_str = async_load[? "result"];
if(is_undefined(r_str)) exit;
var msgs = json_try_parse(r_str, noone);
if(msgs == noone) exit;
2023-06-01 10:32:21 +02:00
var ind = contest_message_req[i][1];
var thr = contests[ind];
thr.messages = msgs;
for( var j = 0; j < array_length(msgs); j++ ) {
var msg = msgs[j];
var aut = msg.author.id;
if(ds_map_exists(nicknames, aut)) continue;
var url = $"https://discord.com/api/v10/guilds/953634069646835773/members/{aut}";
nicknames[? aut] = [ http_request(url, "GET", discord_map, ""), msg.author.username ];
}
thr.title = msgs[array_length(msgs) - 1];
thr.title.meta = {};
var content = thr.title.content;
2023-07-05 15:09:52 +02:00
var _metaSp = string_split(content, "```", false, 2);
2023-06-01 10:32:21 +02:00
if(array_length(_metaSp) == 3 && _metaSp[0] == "") {
var _meta = _metaSp[1];
var _mtS = string_splice(_meta, "\n");
for( var j = 0; j < array_length(_mtS); j++ ) {
var __mt = string_splice(_mtS[j], ":");
if(array_length(__mt) < 2) continue;
thr.title.meta[$ string_lower(string_trim(__mt[0]))] = string_trim(__mt[1]);
}
thr.title.content = string_trim(_metaSp[2]);
}
if(struct_has(thr.title, "attachments") && array_length(thr.title.attachments)) {
var att = thr.title.attachments[0];
thr.title.attachments = att;
2023-06-04 12:38:40 +02:00
var path = DIRECTORY + "temp/" + att.id + filename_ext(att.url);
2023-06-01 10:32:21 +02:00
attachment[? att.id] = [ http_get_file(att.url, path), path ];
} else
thr.title.attachments = noone;
exit;
2023-06-01 10:32:21 +02:00
}
var keys = ds_map_keys_to_array(nicknames);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(keys); i < n; i++ ) {
2023-06-01 10:32:21 +02:00
var nick = nicknames[? keys[i]];
if(!is_array(nick)) continue;
if(async_load[? "id"] != nick[0]) continue;
var r_str = async_load[? "result"];
if(is_undefined(r_str)) exit;
var auth = json_try_parse(r_str, noone);
if(auth == noone) exit;
2023-06-01 10:32:21 +02:00
nicknames[? keys[i]] = struct_try_get(auth, "nick", nick[1]);
exit;
2023-06-01 10:32:21 +02:00
}
var keys = ds_map_keys_to_array(attachment);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(keys); i < n; i++ ) {
2023-06-01 10:32:21 +02:00
var att = attachment[? keys[i]];
if(!is_array(att)) continue;
if(async_load[? "id"] != att[0]) continue;
var path = att[1];
if(!file_exists(path)) {
attachment[? keys[i]] = noone;
exit;
2023-06-01 10:32:21 +02:00
}
var spr = sprite_add(path, 0, false, 0, 0, 0);
attachment[? keys[i]] = spr;
var _sw = sprite_get_width(spr);
var _sh = sprite_get_height(spr);
sprite_set_offset(spr, _sw / 2, _sh / 2);
exit;
2023-06-01 10:32:21 +02:00
}