Skip to content
This repository was archived by the owner on Mar 29, 2021. It is now read-only.

Commit 34d164a

Browse files
committed
fixes #296
adding two settings to handle raids from chat in kong
1 parent 08f1914 commit 34d164a

3 files changed

Lines changed: 86 additions & 51 deletions

File tree

src/mods/raids.js

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ idrinth.raids = {
66
/**
77
* @type Object
88
*/
9-
private: {},
9+
private: { },
1010
/**
1111
* @type Object
1212
*/
@@ -39,35 +39,36 @@ idrinth.raids = {
3939
* @param {string} responseText
4040
* @returns {undefined}
4141
*/
42-
function ( responseText ) {
43-
var delHandler = function ( key ) {
44-
if ( key in idrinth.raids.list ) {
45-
delete idrinth.raids.list[key];
46-
}
47-
if ( key in idrinth.raids.joined ) {
48-
delete idrinth.raids.joined[key];
49-
}
50-
if ( document.getElementById ( 'idrinth-raid-link-' + key ) ) {
51-
idrinth.ui.removeElement ( 'idrinth-raid-link-' + key );
52-
}
53-
};
54-
var list = JSON.parse ( responseText );
55-
for (var key in list) {
56-
if ( list[key].delete ) {
57-
delHandler ( key );
58-
} else {
59-
//worst case: overwriting itself
60-
idrinth.raids.list[key] = list[key];
61-
}
62-
}
63-
},
64-
function () {
65-
},
66-
function () {
67-
},
68-
idrinth.raids.knowRaids ()
69-
);
70-
},
42+
function ( responseText ) {
43+
var delHandler = function ( key ) {
44+
if ( key in idrinth.raids.list ) {
45+
delete idrinth.raids.list[key];
46+
}
47+
if ( key in idrinth.raids.joined ) {
48+
delete idrinth.raids.joined[key];
49+
}
50+
if ( document.getElementById ( 'idrinth-raid-link-' + key ) ) {
51+
idrinth.ui.removeElement ( 'idrinth-raid-link-' + key );
52+
}
53+
};
54+
var list = JSON.parse ( responseText );
55+
for (var key in list) {
56+
if ( list[key].delete ) {
57+
delHandler ( key );
58+
} else {
59+
//worst case: overwriting itself
60+
list[key].private = idrinth.raids.list[key] && idrinth.raids.list[key].private;
61+
idrinth.raids.list[key] = list[key];
62+
}
63+
}
64+
},
65+
function () {
66+
},
67+
function () {
68+
},
69+
idrinth.raids.knowRaids ()
70+
);
71+
},
7172
/**
7273
*
7374
* @returns {String}
@@ -282,11 +283,11 @@ idrinth.raids = {
282283
* @param {String} key
283284
* @returns {Function}
284285
*/
285-
var byMessage = function(key) {
286+
var byMessage = function ( key ) {
286287
idrinth.inframe.send (
287288
'joinRaid',
288-
(idrinth.raids.join.getServerLink ( key )).replace(/^.*raidjoin\.php/,'raidjoin.php')
289-
);
289+
( idrinth.raids.join.getServerLink ( key ) ).replace ( /^.*raidjoin\.php/, 'raidjoin.php' )
290+
);
290291
idrinth.raids.join.messages.trying ( key );
291292
};
292293
/**
@@ -319,7 +320,7 @@ idrinth.raids = {
319320
}
320321
};
321322
var options = [ postLink ];
322-
if ( idrinth.platform === 'armorgames' || idrinth.platform === 'kongregate') {
323+
if ( idrinth.platform === 'armorgames' || idrinth.platform === 'kongregate' ) {
323324
options.push ( byMessage );
324325
}
325326
return options;
@@ -345,9 +346,14 @@ idrinth.raids = {
345346
added++;
346347
options[0] ( key );//post link
347348
if (
348-
(!idrinth.settings.get ( "bannedRaids#" + raid.raid ) && !idrinth.settings.get("raidWhitelist")) ||
349-
(idrinth.settings.get ( "bannedRaids#" + raid.raid ) && idrinth.settings.get("raidWhitelist"))
350-
) {
349+
(
350+
( !idrinth.settings.get ( "bannedRaids#" + raid.raid ) && !idrinth.settings.get ( "raidWhitelist" ) ) ||
351+
( idrinth.settings.get ( "bannedRaids#" + raid.raid ) && idrinth.settings.get ( "raidWhitelist" ) )
352+
) && (
353+
!raid.private ||
354+
idrinth.settings.get ( 'raid#joinPrivate' )
355+
)
356+
) {
351357
for (var count = 1; count < options.length; count++) {
352358
options[count] ( key );
353359
}
@@ -371,41 +377,45 @@ idrinth.raids = {
371377
* requests information for raids caught from a third party(chat for example)
372378
* @returns {undefined}
373379
*/
374-
var handlePrivates = function() {
380+
var handlePrivates = function () {
375381
/**
376382
*
377383
* @param {String} reply
378384
* @returns {undefined}
379385
*/
380-
var handle = function(reply){
381-
if(!reply) {
386+
var handle = function ( reply ) {
387+
if ( !reply ) {
382388
return;
383389
}
384-
reply=JSON.parse(reply);
385-
if(!reply) {
390+
reply = JSON.parse ( reply );
391+
if ( !reply ) {
386392
return;
387393
}
388-
if(!reply.hasOwnProperty ('delete')) {
394+
if ( !reply.hasOwnProperty ( 'delete' ) ) {
389395
idrinth.raids.list[reply.aid] = reply;
396+
idrinth.raids.list[reply.aid].private = true;
390397
}
391-
try{
398+
try {
392399
delete idrinth.raids.private[reply.raidId];
393-
}catch(e) {
394-
idrinth.core.log (e.getMessage?e.getMessage():e.message);
400+
} catch ( e ) {
401+
idrinth.core.log ( e.getMessage ? e.getMessage () : e.message );
395402
}
396403
};
397-
for(var raidId in idrinth.raids.private) {
404+
if ( !idrinth.settings.get ( 'stat#requestPrivate' ) ) {
405+
return;
406+
}
407+
for (var raidId in idrinth.raids.private) {
398408
idrinth.core.ajax.runHome (
399-
'get-raid-service/'+raidId+'/'+idrinth.raids.private[raidId]+'/',
400-
handle
401-
);
409+
'get-raid-service/' + raidId + '/' + idrinth.raids.private[raidId] + '/',
410+
handle
411+
);
402412
}
403413
};
404414
if ( !join () && Date.now () - 60000 > idrinth.raids.requested ) {
405415
idrinth.raids.requested = Date.now ();
406416
idrinth.raids.import ( idrinth.settings.get ( "raids" ) ? idrinth.settings.get ( "favs" ) : '-1' );
407417
}
408-
handlePrivates();
418+
handlePrivates ();
409419
}
410420
},
411421
/**

src/mods/settings.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@ idrinth.settings = {
104104
* @type String
105105
*/
106106
lang: null,
107+
/**
108+
* @type Object
109+
*/
110+
raid: {
111+
/**
112+
*
113+
* @type Boolean
114+
*/
115+
requestPrivate: true,
116+
/**
117+
*
118+
* @type Boolean
119+
*/
120+
joinPrivate: true
121+
},
107122
/**
108123
*
109124
* @type {Object}

src/mods/ui.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,16 @@ idrinth.ui = {
701701
rType: '#input',
702702
type: 'checkbox',
703703
label: "setting.worldserver"
704+
}, {
705+
name: 'raid#requestPrivate',
706+
rType: '#input',
707+
type: 'checkbox',
708+
label: "setting.raid.requestPrivate"
709+
}, {
710+
name: 'raid#joinPrivate',
711+
rType: '#input',
712+
type: 'checkbox',
713+
label: "setting.raid.joinPrivate"
704714
}, {
705715
name: 'newgroundLoad',
706716
rType: '#input',

0 commit comments

Comments
 (0)