Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Kurotaku-sama/bf8fef7e64b6954d6fad35f3682acc5e to your computer and use it in GitHub Desktop.
Save Kurotaku-sama/bf8fef7e64b6954d6fad35f3682acc5e to your computer and use it in GitHub Desktop.
Adds buttons to send commands in the Twitch chat
// ==UserScript==
// @name Twitch hitsquadgodfather command buttons
// @namespace https://kurotaku.de
// @version 1.7
// @description Adds buttons to send commands in the Twitch chat
// @author Kurotaku
// @license MIT
// @match https://www.twitch.tv/hitsquadgodfather*
// @match https://www.twitch.tv/*/hitsquadgodfather/chat*
// @icon https://static.twitchcdn.net/assets/favicon-32-e29e246c157142c94346.png
// @updateURL https://gist.github.com/Kurotaku-sama/bf8fef7e64b6954d6fad35f3682acc5e/raw/Twitch%2520hitsquadgodfather%2520command%2520buttons.user.js
// @downloadURL https://gist.github.com/Kurotaku-sama/bf8fef7e64b6954d6fad35f3682acc5e/raw/Twitch%2520hitsquadgodfather%2520command%2520buttons.user.js
// @require https://gist.github.com/Kurotaku-sama/9ebeb659500f6eee2f780344948e1e8f/raw/kuros_library.user.js
// @require https://gist.github.com/Kurotaku-sama/a5a08a94398ea55123f8c09069fe68ee/raw/kuros_twitch_button_library.user.js
// @require https://openuserjs.org/src/libs/sizzle/GM_config.js
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// ==/UserScript==
let twitch_channel = 'hitsquadgodfather';
(async function() {
await init_gm_config(); // Initialize the configuration
main();
// Zosky's restart timer
if(GM_config.get("script_enabled"))
if(GM_config.get("restart_timer"))
zoskys_restart_timer();
})();
function init_gm_config() {
GM_registerMenuCommand('Settings', () => {
GM_config.open();
});
let frame = document.createElement('div');
document.body.appendChild(frame);
GM_config.init(
{
'id': 'configuration',
'title': 'Twitch hitsquadgodfather config',
'fields':
{
'script_enabled':
{
'label': 'Enable/Disable the script',
'type': 'checkbox',
'default': true
},
'auth_username':
{
'label': 'Username',
'type': 'textbox'
},
'auth_oauth':
{
'label': 'Oauth (required for IRC connection to chat!)<br>Can be generated here: https://twitchapps.com/tmi/',
'type': 'textbox'
},
'restart_timer': {
'label': 'Show approx stream restart timer for voucher redemptions<br>Function made by zosky <3',
'type': 'checkbox',
'default': true
},
'voucher_buttons': {
'label': 'Voucher redemption buttons',
'type': 'checkbox',
'default': true
},
'buttons_general':
{
'label': 'General buttons',
'type': 'checkbox',
'default': true
},
'buttons_trivia':
{
'label': 'Trivia buttons',
'type': 'checkbox',
'default': true
},
'showdown_buttons': {
'label': 'Showdown buttons',
'type': 'checkbox',
'default': true
},
'bypass_shadowban': {
'label': 'Prevent Shadowban:<br>Enable this only, if you get shadowbanned after a couple of commands.<br>(Shadowban is when your messages are temporarily not appear)',
'type': 'checkbox',
'default': false
},
},
'events': {
'save': () => {location.reload()},
},
'frame': frame,
});
}
async function generate_voucher_buttons() {
insert_voucher_buttons(
generate_voucher_button("1,000 Clams Voucher", 5000, "+1k Clams") +
generate_voucher_button("2,000 Clams Voucher", 10000, "+2k Clams")
);
}
function generate_command_buttons() {
let buttongroups = "";
if(GM_config.get("buttons_general"))
buttongroups += `${btngrp_label("General")}
<div class="k-buttongroup">
${btngrp_button("hitsquad", "Hitsquad")}
${btngrp_button("strikes", "Strikes")}
${btngrp_button("coderaid", "Coderaid")}
</div>`;
if(GM_config.get("buttons_trivia"))
buttongroups += `${btngrp_label("Trivia")}
<div class="k-buttongroup">
${btngrp_button("answer1", "1")}
${btngrp_button("answer2", "2")}
${btngrp_button("answer3", "3")}
${btngrp_button("answer4", "4")}
${btngrp_button("triviapoints", "Points")}
</div>`;
if(GM_config.get("showdown_buttons")) {
// Selection
buttongroups += `${btngrp_label("Showdown")}
<div class="k-buttongroup">
${btngrp_button("wizard", "Wizard")}
${btngrp_button("knight", "Knight")}
${btngrp_button("cleric", "Cleric")}
${btngrp_button("experience", "Experience")}
</div>`;
// Labels to show roles
buttongroups += `<div class="k-labelgroup">
${lblgrp_label("wizard", "Wizard")}
${lblgrp_label("knight", "Knight")}
${lblgrp_label("cleric", "Cleric")}
${lblgrp_label("close", "Close")}
</div>`;
// Wizard
buttongroups += `<div class="k-buttongroup k-role hidden" data-role="wizard">
${btngrp_button("attack", "Attack", "targetbutton")}
${btngrp_button("flames", "Flames")}
${btngrp_button("shield", "Shield")}
${btngrp_button("moan", "Moan")}
</div>`;
// Knight
buttongroups += `<div class="k-buttongroup k-role hidden" data-role="knight">
${btngrp_button("attack", "Attack", "targetbutton")}
${btngrp_button("frenzy", "Frenzy")}
${btngrp_button("rally", "Rally")}
${btngrp_button("moan", "Moan")}
</div>`;
// Cleric
buttongroups += `<div class="k-buttongroup k-role hidden" data-role="cleric">
${btngrp_button("attack", "Attack", "targetbutton")}
${btngrp_button("divine", "Divine", "targetbutton")}
${btngrp_button("heal", "Heal")}
${btngrp_button("moan", "Moan")}
</div>`;
}
buttongroups += `</div>
<div id="targets" class="k-buttongroups hidden" data-action="">
<label class="k-buttongroup-label targets">Targets</label>
<div class="k-buttongroup">
${btngrp_button("1", "1")}
${btngrp_button("2", "2")}
${btngrp_button("3", "3")}
${btngrp_button("4", "4")}
${btngrp_button("5", "5")}
<button class="closebutton">Close</button>
</div></div>`;
insert_command_button(buttongroups);
}
// Additional functions
function show_role(event) {
let roles = document.querySelectorAll(".k-role");
roles.forEach(el => {
if(el.getAttribute("data-role") === event.target.getAttribute("data-role"))
el.classList.remove("hidden")
else
el.classList.add("hidden")
});
}
function zoskys_restart_timer() { // Thanks to zosky for this great function!
setInterval(()=>{
// get the current length
let t = document.querySelector('.live-time').textContent.split(':').map(n=>parseInt(n,10))
// parse & calc
let seconds = (t[0]*3600) + t[1]*60 + t[2]
let maxStreamTime = 172800
let timeLeft = maxStreamTime - seconds
let h = Math.floor(timeLeft / 3600)
let m = Math.floor((timeLeft - (h * 3600)) / 60)
let s = timeLeft - (h * 3600) - (m * 60)
// format
if (h < 10) h = "0"+h
if (m < 10) m = "0"+m
if (s < 10) s = "0"+s
let tLeftString = `${h}:${m}:${s}`
// add to page
const newNode = document.createElement("div")
const textNode = document.createTextNode(`Approx ${tLeftString} till stream restart for vouchers`)
newNode.appendChild(textNode)
newNode.id = 'timeLeft'
newNode.style['width'] = '100%'
newNode.style['text-align'] = 'center'
newNode.style['font-size'] = 'x-large'
newNode.style['background'] = 'purple'
const mastHead = document.querySelectorAll("section > div")[0]
try { document.getElementById('timeLeft').remove() } catch {console.log('nodeNotPresentYet') }
mastHead.insertBefore(newNode, mastHead.children[0])
}, 1000 )
}
@Kurotaku-sama
Copy link
Author

after 3 uses the script stopped working, buttons are not pressed

You need to wait a couple of seconds before you send the same command multiple times or commands to fast, otherwise twitch prevents spam in the IRC Chat. I've already integrated a bypass into the script that generate a custom id for the commands, to prevent the anti-spam to occur, but GodFather told me to remove this feature.

still doesn't work :(

Sry than i cant rly help you bcs I can't reproduce it, what you could try is in line 188:
sendMessageToTwitchChat(suffix + cmd); // + ' - ' + makeid(5));
turn it into this:
sendMessageToTwitchChat(suffix + cmd + ' - ' + makeid(5));

Tell me if it worked than please, if it works I will make this as an separate option in the settings.

@MAX1MDEV
Copy link

MAX1MDEV commented May 6, 2024

two minute please

@MAX1MDEV
Copy link

MAX1MDEV commented May 6, 2024

after 3 uses the script stopped working, buttons are not pressed

You need to wait a couple of seconds before you send the same command multiple times or commands to fast, otherwise twitch prevents spam in the IRC Chat. I've already integrated a bypass into the script that generate a custom id for the commands, to prevent the anti-spam to occur, but GodFather told me to remove this feature.

still doesn't work :(

Sry than i cant rly help you bcs I can't reproduce it, what you could try is in line 188: sendMessageToTwitchChat(suffix + cmd); // + ' - ' + makeid(5)); turn it into this: sendMessageToTwitchChat(suffix + cmd + ' - ' + makeid(5));

Tell me if it worked than please, if it works I will make this as an separate option in the settings.

now he's sending messages like this: !hitsquad - slqyh

@Kurotaku-sama
Copy link
Author

Kurotaku-sama commented May 6, 2024

Yea that is a feature I integrated but GF wanted me to disable it.
The purpose of the code behind is that you dont send every time the same message so you don't get shadow banned for a specific time.
So tell me if this works now without any issues, than I will update the script to make this an optional feature in the Settings.

@MAX1MDEV
Copy link

MAX1MDEV commented May 6, 2024

Yea that is a feature I integrated but GF wanted me to disable it. The purpose of the code behind is that you dont send every time the same message so you don't get shadow banned for a specific time. So tell me if this works now without any issues, than I will update the script to make this an optional feature in the Settings.

yes, now always ok, ty <3

@Kurotaku-sama
Copy link
Author

Yea that is a feature I integrated but GF wanted me to disable it. The purpose of the code behind is that you dont send every time the same message so you don't get shadow banned for a specific time. So tell me if this works now without any issues, than I will update the script to make this an optional feature in the Settings.

yes, now always ok, ty <3

Okay I've updated now the script, in the settings of the script is now a new option to enable this shadowban bypass, since I never know when the addons are updating the scripts I recommend doing it manual for now .... I also was shadowbanned the whole day somehow.

@ruzzen
Copy link

ruzzen commented May 7, 2024

I've a trouble with sending commands, after pressing any button it adds "}" in the end, like "!hitsquad}"

@Kurotaku-sama
Copy link
Author

I've a trouble with sending commands, after pressing any button it adds "}" in the end, like "!hitsquad}"

Yea I fixed it a couple of hours ago right after I saw it, sorry for that.
Just reinstall to get the latest release instantly instead of waiting.
Sorry for the inconvenience

@MAX1MDEV
Copy link

MAX1MDEV commented May 8, 2024

work!!!

@MAX1MDEV
Copy link

MAX1MDEV commented May 8, 2024

always ok!!

@Kurotaku-sama
Copy link
Author

Kurotaku-sama commented May 8, 2024

work!!!

I will change sth in a couple of days, so the commands are upper and lower case shufled instead of an ID, if you still get shadowbanned for that tell me on Discord than please. (Name is just Kurotaku there)

@MAX1MDEV
Copy link

i add you, but check your code tomorrow (i'm busy)

@Kurotaku-sama
Copy link
Author

i add you, but check your code tomorrow (i'm busy)

Write me your username or write me a PM instead of adding me, recently I get so extremly much random friendinvites that I had to disable friend requests.

@Kurotaku-sama
Copy link
Author

I am really sorry somehow the auto update for all my userscripts didn't worked for quiet a while now.
Everyone who is using any of my userscripts must reinstall the userscripts, I fixed them all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment