Initial commit - nextbike - Lita Slack chatbot plugin for nextbike interactions.
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit 313798ba3af4f11ab53e9bb687a082db17e87302
(HTM) Author: Jay Scott <me@jay.scot>
Date: Fri, 24 Feb 2017 16:16:46 +0000
Initial commit
Diffstat:
A Gemfile | 16 ++++++++++++++++
A Gemfile.lock | 90 +++++++++++++++++++++++++++++++
A handlers/nextbike.rb | 86 ++++++++++++++++++++++++++++++
A lita_config.rb | 35 +++++++++++++++++++++++++++++++
A requirements.txt | 1 +
A templates/nextbike_cities.slack.erb | 5 +++++
A templates/nextbike_location.slack.… | 5 +++++
7 files changed, 238 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/Gemfile b/Gemfile
@@ -0,0 +1,16 @@
+source "https://rubygems.org"
+
+# Core
+gem "lita"
+
+# Adapters
+gem 'lita-slack'
+
+# Plugins
+gem 'lita-dig', '~> 1.3'
+gem 'lita-whois', '~> 1.1'
+gem "lita-rules"
+gem 'lita-ai'
+
+#Deps
+gem 'nokogiri', '~> 1.6', '>= 1.6.8'
(DIR) diff --git a/Gemfile.lock b/Gemfile.lock
@@ -0,0 +1,90 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ cleverbot_io (1.2.2)
+ httpclient (~> 2.8)
+ oj (~> 2.15)
+ eventmachine (1.2.1)
+ faraday (0.11.0)
+ multipart-post (>= 1.2, < 3)
+ faye-websocket (0.10.5)
+ eventmachine (>= 0.12.0)
+ websocket-driver (>= 0.5.1)
+ htmlentities (4.3.4)
+ http_router (0.11.2)
+ rack (>= 1.0.0)
+ url_mount (~> 0.2.1)
+ httpclient (2.8.3)
+ i18n (0.7.0)
+ ice_nine (0.11.2)
+ lita (4.7.1)
+ bundler (>= 1.3)
+ faraday (>= 0.8.7)
+ http_router (>= 0.11.2)
+ i18n (>= 0.6.9)
+ ice_nine (>= 0.11.0)
+ multi_json (>= 1.7.7)
+ puma (>= 2.7.1)
+ rack (>= 1.5.2, < 2.0.0)
+ rb-readline (>= 0.5.1)
+ redis-namespace (>= 1.3.0)
+ thor (>= 0.18.1)
+ lita-ai (0.1.3)
+ cleverbot_io (~> 1.2.2)
+ htmlentities (~> 4.3)
+ lita (>= 4.6)
+ lita-dig (1.3.0)
+ lita (>= 4.2)
+ net-dns2
+ lita-rules (0.0.1)
+ lita (>= 3.0)
+ lita-slack (1.8.0)
+ eventmachine
+ faraday
+ faye-websocket (>= 0.8.0)
+ lita (>= 4.7.1)
+ multi_json
+ lita-whois (1.1.0)
+ lita (~> 4.2)
+ whois
+ mini_portile2 (2.1.0)
+ multi_json (1.12.1)
+ multipart-post (2.0.0)
+ net-dns2 (0.8.7)
+ packetfu
+ network_interface (0.0.1)
+ nokogiri (1.7.0.1)
+ mini_portile2 (~> 2.1.0)
+ oj (2.18.1)
+ packetfu (1.1.11)
+ network_interface (~> 0.0)
+ pcaprub (~> 0.12)
+ pcaprub (0.12.4)
+ puma (3.6.2)
+ rack (1.6.5)
+ rb-readline (0.5.3)
+ redis (3.3.2)
+ redis-namespace (1.5.2)
+ redis (~> 3.0, >= 3.0.4)
+ thor (0.19.4)
+ url_mount (0.2.1)
+ rack
+ websocket-driver (0.6.4)
+ websocket-extensions (>= 0.1.0)
+ websocket-extensions (0.1.2)
+ whois (4.0.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ lita
+ lita-ai
+ lita-dig (~> 1.3)
+ lita-rules
+ lita-slack
+ lita-whois (~> 1.1)
+ nokogiri (~> 1.6, >= 1.6.8)
+
+BUNDLED WITH
+ 1.13.5
(DIR) diff --git a/handlers/nextbike.rb b/handlers/nextbike.rb
@@ -0,0 +1,86 @@
+require 'nokogiri'
+require 'open-uri'
+
+module Lita
+ module Handlers
+
+ class NextBike < Handler
+ REDIS_CITY_KEY = "nc_"
+
+ template_root File.expand_path("../../templates", __FILE__)
+ route('nextbike', :nextbike, help: { "nextbike" => "Shows how many bikes are at a given location" })
+ route('nextbike status', :status)
+ route('nextbike update', :update)
+ route('nextbike show cities', :listcities)
+ route(/^nextbike show location\s(.+)/, :listlocation)
+
+ def status(response)
+ response.reply "Status: All good in the hood."
+ end
+
+ def update(response)
+ doc = Nokogiri::XML(open("https://nextbike.net/maps/nextbike-official.xml"))
+ count = 0
+ doc.search('//country//city').each do |data|
+ uid = data['uid']
+ name = data['name']
+ redis.hset(REDIS_CITY_KEY,uid,name)
+ count+=1
+ end
+ response.reply "*Update*: #{count} cities added/refreshed."
+ end
+
+ def listcities(response)
+ city_list = redis.hvals(REDIS_CITY_KEY)
+ if city_list.empty?
+ response.reply("*Info*: No cities are stored, run update?")
+ else
+ response.reply(render_template("nextbike_cities.slack", data: city_list))
+ end
+ end
+
+ def getUID
+ end
+
+ def getName
+ end
+
+ def listlocation(response)
+ city_uid = nil
+ city_name = response.matches.first
+ city_list = redis.hgetall(REDIS_CITY_KEY)
+ city_list.each do |key, value|
+ if "#{value.downcase}" == "#{city_name.first}"
+ city_uid = key
+ end
+ end
+
+ if city_uid.nil?
+ response.reply("*Info*: Could not find the city #{city_name.first}")
+ return true
+ end
+
+ doc = Nokogiri::XML(open("https://nextbike.net/maps/nextbike-official.xml?city=#{city_uid}"))
+ location_list = []
+ doc.search('//country//city//place').each do |data|
+ location_list.push(data['name'])
+ end
+
+ response.reply(render_template("nextbike_location.slack", data: location_list))
+ end
+
+ def nextbike(response)
+ doc = Nokogiri::XML(open("https://nextbike.net/maps/nextbike-official.xml?city=237"))
+ doc.search('//country//city//place').each do |data|
+ if data['uid'] == "264308"
+ response.reply("*#{data['name']}* has *#{data['bikes']}* bikes left.")
+ end
+ end
+ end
+
+ end
+
+ Lita.register_handler(NextBike)
+
+ end
+end
(DIR) diff --git a/lita_config.rb b/lita_config.rb
@@ -0,0 +1,35 @@
+require './handlers/nextbike.rb'
+
+Lita.configure do |config|
+
+ # Core
+ config.robot.name = "Gendry"
+ config.robot.alias = "#"
+ config.robot.locale = :en
+ config.robot.log_level = :info
+ #config.robot.adapter = :shell
+ config.robot.admins = ["U3NREU9U0", "U09ADE44V"]
+
+ # Adapter
+ config.robot.adapter = :slack
+ config.adapters.slack.token = ""
+ config.adapters.slack.link_names = true
+ config.adapters.slack.parse = "full"
+ config.adapters.slack.unfurl_links = false
+ config.adapters.slack.unfurl_media = false
+
+ # Redis & HTTP
+ config.redis.host = ""
+ config.redis.port = 6379
+ config.http.port = 7777
+
+ # Plugins
+
+ # lita-dig
+ config.handlers.dig.default_resolver = '8.8.8.8'
+
+ # lita-ai
+ config.handlers.ai.api_user = ''
+ config.handlers.ai.api_key = ''
+
+end
(DIR) diff --git a/requirements.txt b/requirements.txt
@@ -0,0 +1 @@
+libpcap-devel
(DIR) diff --git a/templates/nextbike_cities.slack.erb b/templates/nextbike_cities.slack.erb
@@ -0,0 +1,5 @@
+<% @data.each do | name | %>
+ • <%= name %>
+<% end %>
+
+
(DIR) diff --git a/templates/nextbike_location.slack.erb b/templates/nextbike_location.slack.erb
@@ -0,0 +1,5 @@
+<% @data.each do | name | %>
+ • <%= name %>
+<% end %>
+
+