Pixel-Composer/objects/o_dialog_splash/Other_62.gml

169 lines
4.3 KiB
Plaintext
Raw Permalink Normal View History

2023-06-01 10:32:21 +02:00
/// @description
var _id = async_load[? "id"];
if(_id == contest_req) {
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
}
if(_id == news_req) {
var r_str = async_load[? "result"];
if(is_undefined(r_str)) exit;
var thr_str = json_try_parse(r_str, noone);
if(!is_array(thr_str)) exit;
for (var i = 0, n = array_length(thr_str); i < n; i++) {
var _inf = thr_str[i];
_inf.img = noone;
if(_inf.img_url != "") {
var _fil = $"{DIRECTORY}Cache/{_inf.header}.png";
if(file_exists_empty(_fil)) {
_inf.img = sprite_add(_fil, 0, false, false, 0, 0);
} else {
var _rid = http_get_file(_inf.img_url, _fil);
news_requests[$ _rid] = _inf;
}
}
news_content[i] = _inf;
}
exit;
}
if(struct_has(news_requests, _id)) {
var _status = ds_map_find_value(async_load, "status");
if (_status != 0) exit;
var _path = ds_map_find_value(async_load, "result");
var _inf = news_requests[$ _id];
if(file_exists_empty(_path))
_inf.img = sprite_add(_path, 0, false, false, 0, 0);
exit;
}
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-11-01 08:10:25 +01:00
var path = TEMPDIR + 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];
2023-12-08 03:50:09 +01:00
if(!file_exists_empty(path)) {
2023-06-01 10:32:21 +02:00
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
}