Skip to content

Instantly share code, notes, and snippets.

@imbriaco
Last active February 19, 2016 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imbriaco/43e66845040671729279 to your computer and use it in GitHub Desktop.
Save imbriaco/43e66845040671729279 to your computer and use it in GitHub Desktop.
Cog Sneak Peek

Cog Sneak Peek

This is just a quick example of what adding a very simple shell script as a Cog command would look like. Everything is a work in progress at this stage of alpha and this command does not make use of many of the advanced features in Cog, but I thought folks might find it interesting.

This is a representation of what it would look like if I (@imbriaco) were talking to a bot named cog that was running this bundle.

imbriaco: @cog: simple foo bar baz
cog:

ARG[0]: foo
ARG[1]: bar
ARG[2]: baz

imbriaco: @cog: echo "Hello world" | simple $body
cog:

ARG[0]: Hello world

imbriaco: @cog: seed '{"foo": "foo value", "bar": "bar value"}' | simple $foo $bar
cog:

ARG[0]: foo value
ARG[1]: bar value

Notes

Files:

  • simple.json - This is the configuration file that Cog uses to configure a "Bundle" of commands for use in the bot.
  • simple.sh - The script that is referred to by the config file.
{
"bundle": {
"name": "mybundle",
"type": "foreign"
},
"commands": [
{
"name": "simple",
"version": "0.1",
"executable": "/path/to/simple.sh",
"enforcing": false,
"calling_convention": "bound",
"documentation": "do something simple",
"options": [],
"env_vars": {}
}
],
"templates": [],
"permissions": [],
"rules": []
}
#!/bin/bash
echo '```'
for arg in `seq 0 $((${COG_ARGC} - 1))` ; do
eval value=\$$"COG_ARGV_${arg}"
echo "ARG[${arg}]: ${value}"
done
echo '```'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment