-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bartosz Kopiński
committed
Apr 17, 2015
1 parent
2ef9dc8
commit f300862
Showing
14 changed files
with
167 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Hipbot | ||
module Adaptable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
extend ClassMethods | ||
|
||
Hipbot.adapters.unshift(self) | ||
end | ||
|
||
module ClassMethods | ||
attr_reader :options | ||
|
||
def inherited child | ||
Hipbot.adapters.unshift(child) | ||
end | ||
|
||
def add_config_options *keys | ||
@options ||= [] | ||
@options |= keys | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,7 @@ | ||
module Hipbot | ||
module Adapters | ||
class Hipchat | ||
attr_accessor :client | ||
|
||
def start! | ||
self.client = Initializer.new.client | ||
end | ||
|
||
def restart! | ||
start! | ||
end | ||
|
||
def invite_to_room(room, users) | ||
client.invite(user_ids(users), room.id) | ||
end | ||
|
||
def kick_from_room(room, users) | ||
client.kick(user_ids(users), room.id) | ||
end | ||
|
||
def send_to_room(room, message) | ||
client.send_message(:groupchat, room.id, message) | ||
end | ||
|
||
def send_to_user(user, message) | ||
client.send_message(:chat, user.id, message) | ||
end | ||
|
||
def set_topic(room, topic) | ||
client.send_message(:groupchat, room.id, nil, topic) | ||
end | ||
|
||
def set_presence(status, type) | ||
client.set_presence(status, type) | ||
end | ||
|
||
def join_room(room) | ||
client.join(room.id) | ||
end | ||
|
||
def leave_room(room, reason = '') | ||
client.exit(room.id, reason) | ||
end | ||
|
||
protected | ||
|
||
def user_ids users | ||
Array(users).map(&:id) | ||
end | ||
class Hipchat < XMPP | ||
include Hipbot::Adaptable | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Hipbot | ||
module Adapters | ||
class Hipchat < XMPP | ||
class Client < XMPP::Client | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
module Hipbot | ||
module Adapters | ||
class Shell | ||
include Hipbot::Adaptable | ||
|
||
attr_accessor :connection | ||
|
||
def start! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,7 @@ | ||
module Hipbot | ||
module Adapters | ||
class Slack | ||
attr_accessor :client | ||
|
||
def start! | ||
self.client = XMPP::Initializer.new.client | ||
end | ||
|
||
def restart! | ||
start! | ||
end | ||
|
||
def invite_to_room(room, users) | ||
client.invite(user_ids(users), room.id) | ||
end | ||
|
||
def kick_from_room(room, users) | ||
client.kick(user_ids(users), room.id) | ||
end | ||
|
||
def send_to_room(room, message) | ||
client.send_message(:groupchat, room.id, message) | ||
end | ||
|
||
def send_to_user(user, message) | ||
client.send_message(:chat, user.id, message) | ||
end | ||
|
||
def set_topic(room, topic) | ||
client.send_message(:groupchat, room.id, nil, topic) | ||
end | ||
|
||
def set_presence(status, type) | ||
client.set_presence(status, type) | ||
end | ||
|
||
def join_room(room) | ||
client.join(room.id) | ||
end | ||
|
||
def leave_room(room, reason = '') | ||
client.exit(room.id, reason) | ||
end | ||
|
||
protected | ||
|
||
def user_ids users | ||
Array(users).map(&:id) | ||
end | ||
class Slack < XMPP | ||
add_config_options :slack_api_token, :conference_host | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require "slack" | ||
|
||
module Hipbot | ||
module Adapters | ||
class Slack < XMPP | ||
class Client < XMPP::Client | ||
protected | ||
|
||
def initialize_bot_user | ||
Hipbot.configuration.user = User.find(Hipbot.configuration.jid) | ||
client.name = Hipbot.user.name.delete(" ").downcase | ||
Hipbot.configuration.user.update(mention: client.name) | ||
end | ||
|
||
def initialize_rooms | ||
::Slack.configure do |config| | ||
config.token = Hipbot.configuration.slack_api_token | ||
end | ||
|
||
room_ids = ::Slack.client.channels_list["channels"].map do |channel| | ||
room = Room.find_or_create_by( | ||
name: channel["name"], | ||
id: Jabber::JID.new(channel["name"], Hipbot.configuration.conference_host, "hipbot").to_s | ||
) | ||
room.id | ||
end | ||
|
||
clean_other_objects(Room, room_ids) if room_ids.any? | ||
end | ||
|
||
def initialize_users | ||
user_ids = client.get_users.map do |user_data| | ||
user = User.find_or_create_by(id: user_data.jid) | ||
user.update_attributes(user_data.attributes) | ||
user.id | ||
end | ||
clean_other_objects(User, user_ids) if user_ids.any? | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
module Hipbot | ||
module Adapters | ||
class Telnet | ||
include Hipbot::Adaptable | ||
|
||
attr_accessor :connection | ||
|
||
def start! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module Hipbot | ||
module Adapters | ||
class XMPP | ||
include Hipbot::Adaptable | ||
|
||
add_config_options :jid | ||
|
||
attr_accessor :client | ||
|
||
def start! | ||
self.client = self.class::Client.new.client | ||
end | ||
|
||
def restart! | ||
start! | ||
end | ||
|
||
def invite_to_room(room, users) | ||
client.invite(user_ids(users), room.id) | ||
end | ||
|
||
def kick_from_room(room, users) | ||
client.kick(user_ids(users), room.id) | ||
end | ||
|
||
def send_to_room(room, message) | ||
client.send_message(:groupchat, room.id, message) | ||
end | ||
|
||
def send_to_user(user, message) | ||
client.send_message(:chat, user.id, message) | ||
end | ||
|
||
def set_topic(room, topic) | ||
client.send_message(:groupchat, room.id, nil, topic) | ||
end | ||
|
||
def set_presence(status, type) | ||
client.set_presence(status, type) | ||
end | ||
|
||
def join_room(room) | ||
client.join(room.id) | ||
end | ||
|
||
def leave_room(room, reason = '') | ||
client.exit(room.id, reason) | ||
end | ||
|
||
protected | ||
|
||
def user_ids users | ||
Array(users).map(&:id) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.