/
hello.go
51 lines (42 loc) · 1.26 KB
/
hello.go
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
package static
import (
"fmt"
"math/rand"
"time"
"github.com/starshine-sys/bcr"
"github.com/starshine-sys/pkgo"
)
var pk = pkgo.NewSession(nil)
var greetings = []string{"Hello", "Heya", "Hi", "Hiya"}
// yeah this won't work on any other instance of the bot sadly
var emotes = []string{"👋", "<:MenheraWave:807587508623507456>", "<a:ameowcomfywave:807587518857216021>"}
func (bot *Bot) hello(ctx *bcr.Context) (err error) {
// sleep for a second to give PK time to process the message
time.Sleep(1 * time.Second)
var name string
m, err := pk.GetMessage(ctx.Message.ID.String())
// if there's a non-nil error, chances are PK hasn't registered the message yet
// so just fall back to a normal user
if err != nil {
name = ctx.Author.Mention()
} else {
name = m.Member.Name
}
// spaghetti Lite™ to get some more randomness
greeting := fmt.Sprintf(
"%v, %v!",
greetings[rand.Intn(len(greetings))],
name,
)
if r := rand.Intn(3); r == 1 {
if len(emotes) != 0 {
if r := rand.Intn(2); r == 1 {
greeting = fmt.Sprintf("%v %v", greeting, emotes[rand.Intn(len(emotes))])
} else {
greeting = fmt.Sprintf("%v %v", emotes[rand.Intn(len(emotes))], greeting)
}
}
}
_, err = ctx.NewMessage().Content(greeting).BlockMentions().Send()
return err
}