~witcher/discord_covid19

624d82406a7213b6acb70118a8201d19bf735abc — Witcher01 3 years ago 5534608
added embed for getting incidences
1 files changed, 18 insertions(+), 7 deletions(-)

M discord.go
M discord.go => discord.go +18 -7
@@ 3,6 3,7 @@ package main
import (
	"fmt"
	"strings"
	"time"

	"github.com/bwmarrin/discordgo"
	"github.com/lus/dgc"


@@ 156,17 157,27 @@ func getTrackedIncidences(ctx *dgc.Ctx) {
		return
	}

	var sb strings.Builder
	for i, district := range districts {
		sb.WriteString(fmt.Sprintf("%s: %.2f", district.Name, district.WeekIncidence))
	var fields = make([]*discordgo.MessageEmbedField, len(districts))

		// only write a newline if it's not the last element
		if i < len(districts)-1 {
			sb.WriteRune('\n')
	for i, district := range districts {
		incidence := fmt.Sprintf("%.2f", district.WeekIncidence)
		fields[i] = &discordgo.MessageEmbedField{
			Name:   district.Name,
			Value:  incidence,
			Inline: false,
		}
	}

	ctx.RespondText(sb.String())
	embed := discordgo.MessageEmbed{
		Type:      discordgo.EmbedTypeRich,
		Title:     "Incidences",
		Timestamp: time.Now().Format(time.RFC3339),
		Fields:    fields,
	}

	if err := ctx.RespondEmbed(&embed); err != nil {
		log.Error(err)
	}
}

func getDistrictInformation(ctx *dgc.Ctx) {