-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document roziscoding/grammy-autoquote (#441)
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
1 parent
daad7c4
commit feb1c04
Showing
4 changed files
with
302 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |