-
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.
- Loading branch information
1 parent
834b715
commit f91f052
Showing
5 changed files
with
67 additions
and
0 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
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,51 @@ | ||
package telegram | ||
|
||
import ( | ||
"fmt" | ||
"html" | ||
"main/pkg/constants" | ||
"main/pkg/types" | ||
"strings" | ||
|
||
tele "gopkg.in/telebot.v3" | ||
) | ||
|
||
func (interacter *Interacter) GetLCDDeleteCommand() Command { | ||
return Command{ | ||
Name: "lcd_delete", | ||
Execute: interacter.HandleDeleteLCD, | ||
} | ||
} | ||
|
||
func (interacter *Interacter) HandleDeleteLCD(c tele.Context, chainBinds []string) (string, error) { | ||
args := strings.SplitN(c.Text(), " ", 3) | ||
if len(args) < 3 { | ||
return html.EscapeString(fmt.Sprintf("Usage: %s <chain name> <host>", args[0])), constants.ErrWrongInvocation | ||
} | ||
|
||
chainName, host := args[1], args[2] | ||
chain, err := interacter.Database.GetChainByName(chainName) | ||
if err != nil { | ||
return "Error finding chain!", err | ||
} | ||
|
||
allLCDs, err := interacter.Database.GetLCDHosts(chain) | ||
if err != nil { | ||
return "Error finding LCD hosts!", err | ||
} | ||
|
||
if len(allLCDs) <= 1 { | ||
return "Cannot remove the only chain LCD!", constants.ErrWrongInvocation | ||
} | ||
|
||
deleted, insertErr := interacter.Database.DeleteLCDHost(chain, host) | ||
if insertErr != nil { | ||
return "Error deleting LCD host!", insertErr | ||
} | ||
|
||
if !deleted { | ||
return "Chain LCD host was not found!", constants.ErrLCDNotFound | ||
} | ||
|
||
return interacter.TemplateManager.Render("lcd_delete", types.ChainWithLCD{Chain: *chain, LCDEndpoint: host}) | ||
} |
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,3 @@ | ||
Successfully deleted LCD host! | ||
<strong>Chain name:</strong> <code>{{ .Chain.Name }}</code> | ||
<strong>LCD endpoint:</strong> <code>{{ .LCDEndpoint }}</code> |