initial commit
This commit is contained in:
commit
ec290e067d
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
/node_modules
|
|
@ -0,0 +1,11 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- "0.12"
|
||||
- "0.10"
|
||||
- "iojs"
|
||||
sudo: false
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
notifications:
|
||||
email: false
|
|
@ -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']);
|
||||
};
|
|
@ -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!
|
||||
```
|
|
@ -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)
|
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -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"
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
# bootstrap environment
|
||||
source script/bootstrap
|
||||
|
||||
mocha --compilers coffee:coffee-script
|
|
@ -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(', '));
|
||||
})
|
||||
});
|
||||
|
||||
}
|
Loading…
Reference in New Issue