Skip to content

Commit

Permalink
creds: Support line breaks in values and shorten too long values
Browse files Browse the repository at this point in the history
  • Loading branch information
Brawl345 committed Oct 5, 2024
1 parent 1cd07c7 commit 06a36d8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions plugin/creds/creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (p *Plugin) Handlers(botInfo *gotgbot.User) []plugin.Handler {
AdminOnly: true,
},
&plugin.CommandHandler{
Trigger: regexp.MustCompile(fmt.Sprintf(`(?i)^/creds_add(?:@%s)? ([^\s]+) (.+)$`, botInfo.Username)),
Trigger: regexp.MustCompile(fmt.Sprintf(`(?i)^/creds_add(?:@%s)? ([^\s]+) ([\s\S]+)$`, botInfo.Username)),
HandlerFunc: p.OnAdd,
AdminOnly: true,
},
Expand Down Expand Up @@ -82,7 +82,11 @@ func (p *Plugin) OnGet(b *gotgbot.Bot, c plugin.GobotContext) error {
var sb strings.Builder

for _, key := range keys {
sb.WriteString(fmt.Sprintf("<b>%s</b>:\n<code>%s</code>\n", key, creds[key]))
if len(creds[key]) > 300 {
sb.WriteString(fmt.Sprintf("<b>%s</b>:\n<code>%s...</code>\n", key, creds[key][:297]))
} else {
sb.WriteString(fmt.Sprintf("<b>%s</b>:\n<code>%s</code>\n", key, creds[key]))
}
}

_, err := c.EffectiveMessage.Reply(b, sb.String(), &gotgbot.SendMessageOpts{
Expand Down

0 comments on commit 06a36d8

Please sign in to comment.