Commits

luastoned committed ed3c445

Readded thread.threadNumberOfPagesPattern
Readded thread.threadNamePattern
Readded thread.getName()
Readded thread.getNumberOfPages()

  • Participants
  • Parent commits ecd2aa3

Comments (0)

Files changed (1)

File facepunch/thread.lua

 
 
 -------------------------------------------------------------------------------
+-- threadNumberOfPagesPattern
+-- Purpose: Pattern for getting a threads maximum page number
+-------------------------------------------------------------------------------
+threadNumberOfPagesPattern = "" ..
+"class=\"first_last\"><a href=\"threads/.-/(.-)\""
+
+-------------------------------------------------------------------------------
+-- threadNamePattern
+-- Purpose: Pattern for getting the threads name
+-------------------------------------------------------------------------------
+threadNamePattern = "" ..
+"<title> (.-)</title>"
+
+
+-------------------------------------------------------------------------------
 -- thread.getMembersInPage()
 -- Purpose: Returns all members that have posted on a given thread page, first
 --			returns 0 if there are no errors or 1 in case of errors
 end
 
 -------------------------------------------------------------------------------
+-- thread.getName()
+-- Purpose: Returns the name of the thread
+-- Input: threadPage - string of the requested page
+-- Output: name of thread
+-------------------------------------------------------------------------------
+function getName( threadPage )
+	return string.match( threadPage, threadNamePattern )
+end
+
+-------------------------------------------------------------------------------
+-- thread.getNumberOfPages()
+-- Purpose: Returns the total ammount of pages in a thread
+-- Input: threadID
+-- Output: number of pages
+-------------------------------------------------------------------------------
+function getNumberOfPages( threadPage )
+	local n = string.match( threadPage, threadNumberOfPagesPattern )
+	if ( n == nil ) then return 1 end
+	return tonumber( string.gsub( n, "%?s=%w+", "" ) )
+end
+
+-------------------------------------------------------------------------------
 -- thread.getPage()
 -- Purpose: Returns 0 if the page is retrieved successfully, then the thread
 --			page by ID and page number, if provided, otherwise it returns 1 and