Remotes API

Table of Contents

Remotes IRC Client, built in Remotes
Remotes Editor, built in Remotes
Remotes Code Editor, built in Remotes

Setup
Connecting with a token (recommended)
Console and console
Run code in your browser
Run GUI code in your browser, easily
Install Custom NPM Modules
Included NPM Modules
Instantiating your IRC Connection
Conditionals
States
Events
Commands
Examples (12)
 Hello world
 Console Echo server
 On join message
 Cryptocurrency price bot
 Console IRC Client
 Roulette rolling bot
 Magic 8 ball
 Website Downtime Monitor
 Resolve URLs to titles in chats
 Very Simple IRC Client
 Simple IRC Client with Windows
 Script provided at startup (IRC Client)
User Submitted Scripts

Connecting

Connecting with a token (recommended)


Console and console

It's helpful to see console.log/error output when you're coding. Use your browser's developer tools/console when connected to the remotes UI and all console.log/console.error will pipe there after including this snippet in your Remotes. You can also talk directly to Remotes through the console and receive messages from Remotes directly:

const Console = require("lib/Console");

Receiving from the browser:

Console.on('msg',(data)=>{
  // Do something
});

When the browser starts (e.g., on login or page reload):

Console.on('startup',()=>{
  // Do something
});

Sending to the browser console:

Console.send('msg');

Executing browser side code:

Console.code('code');

Executing browser side code to a specific device:

Console.codeTargeted(id,'code');

Executing browser side code to a specific device at startup once:

Console.codeTargeted(id,'code',true);

On the browser side, myId is your browser ID.


Sending to Remotes from the browser console:

send('msg');

Of course, the standard console.log and console.error will output in your browser's console window!

console.log("Hello, World!");
console.error("Oh no!");

Run code in your browser

You can use the Console class and send code to your browser with Console.code(). This code will run on your browser. Be very careful as this gives access to your browser to the script!

const Console = require("lib/Console");

let app = `
var element = $("<div id='box'>This is a box.</div>").appendTo(document.body);
element.css('z-index',100000);
element.css('position','absolute');
element.css('left','49%');
element.css('top','49%');
element.css('color','#000');
element.css('text-align','center');
element.css('background-color','#fff');
element.css('width','200px');
element.css('height','50px');
setTimeout(()=> {
  element.hide();
},5000);
`;

Console.on('startup',()=>{
  Console.code(app);
})


Run GUI Code in your browser, easily

Want to do GUI apps? Remotes makes it easy.

const Console = require("lib/Console");
const appWindow = require("lib/appWindow");
Console.on('startup',(id)=>{
  Console.codeTargeted(id,appWindow+`
    document.newWindow = new appWindow("newWindow",1,"New Window Title","");
  `,true);
})

It will look like this:



If you would like to make a window and write to it:

const appWindow = require("lib/appWindow");

Console.on('startup',(id)=>{
  Console.codeTargeted(id,appWindow+`
    document.msgs = new appWindow("messagewindow",2,"Message Window","");
    document.msgs.main.css('width','75%');
    document.msgs.main.css('height','50%');
    document.msgs_console_style = $('<style>.msgs_console{ text-align:left; font-size:14px; }</style>').appendTo(document.msgs.main);
    document.msgs_console = $('<div class="msgs_console"></div>').appendTo(document.msgs.main);
  `,true);

  writeToMsgsConsole("Hello, World!");
})
function writeToMsgsConsole(msg) {
  Console.code(`
    document.msgs_console.append("`+msg+`
"); document.msgs_console.scrollTop(document.msgs_console[0].scrollHeight); `); }

You can also add a fifth parameter of true or false whether or not you would like an exit button.


Install Custom NPM Modules

By clicking the 'box' in the remotes interface in the bottom left corner, you can install custom modules from the npm store.



Instantiating your IRC Connection

To instantiate your connection, simply place this line at the top of your code:
 const $ = new (require("lib/IRC"))();
 
You can also instantiate with a different nick and password:
 const $ = new (require("lib/IRC"))("nickname","token");
Finally, you can set the 'echo' to on so that the server will echo all of your messages back to yourself (optional). This is activated by default if you don't enter a nickname and token:
 const $ = new (require("lib/IRC"))("nickname","token",true);
 

The following is a reference list of code you can use. Additionally, Remotes are powered by JavaScript, so any JS is allowed, including jQuery and jQueryUI! If you're new to programming, there's a great tutorial you can find here. We also have a list of npm modules that are pre-installed to make things easier.

Below this you will find examples.

Conditionals

Conditionals return a boolean value, meaning either true or false.

States

Events

IRC Connection

Messages

Channels

Modes

Commands

IRC Connection

Messages

Channels

Modes


Examples

 Hello world
 Console Echo server
 On join message
 Cryptocurrency price bot
 Console IRC Client
 Roulette rolling bot
 Magic 8 ball
 Website Downtime Monitor
 Resolve URLs to titles in chats
 Very Simple IRC Client
 Simple IRC Client with Windows
 Script provided at startup (IRC Client)

Hello World

const Console = require("lib/Console");
console.log("Hello, World!");

Console Echo Server

const Console = require("lib/Console");

Console.on('msg',(msg)=>{
  console.log("From Console to Bot: "+msg);
  Console.send("From Bot to Console: "+msg);
});

On connect, joins #freenode and, upon join, sends a message to freenode -- a more advanced Hello World:

const $ = new (require("lib/IRC"))();

$.on('connected',(data) => {
  $.join("#freenode");
});
$.on('join',(nick,chan) => {
  if($.isEqual(nick,$.me()) && $.isEqual(chan,"#freenode"))
  $.msg("#freenode","Hello, World!");
});

A cryptocurrency price ticker:

const $ = new (require("lib/IRC"))();
const fetch = require('node-fetch');

$.on('privmsg', async (sender,target,msg) => {
  let words = msg.split(" ");
  if($.isEqual(target,"##cryptocurrency") && $.isEqual(words[0],".crypto")) {
    let res = await fetch("https://api.coincap.io/v2/assets?search=" + words[1]);
    let json = await res.json();

    let coin = json.data[0];
    let coinPrice = parseFloat(coin.priceUsd).toFixed(2);

    $.msg(target, `The price of ${coin.name} is ${coinPrice}`);
  }
});

Console IRC Client

const Console = require("lib/Console");
const $ = new (require("lib/IRC"))();

Console.on('msg',(msg)=>{
  $.write(msg);
});
$.on('privmsg',(nick,chan,msg)=> {
  console.log(`<${nick}:${chan}> ${msg}`) 
});

A roulette bot to see who has the highest roll between 1-100 (ops in channel only):

const $ = new (require("lib/IRC"))();

// Roulette: Roll for the highest #
// Change to your channel
let rollChannel="#cool";

// Global Variables
let rollIsRolling=false;
let rollParticipants=[];

$.on('privmsg',(sender,target,msg) => {
  if($.isEqual(target,rollChannel)) {
    if($.isOp(target,sender)){
      switch(msg.toLowerCase()){
        case "!roulette":
          if(!rollIsRolling)
            rollRoulette();
          else
            $.msg(rollChannel,"In a roulette right now.");
          break;
        case "!roll":
          if(rollIsRolling)
            rollRoll(sender);
          else
            $.msg(rollChannel,"We're not rolling.");
          break;
        default:
          break;
      }
    }
  }
});
function rollRoulette() {
  $.msg(rollChannel,"Starting roll, type !roll - you have 30 seconds");
  rollIsRolling=true;
  setTimeout(() => {
    rollIsRolling=false;
    $.msg(rollChannel,"Roulette ended.");
    highest=0;
    highest_person='';
    for ( var person in rollParticipants ) {
      if(rollParticipants[person]>highest) {
        highest=rollParticipants[person];
        highest_person=person;
      }
    }
    $.msg(rollChannel,"The winner is " + highest_person + " with a score of " + highest);
    rollParticipants=[];
  },30000);
}
function rollRoll(from){
  if(typeof rollParticipants[from] === 'undefined') {
    _roll = (Math.floor(Math.random() * 100)+1);
    $.msg(rollChannel,from+': '+_roll+' out of 100');
    rollParticipants[from]=_roll;
  }
  else
    $.msg(rollChannel,'You already rolled, '+from);
}

This code is for a Magic 8 Ball:

const $ = new (require("lib/IRC"))();

// Magic 8 Ball
let fortuneChannel="#cool";
let fortunes = [
    "Yes!",
    "No!",
    "Maybe!",
    "The outlook is not looking good.",
    "Absolutely.",
    "No way!",
    "Ask me again later.",
    "Is the sky blue?",
    "Does a cat meow?",
    "Does a dog bark?",
    "Of course!",
    "In your dreams.",
    "I don't know."
    ];
$.on('privmsg',(sender,target,msg)=> {
  let tokens=msg.split(" ");
  if($.isEqual(target,fortuneChannel) && $.isEqual(tokens[0],"!8ball") && tokens.length > 2 && msg.charAt(msg.length-1) == '?')
    $.msg(fortuneChannel,"The 8ball says: "+fortunes[Math.floor(Math.random() * fortunes.length)]);
});

A website downtime monitor. Messages your channel if a site is inaccessible/down:

const $ = new (require("lib/IRC"))();
const fetch = require('node-fetch');

const REPORT_CHANNEL = '#cool';
const HEARTRATE = 60;
const PATIENCE = 3;
const sites = [
  "https://google.com/",
  "https://nonameasdfasdf.com",
  "https://freenode.net",
  "https://eyearesee.com"
  ];

setInterval(async ()=>{ check(); },HEARTRATE*1000);

async function check() {
  for(var i=0;i < sites.length;i++) {
    try {
      let res = await fetch(sites[i],{timeout:PATIENCE*1000});
    } catch(e) {
      if(e.errno=="ENOTFOUND")
        $.msg(REPORT_CHANNEL,sites[i]+" is DOWN! (DNS Resolution)");
      else if(e.type=="request-timeout")
        $.msg(REPORT_CHANNEL,sites[i]+" is DOWN! (Request Timeout)");
      else
        $.msg(REPORT_CHANNEL,sites[i]+" is DOWN! ("+e.type+")");
    }
  }
}

Resolve URLs to titles in chats:

const $ = new (require("lib/IRC"))();
const fetch = require('node-fetch');

$.on("privmsg",async (sender,target,msg) => {
  if(target.substr(0,1)=='#' && !$.isEqual(sender,$.me())) {
    let url = msg.match(/(https?:\/\/[^\s]+)/ig);
    if (url && typeof url[0] === "string") {
      try {
        let res = await fetch(url[0]);
        let text = await res.text();
        let title = text.match(/<title>([^<]*)<\/title>/i);
        if(title && typeof title[1] === "string")
          $.msg(target, title[1] + " ["+url[0]+"]");
      } catch(e) { }
    }
  }
});

An IRC client (simple, doesn't track)!

const Console = require("lib/Console");
const $ = new (require("lib/IRC"))();

let app = `var style = $(\`<style>
#box {
  z-index:100000;
  position:absolute;
  left:0;
  top:0;
  color:#fff;
  text-align:center;
  background-color:#555;
  border:1px solid #000;
  width:500px;
  height:400px;
}
.title {
  width:100%;
  position:relative;
  top:0;
  height:24px;
  text-align:center;
  background-color:#222;
  color:#fff;
  font-weight:bold;
}
#chat {
  width:100%;
  position:relative;
  height:350px;
  font-size:0.6em;
  text-align:left;
  overflow:scroll;
}
.input_text {
  width:90%;
  position:relative;
  bottom:0;
  height:26px;
  color:#777;
  display:inline-block;
#input_submit {
  display:inline-block;
  width:5%;   
  font-size:0.6em;
}
</style>\`).prependTo(document.body);
var element = $("<div id='box' class='ui-widget-content'></div>").appendTo(document.body);
element.draggable();
var element_title = $("<div class='title'>Simple IRC Client</div>").appendTo(element);
var element_chat = $("<div id='chat'></div>").appendTo(element);
var element_form = $("<form id='irc_input'></form>").appendTo(element);
var element_input = $("<input class='input_text' type='text' id='input_text'>").appendTo(element_form);
var element_submit = $("<input type='submit' id='input_submit' value='Send'>").appendTo(element_form);

$('form#irc_input').submit((e)=> {
  let value = $('input#input_text').val();
  if(value.substr(0,5).toLowerCase()=="/msg ") {
    let tokens = value.split(" ");
    let chan = tokens[1];
    tokens.shift();
    tokens.shift();
    send("PRIVMSG "+chan+" :"+tokens.join(" "));
    $('div#chat').append("<"+"@/"+chan+"> "+tokens.join(" ")+"
"); $('input#input_text').val(''); e.preventDefault(); } }); `; $.on('action',(sender,target,msg)=>{ Console.code(` if($('div#chat')) { $('div#chat').append("* `+sender+`/`+target+` `+msg+`
"); $('div#chat').scrollTop($('div#chat')[0].scrollHeight - $('div#chat')[0].clientHeight); } `); }); $.on('privmsg',(sender,target,msg)=>{ Console.code(` if($('div#chat')) { $('div#chat').append("<`+sender+`/`+target+`> `+msg+`
"); $('div#chat').scrollTop($('div#chat')[0].scrollHeight - $('div#chat')[0].clientHeight); } `); }); Console.on('msg',(msg)=>{ $.write(msg); }); Console.on('startup',()=>{ Console.code(app); })

Another simple (doesn't track) IRC client with windows.

const Console = require("lib/Console");
const $ = new (require("lib/IRC"))();

let app = `var style = $(\`<style>
#box {
  z-index:100000;
  position:absolute;
  left:0;
  top:0;
  color:#fff;
  text-align:center;
  background-color:#555;
  border:1px solid #000;
  width:700px;
  height:400px;
}
.title {
  width:100%;
  position:relative;
  top:0;
  height:24px;
  text-align:center;
  background-color:#222;
  color:#fff;
  font-weight:bold;
}
#sidebar {
  position:absolute;
  width:20%;
  height:376px;
  left:0;
  overflow:scroll;
  text-align:left;
  top:24px;
}
  #sidebar .chatbutton {
    font-size:0.6em;
  }
    #sidebar .chatbutton:hover {
      cursor:pointer;
    }
#chat {
  width:80%;
  position:absolute;
  height:350px;
  left:20%;
}
.chatbox {
  width:100%;
  height:350px;
  font-size:0.6em;
  text-align:left;
  overflow:scroll;
  position:absolute;
  top:0;
  left:0;
  display:none;
}
.input_text {
  width:76.5%;
  position:absolute;
  bottom:0;
  left:20%;
  height:26px;
  color:#777;
}
#input_submit {
  position:absolute;
  right:0;   
  width:3.5%;
  height:26px;
  font-size:0.6em;
  bottom:0;
}
</style>\`).prependTo(document.body);
document.element = $("<div id='box' class='ui-widget-content'></div>").appendTo(document.body);
document.element.draggable();
document.element_title = $("<div class='title'>Simple IRC Client</div>").appendTo(document.element);
document.element_chat = $("<div id='chat'></div>").appendTo(document.element);
document.element_form = $("<form id='irc_input'></form>").appendTo(document.element);
document.element_input = $("<input class='input_text' type='text' id='input_text'>").appendTo(document.element_form);
document.element_submit = $("<input type='submit' id='input_submit' value='>'>").appendTo(document.element_form);
document.element_sidebar = $("<div id='sidebar'></div>").appendTo(document.element);
document.currentNick = "(self)";
$('form#irc_input').submit((e)=> {
  let value = $('input#input_text').val();
  if(value.substr(0,1)!="/") {
    send("PRIVMSG "+document.currentFoc+" :"+value);
    document.channel[document.currentFoc].append("<"+""+document.currentNick+"> "+value+"<br>");
  }
  else {
    let tokens = value.substr(1).split(" ");
    let _message;
    switch(tokens[0].toLowerCase()) {
      case "msg":
        let _chan = tokens[1];
        tokens.shift();
        tokens.shift();
        _message = tokens.join(" ").trim();
        send("PRIVMSG "+_chan+" :"+_message);
        document.handleMessage(document.currentNick,_chan,_message,"msg");
        break;
      case "me":
        tokens.shift();
        _message= tokens.join(" ").trim();
        send("PRIVMSG "+document.currentFoc+ " :"+String.fromCharCode(1)+"ACTION "+_message);
        document.handleMessage(document.currentNick,document.currentFoc,_message,"action");
        break;
    }
  }
  $('input#input_text').val('');
  e.preventDefault(); 

});
document.currentFoc = "";
document.channel=[];
document.button=[];
document.handleMessage = function(sender,target,msg,type) {
  if(target.substr(0,1)!='#' && sender!=="(self)") {
      target=sender;
  }
  if(!document.channel[target]) {
    document.channel[target]=$("<div class='chatbox' name='"+target+"'></div>").appendTo(document.element_chat);
    document.channel[target].hide();
    document.button[target]=$("<div class='chatbutton' name='"+target+"_button'>"+target+"</div>").appendTo(document.element_sidebar);
    document.button[target].data("channel",target);
    document.button[target].click(function() {
      $(this).css('color','white')
      let chanwin = document.channel[$(this).data("channel")];
      if(document.currentFoc.length>0) {
        document.channel[document.currentFoc].hide();
      }
      chanwin.show();
      document.currentFoc=$(this).data("channel");
    });
  }
  if(type=="msg")
    document.channel[target].append("<"+sender+"> "+msg+"<br>");
  else
    document.channel[target].append("* "+sender+" "+msg+"<br>");
  if(target!=document.currentFoc) {
    document.button[target].css('color','red')
  }
  if(document.currentFoc=="") {
    document.currentFoc=target;
    document.button[target].css('color','white')
    document.channel[target].show();
  }
};
`;

$.on('action',(sender,target,msg)=>{
   target=target.toLowerCase();
   Console.code(`
     document.handleMessage("`+sender+`","`+target+`","`+msg+`","action");
   `); 
});
$.on('privmsg',(sender,target,msg)=>{
   target=target.toLowerCase();
   Console.code(`
     document.handleMessage("`+sender+`","`+target+`","`+msg+`","msg");
   `); 
});
Console.on('msg',(msg)=>{
  $.write(msg);
});
Console.on('startup',(id)=>{
  Console.codeTargeted(id,app);
})


Here's the script that is provided at startup (e.g., the IRC client, etc.)

/*
** Welcome to Remotes by IRC.com
** Where your entire experience can be controlled by code.
**
** We have included an IRC client as an example, but you can code anything.
** Find more examples by clicking on the API ("?") link in the bottom left corner.
**
** If this is your first time, wait about 10 seconds and when the light next
** to your username in the bottom right corner turns green, reload the page
** and you will see the Remotes IRC Client, our flagship example Remotes script.
**
** Feel free to edit, improve or run something else altogether.  With Remotes,
** by IRC.com, you can do anything!
**
*/

/*
** The below code instantiates:
**   console - Allows you to write to your browser console (lib/console.js)
**   Console - Send messages and code to your browser (lib/console.js)
**   $       - IRC Connection (lib/irc.js)
**   Client  - Remotes IRC Client (lib/Client/IRC.js)
**   Editor  - Remotes Editor (lib/Editor)
**   CodeEditor  - Remotes Code Editor (lib/CodeEditor)
*/
const Console = require("lib/Console");
const $ = new (require("lib/IRC"))();
const Client = (require("lib/Client"))(Console,$);
const Editor = new (require("lib/Editor"))(Console);
const CodeEditor = new (require("lib/CodeEditor"))(Console);

/*
** Include your own scripts below.  Learn more by clicking on the API
** link ("?") in the bottom left corner.
**
** You can also add your own custon modules from npm.  Simply click on the
** modules area below (the box) and install!
*/


User Submitted Scripts