Skip to content
Extraits de code Groupes Projets
Valider 635b77f9 rédigé par Alexandre Morignot's avatar Alexandre Morignot
Parcourir les fichiers

Ébauche de bot

Il accepte des options et se connectes à irc.
parent d378baeb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
#!/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
#!/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
#!/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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter