From 290656ebffce720540f5a767066d914840e583c8 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 22 Sep 2007 07:12:46 +0000 Subject: New Auth Framework: add make_permanent() and related methods to make a transient BotUser permanent --- lib/rbot/botuser.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'lib/rbot/botuser.rb') 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 -- cgit v1.2.3