Execute irc action on computer - linux

Just as the title says, I want a command be done when a certain word is said in my irc channel.
Ex: If someone types "Hey!" in the channel, the server performs an action like restarting an services.
The channel is private and only I will be getting access to it.
The purpose of it will be that if I send a command from my office that I want to restart Apache (example).
Then I'll type apacherst, the irc sends the command to my server and restarts apache.
Any idea?
Thanks!
/Phew

Check out a program called Hubot. It has a plug-in mechanism to let make your chat server extensible. It supports IRC and many other protocols.

Related

Starting and stopping a node script from the web

I have a node script I'm working on that connects to an IRC channel for twitch.tv and responds to commands, as well as moderates chat lines that are being sent by other users connected.
Currently I open a terminal to the file location and run node app.js to start the IRC connection. But this runs on my mac and I use my PC to play games and watch the chat, so I have to have the Mac next to me to start and stop the IRC chat client app.
I want to move this to a web server where I can log in and start or stop the chat client app from the website, so I don't have to have the Mac next to me all the time.
What would be the best way to go about this?
If you want to see the script I'm working with you can find it here
https://github.com/Jordan4jc/super-fly-twitch-bot
You could create an HTTP server and listen on a port (if you don't mind overkill, express.js could make things easier for you). This server would contain configurations for the URL, authentication, etc. Within the callback that you provide to a URL path, you could close the IRC channels, database connections, and call process.exit(0) once you're confident that you've done everything necessary and you're sure it's what you want.
You can use socket.io as a way to send signals in real time to the application.

Using PubNub, is Unsubscribe a dual use command for Publish and Subscribe?

Yes, I know it seems like a simple question but I just recently started using PubNub and I am confused on how to disconnect from a channel. I think the command to use is "Unsubscribe" and my misunderstanding relates to the dual use of the word.
Logically, I understand that once you initialize PubNub and publish a message a separate process can subscribe to the establish channel. When it's done it unsubscribes. Got it!
Now we want to completely disconnect from PubNub. That is end the channel.
Do I use the command "Unsubscribe" to do this? I guess I am logically looking for an "End" or "Disconnect" command and not an "Unsubscribe" command because it did not subscribe to the channel, it established the channel. I know it seems petty but until I understand this it's difficult to move forward. So is this a dual use command?
Thanks
You are on the right track here. Depending on the client platform in question, an unsubscribe resulting in an empty channel list will completely disconnect you.
On the more sophisticated clients, advanced/smart frameworks, there are the API calls of un/subscribe (which as you described subs /unsubs you to a specific channel), and separately, the public and/or private method calls defining/detecting being "connected" or "online".
For example, iOS has specific connect and disconnect calls, separate from subscribe/unsubscribe calls. On JS, there is no explicit connect/disconnect, but regardless if you are subbed or not to an active channel list, there may be background "pings/heartbeats" being made to the PN cloud to detect connectivity/online/offline state.
If you give more info on the client platform and version you are on, we can give you more info on how to completely sever all connects to the PN cloud and achieve a "complete disconnect".
geremy

How do I run a node IRC bot?

I'd like to run this IRC Eliza bot but I lack some fundamental understanding of how to do it.
https://github.com/isaacs/node-eliza
I don't know anything about IRC or how to connect to them. Could someone explain how I connect to this bot? Do I need to host it remotely? Is there a way to run an IRC client locally and connect to it locally? Currently the program just runs without error but does nothing.
I understand node.js, but I seem to missing some fundamentals in understanding IRC on how to get an IRC bot running.
The readme gives me code that executes but doesn't do anything, quoted below:
Usage
var Eliza = require('eliza/irc.js')
new Eliza({ server: 'irc.freenode.net'
, nick: 'Eliza'
, channels: ['##turtles']
, userName: 'eliza'
, realName: 'eliza' })
IRC is the a global chat system, comprised of many individual hosts, all (eventually) linked. You usually don't run a part of IRC yourself, rather you use a client to connect to one of the hosts and thus gain access to the network and everyone on it.
An IRC bot is a piece of machine code that has its own logic (Eliza's logic, in your case), and is also connected to IRC and issues IRC commands that let it join channels, talk to other people/bots, received messages, etc.
In your case, you would simply need to run the bot, and let it know which IRC server to join (that the server parameter in new Eliza({...), what nick name to choose for itself, etc.
To run the bot just run node, in any environment (your home PC? hosting?) with the contents of the sample file.

A way to transfer IRC chatter/pm to gtalk

I'd like to know if some sort of bot/tool/service exists that would allow people on (regular) IRC chat to me on gtalk
so: irc user X sends a pm to MyBot (f.e.); that pm forwards to me
a irc room to chat would also work fine (so everything said in channel #abc gets into my gtalk conversation with mybot#domain.com
hope I was clear enough for you to understand what I'm looking for and that anyone knows a way for me to solve it.
Thanks!
You can use PircBotX to create an IRC bot in Java yourself, and use pm events to send gtalk messages using any old Jabber library. A quick search finds me Smack.
I did something similar once, but I made two instances of PircBotX, one to connect to the IRC server, and another to connect to this special IRC server somewhere that was configured to automatically pass on messages to popular IM protocols. I can't seem to remember what that service was called, perhaps you'll have better luck.
Well, there's the hans-irc-gtalk bot which does something like that. People need to subscribe to the messages in order to get them from gtalk. Not sure how well supported the project is.

Sending and performing commands from node.js to bash

I'm developing a sort of Flash Operator Pannel for Asterisk but, with Node.js and Socket.io instead of depending of Flash.
I've polished the node server and the front end BUT I don't know how could I send events from Asterisk to node server and do things that will be sended over the socket.
Given the fact that we have a heavily tuned Asterisk to suit our company needs, connecting to the AMI nor the Asterisk socket will solve my problem because we aren't working with real extensions.
So, despite the Asterisk part, I want to know how could I send info to node through bash or curls or whatever
I thought about using curls to the server but this could cause that someone who knows the commands (pretty unlikely) could alter the application flow with unreal data.
EDIT: Rethinking about it, I would just want to be able to receive requests through the socket/server ??? and then be able to perform actions that will be emited through socket.io.
Is that even possible?
The answer really depends upon what specific data you are trying to get from Asterisk to Node. You're trying to replace the Flash Operator Panel, yet you don't have real extensions. I'm guessing that you are using Asterisk as an SBC/proxy of sorts.
If you truly want an event-driven approach, I suggest modifying your dialplan to reach out to Node whenever needed, with whatever data you want. This would most easily be achieved by calling an AGI script with some number of arguments (written in whatever language) that then connects to Node via an HTTP POST, socket, or other.
If you want a more passive approach, you could have Node stream-read the asterisk log files for data, or, as already suggested, connect to the Asterisk Manager Interface (AMI) and stream from there. Contrary to what has been stated previously, I don't consider this to be a very daunting task.
You want to open a socket from Node to Asterisk's AMI (asterisk manager interface). I never used Node, but I would imagine the code would look roughly like this:
var astman = new net.socket().connect(5038);//connect to port 5039 on localhost
astman.on('data', function(data) {
//do something with received data
});
One of the most well maintained ami libraries are FreePBX's php-astmanager. While it's written in php, it should give you a pretty good idea of what your need to do.
You could certainly set up your node.js program to listen on a socket for messages from Asterisk. But you'd have to roll your own connection management scheme, authentication scheme, message durability (possibly), etc.
Alternatively -- and especially if there is the node server and asterisk server are not on the same machine -- you could use a message queue program like RabbitMQ. That takes care of a lot of the important details involved in interprocess communications. It's pretty easy, too. On the node side, check out https://github.com/postwait/node-amqp
I've never used Asterisk but running command line programs can be done with the child_process module.
http://nodejs.org/docs/latest/api/child_processes.html

Resources