+2007-04-12 Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
+
+ * Basic class extensions: Module#define_structure() method. Syntax:
+ define_structure :SomeName, :attr_a, :attr_b
+ is equivalent to
+ SomeName = Struct.new("SomeName", :attr_a, :attr_b)
+ except that the new Struct is not created if it already exists and the
+ attributes list is the same.
+
2007-03-31 Dmitry Kim <dmitry.kim@gmail.com>
* HttpUtil: major rework. get_response() method now respects
been removed (mostly because it won't play well with future HTTP
encodings support), please use get_partial() or get_request() instead.
* Utils: http_get() method has been removed (long obsoleted by
- HttpUtil)
+ HttpUtil)
* different plugins: modified to accomodate for HttpUtil changes.
2007-03-24 Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
# * fixed regexp usage in requirements for plugin map\r
# * add proper auth management\r
\r
-OnJoinAction = Struct.new("OnJoinAction", :host, :action, :channel, :reason)\r
-BadWordAction = Struct.new("BadWordAction", :regexp, :action, :channel, :timer, :reason)\r
-WhitelistEntry = Struct.new("WhitelistEntry", :host, :channel)\r
-\r
+define_structure :OnJoinAction, :host, :action, :channel, :reason\r
+define_structure :BadWordAction, :regexp, :action, :channel, :timer, :reason\r
+define_structure :WhitelistEntry, :host, :channel\r
\r
class BansPlugin < Plugin\r
\r
# TODO:: when Ruby 2.0 gets out, fix the FIXME 2.0 UTF-8 workarounds
# Class for storing question/answer pairs
-QuizBundle = Struct.new( "QuizBundle", :question, :answer )
+define_structure :QuizBundle, :question, :answer
# Class for storing player stats
-PlayerStats = Struct.new( "PlayerStats", :score, :jokers, :jokers_time )
+define_structure :PlayerStats, :score, :jokers, :jokers_time
# Why do we still need jokers_time? //Firetech
# Maximum number of jokers a player can gain
-RouletteHistory = Struct.new("RouletteHistory", :games, :shots, :deaths, :misses, :wins)
+define_structure :RouletteHistory, :games, :shots, :deaths, :misses, :wins
class RoulettePlugin < Plugin
BotConfig.register BotConfigBooleanValue.new('roulette.autospin',
# GB: Ok, we *really* need to switch to db for this plugin too
-Quote = Struct.new("Quote", :num, :date, :source, :quote)
+define_structure :Quote, :num, :date, :source, :quote
class QuotePlugin < Plugin
def initialize
# plugin. You can create them directly in an IRC channel, and invoke them just
# like normal rbot plugins.
-
-Command = Struct.new( "Command", :code, :nick, :created, :channel )
-
+define_structure :Command, :code, :nick, :created, :channel
class ScriptPlugin < Plugin
-Saw = Struct.new("Saw", :nick, :time, :type, :where, :message)
+define_structure :Saw, :nick, :time, :type, :where, :message
class SeenPlugin < Plugin
def help(plugin, topic="")
-Url = Struct.new("Url", :channel, :nick, :time, :url, :info)
+define_structure :Url, :channel, :nick, :time, :url, :info
class ::UrlLinkError < RuntimeError
end
# Please note that global symbols have to be prefixed by :: because this plugin
# will be read into an anonymous module
+# Extensions to the Module class
+#
+class ::Module
+
+ # Many plugins define Struct objects to hold their data. On rescans, lots of
+ # warnings are echoed because of the redefinitions. Using this method solves
+ # the problem, by checking if the Struct already exists, and if it has the
+ # same attributes
+ #
+ def define_structure(name, *members)
+ sym = name.to_sym
+ if Struct.const_defined?(sym)
+ kl = Struct.const_get(sym)
+ if kl.new.members.map { |member| member.intern } == members.map
+ debug "Struct #{sym} previously defined, skipping"
+ const_set(sym, kl)
+ return
+ end
+ end
+ debug "Defining struct #{sym} with members #{members.inspect}"
+ const_set(sym, Struct.new(name.to_s, *members))
+ end
+end
+
# Extensions to the Array class
#
return retval
end
-
end
end