mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-06-27 21:05:53 +00:00
* Fixed: Certain chat actions (Pin, Reply) not working correctly when assigned as a User Context action. * Fixed: When editing a setting using the filter editor, settings are saved correctly. * Changed: When editing chat actions, you can now choose to have a profile not inherit values from other profiles or the default values.
143 lines
No EOL
2.8 KiB
JavaScript
143 lines
No EOL
2.8 KiB
JavaScript
'use strict';
|
|
|
|
// ============================================================================
|
|
// Settings Types
|
|
// ============================================================================
|
|
|
|
const DEFAULT = Symbol('default');
|
|
|
|
export const basic = {
|
|
get(key, profiles) {
|
|
for(const profile of profiles)
|
|
if ( profile.has(key) )
|
|
return [
|
|
profile.get(key),
|
|
[profile.id]
|
|
]
|
|
}
|
|
}
|
|
|
|
|
|
export const object_merge = {
|
|
get(key, profiles, log) {
|
|
const values = [],
|
|
sources = [];
|
|
|
|
for(const profile of profiles)
|
|
if ( profile.has(key) ) {
|
|
const val = profile.get(key);
|
|
if ( typeof val !== 'object' ) {
|
|
log.warn(`Profile #${profile.id} has an invalid value for "${key}" of type ${typeof val}. Skipping.`);
|
|
continue;
|
|
}
|
|
|
|
sources.push(profile.id);
|
|
values.unshift(val);
|
|
}
|
|
|
|
if ( sources.length )
|
|
return [
|
|
Object.assign({}, ...values),
|
|
sources
|
|
]
|
|
}
|
|
}
|
|
|
|
|
|
export const basic_array_merge = {
|
|
get(key, profiles, log) {
|
|
const values = [],
|
|
sources = [];
|
|
|
|
for(const profile of profiles)
|
|
if ( profile.has(key) ) {
|
|
const val = profile.get(key);
|
|
if ( ! Array.isArray(val) ) {
|
|
log.warn(`Profile #${profile.id} has an invalid value for "${key}"`);
|
|
continue;
|
|
}
|
|
|
|
sources.push(profile.id);
|
|
for(const v of val)
|
|
values.push(v);
|
|
}
|
|
|
|
if ( sources.length )
|
|
return [
|
|
values,
|
|
sources
|
|
]
|
|
}
|
|
}
|
|
|
|
|
|
export const array_merge = {
|
|
default(val) {
|
|
const values = [];
|
|
for(const v of val)
|
|
if ( v.t !== 'inherit' && v.t !== 'skip' && v.v )
|
|
values.push(v.v);
|
|
|
|
return values;
|
|
},
|
|
|
|
get(key, profiles, definition, log, ctx) {
|
|
const values = [],
|
|
sources = [];
|
|
let trailing = [];
|
|
let had_value = false;
|
|
|
|
let profs = profiles;
|
|
if ( definition.inherit_default )
|
|
profs = [...profiles, DEFAULT];
|
|
|
|
for(const profile of profs) {
|
|
let value;
|
|
if ( profile === DEFAULT ) {
|
|
value = definition.default;
|
|
if ( typeof value === 'function' )
|
|
value = value(ctx);
|
|
|
|
} else if ( profile.has(key) )
|
|
value = profile.get(key);
|
|
else
|
|
continue;
|
|
|
|
if ( ! Array.isArray(value) ) {
|
|
if ( profile !== DEFAULT )
|
|
log.warn(`Profile #${profile.id} has an invalid value for "${key}" of type ${typeof value}. Skipping.`);
|
|
continue;
|
|
}
|
|
|
|
const trail = [];
|
|
|
|
if ( profile !== DEFAULT )
|
|
sources.push(profile.id);
|
|
|
|
let is_trailing = false;
|
|
for(const val of value) {
|
|
had_value = true;
|
|
if ( val.t === 'inherit' )
|
|
is_trailing = true;
|
|
else if ( val.t === 'skip' )
|
|
continue;
|
|
else if ( is_trailing )
|
|
trail.push(val.v);
|
|
else
|
|
values.push(val.v);
|
|
}
|
|
|
|
trailing = trail.concat(trailing);
|
|
|
|
// If we didn't run into an inherit, don't inherit.
|
|
if ( ! is_trailing && ! definition.always_inherit )
|
|
break;
|
|
}
|
|
|
|
if ( had_value )
|
|
return [
|
|
values.concat(trailing),
|
|
sources
|
|
]
|
|
}
|
|
} |