|
@@ -16,18 +16,24 @@ func WriteMessage(v *tview.TextView, m *discordgo.Message, clientID string) {
|
|
|
switch m.Type {
|
|
switch m.Type {
|
|
|
case discordgo.MessageTypeDefault, discordgo.MessageTypeReply:
|
|
case discordgo.MessageTypeDefault, discordgo.MessageTypeReply:
|
|
|
// Define a new region and assign message ID as the region ID.
|
|
// Define a new region and assign message ID as the region ID.
|
|
|
- // Learn more: https://pkg.go.dev/github.com/rivo/tview#hdr-Regions_and_Highlights
|
|
|
|
|
|
|
+ // Learn more:
|
|
|
|
|
+ // https://pkg.go.dev/github.com/rivo/tview#hdr-Regions_and_Highlights
|
|
|
b.WriteString("[\"")
|
|
b.WriteString("[\"")
|
|
|
b.WriteString(m.ID)
|
|
b.WriteString(m.ID)
|
|
|
b.WriteString("\"]")
|
|
b.WriteString("\"]")
|
|
|
- // Render the message associated with crosspost, channel follow add, pin, or a reply.
|
|
|
|
|
|
|
+ // Render the message associated with crosspost, channel follow add,
|
|
|
|
|
+ // pin, or a reply.
|
|
|
if rm := m.ReferencedMessage; rm != nil {
|
|
if rm := m.ReferencedMessage; rm != nil {
|
|
|
b.WriteString(" ╭ ")
|
|
b.WriteString(" ╭ ")
|
|
|
b.WriteString("[::d]")
|
|
b.WriteString("[::d]")
|
|
|
parseAuthor(&b, rm.Author, clientID)
|
|
parseAuthor(&b, rm.Author, clientID)
|
|
|
|
|
|
|
|
if rm.Content != "" {
|
|
if rm.Content != "" {
|
|
|
- rm.Content = parseMessageMentions(rm.Content, rm.Mentions, clientID)
|
|
|
|
|
|
|
+ rm.Content = parseMessageMentions(
|
|
|
|
|
+ rm.Content,
|
|
|
|
|
+ rm.Mentions,
|
|
|
|
|
+ clientID,
|
|
|
|
|
+ )
|
|
|
b.WriteString(rm.Content)
|
|
b.WriteString(rm.Content)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -35,12 +41,15 @@ func WriteMessage(v *tview.TextView, m *discordgo.Message, clientID string) {
|
|
|
}
|
|
}
|
|
|
// Render the author of the message.
|
|
// Render the author of the message.
|
|
|
parseAuthor(&b, m.Author, clientID)
|
|
parseAuthor(&b, m.Author, clientID)
|
|
|
- // If the message content is not empty, parse the message mentions (users mentioned in the message) and render the message content.
|
|
|
|
|
|
|
+ // If the message content is not empty, parse the message mentions
|
|
|
|
|
+ // (users mentioned in the message) and render the message content.
|
|
|
if m.Content != "" {
|
|
if m.Content != "" {
|
|
|
m.Content = parseMessageMentions(m.Content, m.Mentions, clientID)
|
|
m.Content = parseMessageMentions(m.Content, m.Mentions, clientID)
|
|
|
b.WriteString(m.Content)
|
|
b.WriteString(m.Content)
|
|
|
}
|
|
}
|
|
|
- // If the edited timestamp of the message is not empty; it implies that the message has been edited, hence render the message with edited label for distinction
|
|
|
|
|
|
|
+ // If the edited timestamp of the message is not empty; it implies that
|
|
|
|
|
+ // the message has been edited, hence render the message with edited
|
|
|
|
|
+ // label for distinction
|
|
|
if m.EditedTimestamp != "" {
|
|
if m.EditedTimestamp != "" {
|
|
|
b.WriteString(" [::d](edited)[::-]")
|
|
b.WriteString(" [::d](edited)[::-]")
|
|
|
}
|
|
}
|
|
@@ -67,7 +76,11 @@ func WriteMessage(v *tview.TextView, m *discordgo.Message, clientID string) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func parseMessageMentions(content string, mentions []*discordgo.User, clientID string) string {
|
|
|
|
|
|
|
+func parseMessageMentions(
|
|
|
|
|
+ content string,
|
|
|
|
|
+ mentions []*discordgo.User,
|
|
|
|
|
+ clientID string,
|
|
|
|
|
+) string {
|
|
|
for _, mUser := range mentions {
|
|
for _, mUser := range mentions {
|
|
|
var color string
|
|
var color string
|
|
|
if mUser.ID == clientID {
|
|
if mUser.ID == clientID {
|
|
@@ -90,7 +103,8 @@ func parseMessageMentions(content string, mentions []*discordgo.User, clientID s
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func parseAuthor(b *strings.Builder, u *discordgo.User, clientID string) {
|
|
func parseAuthor(b *strings.Builder, u *discordgo.User, clientID string) {
|
|
|
- // If the message author is the client, modify the text color for distinction.
|
|
|
|
|
|
|
+ // If the message author is the client, modify the text color for
|
|
|
|
|
+ // distinction.
|
|
|
if u.ID == clientID {
|
|
if u.ID == clientID {
|
|
|
b.WriteString("[#57F287]")
|
|
b.WriteString("[#57F287]")
|
|
|
} else {
|
|
} else {
|
|
@@ -99,7 +113,8 @@ func parseAuthor(b *strings.Builder, u *discordgo.User, clientID string) {
|
|
|
|
|
|
|
|
b.WriteString(u.Username)
|
|
b.WriteString(u.Username)
|
|
|
b.WriteString("[-] ")
|
|
b.WriteString("[-] ")
|
|
|
- // If the message author is a bot account, render the message with bot label for distinction.
|
|
|
|
|
|
|
+ // If the message author is a bot account, render the message with bot label
|
|
|
|
|
+ // for distinction.
|
|
|
if u.Bot {
|
|
if u.Bot {
|
|
|
b.WriteString("[#EB459E]BOT[-] ")
|
|
b.WriteString("[#EB459E]BOT[-] ")
|
|
|
}
|
|
}
|
|
@@ -112,13 +127,22 @@ type loginResponse struct {
|
|
|
Token string `json:"token"`
|
|
Token string `json:"token"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Login creates a new request to the `/login` endpoint for essential login information.
|
|
|
|
|
-func Login(s *discordgo.Session, email, password string) (*loginResponse, error) {
|
|
|
|
|
|
|
+// Login creates a new request to the `/login` endpoint for essential login
|
|
|
|
|
+// information.
|
|
|
|
|
+func Login(
|
|
|
|
|
+ s *discordgo.Session,
|
|
|
|
|
+ email, password string,
|
|
|
|
|
+) (*loginResponse, error) {
|
|
|
data := struct {
|
|
data := struct {
|
|
|
Email string `json:"email"`
|
|
Email string `json:"email"`
|
|
|
Password string `json:"password"`
|
|
Password string `json:"password"`
|
|
|
}{email, password}
|
|
}{email, password}
|
|
|
- resp, err := s.RequestWithBucketID("POST", discordgo.EndpointLogin, data, discordgo.EndpointLogin)
|
|
|
|
|
|
|
+ resp, err := s.RequestWithBucketID(
|
|
|
|
|
+ "POST",
|
|
|
|
|
+ discordgo.EndpointLogin,
|
|
|
|
|
+ data,
|
|
|
|
|
+ discordgo.EndpointLogin,
|
|
|
|
|
+ )
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
@@ -154,8 +178,14 @@ func TOTP(s *discordgo.Session, code, ticket string) (*loginResponse, error) {
|
|
|
return &lr, nil
|
|
return &lr, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// HasPermission returns a boolean representing whether the provided user has given permissions or not.
|
|
|
|
|
-func HasPermission(s *discordgo.State, uID string, cID string, perm int64) bool {
|
|
|
|
|
|
|
+// HasPermission returns a boolean representing whether the provided user has
|
|
|
|
|
+// given permissions or not.
|
|
|
|
|
+func HasPermission(
|
|
|
|
|
+ s *discordgo.State,
|
|
|
|
|
+ uID string,
|
|
|
|
|
+ cID string,
|
|
|
|
|
+ perm int64,
|
|
|
|
|
+) bool {
|
|
|
p, err := s.UserChannelPermissions(uID, cID)
|
|
p, err := s.UserChannelPermissions(uID, cID)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return false
|
|
return false
|