Skip to content

Commit

Permalink
feat: clean up docs and code
Browse files Browse the repository at this point in the history
  • Loading branch information
krzko committed Nov 13, 2023
1 parent 39da2dc commit 9c2ccc7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,39 @@ Slack Buddy custom and scheduled statuses can be added via updating the`config.y
* **macOS**: `~/.slack-buddy/config.yaml`
* **Windows**: Not tested yet

### `api_token`

You will need to retrieve a Personal Token from a Slack Workspace Administrator. You can get more details from the Slack [Access Tokens](https://api.slack.com/authentication/token-types) page.

### `user_id`

To retrieve youe `user_id` value, follow these steps:

* Open **Slack**.
* Open **Profile** window.
* Select the **three vertical dots** next to **View As**.
* Select **Copy memeber ID**.

### `disaply_name`

* This is the default disaply name value. All statuses will be set via **`display_name` + "is ..."**.
* This is the value that is set when you select **Clear Status**.

### Example Configuration

* The `title` value has to be unique.
* Custom statuses do not have `days`, `start_time` or `end_time` values set.
* Ensure the `status_emoji` value exists in your Slack workspace.

```yaml
api_token: xoxp-xxx-xxx-xxx-xxx
user_id: XXXXXXXXX
display_name: Kristof
custom_items:
- title: "Zwift"
tooltip: ""
status_text: "on Zwift"
status_emoji: ":bike:"
- title: "School Run"
tooltip: ""
status_text: "on a school run"
Expand Down
9 changes: 0 additions & 9 deletions pkg/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ func (c *StdLibClient) UpdateDisplayName(userID, displayName string) error {
}
defer resp.Body.Close()

// New logging
// respBody, err := io.ReadAll(resp.Body)
// if err != nil {
// return err
// }
// fmt.Printf("Response status: %s, body: %s\n", resp.Status, string(respBody))

// Handle the response (e.g., check for success, handle errors, etc.)

return nil
}

Expand Down
15 changes: 5 additions & 10 deletions pkg/systray/systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ func OnReady() {
// Load configuration
cfg, err := config.LoadConfig()
if err != nil {
// Handle error (e.g., log it)
cfg = &config.Config{} // Create a new config if loading failed
cfg = &config.Config{}
}

// After loading the config, check for duplicate titles
checkForDuplicateTitles(cfg.CustomItems)

handler := &SystrayHandler{
cfg: cfg,
}
Expand All @@ -42,6 +38,9 @@ func OnReady() {
if handler.cfg.ApiToken == "your_default_api_token" || handler.cfg.UserId == "your_default_user_id" || handler.cfg.DisplayName == "your_default_display_name" {
openSettingsDialog(cfg)
}

// After loading the config, check for duplicate titles
checkForDuplicateTitles(cfg.CustomItems)
}

func (h *SystrayHandler) getSlackClient() (*slack.SlackClient, error) {
Expand Down Expand Up @@ -273,7 +272,6 @@ func (h *SystrayHandler) initializeSystray() {
}
}()

// New goroutine for handling custom menu items and separating scheduled items
// New goroutine for handling custom menu items and separating scheduled items
if len(h.cfg.CustomItems) > 0 {
go func() {
Expand Down Expand Up @@ -305,7 +303,7 @@ func openSettingsDialog(cfg *config.Config) {
fmt.Printf("Error displaying User ID dialog: %v\n", err)
return
}
cfg.UserId = userId // Update the value
cfg.UserId = userId

displayName, _, err := dlgs.Entry("Display Name", "Enter your Slack Display Name:", cfg.DisplayName)
if err != nil {
Expand Down Expand Up @@ -395,7 +393,6 @@ func (h *SystrayHandler) unsetStatus() error {
return slackClient.UnsetStatus()
}

// findCustomItemByStatusText finds a custom item by its status text.
func findCustomItemByStatusText(items []config.CustomItem, statusText string) *config.CustomItem {
for _, item := range items {
if item.StatusText == statusText {
Expand All @@ -405,7 +402,6 @@ func findCustomItemByStatusText(items []config.CustomItem, statusText string) *c
return nil
}

// findCustomItemByTitle finds a custom item by its title.
func findCustomItemByTitle(items []config.CustomItem, title string) *config.CustomItem {
for _, item := range items {
if item.Title == title {
Expand All @@ -415,7 +411,6 @@ func findCustomItemByTitle(items []config.CustomItem, title string) *config.Cust
return nil
}

// checkForDuplicateTitles checks for duplicate titles in the custom items and exits if found.
func checkForDuplicateTitles(items []config.CustomItem) {
titles := make(map[string]bool)
for _, item := range items {
Expand Down

0 comments on commit 9c2ccc7

Please sign in to comment.