Skip to content

Commit

Permalink
Add clan message alert logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gmertes committed May 6, 2024
1 parent 95ff386 commit f8783a3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
32 changes: 31 additions & 1 deletion src/iqalert.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const soundAuto = chrome.runtime.getURL("auto.mp3");
const soundBoss = chrome.runtime.getURL("boss.mp3");
const soundEvent = chrome.runtime.getURL("event.mp3");
const soundDone = chrome.runtime.getURL("beep.mp3");
const soundPing = chrome.runtime.getURL("ping.mp3");

let gOptions;
let gDesktopNotificationOnCooldown = false;
Expand Down Expand Up @@ -90,7 +91,7 @@ function handleWSEvent(event) {
}

if (event.type === 'msg') {
let msgText = removeTags(event.data.msg);
const msgText = removeTags(event.data.msg);

if (event.data.type === 'eventGlobal') {
if (msgText.includes('rift to the dark realm has opened')) {
Expand Down Expand Up @@ -123,6 +124,19 @@ function handleWSEvent(event) {
}
return;
}

if (event.channel === 'clan-64') {
if (!gOptions.clanChatAlert.enabled)
return;

const user = event.data.username;

if (user === gPlayerName)
return;

console.debug('Clan message:', user, msgText);
alert(soundPing, msgText, `Clan message by ${user}`);
}
return;
}

Expand Down Expand Up @@ -232,5 +246,21 @@ window.addEventListener('message', function (event) {
dialer.loadClanMembers().then(data => {
const clanMembers = data.members.map(item => item.username);
console.debug('Clan members:', clanMembers);

readOptions().then(options => {
const clanChatAlert = options.clanChatAlert;

for (const member in clanChatAlert.members) {
if (!clanMembers.includes(member))
delete clanChatAlert.members[member];
}
clanMembers.forEach(member => {
if (!(member in clanChatAlert.members))
clanChatAlert.members[member] = false;
});

chrome.storage.sync.set({ clanChatAlert: clanChatAlert });
gOptions = options;
});
}).catch(() => { });
});
1 change: 1 addition & 0 deletions src/manifest-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"boss.mp3",
"event.mp3",
"beep.mp3",
"ping.mp3",
"icon128.png",
"wsproxy.min.js"
]
Expand Down
1 change: 1 addition & 0 deletions src/manifest-v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"boss.mp3",
"event.mp3",
"beep.mp3",
"ping.mp3",
"icon128.png",
"wsproxy.min.js"
],
Expand Down
Binary file added src/ping.mp3
Binary file not shown.
7 changes: 6 additions & 1 deletion src/readoptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ function readOptions() {
removeAuto: false,
trinketScore: false,
trinketScoreType: 'battler',
}
},
clanChatAlert: {
enabled: false,
all: false,
members: {},
},
}, function (options) {
resolve(options);
});
Expand Down

0 comments on commit f8783a3

Please sign in to comment.