From b7204b81c3bc745162c58998a795728055e610d2 Mon Sep 17 00:00:00 2001 From: Ellis Berner Date: Fri, 13 Nov 2015 16:49:33 -0800 Subject: [PATCH] src: add cleverbot initial files --- .gitignore | 1 + LICENSE | 18 +++++++++++++++++ index.coffee | 12 ++++++++++++ package.json | 40 ++++++++++++++++++++++++++++++++++++++ script/bootstrap | 18 +++++++++++++++++ script/test | 6 ++++++ src/cleverbot.coffee | 23 ++++++++++++++++++++++ test/cleverbot_test.coffee | 5 +++++ 8 files changed, 123 insertions(+) create mode 100755 .gitignore create mode 100755 LICENSE create mode 100755 index.coffee create mode 100755 package.json create mode 100755 script/bootstrap create mode 100755 script/test create mode 100755 src/cleverbot.coffee create mode 100755 test/cleverbot_test.coffee diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..aa64348 --- /dev/null +++ b/LICENSE @@ -0,0 +1,18 @@ +Copyright (c) 2015 Ellis Berner + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/index.coffee b/index.coffee new file mode 100755 index 0000000..d00a198 --- /dev/null +++ b/index.coffee @@ -0,0 +1,12 @@ +fs = require 'fs' +path = require 'path' + +module.exports = (robot, scripts) -> + scriptsPath = path.resolve(__dirname, 'src') + fs.exists scriptsPath, (exists) -> + if exists + for script in fs.readdirSync(scriptsPath) + 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 100755 index 0000000..a6563e2 --- /dev/null +++ b/package.json @@ -0,0 +1,40 @@ +{ + "name": "hubot-cleverbot", + "description": "Turns your bot into a snarky little shit", + "version": "1.0.0", + "author": "Ellis Berner ", + "license": "MIT", + + "keywords": [ + "hubot", + "hubot-scripts", + "clever", + "bot", + "cleverbot" + ], + + "repository": { + "type": "git", + "url": "git://github.com/maletor/hubot-cleverbot.git" + }, + + "bugs": { + "url": "https://github.com/maletor/hubot-cleverbot/issues" + }, + + "dependencies": { + "coffee-script": "~1.6", + "cleverbot-node": "~0.2.1" + }, + + "devDependencies": { + "mocha": "*", + "chai": "*" + }, + + "main": "index.coffee", + + "scripts": { + "test": "script/test" + } +} diff --git a/script/bootstrap b/script/bootstrap new file mode 100755 index 0000000..30e87e1 --- /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" diff --git a/script/test b/script/test new file mode 100755 index 0000000..bd23cb9 --- /dev/null +++ b/script/test @@ -0,0 +1,6 @@ +#!/bin/bash + +# bootstrap environment +source script/bootstrap + +mocha --compilers coffee:coffee-script diff --git a/src/cleverbot.coffee b/src/cleverbot.coffee new file mode 100755 index 0000000..b8bc87c --- /dev/null +++ b/src/cleverbot.coffee @@ -0,0 +1,23 @@ +# Description: +# Turns your bot into a snarky little shit +# +# Dependencies: +# "cleverbot-node": "0.2.1" +# +# Configuration: +# None +# +# Commands: +# hubot c +# +# Author: +# maletor + +cleverbot = require("cleverbot-node") + +module.exports = (robot) -> + c = new cleverbot() + + robot.respond /c (.*)/i, (msg) -> + data = msg.match[1].trim() + cleverbot.prepare(( -> c.write(data, (c) => msg.send(c.message)))) diff --git a/test/cleverbot_test.coffee b/test/cleverbot_test.coffee new file mode 100755 index 0000000..96214b3 --- /dev/null +++ b/test/cleverbot_test.coffee @@ -0,0 +1,5 @@ +chai = require 'chai' + +expect = chai.expect + +describe 'hello-world', ->