Marc-Alexandre Chan avatar Marc-Alexandre Chan committed 246cccc

Fix NameError; fix parameter-less messages needing to be blank (reddit doesn't allow)

Comments (0)

Files changed (3)

minibot/commands.txt

 
     There's a _huge_ mirror. Something about your character and mirrors.
 
-Note that you must _only_ use single newlines between parameters, even though
+You must _only_ use single newlines between parameters, even though
 single newlines do not appear in the message after you send it (it'll look like
 one big line/paragraph). A double newline indicates the end of the parameters
 and the beginning of the "text block" parameter (e.g. for the text of the prompt
 to add or update in the queue).
 
+If there is _only_ a text block parameter, leave the first line of the message
+blank. If there are _no_ parameters (either named or text block), then type
+_only_ the name of the command in the message.
+
 The date/time are in the server's local time, which is the U.S. Eastern Time
 (with Daylight Savings Time applied according to the U.S. dates).
 
+
 ___
 
 ## 2 Commands
 
 ### help
 
-Returns this help message.
+Returns this help message. The command message should have the word 'help' as
+the first line of the body.
 
 ___
 
 ## Appendix A Private Message Command Specification
 
-1. The subject line of the message shall be the command name.
+1. a. The subject line of the message shall be the command name.
+   b. The first line of the message may be the command name. (This is provided
+      to allow commands without parameters to be issued, as Reddit does not
+      allow empty messages.)
 2. a. The message may specify additional parameters, one per line.
    b. Exactly one parameter shall be specified per additional line. A blank line
       between parameters is not permitted.
    c. Parameters not marked 'optional' for a given command must be specified.
    d. Parameter lines shall take the form `name: value` or `name = value`.
       Whitespace rules are defined in (3).
-   e. Parameter values may contain the characters `:` and `=`, but shall not
-      contain newlines.
+   e. Parameter names shall not contain the characters ':', '=', or newlines.
+   f. Parameter values may contain the characters `:` and `=`.
+   g. Parameter values shall not contain newlines.
 3. a. Whitespace shall be ignored at the beginning or end of the message, at the
       beginning and end of a line, and around the characters `:` and `=` when
       used to specify an attribute.
    b. Whitespace shall be maintained within within a parameter's value.
 4. a. A command may optionally specify a "text block" parameter.
-   b. A text block must be identified by two newlines after a parameter line.
+   b. A text block must be identified by two newlines after a parameter line or
+      one newline at the beginning of the message.
    c. The text block constitutes the entirety of the text from the two newlines
       described in (4b) to the end of the private message. Whitespace is handled
       as in (3b).
-   d. The text block shall not formally named.
+   d. The text block shall not named (in a name = value pair).
    e. Parameters cannot be specified after a text block.
-5. All date and time parameters are in server local time. This should currently
-   be U.S. Eastern Time with Daylight Savings applied according to the U.S.
-   dates.
+5. All date and time parameters are in server local time.

minibot/events.py

                 break
 
             elif state == self.PARSE_FIELD:
-                # ignore whitespace around line
-                line = line.strip()
+                line = line.strip() # ignore whitespace around line
+
                 # if not blank, parse as field
                 if line:
                     try:
                         field_data = self._parse_field(line)
+                        msg_data[field_data[0].lower()] = field_data[1]
                     except CommandParseError as e:
-                        raise CommandParseError('Parse error in {info}: {error}'.
-                        format(info=self._exc_msg_data(msg), error=str(e)))
-                    msg_data[field_data[0].lower()] = field_data[1]
+                        # if first line and is the action name, ignore
+                        if not msg_data and line == msg.subject.strip().lower():
+                            continue
+                        # otherwise it's a parse error
+                        raise CommandParseError(
+                            'Parse error in {info}: {error}'.format(\
+                            info=self._exc_msg_data(msg), error=str(e)))
                 # else if blank line, denotes the start of text data
                 else:
                     state = self.PARSE_TEXT
         self.title = subject
         self.text = text
 
-        if not isinstance(self.msg, reddit.objects.Inboxable):
+        if not isinstance(self.msg, self.res['reddit'].objects.Inboxable):
             raise MissingParameterError(
                 'Cannot send reply without original message.')
         if not text:

minibot/events.txt

 ## Exception handling
 
 If an exception is thrown during a start(), run() or end() call, the exception
-will be caught by the scheduler, logged, and then the event's
-handle_exception(self, exc_obj).
+will be caught by the scheduler, logged, and then call the event's
+handle_exception method.
 
 ``self.owner.EXC_HANDLED_RETRY`` indicates that the exception was handled and
 that the Scheduler may retry executing the event in ``self.delay`` seconds;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.