Skip to content

Commit

Permalink
Fix variable shadowing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hbollon committed Feb 7, 2021
1 parent 07d08be commit b21712f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (bot *IGopher) SendMessage(user, message string) (bool, error) {

return res, err
}
return false, err
return false, nil
}

func (bot *IGopher) sendMessageWebDriver(user, message string) (bool, error) {
Expand Down
9 changes: 6 additions & 3 deletions cmd/igopher/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,18 @@ func main() {
BotStruct.SeleniumStruct.InitChromeWebDriver()
defer BotStruct.SeleniumStruct.CloseSelenium()

var err error
rand.Seed(time.Now().Unix())
if err := BotStruct.Scheduler.CheckTime(); err == nil {
if err = BotStruct.Scheduler.CheckTime(); err == nil {
BotStruct.ConnectToInstagram()
users, err := BotStruct.FetchUsersFromUserFollowers()
var users []string
users, err = BotStruct.FetchUsersFromUserFollowers()
if err != nil {
log.Error(err)
}
for _, username := range users {
res, err := BotStruct.SendMessage(username, BotStruct.DmModule.DmTemplates[rand.Intn(len(BotStruct.DmModule.DmTemplates))])
var res bool
res, err = BotStruct.SendMessage(username, BotStruct.DmModule.DmTemplates[rand.Intn(len(BotStruct.DmModule.DmTemplates))])
if !res || err != nil {
log.Errorf("Error during message sending: %v", err)
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/igopher/tui/IGopherTUI.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,18 @@ func launchBot() {
BotStruct.SeleniumStruct.InitChromeWebDriver()
defer BotStruct.SeleniumStruct.CloseSelenium()

var err error
rand.Seed(time.Now().Unix())
if err := BotStruct.Scheduler.CheckTime(); err == nil {
if err = BotStruct.Scheduler.CheckTime(); err == nil {
BotStruct.ConnectToInstagram()
users, err := BotStruct.FetchUsersFromUserFollowers()
var users []string
users, err = BotStruct.FetchUsersFromUserFollowers()
if err != nil {
log.Error(err)
}
for _, username := range users {
res, err := BotStruct.SendMessage(username, BotStruct.DmModule.DmTemplates[rand.Intn(len(BotStruct.DmModule.DmTemplates))])
var res bool
res, err = BotStruct.SendMessage(username, BotStruct.DmModule.DmTemplates[rand.Intn(len(BotStruct.DmModule.DmTemplates))])
if !res || err != nil {
log.Errorf("Error during message sending: %v", err)
}
Expand Down
8 changes: 5 additions & 3 deletions dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ func addChrome(ctx context.Context, latestChromeBuild string) error {
}
bkt := client.Bucket(storageBktName)
if latestChromeBuild == "" {
r, err := bkt.Object(lastChangeFile).NewReader(ctx)
var r *storage.Reader
r, err = bkt.Object(lastChangeFile).NewReader(ctx)
if err != nil {
return fmt.Errorf("cannot create a reader for %s%s file: %v", gcsPath, lastChangeFile, err)
}
defer r.Close()
// Read the last change file content for the latest build directory name
data, err := ioutil.ReadAll(r)
var data []byte
data, err = ioutil.ReadAll(r)
if err != nil {
return fmt.Errorf("cannot read from %s%s file: %v", gcsPath, lastChangeFile, err)
}
Expand Down Expand Up @@ -339,7 +341,7 @@ func handleFile(bar *mpb.Bar, file file, downloadBrowsers, forceDl bool) error {
}
}

if extractFile(file) != nil {
if err := extractFile(file); err != nil {
return err
}
if rename := file.rename; len(rename) == 2 {
Expand Down
4 changes: 3 additions & 1 deletion engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const (
var (
seleniumPath = filepath.FromSlash("./lib/selenium-server.jar")
chromePath, chromeDriverPath, geckoDriverPath string
err error
)

func init() {
Expand All @@ -50,6 +49,7 @@ type Selenium struct {
// InitializeSelenium start a Selenium WebDriver server instance
// (if one is not already running).
func (s *Selenium) InitializeSelenium(clientConfig *ClientConfig) {
var err error
s.Config = clientConfig

var output *os.File
Expand Down Expand Up @@ -77,6 +77,7 @@ func (s *Selenium) InitializeSelenium(clientConfig *ClientConfig) {

// InitFirefoxWebDriver init and launch web driver with Firefox
func (s *Selenium) InitFirefoxWebDriver() {
var err error
caps := selenium.Capabilities{"browserName": "firefox"}
s.WebDriver, err = selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", s.Config.Port))
if err != nil {
Expand All @@ -86,6 +87,7 @@ func (s *Selenium) InitFirefoxWebDriver() {

// InitChromeWebDriver init and launch web driver with Chrome
func (s *Selenium) InitChromeWebDriver() {
var err error
caps := selenium.Capabilities{"browserName": "chrome"}
chromeCaps := chrome.Capabilities{
Path: filepath.FromSlash(chromePath),
Expand Down
8 changes: 5 additions & 3 deletions modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,18 @@ type BlacklistManager struct {

// InitializeBlacklist check existence of the blacklist csv file and initialize it if it doesn't exist.
func (bm *BlacklistManager) InitializeBlacklist() error {
var err error
// Check if blacklist csv exist
_, err := os.Stat(fileBlacklistPath)
_, err = os.Stat(fileBlacklistPath)
if err != nil {
if os.IsNotExist(err) {
// Create data folder if not exist
if _, err := os.Stat("data/"); os.IsNotExist(err) {
if _, err = os.Stat("data/"); os.IsNotExist(err) {
os.Mkdir("data/", os.ModePerm)
}
// Create and open csv blacklist
f, err := os.OpenFile(fileBlacklistPath, os.O_RDWR|os.O_CREATE, 0755)
var f *os.File
f, err = os.OpenFile(fileBlacklistPath, os.O_RDWR|os.O_CREATE, 0755)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
// SimulateHandWriting simulate human writing by typing input string character by character with random interruptions
// between letters
func SimulateHandWriting(element selenium.WebElement, input string) bool {
if err := element.Click(); err == nil {
var err error
if err = element.Click(); err == nil {
for _, c := range input {
if err = element.SendKeys(string(c)); err != nil {
logrus.Debug("Unable to send key during message typing")
Expand Down

0 comments on commit b21712f

Please sign in to comment.