-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from yossydev/fix/command
Fix/command
- Loading branch information
Showing
10 changed files
with
154 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Bump Homebrew Formula | ||
on: | ||
push: | ||
branches: [main] | ||
jobs: | ||
homebrew: | ||
name: Bump Homebrew formula | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
steps: | ||
- name: Extract version | ||
id: extract-version | ||
run: | | ||
echo "tag-name=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | ||
- name: Bump Homebrew formula | ||
uses: mislav/bump-homebrew-formula-action@v3 | ||
with: | ||
formula-name: rando_lgtm | ||
formula-path: rando_lgtm.rb | ||
homebrew-tap: yossydev/homebrew-RandoLGTM | ||
base-branch: main | ||
download-url: https://github.com/yossydev/RandoLGTM/archive/refs/tags/${{ steps.extract-version.outputs.tag-name }}.tar.gz | ||
commit-message: | | ||
rando_lgtm ${{ steps.extract-version.outputs.tag-name }} | ||
Created by https://github.com/mislav/bump-homebrew-formula-action | ||
env: | ||
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
/RandoLGTM | ||
/messages.txt | ||
/main |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var addCmd = &cobra.Command{ | ||
Use: "add", | ||
Short: "Add a new LGTM message", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := addMessageToFile(args[0]) | ||
if err != nil { | ||
fmt.Println("Error: ", err) | ||
return | ||
} | ||
fmt.Printf("Added new LGTM message: '%s'\n", args[0]) | ||
}, | ||
} | ||
|
||
func addMessageToFile(message string) error { | ||
file, err := os.OpenFile("messages.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) | ||
if err != nil { | ||
return fmt.Errorf("failed to open file: %v", err) | ||
} | ||
defer file.Close() | ||
_, err = file.WriteString(message + "\n") | ||
if err != nil { | ||
return fmt.Errorf("failed to write to file: %v", err) | ||
} | ||
return nil | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(addCmd) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"strings" | ||
"time" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var emojis = []string{ | ||
"😀", "😃", "😄", "😁", "😆", "😅", "😂", "🤣", "😊", "😇", | ||
"🙂", "🙃", "😉", "😌", "😍", "🥰", "😘", "😗", "😙", "😚", | ||
"😋", "😛", "😝", "😜", "🤪", "🤨", "🧐", "🤓", "😎", "🥸", | ||
"😏", "😒", "😫", "😩", "🥺", "😢", "😭", "😤", "🤯", "😳", | ||
"🤗", "🤭", "🤫", "😬", "😴", "🤤", "🥴", "🤑", "🤠", "😈", | ||
"👹", "👺", "🤡", "👻", "💀", "👽", "👾", "🤖", "🎃", "😺", | ||
"😸", "😹", "😻", "😼", "😽", | ||
} | ||
|
||
var getCmd = &cobra.Command{ | ||
Use: "get", | ||
Short: "Get a random LGTM message", | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
message, err := getRandomMessageFromFile() | ||
if err != nil { | ||
fmt.Println("Error: ", err) | ||
return | ||
} | ||
fmt.Println(message) | ||
}, | ||
} | ||
|
||
func surroundWithEmoji(s string) string { | ||
r := rand.New(rand.NewSource(time.Now().UnixNano())) | ||
emoji := emojis[r.Intn(len(emojis))] | ||
return emoji + s + emoji | ||
} | ||
|
||
var defaultMessages = []string{ | ||
"Looks good to me!", | ||
"Great job!", | ||
"Well done!", | ||
"Keep up the good work!", | ||
} | ||
|
||
func getRandomMessageFromFile() (string, error) { | ||
var messages []string | ||
if _, err := os.Stat("messages.txt"); err == nil { | ||
content, err := os.ReadFile("messages.txt") | ||
if err != nil { | ||
return "", fmt.Errorf("failed to read file: %v", err) | ||
} | ||
lines := strings.Split(string(content), "\n") | ||
for _, line := range lines { | ||
if line != "" { | ||
messages = append(messages, line) | ||
} | ||
} | ||
} | ||
for _, message := range defaultMessages { | ||
if message != "" { | ||
messages = append(messages, message) | ||
} | ||
} | ||
if len(messages) == 0 { | ||
return "", fmt.Errorf("no messages available") | ||
} | ||
r := rand.New(rand.NewSource(time.Now().UnixNano())) | ||
randomMessage := messages[r.Intn(len(messages))] | ||
return surroundWithEmoji(randomMessage), nil | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(getCmd) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
Copyright © 2023 NAME HERE [email protected] | ||
*/ | ||
package main | ||
|
||
|