Skip to content

Commit 416a484

Browse files
committed
cleanup: winstreak code
1 parent d856edb commit 416a484

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/base/chat/winstreak.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { global } from '../../utils/global.js';
44
import { toast as SimpleToast } from '../../utils/2.toasts.js';
55
import isFriend from '../../utils/isFriend.js';
66

7-
settings.register({
7+
const setting = settings.register({
88
name: 'Announcement',
99
key: 'underscript.winstreak',
1010
options: ['Chat', 'Toast', 'Both', 'Hidden'],
@@ -14,29 +14,25 @@ settings.register({
1414
category: 'Winstreak',
1515
});
1616

17-
settings.register({
17+
const friends = settings.register({
1818
name: 'Friends Only',
1919
key: 'underscript.winstreak.friendsOnly',
2020
page: 'Chat',
2121
category: 'Winstreak',
2222
});
2323

24-
const empty = { close() {} };
2524
const toasts = {
2625
v: [],
2726
i: 0,
2827
add(toast) {
29-
(this.v[this.i] || empty).close();
28+
this.v[this.i]?.close();
3029
this.v[this.i] = toast;
3130
this.i = (this.i + 1) % 3;
3231
return toast;
3332
},
3433
};
35-
function friendsOnly() {
36-
return settings.value('underscript.winstreak.friendsOnly');
37-
}
3834
function checkFriend(name) {
39-
return !friendsOnly() || isFriend(name);
35+
return !friends.value() || isFriend(name);
4036
}
4137
function checkCount(amt) {
4238
// return parseInt(amt, 10) >= settings.value('underscript.winstreak.count');
@@ -46,8 +42,8 @@ const events = ['chat-user-ws', 'chat-user-ws-stop'];
4642
eventManager.on('preChat:getMessageAuto', function winstreaks(data) {
4743
const message = JSON.parse(JSON.parse(data.message).args);
4844
if (this.canceled || !events.includes(message[0])) return;
49-
const handling = settings.value('underscript.winstreak');
50-
if (handling === 'Chat' && !friendsOnly()) return; // All default
45+
const handling = setting.value();
46+
if (handling === 'Chat' && !friends.value()) return; // All default
5147
this.canceled = handling !== 'Chat' && handling !== 'Both';
5248
if (handling === 'Hidden') return;
5349
const username = message[message.length - 2];

0 commit comments

Comments
 (0)