commit ec290e067d69dd9e744f637be26f2cd5265f251c Author: henne Date: Sun Apr 24 22:05:56 2016 +0200 initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5760be5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..07e6e47 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/node_modules diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8e2ea8f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: node_js +node_js: + - "0.12" + - "0.10" + - "iojs" +sudo: false +cache: + directories: + - node_modules +notifications: + email: false diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..30deb8a --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,33 @@ +'use strict'; + +module.exports = function (grunt) { + + grunt.initConfig({ + mochaTest: { + test: { + options: { + reporter: 'spec', + require: 'coffee-script' + }, + src: ['test/**/*.coffee'] + } + }, + release: { + options: { + tagName: 'v<%= version %>', + commitMessage: 'Prepared to release <%= version %>.' + } + }, + watch: { + files: ['Gruntfile.js', 'src/**/*.coffee', 'test/**/*.coffee'], + tasks: ['test'] + } + }); + + // load all grunt tasks + require('matchdep').filterDev(['grunt-*', '!grunt-cli']).forEach(grunt.loadNpmTasks); + + grunt.registerTask('test', ['mochaTest']); + grunt.registerTask('test:watch', ['watch']); + grunt.registerTask('default', ['test']); +}; diff --git a/README.md b/README.md new file mode 100644 index 0000000..45d65c4 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# hubot-raumgirl-new + +ctdo raumgirl + +See [`src/raumgirl-new.coffee`](src/raumgirl-new.coffee) for full documentation. + +## Installation + +In hubot project repo, run: + +`npm install hubot-raumgirl-new --save` + +Then add **hubot-raumgirl-new** to your `external-scripts.json`: + +```json +[ + "hubot-raumgirl-new" +] +``` + +## Sample Interaction + +``` +user1>> hubot hello +hubot>> hello! +``` diff --git a/index.coffee b/index.coffee new file mode 100644 index 0000000..41c1e13 --- /dev/null +++ b/index.coffee @@ -0,0 +1,11 @@ +fs = require 'fs' +path = require 'path' + +module.exports = (robot, scripts) -> + scriptsPath = path.resolve(__dirname, 'src') + if fs.existsSync scriptsPath + for script in fs.readdirSync(scriptsPath).sort() + if scripts? and '*' not in scripts + robot.loadFile(scriptsPath, script) if script in scripts + else + robot.loadFile(scriptsPath, script) diff --git a/package.json b/package.json new file mode 100644 index 0000000..8301586 --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "hubot-raumgirl-new", + "description": "ctdo raumgirl", + "version": "0.0.0", + "author": "henne@ctdo.de", + "license": "MIT", + + "keywords": "hubot, hubot-scripts", + + "repository": { + "type": "git", + "url": "git://github.com/hubot-scripts/hubot-raumgirl-new.git" + }, + + "bugs": { + "url": "https://github.com/hubot-scripts/hubot-raumgirl-new/issues" + }, + + "dependencies": { + }, + + "peerDependencies": { + "hubot": "2.x" + }, + + "devDependencies": { + "chai": "^2.1.1", + "coffee-script": "1.6.3", + "grunt": "^0.4.5", + "grunt-cli": "^0.1.13", + "grunt-contrib-watch": "~0.6.1", + "grunt-mocha-test": "~0.12.7", + "grunt-release": "~0.11.0", + "hubot": "2.x", + "matchdep": "~0.3.0", + "mocha": "^2.1.0", + "sinon": "^1.13.0", + "sinon-chai": "^2.7.0" + }, + + "main": "index.coffee", + + "scripts": { + "test": "grunt test" + } +} diff --git a/script/bootstrap b/script/bootstrap new file mode 100755 index 0000000..4c5c66e --- /dev/null +++ b/script/bootstrap @@ -0,0 +1,18 @@ +#!/bin/bash + +# Make sure everything is development forever +export NODE_ENV=development + +# Load environment specific environment variables +if [ -f .env ]; then + source .env +fi + +if [ -f .env.${NODE_ENV} ]; then + source .env.${NODE_ENV} +fi + +npm install + +# Make sure coffee and mocha are on the path +export PATH="node_modules/.bin:$PATH" \ No newline at end of file diff --git a/script/test b/script/test new file mode 100755 index 0000000..e142362 --- /dev/null +++ b/script/test @@ -0,0 +1,6 @@ +#!/bin/bash + +# bootstrap environment +source script/bootstrap + +mocha --compilers coffee:coffee-script \ No newline at end of file diff --git a/src/ctdo.js b/src/ctdo.js new file mode 100644 index 0000000..aea018f --- /dev/null +++ b/src/ctdo.js @@ -0,0 +1,112 @@ +const net = require('net'); + +module.exports = function(robot) { + // old stuff + // lampel + function setLampel(r,ge,gr) { + var x = 0; + if(r) + x+=4; + if(ge) + x+=2; + if(gr) + x+=1; + var command = "io set port 2 0"+x+"\n"; + var client = net.createConnection({port: 2701, host: 'lampel.raum.ctdo.de'}, function() { + client.end(command); + }); + } + robot.hear(/^rot$/i, function(r) { + setLampel(1,0,0); + }); + robot.hear(/^gruen$/i, function(r) { + setLampel(0,0,1); + }); + robot.hear(/^gelb$/i, function(r) { + setLampel(0,1,0); + }); + robot.hear(/^(all|alle)$/i, function(r) { + setLampel(1,1,1); + }); + robot.hear(/^(rotgelb|gelbrot)$/i, function(r) { + setLampel(1,1,0); + }); + robot.hear(/^(gruengelb|gelbgruen)$/i, function(r) { + setLampel(0,1,1); + }); + robot.hear(/^(rotgruen|gruenrot)$/i, function(r) { + setLampel(1,0,1); + }); + // topic + robot.adapter.bot.addListener('topic', function(channel, topic) { + if(typeof(robot.brain.data.topics) !== 'Object') { + robot.brain.data.topics = {} + } + robot.brain.data.topics[channel] = topic + setTopic(topic); + }); + + function setTopic(currentTopic) { + robot.http("http://status.ctdo.de/api/simple/v2") + .header('Accept', 'application/json') + .get()(function(err, res, body) { + var data = JSON.parse(body); + var raum_offen = /(raum: |r: )(auf|offen|open)/ig; + var raum_zu = /(raum: |r: )(zu|geschlossen|closed)/ig + var currentState = data.state; + var newTopic = currentTopic; + if(currentTopic.match(raum_offen)) { + // wenn raum auf drinsteht + if(!data.state) { + newTopic = currentTopic.replace(raum_offen, 'Raum: zu'); + } + } else if(currentTopic.match(raum_zu)) { + // wenn raum zu drinsteht + if(data.state) { + newTopic = currentTopic.replace(raum_zu, 'Raum: auf'); + } + } else { + // wenn nix drinsteht + if(data.state) { + newTopic = "Raum: auf | " + currentTopic; + } else { + newTopic = "Raum: zu | " + currentTopic; + } + } + if(newTopic !== currentTopic) { + robot.brain.data.topics[process.env['HUBOT_IRC_ROOMS']] = newTopic; + robot.adapter.topic({room: process.env['HUBOT_IRC_ROOMS']}, newTopic); + } + }) + } + // topic interval + setInterval(function() { + setTopic(robot.brain.data.topics[process.env['HUBOT_IRC_ROOMS']]); + }, 5000); + // gem + var gem = false; + robot.respond(/gem$/i, function(r) { + if(gem) { + gem = false; + r.reply("Gem Deactivated"); + } else { + gem = true; + var c = Math.floor(Math.random() * 100) + 1; + if(c>99) { + r.reply('Mooooooooooooo!'); + } else { + r.reply("Gem Activated"); + } + } + }); + // new stuff + robot.respond(/status$/i, function(r) { + robot.http("http://status.ctdo.de/api/simple/v2") + .header('Accept', 'application/json') + .get()(function(err, res, body) { + var data = JSON.parse(body); + r.reply("Derzeit im Treff: " + data.names.join(', ')); + }) + }); + +}