Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This script may give errors if your browser is old, if you need a good & updated browser use Firefox!
- // Changelog:
- // Changed in v0.2.2: No longer requires TM
- // Changed in v0.2.1: Added support for /tell'ed commands, added isTelled arg
- // ==UserScript==
- // @name OWOP Chatbot Base
- // @version 0.2.2
- // @description A base for making an OWOP chatbot
- // @author SuperOP535
- // @match *.ourworldofpixels.com/*
- // @match *.wire.ddns.net:9001/*
- // @grant none
- // ==/UserScript==
- (function() {
- var bot = {
- enabled: false, // change to true for auto-enable
- prefix: '!'
- };
- const commands = {
- // command name may not have spaces
- // id will be the rank if there is no id, nick will be empty if /tell was used
- help: (args, msg, nick, id, isTelled) => {
- OWOP.chat.send('Commands: ' + Object.keys(commands).sort().join(', '));
- },
- 'some-command': (args, msg, nick, id, isTelled) => {
- OWOP.chat.send('Hello, person with ' + (isNaN(+id) ? 'rank' : 'id') + ' ' + id + (nick ? ' and nick ' + nick : ''));
- }
- };
- function addBtn() {
- if(!bot.enabled) {
- const btn = document.createElement('button');
- btn.innerHTML = 'Enable bot';
- btn.onclick = function(){btn.style.display='none';bot.enabled=true;};
- document.getElementById('chat').appendChild(btn);
- }
- OWOP.chat.recvModifier = (data) => {
- if(typeof data != 'string' || !bot.enabled) return data;
- const parsed = data.match(/(-> )?\[?\(?(\d+|.)\)?\]? ?>? ?(.*): \u200B?(.*)/);
- if(!parsed) return;
- const [tell, id, nick, msg] = parsed.slice(1);
- const isTelled = tell == '-> ';
- var args = msg.split(' ');
- if(args[0].slice(0,1) != bot.prefix) return data;
- const cmd = args.shift().slice(1);
- if(commands.hasOwnProperty(cmd)) commands[cmd](args, msg, isTelled ? '' : nick, id, isTelled);
- return data;
- };
- }
- window.addEventListener('load', addBtn);
- if(typeof OWOP != 'undefined') addBtn();
- })();
Add Comment
Please, Sign In to add comment