-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin.go
More file actions
37 lines (33 loc) · 769 Bytes
/
plugin.go
File metadata and controls
37 lines (33 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"bytes"
"log"
"os/exec"
"strings"
"github.com/shizeeg/xmpp"
)
// RunPlugin is a generic interface for external commands.
func (s *Session) RunPlugin(stanza xmpp.Stanza, filename string, tonick bool, params ...string) {
message, ok := stanza.Value.(*xmpp.ClientMessage)
if !ok {
log.Println("Wrong Stanza type!")
return
}
lang := "-lang=en"
if len(message.Lang) >= 2 {
lang = "-lang=" + message.Lang[:2]
}
plugin := exec.Command(filename, lang)
plugin.Args = append(plugin.Args, params...)
var out bytes.Buffer
plugin.Stdout = &out
plugin.Stderr = &out
if err := plugin.Run(); err != nil {
log.Println(err)
return
}
msg := strings.TrimSpace(out.String())
if len(msg) > 0 {
s.Say(stanza, msg, tonick, false)
}
}