Skip to content

Commit

Permalink
Document roziscoding/grammy-autoquote (#441) (#482)
Browse files Browse the repository at this point in the history
Co-authored-by: Ciki Momogi <git.fytyt@aleeas.com>
Co-authored-by: WingLim <643089849@qq.com>
Co-authored-by: Rogerio Jurado Munhoz <rogerio.munhoz@macbook-will130867.local>
Co-authored-by: KnorpelSenf <shtrog@gmail.com>
Co-authored-by: Roj <ez@roj.im>
Co-authored-by: Roz <3948961+roziscoding@users.noreply.github.com>
Co-authored-by: Habemuscode <habemuscode@protonmail.com>
  • Loading branch information
7 people committed Aug 22, 2022
1 parent daad7c4 commit 92563ba
Show file tree
Hide file tree
Showing 5 changed files with 453 additions and 2 deletions.
14 changes: 13 additions & 1 deletion site/docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ export default defineUserConfig({
text: "Useful Middleware",
link: "/plugins/middlewares.html",
},
{
text: "Autoquote",
link: "/plugins/autoquote.html",
},
{
text: "[Submit your PR!]",
link: "/plugins/#submitting-your-own-package-to-the-docs",
Expand Down Expand Up @@ -609,9 +613,13 @@ export default defineUserConfig({
link: "/es/plugins/console-time.html",
},
{
text: "Middleware útil",
text: "Middlewares de utilidad",
link: "/es/plugins/middlewares.html",
},
{
text: "Citar automáticamente",
link: "/es/plugins/autoquote.html",
},
{
text: "[¡Envíe su PR!]",
link:
Expand Down Expand Up @@ -976,6 +984,10 @@ export default defineUserConfig({
text: "有用的中间件",
link: "/zh/plugins/middlewares.html",
},
{
text: "自动引用",
link: "/zh/plugins/autoquote.html",
},
{
text: "[等待你的 PR!]",
link: "/zh/plugins/#向文档提交你自己的插件",
Expand Down
3 changes: 2 additions & 1 deletion site/docs/.vuepress/plugins/current-versions/modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"grammy_emoji",
"grammy_parse_mode",
"grammy_storages",
"grammy_conversations"
"grammy_conversations",
"grammy_autoquote"
]
}
146 changes: 146 additions & 0 deletions site/docs/es/plugins/autoquote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Responder siempre a los mensajes

A veces es necesario enviar siempre los mensajes como respuestas, especialmente para los bots que están destinados a ser utilizados en grupos.
Normalmente hacemos esto añadiendo el parámetro `reply_to_message_id` a los métodos que envían el mensaje: `sendText`, `reply`, `sendPhoto`, `replyWithPhoto` y otros.
Sin embargo, si estás haciendo esto para cada mensaje, puede ser un desastre y aburrido.

Este plugin establece el parámetro `reply_to_message_id` a `ctx.msg.message_id` para todos los métodos `reply*` y `send*` que lo soportan para hacer que cada mensaje sea una respuesta al mensaje que lo activó.

## Uso

### En Rutas Específicas

Si quieres que todos los mensajes se envíen dentro de un contexto específico (como un comando específico), puedes aplicar el plugin específicamente a ellos:

<CodeGroup>
<CodeGroupItem title="TypeScript" active>

```ts
import { Bot } from "grammy";
import { addReplyParam } from "@roziscoding/grammy-autoquote";

const bot = new Bot("");

bot.command("demo", async (ctx) => {
ctx.api.config.use(addReplyParam(ctx));
await ctx.reply("¡Comando demo!"); // esto va a citar el mensaje del usuario
});

bot.start();
```

</CodeGroupItem>
<CodeGroupItem title="JavaScript">

```js
const { Bot } = require("grammy");
const { addReplyParam } = require("@roziscoding/grammy-autoquote");

const bot = new Bot("");

bot.command("demo", async (ctx) => {
ctx.api.config.use(addReplyParam(ctx));
await ctx.reply("¡Comando demo!"); // esto va a citar el mensaje del usuario
});

bot.start();
```

</CodeGroupItem>
<CodeGroupItem title="Deno">

```ts
import { Bot } from "https://deno.land/x/grammy/mod.ts";
import { addReplyParam } from "https://deno.land/x/grammy_autoquote/mod.ts";

const bot = new Bot("");

bot.command("demo", async (ctx) => {
ctx.api.config.use(addReplyParam(ctx));
await ctx.reply("¡Comando demo!"); // esto va a citar el mensaje del usuario
});

bot.start();
```

</CodeGroupItem>
</CodeGroup>

### Para todas las rutas

Si quieres que todos los mensajes enviados respondan a los mensajes que los desencadenaron, puedes aplicar el plugin de esta manera:

<CodeGroup>
<CodeGroupItem title="TypeScript" active>

```ts
import { Bot } from "grammy";
import { autoQuote } from "@roziscoding/grammy-autoquote";

const bot = new Bot("");

bot.use(autoQuote);

bot.command("demo", async (ctx) => {
await ctx.reply("¡Comando demo!"); // esto va a citar el mensaje del usuario
});

bot.command("hola", async (ctx) => {
await ctx.reply("Hola :)"); // esto también cita el mensaje del usuario
});

bot.start();
```

</CodeGroupItem>
<CodeGroupItem title="JavaScript">

```js
const { Bot } = require("grammy");
const { autoQuote } = require("@roziscoding/grammy-autoquote");

const bot = new Bot("");

bot.use(autoQuote);

bot.command("demo", async (ctx) => {
await ctx.reply("¡Comando demo!"); // esto va a citar el mensaje del usuario
});

bot.command("hola", async (ctx) => {
await ctx.reply("Hola :)"); // esto también cita el mensaje del usuario
});

bot.start();
```

</CodeGroupItem>
<CodeGroupItem title="Deno">

```ts
import { Bot } from "https://deno.land/x/grammy/mod.ts";
import { autoQuote } from "https://deno.land/x/grammy_autoquote/mod.ts";

const bot = new Bot("");

bot.use(autoQuote);

bot.command("demo", async (ctx) => {
await ctx.reply("¡Comando demo!"); // esto va a citar el mensaje del usuario
});

bot.command("hola", async (ctx) => {
await ctx.reply("Hola :)"); // esto también cita el mensaje del usuario
});

bot.start();
```

</CodeGroupItem>
</CodeGroup>

## Resumen del plugin

- Nombre: Autoquote
- Fuente: <https://github.com/roziscoding/grammy-autoquote>
- Referencia de la API: <https://doc.deno.land/https://deno.land/x/grammy_autoquote/mod.ts>
146 changes: 146 additions & 0 deletions site/docs/plugins/autoquote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Always Replying to Messages

It is sometimes necessary to always send messages as replies, especially for bots that are meant to be used in groups.
We usually do this by adding the `reply_to_message_id` parameter to the methods that send the message: `sendText`, `reply`, `sendPhoto`, `replyWithPhoto` and etc.
However, if you're doing this for every single message, it can get messy and boring.

This plugin sets the `reply_to_message_id` parameter to `ctx.msg.message_id` for all `reply*` and `send*` methods that support it to make every message a reply to the message that triggered it.

## Usage

### In Specific Routes

If you want all messages sent within a specific context (like a specific command), you can specifically apply the plugin to them:

<CodeGroup>
<CodeGroupItem title="TypeScript" active>

```ts
import { Bot } from "grammy";
import { addReplyParam } from "@roziscoding/grammy-autoquote";

const bot = new Bot("");

bot.command("demo", async (ctx) => {
ctx.api.config.use(addReplyParam(ctx));
await ctx.reply("Demo command!"); // this is going to quote the user's message
});

bot.start();
```

</CodeGroupItem>
<CodeGroupItem title="JavaScript">

```js
const { Bot } = require("grammy");
const { addReplyParam } = require("@roziscoding/grammy-autoquote");

const bot = new Bot("");

bot.command("demo", async (ctx) => {
ctx.api.config.use(addReplyParam(ctx));
await ctx.reply("Demo command!"); // this is going to quote the user's message
});

bot.start();
```

</CodeGroupItem>
<CodeGroupItem title="Deno">

```ts
import { Bot } from "https://deno.land/x/grammy/mod.ts";
import { addReplyParam } from "https://deno.land/x/grammy_autoquote/mod.ts";

const bot = new Bot("");

bot.command("demo", async (ctx) => {
ctx.api.config.use(addReplyParam(ctx));
await ctx.reply("Demo command!"); // this is going to quote the user's message
});

bot.start();
```

</CodeGroupItem>
</CodeGroup>

### In for All Routes

If you want every sent message to reply the messages that triggered them, you can apply the plugin this way:

<CodeGroup>
<CodeGroupItem title="TypeScript" active>

```ts
import { Bot } from "grammy";
import { autoQuote } from "@roziscoding/grammy-autoquote";

const bot = new Bot("");

bot.use(autoQuote);

bot.command("demo", async (ctx) => {
await ctx.reply("Demo command!"); // this is going to quote the user's message
});

bot.command("hello", async (ctx) => {
await ctx.reply("Hi there :)"); // this quotes the user's message, too
});

bot.start();
```

</CodeGroupItem>
<CodeGroupItem title="JavaScript">

```js
const { Bot } = require("grammy");
const { autoQuote } = require("@roziscoding/grammy-autoquote");

const bot = new Bot("");

bot.use(autoQuote);

bot.command("demo", async (ctx) => {
await ctx.reply("Demo command!"); // this is going to quote the user's message
});

bot.command("hello", async (ctx) => {
await ctx.reply("Hi there :)"); // this quotes the user's message, too
});

bot.start();
```

</CodeGroupItem>
<CodeGroupItem title="Deno">

```ts
import { Bot } from "https://deno.land/x/grammy/mod.ts";
import { autoQuote } from "https://deno.land/x/grammy_autoquote/mod.ts";

const bot = new Bot("");

bot.use(autoQuote);

bot.command("demo", async (ctx) => {
await ctx.reply("Demo command!"); // this is going to quote the user's message
});

bot.command("hello", async (ctx) => {
await ctx.reply("Hi there :)"); // this quotes the user's message, too
});

bot.start();
```

</CodeGroupItem>
</CodeGroup>

## Plugin Summary

- Name: Autoquote
- Source: <https://github.com/roziscoding/grammy-autoquote>
- API Reference: <https://doc.deno.land/https://deno.land/x/grammy_autoquote/mod.ts>
Loading

0 comments on commit 92563ba

Please sign in to comment.