~kris/9p

disco

ref: ff90b1ac381a970bae32a65a58af0f4f79c37c13 disco/events.go -rw-r--r-- 1.2 KiB
ff90b1ac — henesy break on all errors in line read loop ;; seems to resolve #15 6 years ago
                                                                                
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
package main

import (
	"strings"

	"github.com/bwmarrin/discordgo"
)

func removeReaction(s *discordgo.Session, r *discordgo.MessageReactionRemove) {

}

func newReaction(s *discordgo.Session, m *discordgo.MessageReactionAdd) {
}

// This function will be called (due to AddHandler above) every time a new
// message is created on any channel that the autenticated user has access to.
func newMessage(s *discordgo.Session, m *discordgo.MessageCreate) {

	//State Messages -- don't notify when we're in the channel
	if m.ChannelID == State.Channel.ID && State.Enabled {
		State.AddMessage(m.Message)

		Messages := ReceivingMessageParser(m.Message)

		for _, Msg := range Messages {
			MessagePrint(string(m.Timestamp), m.Author.Username, Msg)
			//log.Printf("> %s > %s\n", UserName(m.Author.Username), Msg)
		}
		return
	}

	//Global Mentions
	Mention := "@" + State.Session.User.Username
	if strings.Contains(m.ContentWithMentionsReplaced(), Mention) {
		go Notify(m.Message)
		return
	}
	DMs, err := Session.DiscordGo.UserChannels()
	if err != nil {
		// No DMs
		return
	}
	for _, channel := range DMs {
		if m.ChannelID == channel.ID {
			go Notify(m.Message)
			return
		}
	}
}