Online Sequencer Make music online
  • Sequences
  • Members
  • Chat
  • Forum
  • Wiki

Existing user? Sign In Create account
Login at Online Sequencer Forums

Online Sequencer Forums › Online Sequencer › Online Sequencer Discussion
« Previous 1 … 51 52 53 54 55 … 79 Next »

Simple OS Chatbot

Thread tools
Simple OS Chatbot
Frank Offline
Grey Hat Script Kiddie who can Compose Music
388 Posts:
 
#1
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.
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')
})()
You can also comment suggestions for me or your own tweaks to my code.


Kim Wrote:##878337 + https://js-game.glitch.me + Doesnt take peopel serious if their has badly speling gramer puntuatin
Reply

Messages In This Thread
Simple OS Chatbot - by Frank - 08-23-2018, 10:03 PM
RE: Simple OS Chatbot - by korwynkim - 08-23-2018, 10:08 PM
RE: Simple OS Chatbot - by Eandrew - 08-23-2018, 10:10 PM
RE: Simple OS Chatbot - by Frank - 08-24-2018, 04:34 PM
RE: Simple OS Chatbot - by Frank - 08-24-2018, 06:39 PM
RE: Simple OS Chatbot - by Jacob_ - 08-24-2018, 07:45 PM
RE: Simple OS Chatbot - by whathappendtous - 12-08-2019, 12:22 AM



Users browsing this thread:   1 Guest(s)


  •  Return to Top
  •  Contact Us
  •   Home
  •  Lite mode
© Rush Crafted with ❤ by iAndrew
Powered By MyBB, © 2002-2025 MyBB Group.
Linear Mode
Threaded Mode
View a Printable Version
Subscribe to this thread
Add Poll to this thread
Send thread to a friend