Add icons to guilds status command. Fixes #32

This commit is contained in:
Tulir Asokan
2023-01-29 15:10:44 +02:00
parent 840e95b388
commit 6974405d7c
3 changed files with 12 additions and 7 deletions

View File

@@ -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)
}
}