08-23-2018, 10:03 PM
Want to make your own chatbot? Void already posted chatbot code, so I assume it is okay for me to post mine.
You can also comment suggestions for me or your own tweaks to my code.
Code:
// ==UserScript==
// @name Frank's Chatbot
// @namespace http://tampermonkey.net/
// @version 0.2
// @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', '!do me --> You are ...', function(command){
post('You are ' + lastUser)
}),
random: new Command('random', '!do random --> ##random (in key)', function(command){
$.get('https://onlinesequencer.net/ajax/random.php', function(r){
post('##'+r.slice(r.search(/="\/\d/)+3,r.search(/\d" o/)+1))
})
}),
stop: new Command('stop', '!do stop --> stops bot', function(command){
clearInterval(clearId);
post('Stopped.')
}),
help: new Command('help', '!do help | [command] --> gives desc. of [command]', function(command){
var helped = commands[command[1]]
if(typeof command[1] == 'undefined') post('!do [command] | [arg1] | [arg2] ... "!do help | help" for help on help. All Commands: ' + Object.keys(commands).join(', '))
else post(helped?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]]) commands[command[0]].code(command, lastUser)
else post('Invalid command. "!do 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. "!do 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