-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Broadcast, Subscribe, Bus, Weather and unit tests(with Spaces) #51
base: cinnabot-go
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,39 @@ | |||
FROM golang:1.9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we don't need this file anymore.
main/.#main.go
Outdated
@@ -0,0 +1 @@ | |||
[email protected] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add this file to gitignore!
model/db.go
Outdated
CheckTagExists (id int, tag string) bool | ||
CheckSubscribed (id int, tag string) bool | ||
UpdateTag (id int, tag string, flag string) error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove newline
model/user.go
Outdated
@@ -2,13 +2,42 @@ package model | |||
|
|||
import ( | |||
"github.com/jinzhu/gorm" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stdlib should appear before 3rd party
model/user.go
Outdated
UserID int `gorm:"primary_key"` | ||
CreatedAt time.Time | ||
UpdatedAt time.Time | ||
//DeletedAt time.Time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the commented line?
} | ||
|
||
// About returns a link to Cinnabot's source code. | ||
func (cb *Cinnabot) About(msg *message) { | ||
cb.SendTextMessage(msg.From.ID, "Touch me: https://github.com/varunpatro/Cinnabot") | ||
cb.SendTextMessage(int(msg.Chat.ID), "Touch me: https://github.com/varunpatro/Cinnabot") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add yourself here too! Say it was developed by you too (before showing the link)
//Link returns useful resources | ||
func (cb *Cinnabot) Resources(msg *message) { | ||
resources := make(map[string]string) | ||
resources["usplife"] = "[fb page](https://www.facebook.com/groups/usplife/)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use const
for strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean:
const usplife = "testString"
resources["usplife"] = usplife
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah but more descriptive const
names such as
const (
uspFacebookUrl := "https://wwww.facebook.com/groups/usplife/"
uspSpacesUrl := "http://www.nususc.com/Spaces.aspx"
)
} | ||
|
||
//Default loc: Cinnamon | ||
loc := &tgbotapi.Location{Latitude: 1.306671, Longitude: 103.773556} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constant can only be declared on character, string, boolean values, so I can only make the latitude and longitude values a constant value.
Since this is the only only use of it in this file, where should I declare the constant? And how should I do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declare two const
s at the top of the file:
const (
cinnamonLat := 1.306671
cinnamonLong := 103.773556
)
client := &http.Client{} | ||
|
||
req, _ := http.NewRequest("GET", "https://api.data.gov.sg/v1/environment/2-hour-weather-forecast", nil) | ||
req.Header.Set("api-key", "d1Y8YtThOpkE5QUfQZmvuA3ktrHa1uWP") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh. Cardinal sin here. Do not check in sensitive info (api keys) into VCS
basic.go
Outdated
"*Subscribe status*\n" + "(sub status) tag: description\n" | ||
for i := 0; i < len(cb.allTags); i += 2 { | ||
if cb.db.CheckSubscribed(msg.From.ID, cb.allTags[i]) { | ||
listText += "✅" + cb.allTags[i] + " : " + cb.allTags[i+1] + "\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after the emoji would be great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to me, a green cross is not the best for unsubscribed status. What about the following pairs:
a/ ✅❌
b/ ✅✖️
c/ ✔️✖️
Update handle for study groups resources
Created a dining hall survey function
* Add function for bot stats * Refactor code to separate files for feedback and broadcast * Add feedback for OHS * Refine and finish stats function * Remove useless log print in echo * Better responses for stats function
…into cinnabot-go
New Changes:
Functions added
Fixed the repeated user bug! Sadly that took me some time.
Features added:
Implemented a cache.
Cache is a field under cinnabot so I can refer to it. It is used in cb.Router only cache last function called.
Current problems:
[I am unsure about my approach to testing as we have not talked about it specifically for these functions before]
1) Problems with unit test for bus and weather
I attempted the use the technique in section 1: Monkey Patching.(Refer to https://husobee.github.io/golang/testing/unit-test/2015/06/08/golang-unit-testing.html) This is to "monkey-patch" the http request as I felt that it was not important to that test. However, the monkey patch requires me to declare a variable. (Refer to line before func() main in image.)
If I do not declare a separate variable:
Hence, is it right for me to monkey-patch so as to not make a URL request? And is monkey-patch the right way to do it?
2) Problems with unit test for broadcast [SOLVED]
Minor notes:
I should have committed early, often, and using lower-case.
I apologise for slightly messy code. I should have cleaned it up proper but I thought that getting your feedback on what I am doing so far is more crucial to the project's success.
I should have better error handling but Im still not sure about go's way of handling errors/exceptions(or the lack of it).