Permalink
Browse files

Remove threads and clean up errors.

Signed-off-by: Jordon Bedwell <jordon@envygeeks.com>
  • Loading branch information...
1 parent d7583dc commit 1090d7b37af642fb06e010bc5eb73f30349d038c @envygeeks envygeeks committed Feb 13, 2012
Showing with 48 additions and 50 deletions.
  1. +48 −50 pry_bot
View
98 pry_bot
@@ -60,71 +60,69 @@ Cinch::Bot.new do
on :message, /\Ashow-(doc|method)\s(.+)/ do |message, command, meth|
begin
Timeout.timeout 5 do
- Thread.new(message, command, meth) do |message, command, meth|
- begin
- if meth.split(/\s/).length > 1
- message.reply 'One command at a time please.'
- else
- out = StringIO.new
- IO.popen('pry --no-color --no-history --no-pager --simple-prompt','r+') do |io|
- io.puts "show-#{command} #{meth}"
- io.close_write
- out.puts io.read
- end
+ begin
+ if meth.split(/\s/).length > 1
+ message.reply 'One command at a time please.'
+ else
+ out = StringIO.new
+ IO.popen('pry --no-color --no-history --no-pager --simple-prompt','r+') do |io|
+ io.puts "show-#{command} #{meth}"
+ io.close_write
+ out.puts io.read
+ end
- if out !~ /\A>>\s*Error/
- out = out.string.split(/\n/)[2..-1]
- file = out[0].split[1].split(/\//).last
- desc = out[0].split(/:/)[1].split(/\//).last
+ if out !~ /\A>>\s*Error/
+ out = out.string.split(/\n/)[2..-1]
+ file = out[0].split[1].split(/\//).last
+ desc = out[0].split(/:/)[1].split(/\//).last
- if command == 'method'
- comment = '#'
- if file.split('.').last == 'c' || file.split('.').last == 'h'
- comment = '//'
- end
-
- out = out.map.with_index do |value, iteration|
- if iteration <= 4 && !value.empty? && value =~ /\A[a-zA-Z\s{1}]+:\s.*/
- value = "#{comment} #{value}"
- end
+ if command == 'method'
+ comment = '#'
+ if file.split('.').last == 'c' || file.split('.').last == 'h'
+ comment = '//'
+ end
- value
+ out = out.map.with_index do |value, iteration|
+ if iteration <= 4 && !value.empty? && value =~ /\A[a-zA-Z\s{1}]+:\s.*/
+ value = "#{comment} #{value}"
end
- else
- file = file.gsub /\.[a-z\-_0-9]+\Z/, '.rdoc'
- out = out.map.with_index do |value, iteration|
- if iteration <= 4 && !value.empty? && value =~ /\A[a-zA-Z\s{1}]+:\s.*/
- value = " #{value}"
- end
-
- value
+
+ value
+ end
+ else
+ file = file.gsub /\.[a-z\-_0-9]+\Z/, '.rdoc'
+ out = out.map.with_index do |value, iteration|
+ if iteration <= 4 && !value.empty? && value =~ /\A[a-zA-Z\s{1}]+:\s.*/
+ value = " #{value}"
end
+
+ value
end
+ end
- final_output = Gistme.create_gist(file, desc, out[1..-1].join("\n"))
- if final_output =~ /\Ahttp/
- message.reply final_output
+ final_output = Gistme.create_gist(file, desc, out[1..-1].join("\n"))
+ if final_output =~ /\Ahttp/
+ message.reply final_output
- if meth =~ /\APry/i && command == 'doc'
- message.reply 'If this doc is ugly please submit a ticket for a format fix.'
- end
- else
- raise
+ if meth =~ /\APry/i && command == 'doc'
+ message.reply 'If this doc is ugly please submit a ticket for a format fix.'
end
else
- # Not Found, more than likely....
- message.reply 'Unknown document.'
+ raise
end
+ else
+ log.info "Unknown #{meth}"
+ message.reply 'Could not find the information you requested.'
end
- rescue => error
- log.fatal error
- message.reply 'Game over: FATALITY!!'
end
+ rescue => error
+ log.fatal error
+ message.reply 'An error has occured, cannot continue.'
end
end
- rescue Timeout::Error
- log.fatal 'MASTER EGMONIT PLEASE KILL ME FOR I HAVE MADE A CRITICAL MISTAKE.'
- message.reply "CRITICAL ERROR: I'm obligated by master EGMONIT to ask only for death."
+ rescue Timeout::Error => error
+ log.fatal error
+ message.reply 'Execution has tried to extend beyond the timeout, killed.'
end
end

0 comments on commit 1090d7b

Please sign in to comment.