Node.js, Steam & IRC relay bot.

So, I was poking about the internet for something fun and interesting to do when I came upon something that I was planning to write myself, but before I ever do that I always look to see if someone else has already done it. Why duplicate effort if you’re just goofing around.  If I was into learning, of course I’d take a crack at it on my own, but I just wanted to find something and get it running.  What I found was this: https://github.com/seishun/irc-steam-relay

It’s pretty simple really, using node.js establish a connection to an IRC channel, and a connection to Steam Chat, and then relay the messages.  The implementation and documentation of this particular project left a bit to be desired however and initially I couldn’t figure out how the heck to get it working.

First things obviously, you need to have Node.js – setting that up is outside the scope of this post so I’m going to skip that bit.

With NPM installed it was very easy to setup irc-steam-relay with:

npm install git://github.com/seishun/irc-steam-relay.git

I set it up in a folder by itself, and the NPM install installed the node-modules directory and nothing more. People who aren’t familiar with node might not know the next step and the documentation isn’t very helpful so here is step by step from this point.

Create a new file, I usually name it “app.js” and paste in the details for setup found on the GitHub page..  here is my example.

var relay = require(‘irc-steam-relay’);
relay({
username: ‘myusername’,
password: ‘mypassword’,
/*authCode: ‘SOMECODE’,*/
chatroom: ‘chatroom GID’,
server: ‘irc.esper.net’,
port: ‘6667’,
nick: ‘myNick’,
channel: ‘#channel’,

msgFormat: ‘<%s> %s’,
msgFormatGame: ‘<%s> %s’,
emoteFormat: ‘<%s> %s’,
emoteFormatGame: ‘<%s> %s’
});

Notice the PORT field.. this isn’t in the README I sort of just felt that one out after having problems connecting to IRC initially.

Connecting to Steam was an even bigger issue, I created a new steam account since I didn’t want to tie up my personal one.. turns out, you can’t initialize a chat without having purchased something. Not even free game, gifted game or even family account. That account must OWN a game, otherwise you would get this.

This must be Steam’s cute way to get you to buy games… actually, it’s to prevent spammers and nuisances, and I get it and I didn’t mind searching for an hour for the right game I wanted to buy which, was Amnesia: Dark Descent for $4.99.  That was last night, now today they release it in their Halloween Humble Bundle FTW seriously? What are the chances of that.  Anyway…

The AUTH code never really came into play for me, not sure why not but I never had to put one in. But if you do, you get it in your email.. put it in, connect once and then comment it out as it won’t be needed again. You can run the app on the command line with:  “node app.js” but this isn’t really sufficient for running something for any length of time and leaving it, so I set this up on my Virtual Host with a simple bash script using screen.

screen -dmS steam node app.js &

This way it runs in a screen process and I can access it with “screen -r steam” whenever I need to and close it gracefully.  That’s really all there is to it, a few tweaks and you’ve connected your steam chat channel to your IRC channel.  Feel free to come check out mine if it’s up and running the steam group is Pwn9, and the IRC channel is #pwn on esper.net

Just one more thing to take away from this, Node.js is totally awesome ain’t it?

 

2 thoughts on “Node.js, Steam & IRC relay bot.”

  1. I was wondering if you can help me with this build error. It has gotten me a bit confused. You have any ideas? I have the newest node, npm and node-gyp.

    The errors started around here:

    iconv.target.mk:118: recipe for target ‘Release/obj.target/iconv/src/binding.o’ failed
    make: *** [Release/obj.target/iconv/src/binding.o] Error 1
    make: Leaving directory ‘/home/zuberlan/node/node_modules/iconv/build’
    gyp ERR! build error
    gyp ERR! stack Error: `make` failed with exit code: 2
    gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
    gyp ERR! stack at ChildProcess.emit (events.js:310:20)
    gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    gyp ERR! System Linux 4.9.0-8-amd64
    gyp ERR! command “/usr/local/bin/node” “/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” “rebuild”
    gyp ERR! cwd /home/zuberlan/node/node_modules/iconv
    gyp ERR! node -v v12.16.3
    gyp ERR! node-gyp -v v5.1.0
    gyp ERR! not ok

    node-icu-charset-detector@0.2.0 install /home/zuberlan/node/node_modules/node-icu-charset-detector
    node-gyp rebuild

    make: Entering directory ‘/home/zuberlan/node/node_modules/node-icu-charset-detector/build’
    CXX(target) Release/obj.target/node-icu-charset-detector/node-icu-charset-detector.o
    ../node-icu-charset-detector.cpp:17:29: error: ‘Handle’ in namespace ‘v8’ does not name a template type
    RegisterClass(const v8::Handle target) {
    ^~~~~~
    ../node-icu-charset-detector.cpp:17:35: error: expected ‘,’ or ‘…’ before ‘<’token
    RegisterClass(const v8::Handle target) {
    ^
    ../node-icu-charset-detector.cpp:60:5: error: expected ‘;’ at end of member declaration
    FromBuffer(v8::Handle bufferObject) {
    ^~~~~~~~~~
    ../node-icu-charset-detector.cpp:60:26: error: expected ‘)’ before ‘<’ token
    FromBuffer(v8::Handle bufferObject) {
    ^
    ../node-icu-charset-detector.cpp: In static member function ‘static void CharsetMatch::RegisterClass(int)’:
    ../node-icu-charset-detector.cpp:33:9: error: ‘target’ was not declared in this scope
    target->Set(Nan::New(ClassName).ToLocalChecked(), constructorTemplate->GetFunction());
    ^~~~~~
    ../node-icu-charset-detector.cpp:33:92: error: no matching function for call to‘v8::FunctionTemplate::GetFunction()’
    >Set(Nan::New(ClassName).ToLocalChecked(), constructorTemplate->GetFunction());
    ^
    In file included from /home/zuberlan/.cache/node-gyp/12.16.3/include/node/node.h:67:0,
    from ../node-icu-charset-detector.cpp:1:
    /home/zuberlan/.cache/node-gyp/12.16.3/include/node/v8.h:6126:46: note: candidate: v8::MaybeLocal v8::FunctionTemplate::GetFunction(v8::Local)
    V8_WARN_UNUSED_RESULT MaybeLocal GetFunction(
    ^~~~~~~~~~~
    /home/zuberlan/.cache/node-gyp/12.16.3/include/node/v8.h:6126:46: note: candidate expects 1 argument, 0 provided
    ../node-icu-charset-detector.cpp: In static member function ‘static Nan::NAN_METHOD_RETURN_TYPE CharsetMatch::New(Nan::NAN_METHOD_ARGS_TYPE)’:
    ../node-icu-charset-detector.cpp:72:9: error: ‘Handle’ is not a member of ‘v8’
    v8::Handle buffer = info[0]->ToObject();
    ^~
    ../node-icu-charset-detector.cpp:72:30: error: expected primary-expression before ‘>’ token
    v8::Handle buffer = info[0]->ToObject();
    ^
    ../node-icu-charset-detector.cpp:72:32: error: ‘buffer’ was not declared in this scope
    v8::Handle buffer = info[0]->ToObject();
    ^~~~~~
    ../node-icu-charset-detector.cpp:72:59: error: no matching function for call to‘v8::Value::ToObject()’
    v8::Handle buffer = info[0]->ToObject();
    ^
    In file included from /home/zuberlan/.cache/node-gyp/12.16.3/include/node/node.h:67:0,
    from ../node-icu-charset-detector.cpp:1:
    /home/zuberlan/.cache/node-gyp/12.16.3/include/node/v8.h:2672:44: note: candidate: v8::MaybeLocal v8::Value::ToObject(v8::Local) const
    V8_WARN_UNUSED_RESULT MaybeLocal ToObject(
    ^~~~~~~~
    /home/zuberlan/.cache/node-gyp/12.16.3/include/node/v8.h:2672:44: note: candidate expects 1 argument, 0 provided
    In file included from /home/zuberlan/.cache/node-gyp/12.16.3/include/node/v8-internal.h:14:0,
    from /home/zuberlan/.cache/node-gyp/12.16.3/include/node/v8.h:27,
    from /home/zuberlan/.cache/node-gyp/12.16.3/include/node/node.h:67,
    from ../node-icu-charset-detector.cpp:1:
    /home/zuberlan/.cache/node-gyp/12.16.3/include/node/v8.h:2686:31: note: candidate: v8::Local v8::Value::ToObject(v8::Isolate*) const
    Local ToObject(Isolate* isolate) const);
    ^
    /home/zuberlan/.cache/node-gyp/12.16.3/include/node/v8config.h:328:3: note: in definition of macro ‘V8_DEPRECATED’
    declarator __attribute__((deprecated(message)))
    ^~~~~~~~~~
    /home/zuberlan/.cache/node-gyp/12.16.3/include/node/v8.h:2686:31: note: candidate expects 1 argument, 0 provided
    Local ToObject(Isolate* isolate) const);
    ^
    /home/zuberlan/.cache/node-gyp/12.16.3/include/node/v8config.h:328:3: note: in definition of macro ‘V8_DEPRECATED’
    declarator __attribute__((deprecated(message)))
    ^~~~~~~~~~
    ../node-icu-charset-detector.cpp:78:44: error: ‘CharsetMatch::FromBuffer’ cannot be used as a function
    CharsetMatch::FromBuffer(buffer)->Wrap(info.This()); // under GC
    ^
    ../node-icu-charset-detector.cpp: In function ‘void RegisterModule(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’:
    ../node-icu-charset-detector.cpp:125:39: error: no matching function for call to‘CharsetMatch::RegisterClass(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE&)’
    CharsetMatch::RegisterClass(target);
    ^
    ../node-icu-charset-detector.cpp:17:5: note: candidate: static void CharsetMatch::RegisterClass(int)
    RegisterClass(const v8::Handle target) {
    ^~~~~~~~~~~~~
    ../node-icu-charset-detector.cpp:17:5: note: no known conversion for argument1 from ‘Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE {aka v8::Local}’ toint’
    node-icu-charset-detector.target.mk:109: recipe for target ‘Release/obj.target/node-icu-charset-detector/node-icu-charset-detector.o’ failed
    make: *** [Release/obj.target/node-icu-charset-detector/node-icu-charset-detector.o] Error 1
    make: Leaving directory ‘/home/zuberlan/node/node_modules/node-icu-charset-detector/build’
    gyp ERR! build error
    gyp ERR! stack Error: `make` failed with exit code: 2
    gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
    gyp ERR! stack at ChildProcess.emit (events.js:310:20)
    gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    gyp ERR! System Linux 4.9.0-8-amd64
    gyp ERR! command “/usr/local/bin/node” “/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” “rebuild”
    gyp ERR! cwd /home/zuberlan/node/node_modules/node-icu-charset-detector
    gyp ERR! node -v v12.16.3
    gyp ERR! node-gyp -v v5.1.0
    gyp ERR! not ok
    npm WARN saveError ENOENT: no such file or directory, open ‘/home/zuberlan/node/package.json’
    npm WARN enoent ENOENT: no such file or directory, open ‘/home/zuberlan/node/package.json’
    npm WARN node No description
    npm WARN node No repository field.
    npm WARN node No README data
    npm WARN node No license field.
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: iconv@2.2.3 (node_modules/iconv):
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: iconv@2.2.3 install: `node-gyp rebuild`
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: node-icu-charset-detector@0.2.0(node_modules/node-icu-charset-detector):
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: node-icu-charset-detector@0.2.0install: `node-gyp rebuild`
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

    + discord.js@12.2.0
    added 15 packages from 17 contributors and audited 456 packages in 11.043s

    1 package is looking for funding
    run `npm fund` for details

    found 1 low severity vulnerability
    run `npm audit fix` to fix them, or `npm audit` for details

  2. Node-gyp build errors are a pain to resolve. Try clearing the NPM cache and also, it looks like the problem is specific to a dependency – “node-icu-charset-detector” – you might have to see if that either has an updated version or, lock it to an older version that is more compatible in the package-lock.json

Leave a Reply

Your email address will not be published. Required fields are marked *