-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot-write.go
More file actions
58 lines (52 loc) · 1.4 KB
/
bot-write.go
File metadata and controls
58 lines (52 loc) · 1.4 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"strings"
)
type botWriteCmd struct {
ContactID uint
}
func (botWriteCmd) Command() string {
return "/write"
}
func (botWriteCmd) Description() string {
return "Nachricht an einen Kontakt senden (Aufruf: /write NAME)"
}
func (cmd botWriteCmd) Execute(worker *automationworker, args []string) {
if len(args) == 0 {
worker.Chat.sendMessage("Keinen Kontaktnamen angegeben")
return
}
filter := contact{OwnerID: worker.Chat.FetchCrew().ID}
var contacts []contact
database.Where(&filter).Find(&contacts)
var contact contact
found := false
for _, item := range contacts {
if strings.ToLower(item.Name) == strings.ToLower(args[0]) {
contact = item
found = true
}
}
if found == false {
worker.Chat.sendMessage("Keinen passenden Kontakt in der Datenbank gefunden.")
return
}
cmd.ContactID = contact.ID
if len(args) > 1 {
message := args[1:]
text := strings.Join(message, " ")
contact.sendMessageToContact(text)
worker.Chat.sendMessage("Ich habe die Nachricht übertragen.")
} else {
worker.Chat.sendMessage("Ich bin ganz Ohr.")
var casted botDataSink = cmd
worker.CurrentFocus = &casted
}
}
func (cmd botWriteCmd) OnMessage(worker *automationworker, msg message) {
var destcontact contact
database.First(&destcontact, cmd.ContactID)
destcontact.sendMessageToContact(msg.Text)
updateSidebar()
worker.Chat.sendMessage("Ich habe die Nachricht übertragen.")
}