Skip to content

Commit

Permalink
chore: add plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
kravetsone committed Feb 23, 2024
1 parent e7437f7 commit 4ec0e1a
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 61 deletions.
Binary file modified bun.lockb
Binary file not shown.
133 changes: 76 additions & 57 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -25,66 +25,85 @@ export default defineConfig({
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: "Home", link: "/" },
{ text: "Get started", link: "/get-started" },
{ text: "Plugins", link: "/plugins/index" },
// { text: "Examples", link: "/markdown-examples" },
],

sidebar: [
{
text: "Guide",
items: [
{ text: "Get started", link: "/get-started" },
{
text: "Contexts",
link: "https://tsdocs.dev/docs/@gramio/contexts",
},
{
text: "Keyboards",
collapsed: false,
items: [
{
text: "Overview",
link: "/keyboards/overview",
},
{
text: "Keyboard",
link: "/keyboards/keyboard",
},
{
text: "Inline Keyboard",
link: "/keyboards/inline-keyboard",
},
{
text: "Remove Keyboard",
link: "/keyboards/remove-keyboard",
},
{
text: "Force Reply Keyboard",
link: "/keyboards/force-reply-keyboard",
},
],
},
{
text: "Files",
collapsed: false,
items: [
{
text: "Overview",
link: "/files/overview",
},
{ text: "Media Upload", link: "/files/media-upload" },
{ text: "Media Input", link: "/files/media-input" },
{
text: "Usage without GramIO",
link: "/files/usage-without-gramio",
},
],
},
{ text: "Formatting", link: "/formatting/index" },
{ text: "Types", link: "/types/index" },
{ text: "Error Handling", link: "/error-handling/index" },
],
},
],
sidebar: {
"/plugins/": [
{
text: "Plugins",
items: [
{
text: "Overview",
link: "/plugins/index",
},
{
text: "How to write a plugin",
link: "/plugins/how-to-write",
},
],
},
],
"/": [
{
text: "Guide",
items: [
{ text: "Get started", link: "/get-started" },
{
text: "Contexts",
link: "https://tsdocs.dev/docs/@gramio/contexts",
},
{
text: "Keyboards",
collapsed: false,
items: [
{
text: "Overview",
link: "/keyboards/overview",
},
{
text: "Keyboard",
link: "/keyboards/keyboard",
},
{
text: "Inline Keyboard",
link: "/keyboards/inline-keyboard",
},
{
text: "Remove Keyboard",
link: "/keyboards/remove-keyboard",
},
{
text: "Force Reply Keyboard",
link: "/keyboards/force-reply-keyboard",
},
],
},
{
text: "Files",
collapsed: false,
items: [
{
text: "Overview",
link: "/files/overview",
},
{ text: "Media Upload", link: "/files/media-upload" },
{ text: "Media Input", link: "/files/media-input" },
{
text: "Usage without GramIO",
link: "/files/usage-without-gramio",
},
],
},
{ text: "Formatting", link: "/formatting/index" },
{ text: "Types", link: "/types/index" },
{ text: "Error Handling", link: "/error-handling/index" },
],
},
],
},
socialLinks: [
{ icon: "github", link: "https://github.com/gramiojs/gramio" },
{
Expand Down
34 changes: 34 additions & 0 deletions docs/plugins/how-to-write.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# How to write a plugin

It happens that you are missing something... And plugins can help you with this!

# Example

```ts twoslash
import { Plugin, Bot } from "gramio";

export class PluginError extends Error {
wow: "type" | "safe" = "type"
}

const plugin = new Plugin("gramio-example")
.error("PLUGIN", PluginError)
.derive(() => {
return {
some: ["derived", "props"] as const,
};
});

const bot = new Bot(process.env.TOKEN!)
.extend(plugin)
.onError({ context, kind, error } => {
if(context.is("message") && kind === "PLUGIN") {
console.log(error.wow);
// ^^^
}
})
.use((context) => {
console.log(context.some);
// ^^^^
});
```
1 change: 1 addition & 0 deletions docs/plugins/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Overview
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"@gramio/files": "^0.0.3",
"@gramio/format": "^0.0.8",
"@gramio/keyboards": "^0.1.6",
"@gramio/types": "^7.1.2",
"@shikijs/vitepress-twoslash": "^1.1.5",
"@types/node": "^20.11.19",
"@gramio/types": "^7.1.3",
"@shikijs/vitepress-twoslash": "^1.1.6",
"@types/node": "^20.11.20",
"form-data-encoder": "^4.0.2",
"gramio": "^0.0.11",
"gramio": "^0.0.16",
"grammy": "^1.21.1",
"undici": "^6.6.2",
"vitepress": "^1.0.0-rc.44"
Expand Down

0 comments on commit 4ec0e1a

Please sign in to comment.