-
-
Save kballenegger/72dfecf39a96a6173d61 to your computer and use it in GitHub Desktop.
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
require 'json' | |
require 'zmq' | |
class ChartboostChatbot | |
def initialize | |
@members = [] | |
@zmq = ZMQ::Context.new(1) | |
@pub = @zmq.socket(ZMQ::PUB) | |
@pub.bind('tcp://*:13001') | |
end | |
def did_startup | |
Thread.new do | |
ctx = ZMQ::Context.new(1) | |
pull = ctx.socket(ZMQ::UPSTREAM) | |
pull.bind('tcp://*:13000') | |
loop do | |
msg = pull.recv | |
puts "ZMQ: received -- #{payload}" | |
say(msg) | |
end | |
end | |
end | |
def setbot bot | |
@bot = bot | |
end | |
def joined(member) | |
@members << member | |
end | |
def left(member) | |
@members.delete member | |
end | |
def say(msg) | |
@bot.respond("PRIVMSG #chartboost :#{msg}") | |
end | |
def process(sender, message) | |
payload = {sender: sender, message: message, members: @members}.to_json | |
puts "ZMQ: sending -- #{payload}" | |
@pub.send(payload) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment