Last active
May 10, 2023 12:07
-
-
Save anKordii/36ae7c2379c6ceddb77ff4dcf4b4a7d7 to your computer and use it in GitHub Desktop.
Simple custom widget for skipping alerts with command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const settings = { | |
id: null, | |
apiToken: null, | |
}; | |
window.addEventListener('onWidgetLoad', async (obj) => { | |
settings.id = obj.detail.channel.id | |
settings.apiToken = obj.detail.channel.apiToken | |
}) | |
window.addEventListener("onEventReceived", async function (obj) { | |
if (!obj.detail.event) { | |
return; | |
} | |
const event = obj.detail.event; | |
const { data, service } = event; | |
if(!service || service && service !== "twitch"){ | |
return | |
} | |
const badges = data.tags.badges; | |
if (!(badges.includes("broadcaster") || badges.includes("moderator"))) { | |
return; | |
} | |
if (data.text !== "!skip2") { | |
return; | |
} | |
await stopAlert(); | |
}); | |
async function stopAlert() { | |
const {id, apiToken} = settings; | |
if(!id || !apiToken){ | |
return console.log("API credentials missing."); | |
} | |
await fetch(`https://api.streamelements.com/kappa/v2/channels/${id}/socket`, { | |
method: 'POST', | |
headers: { | |
'Content-type': 'application/json', | |
Authorization: `apikey ${apiToken}` | |
}, | |
body: '{"event": "event:skip", "data": {}}' | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment