+
+ class Failure
+ STRING = "template %{template} failed to recognize message %{message}"
+ FRIENDLY = "I failed to understand the command"
+ attr_reader :template
+ attr_reader :message
+ def initialize(tmpl, msg)
+ @template = tmpl
+ @message = msg
+ end
+
+ def to_s
+ STRING % {
+ :template => template.template,
+ :regexp => template.regexp,
+ :message => message.message,
+ :action => template.options[:action]
+ }
+ end
+ end
+
+ # failures with a friendly message
+ class FriendlyFailure < Failure
+ def friendly
+ self.class::FRIENDLY rescue FRIENDLY
+ end
+ end
+
+ class NotPrivateFailure < FriendlyFailure
+ STRING = "template %{template} is not configured for private messages"
+ FRIENDLY = "the command must not be given in private"
+ end
+
+ class NotPublicFailure < FriendlyFailure
+ STRING = "template %{template} is not configured for public messages"
+ FRIENDLY = "the command must not be given in public"
+ end
+
+ class NoMatchFailure < Failure
+ STRING = "%{message} does not match %{template} (%{regex})"
+ end
+
+ class PartialMatchFailure < Failure
+ STRING = "%{message} only matches %{template} (%{regex}) partially"
+ end
+
+ class NoActionFailure < FriendlyFailure
+ STRING = "%{template} calls undefined action %{action}"
+ FRIENDLY = "uh-ho, somebody forgot to tell me how to do that ..."
+ end
+