commit 0a26c7b2528ff1dc4bfee8845a6a1a594124c4f7 from: Witcher01 date: Tue Jun 8 21:04:39 2021 UTC removeDistrict -> removeDistricts commit - 0da76f6da3ba5eb309a38dff854d84c757e6b4d9 commit + 0a26c7b2528ff1dc4bfee8845a6a1a594124c4f7 blob - e4dd03b1d7e6b544fc583e316f23c5219f219620 blob + 0aee5e50e7f433d69ba4fcb2dcea98c8f45b01ae --- discord.go +++ discord.go @@ -46,7 +46,7 @@ func InitDiscordBot(s *discordgo.Session) { router.RegisterCmd(&dgc.Command{ Name: "addDistricts", - Description: "adds one or multiple districts to the tracked districts", + Description: "adds one or more districts to the tracked districts", Usage: "addDistricts districtId/name", Example: "addDistricts 05113 wolfsburg", IgnoreCase: true, @@ -54,12 +54,12 @@ func InitDiscordBot(s *discordgo.Session) { }) router.RegisterCmd(&dgc.Command{ - Name: "removeDistrict", - Description: "remove a district from the tracked districts", - Usage: "removeDistrict", - Example: "removeDistrict", + Name: "removeDistricts", + Description: "remove one or more district from the tracked districts", + Usage: "removeDistricts districtId/name", + Example: "removeDistricts 05113 wolfsburg", IgnoreCase: true, - Handler: removeDistrict, + Handler: removeDistricts, }) router.RegisterCmd(&dgc.Command{ @@ -134,28 +134,38 @@ func addDistricts(ctx *dgc.Ctx) { } } -func removeDistrict(ctx *dgc.Ctx) { +func removeDistricts(ctx *dgc.Ctx) { if !checkModerator(ctx) { return } - arguments := ctx.Arguments - arg := arguments.Get(0) + args := ctx.Arguments - name, err := RemoveTrackedDistrict(arg.Raw()) - if err != nil { - log.Error(err.Error()) + names := make([]string, args.Amount()) + for i := 0; i < args.Amount(); i++ { + name, err := RemoveTrackedDistrict(args.Get(i).Raw()) + if err != nil { + log.Error(err.Error()) - if err := ctx.RespondText(err.Error()); err != nil { - log.Error(err) + if err := ctx.RespondText(err.Error()); err != nil { + log.Error(err) + } + + return } - return + names[i] = name } - log.Infof("Removed district %s from trackedDistricts", name) + embed := discordgo.MessageEmbed{ + Title: "Removed districts", + Timestamp: time.Now().Format(time.RFC3339), + Description: strings.Join(names, ", "), + } - if err := ctx.RespondText(fmt.Sprintf("Removed district %s.\n", name)); err != nil { + log.Infof("Removed the following districts from trackedDistricts: %v", names) + + if err := ctx.RespondEmbed(&embed); err != nil { log.Error(err) } }