Skip to content

Commit

Permalink
small tweaks and review comments (extra paren in version, better whit…
Browse files Browse the repository at this point in the history
…espace handling, cleaner trim prefix,...) (#9)

* small tweaks and review comments

* further clean, though mutating the original message may be not super clean

* cuter help/version text with unicode
  • Loading branch information
ldemailly authored Jul 16, 2024
1 parent a771249 commit 19a9a3e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ func handleDM(session *discordgo.Session, message *discordgo.MessageCreate) {
log.S(log.Warning, "ignoring bot message", log.Any("message", message))
return
}
what := message.Content
if strings.HasPrefix(message.Content, "!grol") {
what = what[5:]
}
what := strings.TrimPrefix(message.Content, "!grol")
evalAndReply(session, "dm-reply", message.ChannelID, what)
}

Expand All @@ -62,23 +59,25 @@ func removeTripleBackticks(s string) string {

func evalAndReply(session *discordgo.Session, info, channelID, input string) {
var res string
input = strings.TrimSpace(input)
input = strings.TrimSpace(input) // we do it again so " !grol help" works
switch input {
case "":
fallthrough
case "info":
fallthrough
case "help":
res = "Grol bot help: grol bot evaluates grol language fragments, as simple as expressions like `1+1`" +
" and as complex as defining closures, using map, arrays, etc... the syntax is similar to go.\n\n" +
res = "💡 Grol bot help: grol bot evaluates grol language fragments, as simple as expressions like `1+1`" +
" and as complex as defining closures, using map, arrays, etc... the syntax is similar to go (without :=).\n\n" +
"also supported `!grol version`, `!grol source`, `!grol buildinfo`"
case "source":
res = "[github.com/grol-io/grol-discord-bot](<https://github.com/grol-io/grol-discord-bot>)" +
res = "📄 [github.com/grol-io/grol-discord-bot](<https://github.com/grol-io/grol-discord-bot>)" +
" and [grol-io](<https://grol.io>)"
case "version":
res = "Grol bot version: " + cli.ShortVersion + ", `grol` language version " + growlVersion + ")"
res = "📦 Grol bot version: " + cli.ShortVersion + ", `grol` language version " + growlVersion
case "buildinfo":
res = "```" + cli.FullVersion + "```"
res = "📦ℹ️```" + cli.FullVersion + "```"
case "bug":
res = "🐞 Please report any issue or suggestion at [github.com/grol-io/grol-discord-bot/issues](<https://github.com/grol-io/grol-discord-bot/issues>)"
default:
// TODO: stdout vs stderr vs result. https://github.com/grol-io/grol/issues/33
// TODO: Maybe better quoting.
Expand Down Expand Up @@ -116,6 +115,7 @@ func newMessage(session *discordgo.Session, message *discordgo.MessageCreate) {
return
}
isDM := message.GuildID == ""
message.Content = strings.TrimSpace(message.Content)
if isDM {
handleDM(session, message)
return
Expand Down

0 comments on commit 19a9a3e

Please sign in to comment.