@@ -37,6 +37,7 @@ The following env vars should be set:
3737
3838 * LM_DROPBOX_TOKEN should be set to load a responses.json.
3939 * LM_RESPONSES_PATH should be set to the location of responses.json within dropbox.
40+ * LM_BOT_LUA_PATH should be set to the location of lua to process emoji data within dropbox.
4041 * LM_DISCORD_TOKEN should be set for this to actually function.
4142
4243Command: auto-emote
@@ -55,16 +56,30 @@ func Run(args []string, _ io.Reader) error {
5556 matchersMu .Unlock ()
5657 return err
5758 }
59+ if lp := os .Getenv ("LM_BOT_LUA_PATH" ); lp != "" {
60+ luaC , err = loadLua (dbCl , lp )
61+ if err != nil {
62+ matchersMu .Unlock ()
63+ return err
64+ }
65+ }
5866 matchersMu .Unlock ()
5967 }
6068 if len (args ) > 1 {
6169 for _ , arg := range args [1 :] {
62- fmt .Println (newEmojiSet (arg ).all (0 ))
70+ es := newEmojiSet (arg )
71+
72+ if err := luaEval (es , luaC ); err != nil {
73+ return err
74+ }
75+
76+ fmt .Println (es .all (0 ))
6377 }
6478 return nil
6579 }
6680
6781 if p := os .Getenv ("LM_RESPONSES_PATH" ); p != "" {
82+ lp := os .Getenv ("LM_BOT_LUA_PATH" )
6883 responsesChanged := make (chan struct {})
6984 go func () {
7085 for range responsesChanged {
@@ -77,6 +92,16 @@ func Run(args []string, _ io.Reader) error {
7792 continue
7893 }
7994 fmt .Fprintf (os .Stderr , "updated matchers (%d)\n " , len (matchers ))
95+
96+ if lp != "" {
97+ luaC , err = loadLua (dbCl , lp )
98+ if err != nil {
99+ fmt .Fprintln (os .Stderr , err )
100+ matchersMu .Unlock ()
101+ continue
102+ }
103+ fmt .Fprintf (os .Stderr , "updated lua (%d bytes)\n " , len (luaC ))
104+ }
80105 matchersMu .Unlock ()
81106 }
82107 }()
@@ -169,7 +194,12 @@ func emojiAdd(s *discordgo.Session, a *discordgo.MessageReactionAdd) {
169194 return
170195 }
171196
172- react (s , a .ChannelID , a .MessageID , newEmojiSet (m .Content ))
197+ es := newEmojiSet (m .Content )
198+ if err := luaEval (es , luaC ); err != nil {
199+ fmt .Fprintln (os .Stderr , err )
200+ return
201+ }
202+ react (s , a .ChannelID , a .MessageID , es )
173203}
174204
175205var messageCreateTotal = prometheus .NewGaugeVec (prometheus.GaugeOpts {
@@ -182,6 +212,7 @@ func init() {
182212}
183213
184214var matchers []matcher
215+ var luaC string
185216var matchersMu = & sync.Mutex {}
186217
187218func messageCreate (s * discordgo.Session , m * discordgo.MessageCreate ) {
@@ -200,6 +231,10 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
200231 }
201232
202233 es := newEmojiSet (m .Message .Content )
234+ if err := luaEval (es , luaC ); err != nil {
235+ fmt .Fprintln (os .Stderr , err )
236+ return
237+ }
203238
204239 lucky := rand .Intn (100 ) == 0
205240
0 commit comments