Skip to content

Instantly share code, notes, and snippets.

@nappa85
Last active September 5, 2018 07:24
Show Gist options
  • Save nappa85/dd48bc7be89c57eaf8ca85ff0290d90c to your computer and use it in GitHub Desktop.
Save nappa85/dd48bc7be89c57eaf8ca85ff0290d90c to your computer and use it in GitHub Desktop.
BiteTheBot hack
// ==UserScript==
// @include https://web.telegram.org/*
// ==/UserScript==
const url = "https://web.telegram.org/#/im?p=@bitethebot";
const action_timeout = 6000;
const min_timeout = 60000;
const max_timeout = 300000;
const start_timeout = 5000;
const max_timeout_delta = max_timeout - min_timeout;
const after_beer_timeout = 15000;
const after_win_timeout = 5400000;
const potato_polling = 1000;
var hack0 = function() {
if(window.location.href == url) {
//document.getElementsByClassName("composer_rich_textarea")[0].innerHTML = ":rocket: Extra";
//unsafeWindow.$(".im_submit").trigger("mousedown");
unsafeWindow.$("div.im_send_keyboard_wrap button:contains(Extra)").trigger("click");
beerTimeout = window.setTimeout(hack1, action_timeout);
}
else {
beerTimeout = window.setTimeout(hack0, action_timeout);
}
};
var hack1 = function() {
if(window.location.href == url) {
//document.getElementsByClassName("composer_rich_textarea")[0].innerHTML = ":beer: Beer";
//unsafeWindow.$(".im_submit").trigger("mousedown");
unsafeWindow.$("div.im_send_keyboard_wrap button:contains(Brewery)").trigger("click");
beerTimeout = window.setTimeout(hack2, action_timeout);
}
else {
beerTimeout = window.setTimeout(hack1, action_timeout);
}
};
var hack2 = function() {
if(window.location.href == url) {
unsafeWindow.$("div.im_send_keyboard_wrap button:contains(Single Beer)").trigger("click");
beerTimeout = window.setTimeout(hack3, action_timeout);
}
else {
beerTimeout = window.setTimeout(hack2, action_timeout);
}
};
var hack3 = function() {
if(window.location.href == url) {
unsafeWindow.$("div.im_message_keyboard button:contains(Yes)").trigger("click");
//wait a little longer to catch the "Congratulations!" message
beerTimeout = window.setTimeout(hack4, after_beer_timeout);
}
else {
beerTimeout = window.setTimeout(hack3, action_timeout);
}
};
var hack4 = function() {
if(window.location.href == url) {
//document.getElementsByClassName("composer_rich_textarea")[0].innerHTML = ":arrow_backward: Back";
//unsafeWindow.$(".im_submit").trigger("mousedown");
unsafeWindow.$("div.im_send_keyboard_wrap button:contains(Back)").trigger("click");
//retrieve messages after last beer
//var should_skip = unsafeWindow.$("div.im_message_text:contains(Beer)").last().parents("div.im_history_message_wrap").nextAll().find("div.im_message_text").each(function() {
//var text = unsafeWindow.$(this).innerHTML.trim();
//return (text == "Oh yeah, let me drink it...") || (text === "Wait wait, I can get one beer at time!") || (text === ":dizzy_face: You got me drunk!");
//});
var messages = unsafeWindow.$("div.im_message_text:contains(Beer)").last().parents("div.im_history_message_wrap").nextAll();
var should_skip = messages.find("div.im_message_text:contains(Oh yeah, let me drink it...)").length +
messages.find("div.im_message_text:contains(Wait wait, I can get one beer at time!):not(:contains(I'm still drinking))").length +
messages.find("div.im_message_text:contains(You got me drunk!)").length;
//if I won or got the bot drunk, wait an hour, else a random between 1 ad 5 minutes
beerTimeout = window.setTimeout(hack0, (should_skip > 0) ? after_win_timeout : Math.round(min_timeout + Math.random() * max_timeout_delta));
}
else {
beerTimeout = window.setTimeout(hack4, action_timeout);
}
};
var beerTimeout = window.setTimeout(hack0, start_timeout);
var potato0 = function() {
if(window.location.href == url) {
var potato = unsafeWindow.$("div.im_message_keyboard button:contains(Throw it)");
if(potato.length > 0) {
//stop beer timeouts
window.clearTimeout(beerTimeout);
potato.trigger("click");
window.setTimeout(potato1, 1);
}
else {
window.setTimeout(potato0, potato_polling);
}
}
else {
window.setTimeout(potato0, potato_polling);
}
};
var potato1 = function() {
if(window.location.href == url) {
//select first user inside the paginated list
var button = unsafeWindow.$("div.im_message_keyboard button:contains(>>)").last().parents("div.im_message_keyboard").find("button").first();
if(button.length > 0) {
button.trigger("click");
//restart beer timeouts
beerTimeout = window.setTimeout(hack0, start_timeout);
//keep it up with potato check
window.setTimeout(potato0, potato_polling);
}
else {
window.setTimeout(potato1, 1);
}
}
else {
window.setTimeout(potato1, potato_polling);
}
};
window.setTimeout(potato0, start_timeout);
@zoten
Copy link

zoten commented Aug 8, 2018

https://gist.github.com/zoten/a2c71d6629560f5ead965442804bc161 ho solo messo le costanti a inizio paggggina

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