diff --git a/lib/playbot.rb b/lib/playbot.rb new file mode 100644 index 0000000000000000000000000000000000000000..c39a383e2317ed85e3fa8f158cb7f4885255785c --- /dev/null +++ b/lib/playbot.rb @@ -0,0 +1,60 @@ +#!/usr/bin/ruby + + +require 'rubygems' +require 'net/yail/irc_bot' + + +class PlayBot < IRCBot + BOTNAME = 'PlayBot' + + public + # Star a new instance + # + # Options: + # * <tt>:address</tt>: irc server + # * <tt>:port</tt>: port number, default to 6667 + # * <tt>:nicknames</tt>: array of nicknames to cycle through + # * <tt>:nick_passwd</tt>: password for the first nick of :nicknames + # if we are not connected with this nick, we will use ghost and take this nick + # * <tt>:channels</tt>: the channels we are going to connect to + # * <tt>:admin</tt>: the nick of the user who can command the bot + def initialize(options = {}) + @admin = options.delete(:admin) + raise "You must provide an admin !" if !@admin + + if options[:nick_passwd] + @nick = options[:nicknames].first + @nick_paswd = options.delete[:nick_passwd] + end + + options[:username] = BOTNAME + options[:realname] = BOTNAME + + super(options) + self.connect_socket + self.start_listening + end + + # This metod is called by IRCBot#connect_socket + def add_custom_handlers() + @irc.hearing_welcome self.method(:_in_welcome) + #@irc.on_msg self.method(:_in_msg) + end + + private + # Welcome event handler + # + # We use it to identify us against NickServ + def _in_welcome(event) + return if !@nick + + if self.bot_name != @nick + msg('NickServ', "ghost #{nick} #{nick_passwd}") + sleep 30 + nick @nick + end + + msg('NickServ', "identify #{nick_passwd}") + end +end diff --git a/playbot.rb b/playbot.rb new file mode 100755 index 0000000000000000000000000000000000000000..76db536195d6ad6d2bf5699035fc9385e28fd45c --- /dev/null +++ b/playbot.rb @@ -0,0 +1,60 @@ +#!/usr/bin/ruby + + +require 'rubygems' +require 'net/yail/irc_bot' + + +class PlayBot < IRCBot + BOTNAME = 'PlayBot' + + public + # Star a new instance + # + # Options: + # * <tt>:address</tt>: irc server + # * <tt>:port</tt>: port number, default to 6667 + # * <tt>:nicknames</tt>: array of nicknames to cycle through + # * <tt>:nick_passwd</tt>: password for the first nick of :nicknames + # if we are not connected with this nick, we will use ghost and take this nick + # * <tt>:channels</tt>: the channels we are going to connect to + # * <tt>:admin</tt>: the nick of the user who can command the bot + def initialize(options = {}) + @admin = options.delete(:master) + (!@admin) ? raise "You must provide an admin !" + + if options[:nick_passwd] + @nick = options[:nicknames].first + @nick_paswd = options.delete[:nick_passwd] + end + + options[:username] = BOTNAME + options[:realname] = BOTNAME + + self.connect_socket + self.start_listening + end + + # This metod is called by IRCBot#connect_socket + def add_custom_handlers() + @irc.on_welcome self.method(:_in_welcome) + @irc.on_msg self.method(:_in_msg) + @irc.saying_join self.method(:_out_join) + end + + private + # Welcome event handler + # + # We use it to identify us against NickServ + def _in_welcome(event) + return if !@nick + + if self.bot_name != @nick + msg('NickServ', "ghost #{nick} #{nick_passwd}") + sleep 30 + nick @nick + end + + msg('NickServ', "identify #{nick_passwd}") + end +end diff --git a/run.rb b/run.rb new file mode 100755 index 0000000000000000000000000000000000000000..165659fb27172b8f7317f59b73ab7fd0e1239727 --- /dev/null +++ b/run.rb @@ -0,0 +1,50 @@ +#!/usr/bin/ruby + +require 'logger' +require 'optparse' + +$LOAD_PATH << './lib' +require 'playbot' + +# This code start the PlayBot with somes options. + +options = {} + +OptionParser.new do |opts| + opts.banner = "Usage: ./run.rb [OPTIONS]" + + opts.on('-h', '--help', 'show this help') do + puts opts + exit + end + + opts.on('-s', '--silent', 'set log to FATAL') do + options[:silent] = true + end + + opts.on('-a', '--admin', 'admin nick') do + options[:admin] = arg + end + + opts.on('-n', '--network', 'server address') do + options[:address] = arg + end + + opts.on('-p', '--port', 'server port') do + options[:port] = arg + end +end.parse! + +options[:silent] ||= false +options[:admin] ||= 'moise' +options[:address] ||= 'irc.iiens.net' + +bot = PlayBot.new( + :address => options[:address], + :port => options[:port], + :nicknames => ['PlayBot', 'Play_Bot', 'Play__Bot', 'Play___Bot'], + :channels => ['#hormone'], + :admin => options[:admin], + :silent => options[:silent] +) +bot.irc_loop