Skip to content

Commit

Permalink
Document roziscoding/grammy-autoquote (#441)
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>
  • Loading branch information
6 people committed Aug 22, 2022
1 parent daad7c4 commit feb1c04
Show file tree
Hide file tree
Showing 4 changed files with 302 additions and 1 deletion.
8 changes: 8 additions & 0 deletions 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 @@ -976,6 +980,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/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>
146 changes: 146 additions & 0 deletions site/docs/zh/plugins/autoquote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# 总是回复消息

有时候有必要总是将消息作为回复发送,特别是对于那些打算要在群组中使用的 bot。
我们通常通过在发送消息的方法中添加 `reply_to_message_id` 参数来实现这一点:`sendText`, `reply`, `sendPhoto`, `replyWithPhoto` 等等。
然而,如果你对每一条消息都这样做,这会使得代码变得很无聊和繁琐。

这个插件将所有 `reply*``send*` 方法的 `reply_to_message_id` 参数设置为 `ctx.msg.message_id`,以便每条消息都是对触发这条消息的回复。

## 使用方式

### 在指定的路由中

如果你想让所有在特定上下文的消息进行回复(比如特定的命令),你可以专门应用这个插件到它们上面:

<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!"); // 这将会引用用户的消息
});

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!"); // 这将会引用用户的消息
});

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!"); // 这将会引用用户的消息
});

bot.start();
```

</CodeGroupItem>
</CodeGroup>

### 在所有路由中

如果你希望每条发送的消息都回复触发它的消息,你可以通过这样的方式应用这个插件:

<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!"); // 这将会引用用户的消息
});

bot.command("hello", async (ctx) => {
await ctx.reply("Hi there :)"); // 这也会引用用户的消息
});

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!"); // 这将会引用用户的消息
});

bot.command("hello", async (ctx) => {
await ctx.reply("Hi there :)"); // 这也会引用用户的消息
});

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!"); // 这将会引用用户的消息
});

bot.command("hello", async (ctx) => {
await ctx.reply("Hi there :)"); // 这也会引用用户的消息
});

bot.start();
```

</CodeGroupItem>
</CodeGroup>

## 插件概述

- 名字:Autoquote
- 源码:<https://github.com/roziscoding/grammy-autoquote>
- API 参考:<https://doc.deno.land/https://deno.land/x/grammy_autoquote/mod.ts>

0 comments on commit feb1c04

Please sign in to comment.