Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const admins = ["katiserie"]; // include your realUsername in the list and exclude any unwanted admins
- var started = false;
- var savedPeople = {};
- function randint(min,max) {
- return Math.round(Math.random()*(max-min))+min;
- }
- function handleBal(name, length, silent) {
- if(silent){
- console.log(`${name} has ${length}H in their bank account.`);
- } else {
- sendMsg(`${name} has ${length}H in their bank account.`);
- }
- if (!savedPeople[name]) savedPeople[name] = length;
- }
- function sendMsg(msg) {
- if (started) {
- api_chat_send(msg, {nick: "Brisbane (!help)", color: "#E4B3FF"});
- } else {
- console.log(`There was an attempt to send "${msg}" while the bot was offline`);
- }
- }
- function balMod(user,amount) {
- if (started) {
- savedPeople[user] = savedPeople[user] + amount;
- console.log(`Script added ${amount} to ${user}'s bank account`)
- }
- }
- function safeParseInt(int) {
- let parsedInt = parseInt(int);
- if (parsedInt != NaN) {
- return parsedInt;
- } else {
- console.error("THAT IS NOT WHERE A STRING GOES YOU IDIOT")
- }
- }
- w.on("chat", function (data) {
- if (data.id == 0) return;
- var person = data.realUsername || data.id;
- var args = data.message.split(" ");
- var personName = args[1];
- var personLength = savedPeople[personName];
- if (!savedPeople[person]) {
- var bal = 100;
- handleBal(person, bal, true);
- }
- switch (args[0].toLowerCase()) {
- case "!bal":
- if (personName == null) {
- if (data.realUsername) {
- handleBal(data.realUsername, savedPeople[data.realUsername], false);
- } else {
- handleBal(data.id, savedPeople[data.id], false);
- }
- } else {
- if (!personLength) return sendMsg("Nobody exists with that username or ID.");
- handleBal(personName, personLength, false);
- }
- break;
- case "!donate":
- let cashAmt = safeParseInt(args[2])
- let negCashAmt = -cashAmt
- if (personName == null) {
- sendMsg("You must specify a person to donate to.")
- } else if (args[2] == null) {
- sendMsg("You must specify an amount to donate.")
- } else if (personName == data.realUsername || personName == data.id) {
- sendMsg("You cannot donate to yourself.")
- } else if (safeParseInt(cashAmt) < 0) {
- sendMsg("You cannot donate a negative amount of money to a person.")
- } else if (safeParseInt(cashAmt) > safeParseInt(personLength)) {
- sendMsg("You cannot donate more than you have in your bank account.")
- } else {
- balMod(person, negCashAmt);
- balMod(personName, cashAmt);
- sendMsg(`You donated ${args[2]} to ${personName}`)
- }
- break;
- case "!cf":
- let betAmt = safeParseInt(personName);
- if (betAmt < 0) {
- sendMsg("You cannot coin flip a negative amount of money.")
- } else if (betAmt > safeParseInt(personLength)) {
- sendMsg("You cannot coin flip more than you have in your bank account.")
- } else {
- let rand = Math.random();
- if (rand >= 0.5) {
- sendMsg(`You won the coinflip and recieved ${personName}H.`)
- balMod(person, betAmt);
- } else {
- sendMsg(`You lost the coinflip and lost ${personName}H.`)
- balMod(person, -betAmt);
- }
- }
- break;
- case "!help":
- sendMsg("Commands: !help, !bal, !donate, !cf");
- break;
- }
- if (args[0].toLowerCase() == "!start" && admins.indexOf(data.realUsername) != -1) {
- if(started) {
- sendMsg("Admin has stopped the bot.")
- started = false;
- } else {
- started = true;
- sendMsg("Admin has started the bot.")
- }
- }
- });
- console.log("Started bot.");
Advertisement