i´m trying to build a irc-bot in ruby, and i´ve no problem with that so far.
but i´m trying to minimize the need for a restart, and want to require some external code at runtime.
i know there is require "external.rb", but this seems to work only once, if i require a script twice while running the program and change it meanwhile, it doesn´t seem to use the changed code, and also i don´t know how i get rid of the last required code.
that´s yet another typical noob-question, i beg your pardon
btw, in case you didn´t really understood what i need - the same thing works in php with include("somescript.php") and that´s exactly how i want it to become.
To get rid of old code, you might want to do something like I do.
inside a particular 'module':
class Foo < ScriptModule
def initialize() ...
register_command("foo") { |args| ... }
end
def cleanup
unregister_command("foo")
end
end
When I load() a script module, I attach all its class to its filename.
When I want to reload said filename, I first call cleanup, causing it to
unregister old code, etc, and then load() it again.
- Greg
manveru wrote:
···
hi to all,
i´m trying to build a irc-bot in ruby, and i´ve no problem with that so
far.
but i´m trying to minimize the need for a restart, and want to require
some external code at runtime.
i know there is require "external.rb", but this seems to work only once,
if i require a script twice while running the program and change it
meanwhile, it doesn´t seem to use the changed code, and also i don´t
know how i get rid of the last required code.
that´s yet another typical noob-question, i beg your pardon
btw, in case you didn´t really understood what i need - the same thing
works in php with include("somescript.php") and that´s exactly how i
want it to become.
Use load instead of require. Load needs the path to the file, but will
reload everytime, require is built to load everything only once.
regards,
Brian
···
On 01/08/05, manveru <ulmo@valaraan.de> wrote:
hi to all,
i´m trying to build a irc-bot in ruby, and i´ve no problem with that so far.
but i´m trying to minimize the need for a restart, and want to require
some external code at runtime.
i know there is require "external.rb", but this seems to work only once,
if i require a script twice while running the program and change it
meanwhile, it doesn´t seem to use the changed code, and also i don´t
know how i get rid of the last required code.
that´s yet another typical noob-question, i beg your pardon
btw, in case you didn´t really understood what i need - the same thing
works in php with include("somescript.php") and that´s exactly how i
want it to become.
If you have the possibility, can you relase an Irc::Bot lib?
It would be wonderfull.
Tanks to the two who helped me with load(). it´s working fine, and i can code a lot faster now:
but i stumbled over another problem:
i have got the hostmask of a person and i made a class User with the method nick.
now i wonder, how do i create a object to represent a User?
is there a way to create a object out of a hostmask? because somewhere i read that a string is no object... is that true?
this is my Userclass so far... (i know there are ways to improve that, but i´m with ruby since 3 days only
class User
attr_accessor :hostmask
attr_reader :nick
def initialize @hostmask = "" @nick = ""
end
def nick(hostmask = @hostmask)
if hostmask != "" @nick = hostmask.split("!") @nick = @nick[0].split(":") @nick[1].chomp
end
@dave
so far i don´t know if i get to that point, as i´m making a very specialized kind of bot to control some channels.
but if you let me know what that bot should be able to do, i´ll try to implement it and put it online
btw: wouldn´t it be cool to have a GPL-bot who distributes his code by DCC?
so far it´s able to respond to the most common things like PING or VERSION, so it will survive in IRC, now í´m coding some user and channel-objects for manipulation.
wouldn´t it be cool to have a GPL-bot who distributes his code by
DCC?
Yes.
specialized kind of bot to control some channels
module Irc
class Bot
# An "abstract" bot could be initalized with a settings obj.
# The setting obj may contain the bot name, version, and channels
# to control.
def initialize(settings)
end
def connect_to_server(server)
end
def connect_to_servers(server_ary)
end
def connect_to_server_list()
end
def disconnect()
end
# Join channels to control
def join_channels(server)
end
# Define a trigger
def define_trigger(trigger)
end
# Activate the trigger
def activate_trigger(trigger_name)
end
end
end
I thinck this should be a good starting point for a base class.