using terms from application "Colloquy"
	on process user command c with arguments for view
		if c is "safari" then
			if arguments is "" then
				tell view to send message my get_current_link()
				return true
			else if arguments is "aantal" then
				tell view to send message my get_current_number()
				return true
			else if arguments is "sluit" then
				tell application "Safari"
					quit
				end tell
			else if arguments is URL then
				open location arguments
			end if
		else if body of m starts with "!safari" then
			tell view to send message my get_current_link()
			return true
		end if
	end process user command
end using terms from

on get_current_link()
	tell application "System Events"
		if ((application processes whose (name is equal to "Safari")) count) is greater than 0 then
			using terms from application "Safari"
				tell application "Safari"
					if (count of documents) is greater than 0 then
						set link to "[ 12Safari status01 ][ " & (name of front document) & " | " & (URL of front document) & " ]"
					else
						set link to "[ 12Safari status01 ][ Geen kaders open ]"
					end if
				end tell
			end using terms from
		else
			set link to "[ 12Safari status01 ][ Niet open ]"
		end if
	end tell
end get_current_link

on get_current_number()
	tell application "System Events"
		if ((application processes whose (name is equal to "Safari")) count) is greater than 0 then
			using terms from application "Safari"
				tell application "Safari"
					if (count of documents) is 1 then
						set link to "[ 12Safari status01 ][ " & (count of documents) & " Kader is open ]"
					else
						set link to "[ 12Safari status01 ][ " & (count of documents) & " Kaders zijn open ]"
					end if
				end tell
			end using terms from
		else
			set link to "[ 12Safari status01 ][ Niet open ]"
		end if
	end tell
end get_current_number