commit 3ef5f8a20e57289457c54a9c573538801692ea7e from: Witcher01 date: Tue Jun 8 18:03:40 2021 UTC added primitive moderation capabilities commit - cfe1798c7f38b9f7bd84fbbce443f8eb417c4883 commit + 3ef5f8a20e57289457c54a9c573538801692ea7e blob - 8c5b20c35dd8cb084a4a50fa08cd57b36b2a36e2 blob + 2a075c4a44f5862ea6fdc152d8b84dd5edc765b3 --- args.go +++ args.go @@ -9,11 +9,11 @@ import ( type argT struct { cli.Helper - ApiUrl string `cli:"a,api" usage:"api url to use, remember the trailing \"/\"" dft:"https://rkiapi.wiredspace.de/"` - Token string `cli:"*t,token" usage:"token for the discord bot"` - ChannelId string `cli:"*c,channelid" usage:"discord channel to post updates to"` - Districts []string `cli:"d,districts" usage:"districts to track"` - AdminIds []string `cli:"m,moderator" usage:"ids of accounts that are able to moderate the mod"` + ApiUrl string `cli:"a,api" usage:"api url to use, remember the trailing \"/\"" dft:"https://rkiapi.wiredspace.de/"` + Token string `cli:"*t,token" usage:"token for the discord bot"` + ChannelId string `cli:"*c,channelid" usage:"discord channel to post updates to"` + Districts []string `cli:"d,districts" usage:"districts to track"` + ModeratorIds []string `cli:"m,moderator" usage:"ids of accounts that are able to moderate the mod"` } var ParsedArgs *argT = new(argT) blob - 63cad23aa2490478820ef5fb30e9be092ecefabd blob + 6767ff7fe3a3df6126dadaebd4c240adccb8ef01 --- covid.go +++ covid.go @@ -68,7 +68,7 @@ func GetDistrict(d string) (DistrictResponse, error) { var err error = nil var district DistrictResponse - if _, err := strconv.Atoi(d); err != nil { + if _, err = strconv.Atoi(d); err != nil { // district name district, err = getDistrictByName(d) } else { blob - b1720013f19b45637f8d431044965a42b7709644 blob + 273e1d2b97e162df0cf8a93060184e8153132d88 --- discord.go +++ discord.go @@ -9,6 +9,24 @@ import ( log "github.com/sirupsen/logrus" ) +var moderator = []string{} + +func AddModerators(userIds []string) { + moderator = append(moderator, userIds...) +} + +func checkModerator(ctx *dgc.Ctx) bool { + fmt.Println(moderator) + for _, a := range moderator { + if ctx.Event.Author.ID == a { + return true + } + } + + log.Infof("User with ID %s is not a moderator", ctx.Event.Author.ID) + return false +} + func InitDiscordBot(s *discordgo.Session) { router := dgc.Create(&dgc.Router{ Prefixes: []string{ @@ -72,6 +90,10 @@ func InitDiscordBot(s *discordgo.Session) { } func addDistrict(ctx *dgc.Ctx) { + if !checkModerator(ctx) { + return + } + arguments := ctx.Arguments arg := arguments.Get(0) @@ -87,6 +109,10 @@ func addDistrict(ctx *dgc.Ctx) { } func removeDistrict(ctx *dgc.Ctx) { + if !checkModerator(ctx) { + return + } + arguments := ctx.Arguments arg := arguments.Get(0) blob - 991e79d1f6b67dda8680af86953bf5caa36e9acc blob + f7f68c0739ee745d3dcb9321b7bd0b9fd7ed64fb --- main.go +++ main.go @@ -26,6 +26,9 @@ func main() { log.Fatalf("%s is not a valid district. exiting", v) } } + log.Infof("Added districts: %+v", ParsedArgs.Districts) + // initialize moderators + AddModerators(ParsedArgs.ModeratorIds) discord, err := discordgo.New("Bot " + ParsedArgs.Token) // Cleanly close down the Discord session on program end