Guest User

Untitled

a guest
Dec 11th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var debug = process.argv[3] || true;
  2.  
  3. var config = {
  4.     channels: ["#tomcosm"],
  5.     server: "irc.twitch.tv",
  6.     username: "ambitron",
  7.     nick: "ambitron",
  8.     password: "oauth:##################################",
  9.     sasl: true
  10. };
  11.  
  12. // Get the lib
  13. var irc = require("irc");
  14.  
  15. // Create the bot name
  16. var bot = new irc.Client(config.server, config.nick, config);
  17.  
  18. // var io = require('socket.io-client');
  19. var osc = require('osc-min');
  20. var dgram = require('dgram');
  21.  
  22. var udpDest = "127.0.0.1";
  23. var udpPort = process.argv[2] || 10000;
  24.  
  25. // var socket = io.connect("#####");
  26.  
  27. // var udpClient = dgram.createSocket("udp4");
  28.  
  29. // socket.on('action', outputHandler);
  30.  
  31. /* function outputHandler(data) {
  32.   oscData =  { oscType: "message",
  33.                address: "/web",
  34.                args: data.action };
  35.   oscBuffer = osc.toBuffer(oscData);
  36.   console.log("sending OSC UDP:");
  37.   console.dir(oscData);
  38.   udpClient.send(oscBuffer, 0, oscBuffer.length, udpPort, udpDest);
  39. }
  40. */
  41. function chatOutputHandler(data) {
  42.   oscData =  { oscType: "message",
  43.                address: "/chat/",
  44.                args: data.action };
  45.   oscBuffer = osc.toBuffer(oscData);
  46.   console.log("sending OSC UDP:");
  47.   console.dir(oscData);
  48.   udpClient.send(oscBuffer, 0, oscBuffer.length, 7405, udpDest);
  49. }
  50.  
  51. function udpResultHandler() {
  52. }
  53.  
  54. bot.addListener("message", function(from, to, text, message) {
  55.   chatOutputHandler({action: from + " " + text});
  56. });
  57.  
  58. if(debug) {
  59.   var udpServer = dgram.createSocket("udp4");
  60.   udpServer.bind({address: "127.0.0.1", port: 7403, exclusive: true});
  61.   udpServer.on("message", function(udpMessage, remoteInfo) {
  62.     console.log("OSC UDP received:");
  63.     console.dir(osc.fromBuffer(udpMessage));
  64.     udpMessage = osc.fromBuffer(udpMessage);
  65.     if(udpMessage.address === '/irc/' && udpMessage.args[0].type === "string") bot.say(config.channels[0], udpMessage.args.map(function(arg) { return arg.value }).join(" "));
  66.   });
  67. }
Add Comment
Please, Sign In to add comment