summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-23 23:24:17 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-23 23:24:17 +0000
commit331da006da62c68bd80d688bdc844bbf1936c198 (patch)
tree41590f2b727dc4a1da48ae85e23aac6e9d24e1ca
parentf22279cf33fd211baf4c3b0e89ae0037d2607d36 (diff)
core/userdata: with_botdata method
-rw-r--r--lib/rbot/core/userdata.rb29
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/rbot/core/userdata.rb b/lib/rbot/core/userdata.rb
index 85f386b2..844a6c58 100644
--- a/lib/rbot/core/userdata.rb
+++ b/lib/rbot/core/userdata.rb
@@ -23,12 +23,23 @@ module ::Irc
# _key_; if a block is passed, it will be called with the previous
# _key_ value as parameter, and its return value will be stored as
# the new value. If _value_ is present in the block form, it will
- # be used to initialize _key_ if it's missing
+ # be used to initialize _key_ if it's missing.
+ #
+ # If you have to do large-scale editing of the Bot data Hash,
+ # please use with_botdata.
#
def set_botdata(key, value=nil, &block)
Irc::Utils.bot.plugins['userdata'].set_data(self, key, value, &block)
end
+ # This method yields the entire Bot data Hash to the block,
+ # and stores any changes done to it, returning a copy
+ # of the (changed) Hash.
+ #
+ def with_botdata(&block)
+ Irc::Utils.bot.plugins['userdata'].with_data(self, &block)
+ end
+
end
end
@@ -92,6 +103,22 @@ class UserDataModule < CoreBotModule
return ret
end
+ def with_data(user, &block)
+ h = get_data_hash(user)
+ debug h
+ yield h
+
+ iu = user.to_irc_user
+ bu = iu.botuser
+
+ if bu.transient? or bu.default?
+ @ircuser[iu.nick] = h
+ else
+ @botuser[bu.username] = h
+ end
+ return h
+ end
+
def handle_get(m, params)
user = m.server.get_user(params[:nick]) || m.source
key = params[:key].intern