Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Octopus
- class Irc
- attr_accessor :http, :bot, :logger
- def initialize(http, logger, options = {})
- self.http = http
- self.logger = logger
- # Initialize array for threads
- self.threads = []
- bot = Cinch::Bot.new do
- configure do |c|
- c.server = options["server"]
- c.channels = options["channels"]
- c.nick = options["nick"]
- c.realname = options["real_name"]
- end
- end
- self.bot = bot
- self.logger.debug("Initialized IRC")
- end
- def clean_up_threads
- # Clean up all threads
- self.threads.each {|t| t.terminate}
- end
- def run!
- should_run = true
- self.logger.debug("Running bot!")
- @Thread.new do
- self.bot.start
- end
- # Trap ctrl+c SIGINT
- Signal.trap("SIGINT") do
- # Stop while loop in run!
- should_run = false
- clean_up_threads
- end
- sleep 3
- while should_run
- if http.message
- message = http.message[:message]
- channel = http.message[:channel]
- if message
- self.logger.debug("Sending: #{http.message}")
- puts channel
- if channel
- channel = self.bot.channels.find{|x| x == "##{channel}"}
- end
- channel ||= self.bot.channels.first
- channel.safe_send(message)
- http.message = nil
- end
- sleep 1
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment