Mercurial > hg > Members > anatofuz > logroulette
changeset 8:2528c160021a default tip
...
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 25 Nov 2020 08:32:01 +0900 |
parents | 0d871c373996 |
children | |
files | members.pl run.go user.go |
diffstat | 3 files changed, 13 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/members.pl Tue Nov 24 20:21:21 2020 +0900 +++ b/members.pl Wed Nov 25 08:32:01 2020 +0900 @@ -74,7 +74,6 @@ e185761@ie.u-ryukyu.ac.jp e185761チャンネルのメンバー k188580 profile image -@k188580 - 外間 政尊 (ryokka) k188580@ie.u-ryukyu.ac.jp
--- a/run.go Tue Nov 24 20:21:21 2020 +0900 +++ b/run.go Wed Nov 25 08:32:01 2020 +0900 @@ -14,23 +14,23 @@ var botName string = "ログルーレット" var webhook string -func Run(jsonp string) int { +func Run(jsonPATH string) int { if webhook == "" { os.Getenv("MATTERMOST_WEBHOOK") } - users, err := convertFromJSonToUserInfo(jsonp) + users, err := convertFromJSONToUserInfo(jsonPATH) if err != nil { fmt.Println(err) return 1 } - targetUser, newUsers, err := perform(users) + targetUser, updateUsers, err := perform(users) if err != nil { fmt.Println(err) return 1 } - if err := converUserInfoToJSON(newUsers, jsonp); err != nil { + if err := converUserInfoToJSON(updateUsers, jsonPATH); err != nil { fmt.Println(err) return 1 } @@ -55,7 +55,7 @@ name2Index := make(map[string]int, len(entryUsers)) for i, user := range users { - name2Index[user.Id] = i + name2Index[user.ID] = i if user.Done { continue } @@ -71,10 +71,10 @@ } targetUser := loulette(entryUsers) - newUsers := users - newUsers[name2Index[targetUser.Id]].Done = true + updateUsers := users + updateUsers[name2Index[targetUser.ID]].Done = true - return targetUser.Id, newUsers, nil + return targetUser.ID, updateUsers, nil } func loulette(users []UserInfo) UserInfo {
--- a/user.go Tue Nov 24 20:21:21 2020 +0900 +++ b/user.go Wed Nov 25 08:32:01 2020 +0900 @@ -7,12 +7,12 @@ ) type UserInfo struct { - Id string `json:"id"` + ID string `json:"id"` Done bool `json:"done"` } -func convertFromJSonToUserInfo(filep string) ([]UserInfo, error) { - raw, err := ioutil.ReadFile(filep) +func convertFromJSONToUserInfo(filePATH string) ([]UserInfo, error) { + raw, err := ioutil.ReadFile(filePATH) if err != nil { return nil, err } @@ -22,10 +22,10 @@ return users, nil } -func converUserInfoToJSON(users []UserInfo, filep string) error { +func converUserInfoToJSON(users []UserInfo, filePATH string) error { b, err := json.Marshal(users) if err != nil { return err } - return ioutil.WriteFile(filep, b, 0755) + return ioutil.WriteFile(filePATH, b, 0755) }