typing, reactions
This commit is contained in:
parent
20778e93ca
commit
3f6a557e05
5 changed files with 65 additions and 1 deletions
|
@ -68,6 +68,8 @@ func SendMode() {
|
|||
prompt = ansi.Color(prompt, "cyan+b")
|
||||
}
|
||||
|
||||
client.Typing(channel.ID)
|
||||
|
||||
lib.MakePrompt(prompt, true, func(input string, interrupt bool) {
|
||||
if input == "" {
|
||||
if interrupt {
|
||||
|
|
|
@ -8,5 +8,6 @@ func Setup(session *ningen.State) {
|
|||
session.PreHandler.AddHandler(Ready)
|
||||
session.PreHandler.AddHandler(MessageCreate)
|
||||
session.PreHandler.AddHandler(MessageUpdate)
|
||||
session.PreHandler.AddHandler(ReactionAdd)
|
||||
SetupClock()
|
||||
}
|
||||
|
|
56
events/reactions.go
Normal file
56
events/reactions.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package events
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Cynosphere/comcord/lib"
|
||||
"github.com/Cynosphere/comcord/state"
|
||||
"github.com/diamondburned/arikawa/v3/discord"
|
||||
"github.com/diamondburned/arikawa/v3/gateway"
|
||||
)
|
||||
|
||||
func ReactionAdd(event *gateway.MessageReactionAddEvent) {
|
||||
client := state.GetClient()
|
||||
currentChannel := state.GetCurrentChannel()
|
||||
|
||||
if event.ChannelID.String() != currentChannel {
|
||||
return
|
||||
}
|
||||
|
||||
emote := event.Emoji.Name
|
||||
if event.Emoji.IsCustom() {
|
||||
emote = ":" + emote + ":"
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
nowSnowflake := discord.NewSnowflake(now)
|
||||
|
||||
message, err := client.MessageStore.Message(event.ChannelID, event.MessageID)
|
||||
if err != nil {
|
||||
message, err = client.Message(event.ChannelID, event.MessageID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
msg := discord.Message{
|
||||
Content: fmt.Sprintf("*reacted with %s*", emote),
|
||||
Author: event.Member.User,
|
||||
ChannelID: event.ChannelID,
|
||||
GuildID: event.GuildID,
|
||||
ID: discord.MessageID(nowSnowflake),
|
||||
ReferencedMessage: message,
|
||||
Type: discord.InlinedReplyMessage,
|
||||
Timestamp: discord.Timestamp(now),
|
||||
}
|
||||
|
||||
if state.IsInPrompt() {
|
||||
state.AddMessageToQueue(msg)
|
||||
} else {
|
||||
lines := lib.ProcessMessage(msg, lib.MessageOptions{NoColor: state.HasNoColor()})
|
||||
for _, line := range lines {
|
||||
fmt.Print(line)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -301,7 +301,6 @@ func FormatMessage(options MessageOptions) []string {
|
|||
}
|
||||
} else {
|
||||
content := options.Content
|
||||
content = ReplaceMarkdown(content, options.NoColor)
|
||||
|
||||
if options.IsDM {
|
||||
name := fmt.Sprintf("*%s*", options.Name)
|
||||
|
@ -309,6 +308,8 @@ func FormatMessage(options MessageOptions) []string {
|
|||
name = ansi.Color(name, "red+b")
|
||||
}
|
||||
|
||||
content = ReplaceMarkdown(content, options.NoColor)
|
||||
|
||||
lines = append(lines, fmt.Sprintf("%s %s\x07\n\r", name, content))
|
||||
} else if utf8.RuneCountInString(content) > 1 &&
|
||||
(strings.HasPrefix(content, "*") && strings.HasSuffix(content, "*") && !strings.HasPrefix(content, "**") && !strings.HasSuffix(content, "**")) ||
|
||||
|
@ -353,6 +354,8 @@ func FormatMessage(options MessageOptions) []string {
|
|||
nameColor = "yellow+b"
|
||||
}
|
||||
|
||||
content = ReplaceMarkdown(content, options.NoColor)
|
||||
|
||||
name := fmt.Sprintf("[%s]", options.Name)
|
||||
if !options.NoColor {
|
||||
name = ansi.Color(name, nameColor)
|
||||
|
|
2
main.go
2
main.go
|
@ -128,7 +128,9 @@ func main() {
|
|||
client.AddIntents(gateway.IntentGuildPresences)
|
||||
client.AddIntents(gateway.IntentGuildMembers)
|
||||
client.AddIntents(gateway.IntentGuildMessages)
|
||||
client.AddIntents(gateway.IntentGuildMessageReactions)
|
||||
client.AddIntents(gateway.IntentDirectMessages)
|
||||
client.AddIntents(gateway.IntentDirectMessageReactions)
|
||||
client.AddIntents(gateway.IntentMessageContent)
|
||||
|
||||
state.Setup(config, client)
|
||||
|
|
Loading…
Reference in a new issue