gchiu / rebolbot

A stackoverflow chat bot for Rebol
20 stars 6 forks source link

Check for a valid extension when loading commands #28

Closed AstDerek closed 11 years ago

AstDerek commented 11 years ago

Some systems might create some hidden files (like .DS_Store files under Mac OS X), causing the script to fail.

Commands can now be deactivated by changing the extension.

johnk- commented 11 years ago

My 2c are that AstDerek's approach offers a simple solution with the minimum effort. I agree that using the header would probably be cleaner, especially when we have more scripts, but it would also not be perfect in all circumstances. Take the example of a text editor that stores a temporary backup of the file you are currently editing in the same directory. This would have the correct header, but would probably have the wrong extension such as tmp. I guess implementing both changes would probably be most complete. More concisely, I think it is a useful merge.

asampal commented 11 years ago

I agree, a header check can be done in addition to this check, so the merge would be useful as it stands.

AstDerek commented 11 years ago

Which header block/path would be the best to validate a file? I now have this:

do sync-commands: func [] [
    clear head lib/commands: []
    foreach command read command-dir [
        if system/options/default-suffix = suffix? command [
            header: load/header rejoin [command-dir command]
            if true = attempt ['bot-api = header/1/needs/1] [
                append lib/commands cmd: import/no-lib rejoin [command-dir command]
            ]
        ]
    ]
]