A modular, command driven Twitter bot, currently only generating visualizations of L-Systems, though easily adaptable for more interesting purposes.
- Configurable poll time (not using streaming api (yet))
- Can send media tweets (w/ image attachments)
- Keeps track of last processed tweet ID (to avoid duplicates)
- Adds proper source tweet ID for replies
Overall tweet syntax is:
@botname command,command-specific-arguments
Example tweet to generate an L-System visualization (note: the bot is not running 24/7 at the moment):
@thingybot lsys,#fff,16,60,90:s=a,a=a+b+,b=-a-b
The overall format for the lsys
command is: header:rules
, where
header
is a comma separated list of:
- CSS hex color string
- Number of iterations
- Start angle
- Rotation angle
A ruleset is a comma separated list of single letter rule IDs an
their replacements. The ruleset must contain a rule named s
-
the start rule (axiom, also see above example).
E.g. s=f-f-f-fs
defines a rule named s
which is iteratively
expanded into:
f-f-f-fs
f-f-f-ff-f-f-fs
f-f-f-ff-f-f-ff-f-f-fs
etc.
Other rule symbols are:
f
- forward (draw line)-
- rotate left+
- rotate right[
- store state (e.g. for branching)]
- pop state (end branch)
Run-length encoding can be used for multiple consecutive symbols (to
save precious char counts), e.g. 5+
expands to +++++
. Only the
single-digit numbers 2
- 9
can be used for this purpose.
Furthermore, the symbols a
- e
can be used as markers or for more
complex, mutually recursive replacements and each also execute an
implicit forward motion. The symbols x
,y
,z
are similar too, but
do not incl. a forward motion.
For security reasons the bot will refuse to execute systems expanding to more than 1 million symbols.
If there're any syntax errors, you'll most likely get a text-only reply telling you so, or if the error is more subtle, receive an image based on default values for the ones which were unspecified or contained errors (e.g. header settings, missing rules).
First edit launch-sample.sh
and add your Twitter API details (see
below). Save file as launch.sh
, then launch via:
./launch.sh repl
In the REPL kick off with:
;; start bot w/ 60s poll interval
;; (shorter periods will trigger Twitter's API rate limit)
(def bot (run state 60000))
;; `bot` is a control channel, which should be closed to stop the bot
(close! bot)
- Go to: https://apps.twitter.com/
- Create new app (don't need callback URL)
- Copy Consumer key/secret & Access token/secret into
launch-sample.sh
- Change the bot user name
Copyright © 2015 Karsten Schmidt
Distributed under the Apache Software License 2.0.