-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add mutes * chore: fixed linting * chore: fixed linting, v2 * chore: fixed linting, v3 * feat: allow listing mutes
- Loading branch information
1 parent
340b7cb
commit ad0060c
Showing
10 changed files
with
321 additions
and
21 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 |
---|---|---|
|
@@ -35,3 +35,4 @@ linters: | |
- tagliatelle | ||
- errorlint | ||
- gofumpt | ||
- noctx |
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
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 main | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
|
||
"github.com/rs/zerolog" | ||
) | ||
|
||
type MutesManager struct { | ||
MutesPath string | ||
Logger zerolog.Logger | ||
Mutes Mutes | ||
} | ||
|
||
func NewMutesManager(mutesPath string, logger *zerolog.Logger) *MutesManager { | ||
return &MutesManager{ | ||
MutesPath: mutesPath, | ||
Logger: logger.With().Str("component", "mutes_manager").Logger(), | ||
Mutes: Mutes{}, | ||
} | ||
} | ||
|
||
func (m *MutesManager) Load() { | ||
if m.MutesPath == "" { | ||
m.Logger.Debug().Msg("Mutes path not configured, not loading.") | ||
return | ||
} | ||
|
||
content, err := os.ReadFile(m.MutesPath) | ||
if err != nil { | ||
m.Logger.Warn().Err(err).Msg("Could not load mutes") | ||
return | ||
} | ||
|
||
var mutes Mutes | ||
if err = json.Unmarshal(content, &mutes); err != nil { | ||
m.Logger.Warn().Err(err).Msg("Could not unmarshall mutes") | ||
m.Mutes = Mutes{} | ||
} | ||
|
||
m.Mutes = mutes | ||
} | ||
|
||
func (m *MutesManager) Save() { | ||
if m.MutesPath == "" { | ||
m.Logger.Debug().Msg("Mutes path not configured, not saving.") | ||
return | ||
} | ||
|
||
content, err := json.Marshal(m.Mutes) | ||
if err != nil { | ||
m.Logger.Warn().Err(err).Msg("Could not marshal mutes") | ||
return | ||
} | ||
|
||
if err = os.WriteFile(m.MutesPath, content, 0o600); err != nil { | ||
m.Logger.Warn().Err(err).Msg("Could not save mutes") | ||
return | ||
} | ||
} | ||
|
||
func (m *MutesManager) IsMuted(chain string, proposalID string) bool { | ||
if m.MutesPath == "" { | ||
return false | ||
} | ||
|
||
return m.Mutes.IsMuted(chain, proposalID) | ||
} | ||
|
||
func (m *MutesManager) AddMute(mute Mute) { | ||
m.Mutes.AddMute(mute) | ||
m.Save() | ||
} | ||
|
||
func (m *MutesManager) DeleteMute(chain string, proposalID string) { | ||
m.Mutes.DeleteMute(chain, proposalID) | ||
m.Save() | ||
} |
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
Oops, something went wrong.