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
korwynkim Offline
cat
16 Posts:
 
#2
08-23-2018, 10:08 PM
What commands do you have planned for the future? I'm not sure how much a bot can help with making or listening to music. Maybe some quick references for scales and chords, motif generation etc?


Trophy: https://imgur.com/a/4B0juxZ
  • x1
    • x1
    • Frank
Reply
Eandrew Offline
A man that can do both
98 Posts:
   
#3
08-23-2018, 10:10 PM
Maybe you could add a command that selects and displays a sequence from the profile of the person who uses the command, based on how many plays or notes it has, or just randomly. That would be lit


Check my OS Music, Soundcloud, or MIDI Art Smile
  • x1
    • x1
    • Frank
Reply
Frank Offline
Grey Hat Script Kiddie who can Compose Music
388 Posts:
 
#4
08-24-2018, 04:34 PM (This post was last modified: 08-24-2018, 05:08 PM by Frank.)
Both suggestions so far are surprisingly applicable and amazing.
Current changelog:
Added Eandrew's suggestion.
Code:
// ==UserScript==
// @name         Frank's Chatbot
// @namespace    http://tampermonkey.net/
// @version      0.3
// @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 [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')
                })
            }
        }),
        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
Reply
Frank Offline
Grey Hat Script Kiddie who can Compose Music
388 Posts:
 
#5
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
Reply
Jacob_ Offline
Administrator
343 Posts:
 
#6
08-24-2018, 07:45 PM
Now use a neural network, and train it on the chat logs so you can generate entire conversations! http://karpathy.github.io/2015/05/21/rnn-effectiveness/


Reply
whathappendtous Offline
good boy
1 Posts:
 
#7
12-08-2019, 12:22 AM
how do you use this?


Reply



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