Compare commits

..

3 commits

Author SHA1 Message Date
781402297a update readme 2023-07-29 22:37:40 -06:00
3f6a557e05 typing, reactions 2023-07-29 22:29:55 -06:00
20778e93ca fix timestamps 2023-07-29 21:31:17 -06:00
6 changed files with 78 additions and 4 deletions

View file

@ -35,20 +35,28 @@ Go is more portable than Node.js
- [ ] AFK toggle (A) - [ ] AFK toggle (A)
- [ ] Send DM (s) - [ ] Send DM (s)
- [ ] Answer DM (a) - [ ] Answer DM (a)
- [x] Current time (+)
- [ ] DM history (TBD)
- [ ] Reply to message (TBD)
- [ ] Toggle color (z)
- [x] Message Receiving - [x] Message Receiving
- Markdown styling - Markdown styling
- [x] Emotes - [x] Emotes
- [ ] Timestamp parsing - [x] Timestamp parsing
- [x] Mentions parsing - [x] Mentions parsing
- [ ] Embeds in the style of commode's posted links - [ ] Embeds
- [ ] Plain links with title = commode's posted links
- [x] Messages wrapped in `*`'s or `_`'s parsed as emotes - [x] Messages wrapped in `*`'s or `_`'s parsed as emotes
- [x] Inline DMs to replicate commode's private messages - [x] Inline DMs to replicate commode's private messages
- [x] Replies - [x] Replies
- [ ] Group DMs - [ ] Group DMs
- [ ] Only works with user accounts, might not even be worth doing
- [x] Message sending - [x] Message sending
- [x] Puts incoming messages into queue whilst in send mode - [x] Puts incoming messages into queue whilst in send mode
- [x] Send typing
- [ ] Mentioning
- [x] Configuration - [x] Configuration
- [x] Write token from argv into rc file if rc file doesn't exist - [x] Write token from argv into rc file if rc file doesn't exist
- [x] Default guild/channel - [x] Default guild/channel
- [ ] Threads - [ ] Threads/Forums
- [ ] External rich presence when using bot accounts - [ ] External rich presence when using bot accounts

View file

@ -68,6 +68,8 @@ func SendMode() {
prompt = ansi.Color(prompt, "cyan+b") prompt = ansi.Color(prompt, "cyan+b")
} }
client.Typing(channel.ID)
lib.MakePrompt(prompt, true, func(input string, interrupt bool) { lib.MakePrompt(prompt, true, func(input string, interrupt bool) {
if input == "" { if input == "" {
if interrupt { if interrupt {

View file

@ -8,5 +8,6 @@ func Setup(session *ningen.State) {
session.PreHandler.AddHandler(Ready) session.PreHandler.AddHandler(Ready)
session.PreHandler.AddHandler(MessageCreate) session.PreHandler.AddHandler(MessageCreate)
session.PreHandler.AddHandler(MessageUpdate) session.PreHandler.AddHandler(MessageUpdate)
session.PreHandler.AddHandler(ReactionAdd)
SetupClock() SetupClock()
} }

56
events/reactions.go Normal file
View 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)
}
}
}

View file

@ -301,7 +301,6 @@ func FormatMessage(options MessageOptions) []string {
} }
} else { } else {
content := options.Content content := options.Content
content = ReplaceMarkdown(content, options.NoColor)
if options.IsDM { if options.IsDM {
name := fmt.Sprintf("*%s*", options.Name) name := fmt.Sprintf("*%s*", options.Name)
@ -309,6 +308,8 @@ func FormatMessage(options MessageOptions) []string {
name = ansi.Color(name, "red+b") name = ansi.Color(name, "red+b")
} }
content = ReplaceMarkdown(content, options.NoColor)
lines = append(lines, fmt.Sprintf("%s %s\x07\n\r", name, content)) lines = append(lines, fmt.Sprintf("%s %s\x07\n\r", name, content))
} else if utf8.RuneCountInString(content) > 1 && } else if utf8.RuneCountInString(content) > 1 &&
(strings.HasPrefix(content, "*") && strings.HasSuffix(content, "*") && !strings.HasPrefix(content, "**") && !strings.HasSuffix(content, "**")) || (strings.HasPrefix(content, "*") && strings.HasSuffix(content, "*") && !strings.HasPrefix(content, "**") && !strings.HasSuffix(content, "**")) ||
@ -353,6 +354,8 @@ func FormatMessage(options MessageOptions) []string {
nameColor = "yellow+b" nameColor = "yellow+b"
} }
content = ReplaceMarkdown(content, options.NoColor)
name := fmt.Sprintf("[%s]", options.Name) name := fmt.Sprintf("[%s]", options.Name)
if !options.NoColor { if !options.NoColor {
name = ansi.Color(name, nameColor) name = ansi.Color(name, nameColor)
@ -477,6 +480,7 @@ func ProcessMessage(msg discord.Message, options MessageOptions) []string {
if i == 0 { if i == 0 {
options.Reply = msg.ReferencedMessage options.Reply = msg.ReferencedMessage
} }
options.Timestamp = time.Time(msg.Timestamp)
options.IsMention = isPing options.IsMention = isPing
options.IsDM = isDM options.IsDM = isDM
options.IsJoin = msg.Type == discord.GuildMemberJoinMessage options.IsJoin = msg.Type == discord.GuildMemberJoinMessage
@ -497,6 +501,7 @@ func ProcessMessage(msg discord.Message, options MessageOptions) []string {
options.Attachments = msg.Attachments options.Attachments = msg.Attachments
options.Stickers = msg.Stickers options.Stickers = msg.Stickers
options.Reply = msg.ReferencedMessage options.Reply = msg.ReferencedMessage
options.Timestamp = time.Time(msg.Timestamp)
options.IsMention = isPing options.IsMention = isPing
options.IsDM = isDM options.IsDM = isDM
options.IsJoin = msg.Type == discord.GuildMemberJoinMessage options.IsJoin = msg.Type == discord.GuildMemberJoinMessage

View file

@ -128,7 +128,9 @@ func main() {
client.AddIntents(gateway.IntentGuildPresences) client.AddIntents(gateway.IntentGuildPresences)
client.AddIntents(gateway.IntentGuildMembers) client.AddIntents(gateway.IntentGuildMembers)
client.AddIntents(gateway.IntentGuildMessages) client.AddIntents(gateway.IntentGuildMessages)
client.AddIntents(gateway.IntentGuildMessageReactions)
client.AddIntents(gateway.IntentDirectMessages) client.AddIntents(gateway.IntentDirectMessages)
client.AddIntents(gateway.IntentDirectMessageReactions)
client.AddIntents(gateway.IntentMessageContent) client.AddIntents(gateway.IntentMessageContent)
state.Setup(config, client) state.Setup(config, client)