Add icons to guilds status command. Fixes #32
This commit is contained in:
13
commands.go
13
commands.go
@@ -21,6 +21,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -340,7 +341,7 @@ func fnGuilds(ce *WrappedCommandEvent) {
|
||||
}
|
||||
|
||||
func fnListGuilds(ce *WrappedCommandEvent) {
|
||||
var output strings.Builder
|
||||
var items []string
|
||||
for _, userGuild := range ce.User.GetPortals() {
|
||||
guild := ce.Bridge.GetGuildByID(userGuild.DiscordID, false)
|
||||
if guild == nil {
|
||||
@@ -350,12 +351,16 @@ func fnListGuilds(ce *WrappedCommandEvent) {
|
||||
if guild.MXID != "" {
|
||||
status = "bridged"
|
||||
}
|
||||
_, _ = fmt.Fprintf(&output, "* %s (`%s`) - %s\n", guild.Name, guild.ID, status)
|
||||
var avatarHTML string
|
||||
if !guild.AvatarURL.IsEmpty() {
|
||||
avatarHTML = fmt.Sprintf(`<img data-mx-emoticon height="24" width="24" src="%s" alt="" title="Guild avatar"> `, guild.AvatarURL.String())
|
||||
}
|
||||
items = append(items, fmt.Sprintf("<li>%s%s (<code>%s</code>) - %s</li>", avatarHTML, html.EscapeString(guild.Name), guild.ID, status))
|
||||
}
|
||||
if output.Len() == 0 {
|
||||
if len(items) == 0 {
|
||||
ce.Reply("No guilds found")
|
||||
} else {
|
||||
ce.Reply("List of guilds:\n\n%s", output.String())
|
||||
ce.ReplyAdvanced(fmt.Sprintf("<p>List of guilds:</p><ul>%s</ul>", strings.Join(items, "")), false, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
go.mod
2
go.mod
@@ -14,7 +14,7 @@ require (
|
||||
github.com/stretchr/testify v1.8.1
|
||||
github.com/yuin/goldmark v1.5.3
|
||||
maunium.net/go/maulogger/v2 v2.3.2
|
||||
maunium.net/go/mautrix v0.13.1-0.20230129104640-4a2a7653e437
|
||||
maunium.net/go/mautrix v0.13.1-0.20230129131014-888cfabd8a52
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
4
go.sum
4
go.sum
@@ -77,5 +77,5 @@ maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
|
||||
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
|
||||
maunium.net/go/maulogger/v2 v2.3.2 h1:1XmIYmMd3PoQfp9J+PaHhpt80zpfmMqaShzUTC7FwY0=
|
||||
maunium.net/go/maulogger/v2 v2.3.2/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
|
||||
maunium.net/go/mautrix v0.13.1-0.20230129104640-4a2a7653e437 h1:BMfeE1yJNs97rIXCRzIY284g7dXa7E6OaM0HCWpddwU=
|
||||
maunium.net/go/mautrix v0.13.1-0.20230129104640-4a2a7653e437/go.mod h1:gYMQPsZ9lQpyKlVp+DGwOuc9LIcE/c8GZW2CvKHISgM=
|
||||
maunium.net/go/mautrix v0.13.1-0.20230129131014-888cfabd8a52 h1:7KoJL/7eozYlu4GW2jADHO+Qhm8WL45Afcm7A45BivM=
|
||||
maunium.net/go/mautrix v0.13.1-0.20230129131014-888cfabd8a52/go.mod h1:gYMQPsZ9lQpyKlVp+DGwOuc9LIcE/c8GZW2CvKHISgM=
|
||||
|
||||
Reference in New Issue
Block a user