Skip to content

Commit 73d0c59

Browse files
committed
auto-emote: document lua interface
1 parent e683ad3 commit 73d0c59

File tree

3 files changed

+225
-33
lines changed

3 files changed

+225
-33
lines changed

README.mdwn

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,72 @@ DENTISTRY SYMBOL LIGHT VERTICAL AND BOTTOM LEFT
110110

111111
`auto-emote` comments to discord and reacts to all messages with vaguely related emoji.
112112

113+
The following env vars should be set:
114+
115+
* LM_DROPBOX_TOKEN should be set to load a responses.json.
116+
* LM_BOT_LUA_PATH should be set to the location of lua to process emoji data within dropbox.
117+
* LM_DISCORD_TOKEN should be set for this to actually function.
118+
119+
Here's an example of lua code that works for this:
120+
121+
if es:messagematches("cronos") then
122+
es:addrequired("👶")
123+
es:addrequired("🥘")
124+
end
125+
126+
The lua code has a global var called `es` (for emoji set) and an imported
127+
package called `turtleemoji`. `es` is how you access the current message,
128+
currently added emoji, etc. Here are the methods on `es`:
129+
130+
#### `es:addoptional("💀")`
131+
132+
Adds an emoji to randomly include in the reaction.
133+
134+
#### `es:hasoptional("💀") // bool`
135+
136+
Returns true of the passed emoji is in the list of optional emoji to include
137+
(at random) on the reaction.
138+
139+
#### `es:removeoptional("💀")`
140+
141+
Remove the passed emoji from the optionally included emoji.
142+
143+
#### `es:hasrequired("💀")` // bool
144+
145+
Returns true if the passed emoji is going to be included in the reaction.
146+
147+
#### `es:addrequired("💀")`
148+
149+
Add an emoji to the reaction.
150+
151+
#### `es:removerequired("💀")`
152+
153+
Remove an emoji that is going to be included in the reaction.
154+
155+
#### `es:message()` // string
156+
157+
Returns the message that triggered the reaction.
158+
159+
#### `es:messagematches("regexp")` // bool
160+
161+
True if the message matches the passed regex.
162+
[Docs for regex syntax are here](https://golang.org/pkg/regexp/syntax/).
163+
164+
#### `es:hasword("word")` // bool
165+
166+
True if the word is included in the message. Tokenization of words happens on
167+
all non-alpha characters and the message is lowerecased.
168+
169+
All of the following are thin veneers atop
170+
[github.com/hackebrot/turtle](https://github.com/hackebrot/turtle):
171+
172+
* `turtle.findbyname("skull")` // turtleemoji
173+
* `turtle.findbychar("💀")` // turtleemoji
174+
* `turtleemoji#name()` // string
175+
* `turtleemoji#category()` // string
176+
* `turtleemoji#char()` // string
177+
* `turtleemoji#haskeyword("keyword")` // bool
178+
113179
### `backlight`
114180

115181
`backlight` is a faster version of `xbacklight` by directly writing to `/sys`. Example:

help_generated.go

Lines changed: 99 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,72 @@ DENTISTRY SYMBOL LIGHT VERTICAL AND BOTTOM LEFT
111111
112112
` + "`" + `auto-emote` + "`" + ` comments to discord and reacts to all messages with vaguely related emoji.
113113
114+
The following env vars should be set:
115+
116+
* LM_DROPBOX_TOKEN should be set to load a responses.json.
117+
* LM_BOT_LUA_PATH should be set to the location of lua to process emoji data within dropbox.
118+
* LM_DISCORD_TOKEN should be set for this to actually function.
119+
120+
Here's an example of lua code that works for this:
121+
122+
if es:messagematches("cronos") then
123+
es:addrequired("👶")
124+
es:addrequired("🥘")
125+
end
126+
127+
The lua code has a global var called ` + "`" + `es` + "`" + ` (for emoji set) and an imported
128+
package called ` + "`" + `turtleemoji` + "`" + `. ` + "`" + `es` + "`" + ` is how you access the current message,
129+
currently added emoji, etc. Here are the methods on ` + "`" + `es` + "`" + `:
130+
131+
#### ` + "`" + `es:addoptional("💀")` + "`" + `
132+
133+
Adds an emoji to randomly include in the reaction.
134+
135+
#### ` + "`" + `es:hasoptional("💀") // bool` + "`" + `
136+
137+
Returns true of the passed emoji is in the list of optional emoji to include
138+
(at random) on the reaction.
139+
140+
#### ` + "`" + `es:removeoptional("💀")` + "`" + `
141+
142+
Remove the passed emoji from the optionally included emoji.
143+
144+
#### ` + "`" + `es:hasrequired("💀")` + "`" + ` // bool
145+
146+
Returns true if the passed emoji is going to be included in the reaction.
147+
148+
#### ` + "`" + `es:addrequired("💀")` + "`" + `
149+
150+
Add an emoji to the reaction.
151+
152+
#### ` + "`" + `es:removerequired("💀")` + "`" + `
153+
154+
Remove an emoji that is going to be included in the reaction.
155+
156+
#### ` + "`" + `es:message()` + "`" + ` // string
157+
158+
Returns the message that triggered the reaction.
159+
160+
#### ` + "`" + `es:messagematches("regexp")` + "`" + ` // bool
161+
162+
True if the message matches the passed regex.
163+
[Docs for regex syntax are here](https://golang.org/pkg/regexp/syntax/).
164+
165+
#### ` + "`" + `es:hasword("word")` + "`" + ` // bool
166+
167+
True if the word is included in the message. Tokenization of words happens on
168+
all non-alpha characters and the message is lowerecased.
169+
170+
All of the following are thin veneers atop
171+
[github.com/hackebrot/turtle](https://github.com/hackebrot/turtle):
172+
173+
* ` + "`" + `turtle.findbyname("skull")` + "`" + ` // turtleemoji
174+
* ` + "`" + `turtle.findbychar("💀")` + "`" + ` // turtleemoji
175+
* ` + "`" + `turtleemoji#name()` + "`" + ` // string
176+
* ` + "`" + `turtleemoji#category()` + "`" + ` // string
177+
* ` + "`" + `turtleemoji#char()` + "`" + ` // string
178+
* ` + "`" + `turtleemoji#haskeyword("keyword")` + "`" + ` // bool
179+
114180
### ` + "`" + `backlight` + "`" + `
115181
116182
` + "`" + `backlight` + "`" + ` is a faster version of ` + "`" + `xbacklight` + "`" + ` by directly writing to ` + "`" + `/sys` + "`" + `. Example:
@@ -505,70 +571,70 @@ func init() {
505571

506572
"alluni": readme[2642:3468],
507573

508-
"auto-emote": readme[3468:3575],
574+
"auto-emote": readme[3468:5561],
509575

510-
"backlight": readme[3575:3777],
576+
"backlight": readme[5561:5763],
511577

512-
"clocks": readme[3777:3993],
578+
"clocks": readme[5763:5979],
513579

514-
"csv2json": readme[3993:4133],
580+
"csv2json": readme[5979:6119],
515581

516-
"csv2md": readme[4133:4207],
582+
"csv2md": readme[6119:6193],
517583

518-
"debounce": readme[4207:4551],
584+
"debounce": readme[6193:6537],
519585

520-
"dump-mozlz4": readme[4551:4734],
586+
"dump-mozlz4": readme[6537:6720],
521587

522-
"email2json": readme[4734:5449],
588+
"email2json": readme[6720:7435],
523589

524-
"expand-url": readme[5449:5625],
590+
"expand-url": readme[7435:7611],
525591

526-
"export-bamboohr": readme[5625:5709],
592+
"export-bamboohr": readme[7611:7695],
527593

528-
"export-bamboohr-tree": readme[5709:5796],
594+
"export-bamboohr-tree": readme[7695:7782],
529595

530-
"fn": readme[5796:5932],
596+
"fn": readme[7782:7918],
531597

532-
"group-by-date": readme[5932:6150],
598+
"group-by-date": readme[7918:8136],
533599

534-
"minotaur": readme[6150:7969],
600+
"minotaur": readme[8136:9955],
535601

536-
"name2rune": readme[7969:8074],
602+
"name2rune": readme[9955:10060],
537603

538-
"netrc-password": readme[8074:8239],
604+
"netrc-password": readme[10060:10225],
539605

540-
"notes": readme[8239:8375],
606+
"notes": readme[10225:10361],
541607

542-
"pomotimer": readme[8375:8867],
608+
"pomotimer": readme[10361:10853],
543609

544-
"prepend-hist": readme[8867:9108],
610+
"prepend-hist": readme[10853:11094],
545611

546-
"proj": readme[9108:10427],
612+
"proj": readme[11094:12413],
547613

548-
"render-mail": readme[10427:10561],
614+
"render-mail": readme[12413:12547],
549615

550-
"replace-unzip": readme[10561:10791],
616+
"replace-unzip": readme[12547:12777],
551617

552-
"slack-deaddrop": readme[10791:11011],
618+
"slack-deaddrop": readme[12777:12997],
553619

554-
"slack-open": readme[11011:11145],
620+
"slack-open": readme[12997:13131],
555621

556-
"slack-status": readme[11145:11290],
622+
"slack-status": readme[13131:13276],
557623

558-
"sm-list": readme[11290:11566],
624+
"sm-list": readme[13276:13552],
559625

560-
"srv": readme[11566:12049],
626+
"srv": readme[13552:14035],
561627

562-
"status": readme[12049:12506],
628+
"status": readme[14035:14492],
563629

564-
"toml2json": readme[12506:12681],
630+
"toml2json": readme[14492:14667],
565631

566-
"uni": readme[12681:12843],
632+
"uni": readme[14667:14829],
567633

568-
"update": readme[12843:13066],
634+
"update": readme[14829:15052],
569635

570-
"yaml2json": readme[13066:13143],
636+
"yaml2json": readme[15052:15129],
571637

572-
"zine": readme[13143:13199],
638+
"zine": readme[15129:15185],
573639
}
574640
}

internal/tool/automoji/automoji.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,66 @@ The following env vars should be set:
3939
* LM_BOT_LUA_PATH should be set to the location of lua to process emoji data within dropbox.
4040
* LM_DISCORD_TOKEN should be set for this to actually function.
4141
42+
Here's an example of lua code that works for this:
43+
44+
if es:messagematches("cronos") then
45+
es:addrequired("👶")
46+
es:addrequired("🥘")
47+
end
48+
49+
The lua code has a global var called `es` (for emoji set) and an imported
50+
package called `turtleemoji`. `es` is how you access the current message,
51+
currently added emoji, etc. Here are the methods on `es`:
52+
53+
#### `es:addoptional("💀")`
54+
55+
Adds an emoji to randomly include in the reaction.
56+
57+
#### `es:hasoptional("💀") // bool`
58+
59+
Returns true of the passed emoji is in the list of optional emoji to include
60+
(at random) on the reaction.
61+
62+
#### `es:removeoptional("💀")`
63+
64+
Remove the passed emoji from the optionally included emoji.
65+
66+
#### `es:hasrequired("💀")` // bool
67+
68+
Returns true if the passed emoji is going to be included in the reaction.
69+
70+
#### `es:addrequired("💀")`
71+
72+
Add an emoji to the reaction.
73+
74+
#### `es:removerequired("💀")`
75+
76+
Remove an emoji that is going to be included in the reaction.
77+
78+
#### `es:message()` // string
79+
80+
Returns the message that triggered the reaction.
81+
82+
#### `es:messagematches("regexp")` // bool
83+
84+
True if the message matches the passed regex.
85+
[Docs for regex syntax are here](https://golang.org/pkg/regexp/syntax/).
86+
87+
#### `es:hasword("word")` // bool
88+
89+
True if the word is included in the message. Tokenization of words happens on
90+
all non-alpha characters and the message is lowerecased.
91+
92+
All of the following are thin veneers atop
93+
[github.com/hackebrot/turtle](https://github.com/hackebrot/turtle):
94+
95+
* `turtle.findbyname("skull")` // turtleemoji
96+
* `turtle.findbychar("💀")` // turtleemoji
97+
* `turtleemoji#name()` // string
98+
* `turtleemoji#category()` // string
99+
* `turtleemoji#char()` // string
100+
* `turtleemoji#haskeyword("keyword")` // bool
101+
42102
Command: auto-emote
43103
*/
44104
func Run(args []string, _ io.Reader) error {

0 commit comments

Comments
 (0)