delay.rb 1.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/env ruby

# Plugin to do delayed actions
# Basically just an interface to the timer class
class Delay

	# This method is called when the plugin is first loaded
	def initialize( status, config, output, irc, timer )
		@status  = status
		@config  = config
		@output  = output
		@irc     = irc
		@timer   = timer
	end

	# Default method
Cool Fire's avatar
Cool Fire committed
17
	def main( nick, _user, _host, _from, _msg, _arguments, _con )
18 19 20 21
		@irc.notice( nick, "Use 'ruby' or 'irc' as the method.")
	end
	
	# Function to send help about this plugin (Can also be called by the help plugin.)
Cool Fire's avatar
Cool Fire committed
22
	def help( nick, _user, _host, _from, _msg, _arguments, con )
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
		help = [
			"This plugin to delay actions.",
			"  delay ruby [seconds] [action]    - Set ruby command to be carried out later."
		]

		# Print out help
		help.each do |line|
			if( con )
				@output.c( line + "\n" )
			else
				@irc.notice( nick, line )
			end
		end
	end
		
	# Functions to do delayed actions
Cool Fire's avatar
Cool Fire committed
39
	def ruby( _nick, _user, host, from, _msg, arguments, con )
40 41 42 43 44 45 46 47 48 49
		if( @config.auth( host, con ) )
			if( !arguments.nil? && !arguments.empty? )
				delay, action = arguments.split( ' ', 2 )

				@timer.action( delay.to_i, action.to_s )
				@irc.message( from, "Recorded ruby command '#{action}' to be executed in #{delay} seconds." )
			end
		end
	end
end