lib/ruboty/handlers/fop.rb in ruboty-fop-0.0.2 vs lib/ruboty/handlers/fop.rb in ruboty-fop-0.0.3
- old
+ new
@@ -36,12 +36,12 @@
CARD:
#{fop.valid_cards.map { |_| "- `#{_.code}` #{_.name}" }.join("\n")}
CLASS: #{fop.valid_dom_classes.map { |_| "`#{_.code}` #{_.name}" }.join(", ")}
FARE:
-#{fop.valid_dom_fares.map { |_| "- dom: `#{_.code}` #{_.name}: #{_.remark}" }.join("\n")}
-#{fop.valid_intl_fares.map { |_| "- intl: `#{_.code}` #{_.name}: #{_.remark}" }.join("\n")}
+#{fop.valid_dom_fares.map { |_| "- dom: `#{_.code}` #{_.name}: #{_.remark.gsub(/\*|_/,'')}" }.join("\n")}
+#{fop.valid_intl_fares.map { |_| "- intl: `#{_.code}` #{_.name}: #{_.remark.gsub(/\*|_/,'')}" }.join("\n")}
EOF
rescue ::Fop::Error
message.reply e.inspect
rescue StandardError => e
message.reply e.inspect
@@ -126,19 +126,19 @@
message.reply <<-EOF
#{from.code} (#{from.name}) - #{to.code} (#{to.name})
#{klass ? "#{klass.name}, " : nil}#{fare.name}, #{status.name} (#{card.name})
-*single-trip #{result.miles} miles, #{result.fop} FOP*
-*round-trip #{result.miles * 2} miles, #{result.fop * 2} FOP*
+#{bold}single-trip #{result.miles} miles, #{result.fop} FOP#{bold}
+#{italic}round-trip #{result.miles * 2} miles, #{result.fop * 2} FOP#{italic}
-Mileage:
-- #{result.flight_miles} (#{result.flight_miles_remark})
-#{result.bonus_miles ? "- #{result.bonus_miles} (#{result.bonus_miles_remark})" : nil}
-FOP:
-- #{result.flight_miles} * #{result.fop_rate}
-#{result.fop_bonus ? "- #{result.fop_bonus } (#{result.fop_bonus_remark})" : nil}
+#{bold}Mileage:#{bold}
+- #{result.flight_miles} (#{result.flight_miles_remark.gsub(/\*|_/,'')})
+#{result.bonus_miles ? "- #{result.bonus_miles} (#{result.bonus_miles_remark.gsub(/\*|_/,'')})" : nil}
+#{bold}FOP:#{bold}
+#{result.flight_miles} x #{result.fop_rate}
+#{result.fop_bonus ? "- #{result.fop_bonus } (#{result.fop_bonus_remark.gsub(/\*|_/,'')})" : nil}
EOF
rescue ::Fop::Error => e
message.reply e.message
rescue StandardError => e
message.reply e.inspect
@@ -189,11 +189,11 @@
end
def find_dom_fare(str)
fare = fop.valid_dom_fares.find { |_| _.code == str }
unless fare
- list = fop.valid_dom_fares.map { |_| "- `#{_.code}` #{_.name}: #{_.remark}" }.join("\n")
+ list = fop.valid_dom_fares.map { |_| "- `#{_.code}` #{_.name}: #{_.remark.gsub(/\*|_/,'')}" }.join("\n")
if str
raise ::Fop::Error, "fare #{str.inspect} is not valid\n#{list}"
else
raise ::Fop::Error, "fare is required\n#{list}"
end
@@ -202,11 +202,11 @@
end
def find_intl_fare(str)
fare = fop.valid_intl_fares.find { |_| _.code == str }
unless fare
- list = fop.valid_intl_fares.map { |_| "- `#{_.code}` #{_.name}: #{_.remark}" }.join("\n")
+ list = fop.valid_intl_fares.map { |_| "- `#{_.code}` #{_.name}: #{_.remark.gsub(/\*|_/,'')}" }.join("\n")
if str
raise ::Fop::Error, "fare #{str.inspect} is not valid\n#{list}"
else
raise ::Fop::Error, "fare is required\n#{list}"
end
@@ -245,9 +245,23 @@
(robot.brain.data['fop.preference'] ||= {})[u] ||= {}
end
def parse_options(str)
str&.scan(/-(.+?) (.+?)(?:\s+|$)/)&.map{ |_| [_[0].to_sym, _[1]] }.to_h || {}
+ end
+
+ def bold
+ markdown? ? '**' : '*'
+ end
+
+ def italic
+ '_'
+ end
+
+ def markdown?
+ return @use_markdown if @markdown_detected
+ @markdown_detected = true
+ @use_markdown = ENV['RUBOTY_FOP_MARKDOWN'] || Ruboty::AdapterBuilder.adapter_classes.last.name.include?('Discord')
end
end
end
end