Skip to content

Instantly share code, notes, and snippets.

@delasy
Last active October 7, 2024 08:34
Show Gist options
  • Save delasy/7ef35c70cafe3c565949af6784a5b291 to your computer and use it in GitHub Desktop.
Save delasy/7ef35c70cafe3c565949af6784a5b291 to your computer and use it in GitHub Desktop.
Script that randomly applies promo codes for HamsterKombat
// insert hamster-kombat-playground-games-promo-keys-generator.js here
// with removed `async function main() {...}` and `main().catch(Logger.panic);`
const { CronJob } = require('cron');
const HK_TOKEN = '<api-token>';
async function applyPromo(promoCode) {
await fetch('https://api.hamsterkombatgame.io/clicker/apply-promo', {
method: 'POST',
headers: {
Authorization: `Bearer ${HK_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ promoCode }),
});
}
async function applyPromoCron(gameKey) {
const gp = new GamePromo();
for (let j = 0; j < 4; j++) {
const promoCode = await gp.getCode(gameKey);
await applyPromo(promoCode);
}
}
const jobs = [
{
schedule: '0 42 10 * * *',
command: async () => applyPromoCron('BIKE'),
},
{
schedule: '0 15 12 * * *',
command: async () => applyPromoCron('TRAIN'),
},
{
schedule: '0 31 14 * * *',
command: async () => applyPromoCron('CUBE'),
},
{
schedule: '0 21 16 * * *',
command: async () => applyPromoCron('CLONE'),
},
{
schedule: '0 36 18 * * *',
command: async () => applyPromoCron('MERGE'),
},
{
schedule: '0 12 20 * * *',
command: async () => applyPromoCron('TWERK'),
},
{
schedule: '0 21 22 * * *',
command: async () => applyPromoCron('POLY'),
},
];
jobs.forEach((job) => {
CronJob.from({
cronTime: job.schedule,
onTick: job.command,
start: true,
timeZone: 'utc',
});
});
const { CronJob } = require('cron');
const HK_TOKEN = '<api-token>';
function sync() {
const randomMinute = Math.floor(Math.random() * 60);
setTimeout(() => {
fetch('https://api.hamsterkombatgame.io/clicker/sync', {
method: 'POST',
headers: {
Authorization: `Bearer ${HK_TOKEN}`,
'Content-Type': 'application/json',
}
});
}, randomMinute * 60_000);
}
CronJob.from({
cronTime: '0 0 */2 * * *',
onTick: sync,
start: true,
timeZone: 'utc',
});
@delasy
Copy link
Author

delasy commented Sep 9, 2024

what do you mean by configuration? I have this sync js you provided running on the same internet connection

then you should be good

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