~witcher/discord_covid19

f5c547a2f51e7a576c3cf9e1fd52410ad8d79b77 — Witcher01 3 years ago 6351f7a
added embed and multiple args for addDistrict
1 files changed, 24 insertions(+), 8 deletions(-)

M discord.go
M discord.go => discord.go +24 -8
@@ 98,22 98,38 @@ func addDistrict(ctx *dgc.Ctx) {
	}

	arguments := ctx.Arguments
	arg := arguments.Get(0)

	name, err := AddTrackedDistrict(arg.Raw())
	if err != nil {
		log.Error(err.Error())

		if err := ctx.RespondText(err.Error()); err != nil {
	if arguments.Amount() < 1 {
		if err := ctx.RespondText("wrong number of arguments!"); err != nil {
			log.Error(err)
		}

		return
	}

	log.Infof("Added district %s to trackedDistricts", name)
	names := make([]string, arguments.Amount())
	for i := 0; i < arguments.Amount(); i++ {
		name, err := AddTrackedDistrict(arguments.Get(i).Raw())
		if err != nil {
			log.Error(err)

			if err := ctx.RespondText(err.Error()); err != nil {
				log.Error(err)
			}

	if err := ctx.RespondText(fmt.Sprintf("Added district %s.\n", name)); err != nil {
			return
		}
		names[i] = name
	}
	log.Infof("Added the following districts to trackedDistricts: %v", names)

	embed := discordgo.MessageEmbed{
		Title: "Added districts",
		Timestamp: time.Now().Format(time.RFC3339),
		Description: strings.Join(names, ", "),
	}

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