https://github.com/slice/boozle
"scalacord" would've been too overt
https://github.com/slice/boozle
Last synced: 7 days ago
JSON representation
"scalacord" would've been too overt
- Host: GitHub
- URL: https://github.com/slice/boozle
- Owner: slice
- Created: 2025-02-16T06:30:55.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-18T05:55:31.000Z (over 1 year ago)
- Last Synced: 2025-02-25T15:48:00.068Z (about 1 year ago)
- Language: Scala
- Homepage:
- Size: 107 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# boozle
> [!WARNING]
> Work in progress. Not for general consumption. Contains chemicals known to
> the State of California to cause cancer and birth defects or other
> reproductive harm.[1]
Write [Discord] bots while leveraging the [Typelevel] ecosystem.
[discord]: https://discord.com
[typelevel]: https://github.com/typelevel
This example sends an embed with a button component that lets users increment
the value displayed. The embed displays who performed the last three increments,
and the updates are debounced to only occur every 3 seconds at most.
```scala
def counter[F[_]] = Cmd:
for
increment = Button[F]("+1")
msg <- replyEmbed(embed { title("0") }, components = List(increment))
_ <- increment.clicks(in = msg)
.interactTap { deferEdit } // immediately respond to the interaction…
.buffer(1)
.zipWithIndex
.map { case (given Interaction[F], count) =>
(count, s"$count. Clicked by **${invoker.mention}**!")
}
.sliding(3)
.debounce(3.seconds) // …but limit updates to a max of once every 3s
.evalMap { lastThreeClicks =>
val (latestCount, _) = lastThreeClicks.last.get
val summary = lastThreeClicks.map(_._2).mkString_("\n")
msg.edit(embed {
title(s"$latestCount".refineUnsafe)
description(summary.refineUnsafe)
})
}
.runFor(5.minutes)
yield msg
```