def help( plugin, topic="" )
if topic == "add"
- "Scripts are little Ruby programs that run in the context of the script plugin. You can access @bot (class IrcBot), m (class PrivMessage), user (class String, either the first argument, or if missing the sourcenick), and args (class Array, an array of arguments). Example: 'script add greet m.reply( 'Hello ' + user )'. Invoke the script just like a plugin: '<botnick>: greet'."
+ "Scripts are little Ruby programs that run in the context of the script plugin. You can access @bot (class Irc::Bot), m (class Irc::PrivMessage), user (class String, either the first argument, or if missing the sourcenick), and args (class Array, an array of arguments). Example: 'script add greet m.reply( 'Hello ' + user )'. Invoke the script just like a plugin: '<botnick>: greet'."
else
"Create mini plugins on IRC. 'script add <name> <code>' => Create script named <name> with the Ruby program <code>. 'script list' => Show a list of all known scripts. 'script show <name>' => Show the source code for <name>. 'script del <name>' => Delete the script <name>."
end
# Main bot class, which manages the various components, receives messages,
# handles them or passes them to plugins, and contains core functionality.
-class IrcBot
- # the bot's IrcAuth data
+class Bot
+ # the bot's Auth data
attr_reader :auth
# the bot's BotConfig data
# bot User in the client/server connection
# TODO multiserver
def myself
- @client.client
+ @client.user
end
# bot User in the client/server connection
myself.nick
end
- # create a new IrcBot with botclass +botclass+
+ # create a new Bot with botclass +botclass+
def initialize(botclass, params = {})
# BotConfig for the core bot
# TODO should we split socket stuff into ircsocket, etc?
@socket = IrcSocket.new(@config['server.name'], @config['server.port'], @config['server.bindhost'], @config['server.sendq_delay'], @config['server.sendq_burst'], :ssl => @config['server.ssl'])
- @client = IrcClient.new
+ @client = Client.new
# Channels where we are quiet
# Array of channels names where the bot should be quiet
RPL_DATASTR=290
# implements RFC 2812 and prior IRC RFCs.
- # clients register handler proc{}s for different server events and IrcClient
+ # clients register handler proc{}s for different server events and Client
# handles dispatch
- class IrcClient
+ class Client
- attr_reader :server, :client
+ attr_reader :server, :user
- # create a new IrcClient instance
+ # create a new Client instance
def initialize
@server = Server.new # The Server
- @client = @server.user("") # The User representing the client on this Server
+ @user = @server.user("") # The User representing the client on this Server
@handlers = Hash.new
data[:target] = argv[0]
# A numeric reply /should/ be directed at the client, except when we're connecting with a used nick, in which case
# it's directed at '*'
- not_us = !([@client.nick, '*'].include?(data[:target]))
+ not_us = !([@user.nick, '*'].include?(data[:target]))
if not_us
- warning "Server reply #{serverstring.inspect} directed at #{data[:target]} instead of client (#{@client.nick})"
+ warning "Server reply #{serverstring.inspect} directed at #{data[:target]} instead of client (#{@user.nick})"
end
num=command.to_i
# "Welcome to the Internet Relay Network
# <nick>!<user>@<host>"
if not_us
- warning "Server thinks client (#{@client.inspect}) has a different nick"
- @client.nick = data[:target]
+ warning "Server thinks client (#{@user.inspect}) has a different nick"
+ @user.nick = data[:target]
end
if argv[1] =~ /(\S+)(?:!(\S+?))?@(\S+)/
nick = $1
user = $2
host = $2
warning "Welcome message nick mismatch (#{nick} vs #{data[:target]})" if nick != data[:target]
- @client.user = user if user
- @client.host = host if host
+ @user.user = user if user
+ @user.host = host if host
end
handle(:welcome, data)
when RPL_YOURHOST
data[:message] = argv[2]
@server.delete_user_from_channel(data[:target], data[:channel])
- if data[:target] == @client
+ if data[:target] == @user
@server.delete_channel(data[:channel])
end
data[:message] = argv[1]
@server.delete_user_from_channel(data[:source], data[:channel])
- if data[:source] == @client
+ if data[:source] == @user
@server.delete_channel(data[:channel])
end