diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-09-22 07:12:46 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-09-22 07:12:46 +0000 |
commit | 290656ebffce720540f5a767066d914840e583c8 (patch) | |
tree | 3dcf0ba09f41243d495303682fdde42ebf01cd91 /lib/rbot/botuser.rb | |
parent | 8b3111e32425190b0130f658bc4e1b553184dea6 (diff) |
New Auth Framework: add make_permanent() and related methods to make a transient BotUser permanent
Diffstat (limited to 'lib/rbot/botuser.rb')
-rw-r--r-- | lib/rbot/botuser.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/rbot/botuser.rb b/lib/rbot/botuser.rb index ccbef4fe..1504a656 100644 --- a/lib/rbot/botuser.rb +++ b/lib/rbot/botuser.rb @@ -268,6 +268,15 @@ class Bot @transient=!bool
end
+ # Make the BotUser permanent
+ def make_permanent(name)
+ raise TypError, "permanent already" if permanent?
+ @username = BotUser.sanitize_username(name)
+ @transient = false
+ reset_autologin
+ reset_password # or not?
+ end
+
# Create a new BotUser with given username
def initialize(username, options={})
opts = {:transient => false}.merge(options)
@@ -791,6 +800,33 @@ class Bot end
end
+ # Makes transient BotUser _user_ into a permanent BotUser
+ # named _name_; if _user_ is an Irc::User, act on the transient
+ # BotUser (if any) it's logged in as
+ #
+ def make_permanent(user, name)
+ # TODO merge BotUser instead?
+ raise "there's already a BotUser called #{name}" if include?(name)
+
+ tuser = nil
+ case user
+ when String, Irc::User
+ tuser = irc_to_botuser(user)
+ when BotUser
+ tuser = user
+ else
+ raise TypeError, "sorry, don't know how to make #{user.class} into a permanent BotUser"
+ end
+ return nil unless tuser
+ raise TypeError, "#{tuser} is not transient" unless tuser.transient?
+
+ @transients.delete(tuser)
+ tuser.make_permanent(name)
+ @allbotusers[tuser.username.to_sym] = tuser
+
+ return tuser
+ end
+
# Checks if User _user_ can do _cmd_ on _chan_.
#
# Permission are checked in this order, until a true or false
|