Skip to content

Commit

Permalink
Start work on docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Katrix committed Oct 16, 2023
1 parent e695c6b commit 82d7202
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 8 deletions.
10 changes: 2 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ lazy val publishSettings = Seq(
publishMavenStyle := true,
Test / publishArtifact := false,
licenses := Seq("MIT" -> url("http://opensource.org/licenses/MIT")),
scmInfo := Some(
ScmInfo(
url("https://github.com/Katrix/AckCord"),
"scm:git:github.com/Katrix/AckCord",
Some("scm:git:github.com/Katrix/AckCord")
)
),
moduleName := {
val old = moduleName.value
s"ackcord-$old"
Expand Down Expand Up @@ -178,7 +171,8 @@ lazy val docs = project
dataJVM,
requestsJVM,
gatewayJVM,
interactionsJVM
interactionsJVM,
ackcordJVM
),
Compile / doc / scalacOptions ++= Seq("-skip-packages", "com.iwebpp"),
docsMappingsAPIDir := "api",
Expand Down
1 change: 1 addition & 0 deletions docs/src/main/mdoc/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ackcord.katsstuff.net
34 changes: 34 additions & 0 deletions docs/src/main/mdoc/docs/data_objects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
layout: docs
title: Data objects
---

# {{page.title}}

Being a library for Discord is not always easy, especially for all the data
objects AckCord has to handle. Keeping everything as case classes might seem
simple at first, but also means an upfront cost of decoding the JSON, and the
chance that the decoder is just wrong. It also makes it harder to evolve the
library in a binary compatible way.

To get around these issues, AckCord instead keeps the JSON around, decoding each
field as needed. This does mean that if AckCord has the wrong types for a field,
accessing it will throw an exception. It also means that you as the user can
easily work around this issue until AckCord releases a new fixed version.

## Selecting fields manually
AckCord's data class field accessors generally call the function
`DiscordObject#selectDynamic`. If a field is missing, or has the wrong type,
nothing stops you as a user from calling this function yourself with the correct
field name and type.

## Retyping data
Calling `asInstanceOf` on a data object is often an error. Instead, what you
might want is `retype`. `asInstanceOf` casts the data object to a different
class, failing if the data object is not an instance of that class. `retype`
meanwhile reinterprets the data object as a different type.

There are many uses of retyping data. The most common is that an object is
all fields of `X`, in addition to fields `a`, `b` and `c`. This can be
represented as a data object with accessors `a`, `b`, and `c`, and another
accessor `x` which retypes the object to `X`.
14 changes: 14 additions & 0 deletions docs/src/main/mdoc/docs/requests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
layout: docs
title: Requests
---

# {{page.title}}

Requests are how most bot actions are done. Stuff like sending messages,
creating channels and managing users. AckCord represents every request as an
object you construct. To run these requests, you need a `Requests` object, which
is backed by sttp. The easiest way to get a `Requests` is using the one found
through `BotSettings#requests`. The get the request object, you call a function
to create it on an object defined in `ackcord.requests`. Which object it is in
depends on what page in the discord docs the request appears on.
22 changes: 22 additions & 0 deletions docs/src/main/mdoc/docs/snowflakes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
layout: docs
title: Snowflake types
---

# {{page.title}}
Unlike other Discord libraries, AckCord doesn't have one specific snowflake type,
instead it uses a type `Snowflake[A]` to refer to something of type `A`.
Most of these types also have aliases, like `UserId` being an alias
for `Snowflake[User]`.

## Converting to snowflake
To convert a long or string(prefer string) to a snowflake, use the apply method
on the companion object. For example: `UserId(0L)`

You can also use this to "cast" one snowflake type to another.
For example: `RoleId(guildId)`.

## Raw snowflakes
In some cases it's not possible to give a concrete type to the snowflake.
In those cases `RawSnowflake` is used instead, an alias for `SnowflakeType[Any]`.
In most cases you'll have to cast this to what you need yourself.
29 changes: 29 additions & 0 deletions docs/src/main/mdoc/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
layout: home
title: "AckCord"
---

{% assign versions = site.data.versions %}

# AckCord
*You do what you want, exactly how you want it.*

AckCord is a Scala Discord library, powered by sttp. AckCord's focus is on
letting you choose the level of abstraction you want, without sacrificing speed.
Want to work with the raw events from the gateway? Works for that. Maybe you
don't want to bother with any of the underlying implementation and technicalities.
Works for that too. Only interested in the REST requests? Pull in that module
and ignore the rest. AckCord is fast, modular, and clean, focusing on
letting you write good code.

Add AckCord to your project by adding these statements to your `build.sbt` file.
```scala
libraryDependencies += "net.katsstuff" %% "ackcord" % "{{versions.ackcord}}"
```

# More information
For more information, either see the the examples or the ScalaDoc.

Or you can just join the Discord server (we got cookies).

[![](https://discord.com/api/guilds/399373512072232961/embed.png?style=banner1)](https://discord.gg/5UH627u)
9 changes: 9 additions & 0 deletions docs/src/main/resources/microsite/data/menu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
options:
- title: AckCord's data objects
url: docs/data_objects.html

- title: Requests
url: docs/requests.html

- title: Snowflake types
url: docs/snowflakes.html
1 change: 1 addition & 0 deletions docs/src/main/resources/microsite/data/versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ackcord: "2.0.0.0-M1"

0 comments on commit 82d7202

Please sign in to comment.