Skip to content

Commit

Permalink
Armory fixes, notice fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tecnobrat committed Aug 6, 2010
1 parent c294688 commit 19015c9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
29 changes: 29 additions & 0 deletions core/includes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,33 @@ def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
end
end

def html2text(html)
text = html.
gsub(/( |\n|\s)+/im, ' ').squeeze(' ').strip.
gsub(/<([^\s]+)[^>]*(src|href)=\s*(.?)([^>\s]*)\3[^>]*>\4<\/\1>/i, '\4')

links = []
linkregex = /<[^>]*(src|href)=\s*(.?)([^>\s]*)\2[^>]*>\s*/i
while linkregex.match(text)
links << $~[3]
text.sub!(linkregex, "[#{links.size}]")
end

text = CGI.unescapeHTML(
text.
gsub(/<(script|style)[^>]*>.*<\/\1>/im, '').
gsub(/<!--.*-->/m, '').
gsub(/<hr(| [^>]*)>/i, "___\n").
gsub(/<li(| [^>]*)>/i, "\n* ").
gsub(/<blockquote(| [^>]*)>/i, '> ').
gsub(/<(br)(| [^>]*)>/i, "\n").
gsub(/<(\/h[\d]+|p)(| [^>]*)>/i, "\n\n").
gsub(/<[^>]*>/, '')
).lstrip.gsub(/\n[ ]+/, "\n") + "\n"

for i in (0...links.size).to_a
text = text + "\n [#{i+1}] <#{CGI.unescapeHTML(links[i])}>" unless links[i].nil?
end
links = nil
text
end
3 changes: 2 additions & 1 deletion modules/wow/config/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ greed:
command: "ArmoryModule.greed"
num_args: 3
notices:
help: "Wow Breaking News Displayer The format for @notices is '@notices'."
help: "Wow Breaking News Displayer The format for @notices is '@notices <us/eu>'."
regex: '^(us|eu)'
command: "WowModule.notices"
32 changes: 17 additions & 15 deletions modules/wow/core/wow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,28 @@ def self.realmstatus(args, event)
end

def self.notices(args, event)
return getnotices
if args =~ /^(us|eu|US|EU)$/
if $1 == "us" or $1 == "US"
return getnotices("http://launcher.worldofwarcraft.com/alert")
else
return getnotices("http://status.wow-europe.com/en/alert")
end
end
return false
end

def self.getnotices
def self.getnotices(url)
output = ""
number = 0
url = URI.parse('http://launcher.worldofwarcraft.com/alert').to_s
url = URI.parse(url).to_s
doc = RemoteRequest.new("get").read(url)
doc = doc.gsub(/\<br \/\>\<br \/\>/, "\n")
doc = doc.gsub(/\<br \/\>/, "\n")
doc = html2text(doc)
doc.split("\n").each do |line|
unless line == "SERVERALERT:" or line == ""
if line =~ /^\[.*\]$/
number = number + 1
line = line + " - "
end
return output if number > 1
output = output + line
end
line = line.gsub(/SERVERALERT\:/, "")
output = output + line
end
return output
return output.strip
end

def self.getrealmstatus_us
Expand Down Expand Up @@ -115,7 +118,7 @@ def self.getrealmstatus_eu
up = 0
down = 0
armoryinfo.elements.each('/rss/channel/item') do |item|
i=i+1
i=i+1 unless item.elements['category'].nil?
status = item.elements['description'].text
if status =~ /^(.*) - Realm Up - (.*)$/
up=up+1
Expand All @@ -128,4 +131,3 @@ def self.getrealmstatus_eu
return false
end
end

0 comments on commit 19015c9

Please sign in to comment.