08-24-2018, 06:39 PM
0.4 - added markov chains! Copy and paste them for ideas!
Code:
// ==UserScript==
// @name Frank's Chatbot
// @namespace http://tampermonkey.net/
// @version 0.4
// @description try to take over the world! maybe some musical stuff, too
// @author Frank
// @match https://onlinesequencer.net/chat/
// @grant none
// @run-at context-menu
// ==/UserScript==
(function() {
'use strict';
var botKeyword = '!do ';
var lastChatId;
var lastUser;
function Command(name, desc, code){
this.name=name;
this.desc=desc;
this.code=code;
this.toString = () => this.name
}
var commands = {
me: new Command('me', 'me --> You are ...', function(command){
post('You are ' + lastUser)
}),
random: new Command('random', 'random | [user id] --> ##random (in key / featured from [user id])', function(command){
if(typeof command[1] == 'undefined') {
$.get('https://onlinesequencer.net/ajax/random.php', function(r){
post('##'+r.slice(r.search(/="\/\d/)+3,r.search(/\d" o/)+1))
})
}
else {
$.get('https://onlinesequencer.net/ajax/random.php?user='+command[1], function(r){
var userArg = r.slice(r.search('More by'),r.search('</a>\n'));
if (userArg) post(userArg+': ##'+r.slice(r.search(/="\/\d/)+3,r.search(/\d" o/)+1))
else post('Unknown User Id')
})
}
}),
markov: new Command('markov', 'markov | [notes] --> generates a markov chain of [notes] notes which you can copy', function(command){
function txtNote(time, type) {
this.time = time;
this.type = type;
this.toString = () => time + ' ' + types[type] + ' 1 0;'
}
var notes = [new txtNote(0, 0), new txtNote(1, Math.floor(3 * Math.random()))];
var types = ['A5', 'D5', 'G5'];
var chainData = {
'00': [0.18, 0.6, 0.22],
'01': [0.5, 0.5, 0],
'02': [0.15, 0.75, 0.1],
'10': [0, 0, 1],
'11': [0.25, 0, 0.75],
'12': [0.9, 0.1, 0],
'20': [0.4, 0.4, 0.2],
'21': [0.5, 0.25, 0.25],
'22': [1, 0, 0]
}
var loop = 16;
if(!isNaN(parseInt(command[1]))) loop = parseInt(command[1]);
for (var time = 2; time < loop; time++) {
var past = notes.slice(-2).map(x => x.type).join('');
var rand = Math.random();
var type = 0;
while (rand >= chainData[past][type]) {
rand -= chainData[past][type];
type++
}
notes.push(new txtNote(time, type))
}
post('Online Sequencer:1:' + notes.join(''))
}),
stop: new Command('stop', 'stop --> stops bot', function(command){
clearInterval(clearId);
post('Stopped.')
}),
help: new Command('help', 'help | [command] --> gives desc. of [command]', function(command){
var helped = commands[command[1]]
if(typeof command[1] == 'undefined') post(botKeyword+'[command] | [arg1] | [arg2] ... "'+botKeyword+'help | help" for help on help. All Commands: ' + Object.keys(commands).join(', '))
else post(helped?botKeyword+helped.desc:'Unknown command. Cannot help.')
})
}
function tickBot() {
//get latest chat message
var lastChat = document.getElementById('chat_table').lastElementChild;
//check if it is new
if (lastChat.id == lastChatId) {
lastChatId = lastChat.id;
return
} else {
lastChatId = lastChat.id
}
//parse the chat message
lastUser = lastChat.children[0].children[0].innerText;
var lastMessage = lastChat.children[1].innerText;
//logic and send
if (lastMessage.substr(0, botKeyword.length) == botKeyword) {
var command = lastMessage.slice(botKeyword.length).split(' | ');
if(commands[command[0]]) setTimeout(commands[command[0]].code,0,command)
else post('Invalid command. "'+botKeyword+'help" for help.')
}
}
function post(message) {
var message1 = '' + message
if (message1.length > 256) return post('Tried to post; message too long.')
$.post('xmlhttp.php?action=ajaxchat_send', {
message: message1
})
}
if($.post) {post('Started. "'+botKeyword+'help" for help.');
var clearId = setInterval(tickBot, 500)
}
else console.log('Not in IFrame')
})()
Kim Wrote:##878337 + https://js-game.glitch.me + Doesnt take peopel serious if their has badly speling gramer puntuatin