Advertisement
Guest User

utility

a guest
May 7th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 KB | None | 0 0
  1. require("curl")
  2.  
  3. --Variables
  4.  
  5.  
  6.  
  7. function alias_handler( input )
  8. end
  9.  
  10. --THIS IS THE PROMPT, leaving this in until I decide I don't need it for any of these I guess
  11. function prompt_handler()
  12. eq,bal = string.match(mb.line, "^H:%d+.*<([e-])([b-])")
  13. end
  14. mb.server_prompt = prompt_handler
  15.  
  16.  
  17.  
  18. function trigger_handler()
  19. end
  20. mb.server_line = trigger_handler
  21.  
  22.  
  23. function alias_handler( input )
  24. if string.match(input, "^truehonors %w+$") then
  25. local buffer = {}
  26. local c = curl.easy_init()
  27. c:setopt(curl.OPT_URL,'http://www.ironrealms.com/game/honors/Imperian/'..string.sub(input,12))
  28. c:setopt(curl.OPT_CONNECTTIMEOUT,'5')
  29. c:setopt(curl.OPT_WRITEFUNCTION,
  30. function (s, len) table.insert(buffer,s) return len end)
  31. res = c:perform()
  32. local pat = "Information about %w+ from Imperian.*Pk level: %d+"
  33. local stuffIwant = ""
  34. for i,v in ipairs(buffer) do if(string.match(v,pat)) then stuffIwant = string.match(v,pat) end end
  35. stuffIwant = string.gsub(stuffIwant,"</h3>","")
  36. stuffIwant = string.gsub(stuffIwant,"<[/]?div>","")
  37. stuffIwant = string.gsub(stuffIwant,"Imperian","Imperian\n")
  38. stuffIwant = string.gsub(stuffIwant,"Full name","\nFull name")
  39. stuffIwant = string.gsub(stuffIwant,"City","\nCity")
  40. stuffIwant = string.gsub(stuffIwant,"Guild","\nGuild")
  41. stuffIwant = string.gsub(stuffIwant,"Towne","\nTowne")
  42. stuffIwant = string.gsub(stuffIwant,"Level","\nLevel")
  43. stuffIwant = string.gsub(stuffIwant,"Bashing","\nBashing")
  44. stuffIwant = string.gsub(stuffIwant,"Questing","\nQuesting")
  45. stuffIwant = string.gsub(stuffIwant,"Pk","\nPk")
  46. echo(stuffIwant)
  47. return(true)
  48. elseif string.match(input, "^deathlog$") then
  49. local input = ""
  50. local c = curl.easy_init()
  51. c:setopt(curl.OPT_URL,'http://old.imperian.com/players.php?search=deathlog&day=0')
  52. c:setopt(curl.OPT_CONNECTTIMEOUT,'5')
  53. c:setopt(curl.OPT_WRITEFUNCTION,
  54. function (s, len) input = input..s return len end)
  55. res = c:perform()
  56. local output = ""
  57. local pat = "Player Deaths for Today.*</p"
  58. output = string.match(input,pat)
  59. --for i,v in ipairs(buffer) do if(string.match(v,pat)) then output = string.match(v,pat) end end
  60. output = string.gsub(output,"><p> ","\n ")
  61. output = string.gsub(output,"</p","")
  62. output = string.gsub(output,"</p>","")
  63. output = string.gsub(output,"<a href='/players\.php%?lookup=%w+'>","")
  64. output = string.gsub(output,"<a href='/players\.php%?lookup=%w+ %w+'>","")
  65. output = string.gsub(output,"<a href='/players\.php%?lookup=%w+ %w+ %w+'>","")
  66. output = string.gsub(output,"</a>","")
  67. output = string.gsub(output,"<br />","\n")
  68. echo(output)
  69. --echo(input)
  70. return(true)
  71. elseif string.match(input,"^checkdesc %w+$") then
  72. local buffer = {}
  73. name = string.sub(input,11):gsub("^%l", string.upper)
  74. local c = curl.easy_init()
  75. c:setopt(curl.OPT_URL,'http://old.imperian.com/players.php?lookup='..name..'&extra=description')
  76. c:setopt(curl.OPT_CONNECTTIMEOUT,'5')
  77. c:setopt(curl.OPT_WRITEFUNCTION,
  78. function (s, len) input = input..s return len end)
  79. res = c:perform()
  80. local pat = name.."'s Description.+</p></td>"
  81. local output = ""
  82. output = string.match(input,pat)
  83. output = string.gsub(output,"\n.*","")
  84. output = string.gsub(output,name.."'s Description.*>","")
  85. echo(output)
  86. return(true)
  87. elseif string.match(input,"^checkstatpack %w+$") then
  88. local buffer = {}
  89. name = string.sub(input,15):gsub("^%l", string.upper)
  90. local c = curl.easy_init()
  91. c:setopt(curl.OPT_URL,'http://old.imperian.com/players.php?lookup='..name..'&extra=description')
  92. c:setopt(curl.OPT_CONNECTTIMEOUT,'5')
  93. c:setopt(curl.OPT_WRITEFUNCTION,
  94. function (s, len) input = input..s return len end)
  95. res = c:perform()
  96. local pat = "e is an? %w+ %w+\."
  97. output = string.match(input,pat)
  98. output = string.gsub(output,"e is an? ","")
  99. echo(output)
  100. return(true)
  101. elseif string.match(input,"^checkworn %w+$") then
  102. local buffer = {}
  103. name = string.sub(input,11):gsub("^%l", string.upper)
  104. local c = curl.easy_init()
  105. c:setopt(curl.OPT_URL,'http://old.imperian.com/players.php?lookup='..name..'&extra=description')
  106. c:setopt(curl.OPT_CONNECTTIMEOUT,'5')
  107. c:setopt(curl.OPT_WRITEFUNCTION,
  108. function (s, len) input = input..s return len end)
  109. res = c:perform()
  110. local pat = "e is wearing .+</p></td>"
  111. output = string.match(input,pat)
  112. output = string.gsub(output,"e is wearing ","")
  113. output = string.gsub(output,"\n.*","")
  114. echo(output)
  115. return(true)
  116. elseif string.match(input,"^truewho$") then
  117. local buffer = {}
  118. local c = curl.easy_init()
  119. c:setopt(curl.OPT_URL,'http://old.imperian.com/players.php?search=who')
  120. c:setopt(curl.OPT_CONNECTTIMEOUT,'5')
  121. c:setopt(curl.OPT_WRITEFUNCTION,
  122. function (s, len) input = input..s return len end)
  123. res = c:perform()
  124. local pat = "Current Players Online: .+</a></td></tr></table>"
  125. output = string.match(input,pat)
  126. output = string.gsub(output,"</a></td></tr></table>","")
  127. output = string.gsub(output,"</a></td>","")
  128. output = string.gsub(output,"<td width='20%%'>",", ")
  129. output = string.gsub(output,"</strong>.+their name below\.",", ")
  130. output = string.gsub(output,"<a href='/players\.php%?lookup=%w+'>","")
  131. output = string.gsub(output,"</tr>","")
  132. output = string.gsub(output,"<tr>","")
  133. output = string.gsub(output,", </p>","")
  134. output = string.gsub(output,"<table width='100%%'>, ","")
  135. echo(output)
  136. return(true)
  137. elseif string.match(input,"^truewho %w+$") then
  138. local buffer = {}
  139. local name = string.sub(input,9)
  140. local output = ""
  141. local c = curl.easy_init()
  142. c:setopt(curl.OPT_URL,'http://old.imperian.com/players.php?search=who')
  143. c:setopt(curl.OPT_CONNECTTIMEOUT,'5')
  144. c:setopt(curl.OPT_WRITEFUNCTION,
  145. function (s, len) output = output..s return len end)
  146. res = c:perform()
  147. if (string.match(output,name)) then
  148. echo("That person is online.")
  149. else
  150. echo("That person is not online.")
  151. end
  152. return(true)
  153. end
  154. end
  155. mb.client_aliases = alias_handler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement