From 7c178c58e8bc3d2b0ae60c264da1f0fb5ab0a8f7 Mon Sep 17 00:00:00 2001 From: Rogerio Jurado Munhoz Date: Thu, 21 Jul 2022 17:36:28 -0300 Subject: [PATCH 01/16] docs: add graamy-autoquote to docs --- site/docs/.vuepress/config.ts | 12 +++++++ site/docs/es/plugins/autoquote.md | 56 +++++++++++++++++++++++++++++++ site/docs/plugins/autoquote.md | 56 +++++++++++++++++++++++++++++++ site/docs/zh/plugins/autoquote.md | 56 +++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 site/docs/es/plugins/autoquote.md create mode 100644 site/docs/plugins/autoquote.md create mode 100644 site/docs/zh/plugins/autoquote.md diff --git a/site/docs/.vuepress/config.ts b/site/docs/.vuepress/config.ts index 39fc87ce6..320db6240 100644 --- a/site/docs/.vuepress/config.ts +++ b/site/docs/.vuepress/config.ts @@ -249,6 +249,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", @@ -611,6 +615,10 @@ export default defineUserConfig({ text: "Middleware útil", link: "/es/plugins/middlewares.html", }, + { + text: "Autocita", + link: "/es/plugins/autoquote.html", + }, { text: "[¡Envíe su PR!]", link: @@ -971,6 +979,10 @@ export default defineUserConfig({ text: "有用的中间件", link: "/zh/plugins/middlewares.html", }, + { + text: "自动报价", + link: "/zh/plugins/autoquote.html", + }, { text: "[等待你的 PR!]", link: "/zh/plugins/#向文档提交你自己的插件", diff --git a/site/docs/es/plugins/autoquote.md b/site/docs/es/plugins/autoquote.md new file mode 100644 index 000000000..beea0cbce --- /dev/null +++ b/site/docs/es/plugins/autoquote.md @@ -0,0 +1,56 @@ +# Siempre respondiendo a los mensajes + +A veces, especialmente para los bots que están destinados a ser utilizados en grupos, siempre es necesario enviar mensajes como respuesta (o cita) al mensaje que inició la interacción. Por lo general, la forma de hacerlo es agregar manualmente `reply_to_message_id` a los parámetros del método que envía el mensaje (`sendText` / `reply`, `sendPhoto` / `replyWithPhoto`). Sin embargo, si está haciendo esto para cada mensaje, puede volverse un poco complicado y agotador. + +Este complemento establece el valor del parámetro `reply_to_message_id` en `ctx.msg.message_id` para cada método `send` (excepto `sendChatAction`, que no admite este parámetro), por lo que hace que cada mensaje sea una respuesta al mensaje que activó esa actualización. + +## Uso + +### Para una sola ruta + +Use esto si desea que todos los mensajes enviados desde un contexto específico (como un comando específico) + +```ts +import { Bot } from "grammy"; +import { addReplyParam } from "@roziscoding/grammy-autoquote"; +// 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)); + ctx.reply("Demo command!"); // This will quote the user's message +}); + +bot.start(); +``` + +### Uso para cada ruta + +Úselo si desea absolutamente todos los mensajes posibles enviados desde su bot para citar el mensaje desencadenante. + +```ts +import { Bot } from "grammy"; +import { autoQuote } from "@roziscoding/grammy-autoquote"; +// import { autoQuote } from 'https://deno.land/x/grammy_autoquote/mod.ts' + +const bot = new Bot(""); + +bot.use(autoQuote); + +bot.command("demo", async (ctx) => { + ctx.reply("Demo command!"); // This will quote the user's message +}); + +bot.command("hello", async (ctx) => { + ctx.reply("Hi there :)"); // Also quotes the user's message +}); + +bot.start(); +``` + +## Resumen del complemento + +- Name: Autoquote +- Source: +- Reference: diff --git a/site/docs/plugins/autoquote.md b/site/docs/plugins/autoquote.md new file mode 100644 index 000000000..87f802119 --- /dev/null +++ b/site/docs/plugins/autoquote.md @@ -0,0 +1,56 @@ +# Always replying to messages + +Sometimes, especially for bots that are meant to be used in groups, it is necessary to always send messages as a reply (or quote) to the message that started the interaction. Usually, the way to do that is to mannualy add `reply_to_message_id` to the params of the mathod that sends the message (`sendText` / `reply`, `sendPhoto` / `replyWithPhoto`). However, if you're doing this for every message, it can get a bit messy and tiring. + +This plugin sets the value of `reply_to_message_id` param to `ctx.msg.message_id` for every `send` method (except for `sendChatAction`, which does not support this parameter), thus making every message a reply to the message that triggered that update. + +## Usage + +### For a single route + +Use this if you want all messages sent from within a specific context (like a specific command) to + +```ts +import { Bot } from "grammy"; +import { addReplyParam } from "@roziscoding/grammy-autoquote"; +// 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)); + ctx.reply("Demo command!"); // This will quote the user's message +}); + +bot.start(); +``` + +### Usage for every route + +Use this if you want absolutelly every possible message sent from your bot to quote the triggering message. + +```ts +import { Bot } from "grammy"; +import { autoQuote } from "@roziscoding/grammy-autoquote"; +// import { autoQuote } from 'https://deno.land/x/grammy_autoquote/mod.ts' + +const bot = new Bot(""); + +bot.use(autoQuote); + +bot.command("demo", async (ctx) => { + ctx.reply("Demo command!"); // This will quote the user's message +}); + +bot.command("hello", async (ctx) => { + ctx.reply("Hi there :)"); // Also quotes the user's message +}); + +bot.start(); +``` + +## Plugin Summary + +- Name: Autoquote +- Source: +- Reference: diff --git a/site/docs/zh/plugins/autoquote.md b/site/docs/zh/plugins/autoquote.md new file mode 100644 index 000000000..1707fe48c --- /dev/null +++ b/site/docs/zh/plugins/autoquote.md @@ -0,0 +1,56 @@ +# 总是回复消息 + +有时,特别是对于打算在组中使用的机器人,有必要始终发送消息作为对开始交互的消息的回复(或引用)。通常,这样做的方法是手动将 `reply_to_message_id` 添加到发送消息的方法的参数中(`sendText` / `reply`、`sendPhoto` / `replyWithPhoto`)。但是,如果您对每条消息都这样做,它可能会变得有点混乱和累人。 + +该插件将每个 `send` 方法的 `reply_to_message_id` 参数的值设置为 `ctx.msg.message_id`(`sendChatAction` 除外,它不支持此参数),从而使每条消息都成为对触发消息的回复那个更新。 + +## 用法 + +### 对于单条路线 + +如果您希望从特定上下文(如特定命令)中发送的所有消息,请使用此选项 + +```ts +import { Bot } from "grammy"; +import { addReplyParam } from "@roziscoding/grammy-autoquote"; +// 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)); + ctx.reply("Demo command!"); // This will quote the user's message +}); + +bot.start(); +``` + +### 每条路线的使用情况 + +如果您绝对希望从您的机器人发送的所有可能消息都引用触发消息,请使用此选项。 + +```ts +import { Bot } from "grammy"; +import { autoQuote } from "@roziscoding/grammy-autoquote"; +// import { autoQuote } from 'https://deno.land/x/grammy_autoquote/mod.ts' + +const bot = new Bot(""); + +bot.use(autoQuote); + +bot.command("demo", async (ctx) => { + ctx.reply("Demo command!"); // This will quote the user's message +}); + +bot.command("hello", async (ctx) => { + ctx.reply("Hi there :)"); // Also quotes the user's message +}); + +bot.start(); +``` + +## 插件总结 + +- 名称:自动报价 +- 来源: +- 参考: From 153b68b299fa9e7827cc25d6b9f163e8a08d0264 Mon Sep 17 00:00:00 2001 From: Roz Date: Fri, 22 Jul 2022 16:23:14 -0300 Subject: [PATCH 02/16] docs: remove bad translation pages The links were also removed since I can't really translate the plugin name well --- notifier/db.ts | 6 ++-- site/docs/.vuepress/config.ts | 8 ----- site/docs/es/plugins/autoquote.md | 56 ------------------------------- site/docs/zh/plugins/autoquote.md | 56 ------------------------------- 4 files changed, 4 insertions(+), 122 deletions(-) delete mode 100644 site/docs/es/plugins/autoquote.md delete mode 100644 site/docs/zh/plugins/autoquote.md diff --git a/notifier/db.ts b/notifier/db.ts index 0a23301c5..68f04aa68 100644 --- a/notifier/db.ts +++ b/notifier/db.ts @@ -23,7 +23,8 @@ export function createNotification( text: string, ) { return client - .queryArray`INSERT INTO notifications VALUES (${prNumber}, ${messageId}, ${text});`; + .queryArray + `INSERT INTO notifications VALUES (${prNumber}, ${messageId}, ${text});`; } export async function getNotification(prNumber: number) { @@ -36,7 +37,8 @@ export async function getNotification(prNumber: number) { export function updateNotification(messageId: number, text: string) { return client - .queryArray`UPDATE notifications SET text=${text} WHERE message_id=${messageId};`; + .queryArray + `UPDATE notifications SET text=${text} WHERE message_id=${messageId};`; } export function deleteNotification(prNumber: number) { diff --git a/site/docs/.vuepress/config.ts b/site/docs/.vuepress/config.ts index 320db6240..1f8b0ad00 100644 --- a/site/docs/.vuepress/config.ts +++ b/site/docs/.vuepress/config.ts @@ -615,10 +615,6 @@ export default defineUserConfig({ text: "Middleware útil", link: "/es/plugins/middlewares.html", }, - { - text: "Autocita", - link: "/es/plugins/autoquote.html", - }, { text: "[¡Envíe su PR!]", link: @@ -979,10 +975,6 @@ export default defineUserConfig({ text: "有用的中间件", link: "/zh/plugins/middlewares.html", }, - { - text: "自动报价", - link: "/zh/plugins/autoquote.html", - }, { text: "[等待你的 PR!]", link: "/zh/plugins/#向文档提交你自己的插件", diff --git a/site/docs/es/plugins/autoquote.md b/site/docs/es/plugins/autoquote.md deleted file mode 100644 index beea0cbce..000000000 --- a/site/docs/es/plugins/autoquote.md +++ /dev/null @@ -1,56 +0,0 @@ -# Siempre respondiendo a los mensajes - -A veces, especialmente para los bots que están destinados a ser utilizados en grupos, siempre es necesario enviar mensajes como respuesta (o cita) al mensaje que inició la interacción. Por lo general, la forma de hacerlo es agregar manualmente `reply_to_message_id` a los parámetros del método que envía el mensaje (`sendText` / `reply`, `sendPhoto` / `replyWithPhoto`). Sin embargo, si está haciendo esto para cada mensaje, puede volverse un poco complicado y agotador. - -Este complemento establece el valor del parámetro `reply_to_message_id` en `ctx.msg.message_id` para cada método `send` (excepto `sendChatAction`, que no admite este parámetro), por lo que hace que cada mensaje sea una respuesta al mensaje que activó esa actualización. - -## Uso - -### Para una sola ruta - -Use esto si desea que todos los mensajes enviados desde un contexto específico (como un comando específico) - -```ts -import { Bot } from "grammy"; -import { addReplyParam } from "@roziscoding/grammy-autoquote"; -// 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)); - ctx.reply("Demo command!"); // This will quote the user's message -}); - -bot.start(); -``` - -### Uso para cada ruta - -Úselo si desea absolutamente todos los mensajes posibles enviados desde su bot para citar el mensaje desencadenante. - -```ts -import { Bot } from "grammy"; -import { autoQuote } from "@roziscoding/grammy-autoquote"; -// import { autoQuote } from 'https://deno.land/x/grammy_autoquote/mod.ts' - -const bot = new Bot(""); - -bot.use(autoQuote); - -bot.command("demo", async (ctx) => { - ctx.reply("Demo command!"); // This will quote the user's message -}); - -bot.command("hello", async (ctx) => { - ctx.reply("Hi there :)"); // Also quotes the user's message -}); - -bot.start(); -``` - -## Resumen del complemento - -- Name: Autoquote -- Source: -- Reference: diff --git a/site/docs/zh/plugins/autoquote.md b/site/docs/zh/plugins/autoquote.md deleted file mode 100644 index 1707fe48c..000000000 --- a/site/docs/zh/plugins/autoquote.md +++ /dev/null @@ -1,56 +0,0 @@ -# 总是回复消息 - -有时,特别是对于打算在组中使用的机器人,有必要始终发送消息作为对开始交互的消息的回复(或引用)。通常,这样做的方法是手动将 `reply_to_message_id` 添加到发送消息的方法的参数中(`sendText` / `reply`、`sendPhoto` / `replyWithPhoto`)。但是,如果您对每条消息都这样做,它可能会变得有点混乱和累人。 - -该插件将每个 `send` 方法的 `reply_to_message_id` 参数的值设置为 `ctx.msg.message_id`(`sendChatAction` 除外,它不支持此参数),从而使每条消息都成为对触发消息的回复那个更新。 - -## 用法 - -### 对于单条路线 - -如果您希望从特定上下文(如特定命令)中发送的所有消息,请使用此选项 - -```ts -import { Bot } from "grammy"; -import { addReplyParam } from "@roziscoding/grammy-autoquote"; -// 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)); - ctx.reply("Demo command!"); // This will quote the user's message -}); - -bot.start(); -``` - -### 每条路线的使用情况 - -如果您绝对希望从您的机器人发送的所有可能消息都引用触发消息,请使用此选项。 - -```ts -import { Bot } from "grammy"; -import { autoQuote } from "@roziscoding/grammy-autoquote"; -// import { autoQuote } from 'https://deno.land/x/grammy_autoquote/mod.ts' - -const bot = new Bot(""); - -bot.use(autoQuote); - -bot.command("demo", async (ctx) => { - ctx.reply("Demo command!"); // This will quote the user's message -}); - -bot.command("hello", async (ctx) => { - ctx.reply("Hi there :)"); // Also quotes the user's message -}); - -bot.start(); -``` - -## 插件总结 - -- 名称:自动报价 -- 来源: -- 参考: From 469c0217ade38cf8a8b81dfb94902a404e6351bc Mon Sep 17 00:00:00 2001 From: Roz Date: Sun, 24 Jul 2022 12:20:14 -0300 Subject: [PATCH 03/16] chore: fix weird formatting --- notifier/db.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/notifier/db.ts b/notifier/db.ts index 68f04aa68..0a23301c5 100644 --- a/notifier/db.ts +++ b/notifier/db.ts @@ -23,8 +23,7 @@ export function createNotification( text: string, ) { return client - .queryArray - `INSERT INTO notifications VALUES (${prNumber}, ${messageId}, ${text});`; + .queryArray`INSERT INTO notifications VALUES (${prNumber}, ${messageId}, ${text});`; } export async function getNotification(prNumber: number) { @@ -37,8 +36,7 @@ export async function getNotification(prNumber: number) { export function updateNotification(messageId: number, text: string) { return client - .queryArray - `UPDATE notifications SET text=${text} WHERE message_id=${messageId};`; + .queryArray`UPDATE notifications SET text=${text} WHERE message_id=${messageId};`; } export function deleteNotification(prNumber: number) { From e51f607ff7722942300c5382febf5ed5982a8c96 Mon Sep 17 00:00:00 2001 From: Roz <3948961+roziscoding@users.noreply.github.com> Date: Sun, 24 Jul 2022 17:10:00 -0300 Subject: [PATCH 04/16] Update site/docs/plugins/autoquote.md Co-authored-by: Roj --- site/docs/plugins/autoquote.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/site/docs/plugins/autoquote.md b/site/docs/plugins/autoquote.md index 87f802119..0b9cbc886 100644 --- a/site/docs/plugins/autoquote.md +++ b/site/docs/plugins/autoquote.md @@ -1,6 +1,8 @@ # Always replying to messages -Sometimes, especially for bots that are meant to be used in groups, it is necessary to always send messages as a reply (or quote) to the message that started the interaction. Usually, the way to do that is to mannualy add `reply_to_message_id` to the params of the mathod that sends the message (`sendText` / `reply`, `sendPhoto` / `replyWithPhoto`). However, if you're doing this for every message, it can get a bit messy and tiring. +Sometimes, especially for bots that are meant to be used in groups, it is necessary to always send messages as a reply (or quote) to the message that started the interaction. +Usually, the way to do that is to mannualy add `reply_to_message_id` to the params of the mathod that sends the message (`sendText` / `reply`, `sendPhoto` / `replyWithPhoto`). +However, if you're doing this for every message, it can get a bit messy and tiring. This plugin sets the value of `reply_to_message_id` param to `ctx.msg.message_id` for every `send` method (except for `sendChatAction`, which does not support this parameter), thus making every message a reply to the message that triggered that update. From 7004988d9b44724e8db7307edb0c6113355b3b33 Mon Sep 17 00:00:00 2001 From: Roz <3948961+roziscoding@users.noreply.github.com> Date: Sun, 24 Jul 2022 22:52:13 -0300 Subject: [PATCH 05/16] Apply suggestions from code review --- site/docs/plugins/autoquote.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/site/docs/plugins/autoquote.md b/site/docs/plugins/autoquote.md index 0b9cbc886..b0a73ed93 100644 --- a/site/docs/plugins/autoquote.md +++ b/site/docs/plugins/autoquote.md @@ -1,21 +1,21 @@ -# Always replying to messages +# Always Replying to Messages Sometimes, especially for bots that are meant to be used in groups, it is necessary to always send messages as a reply (or quote) to the message that started the interaction. -Usually, the way to do that is to mannualy add `reply_to_message_id` to the params of the mathod that sends the message (`sendText` / `reply`, `sendPhoto` / `replyWithPhoto`). +Usually, the way to do that is to mannualy add `reply_to_message_id` to the params of the method that sends the message (`sendText` / `reply`, `sendPhoto` / `replyWithPhoto`). However, if you're doing this for every message, it can get a bit messy and tiring. This plugin sets the value of `reply_to_message_id` param to `ctx.msg.message_id` for every `send` method (except for `sendChatAction`, which does not support this parameter), thus making every message a reply to the message that triggered that update. ## Usage -### For a single route +### For a Single Route Use this if you want all messages sent from within a specific context (like a specific command) to ```ts import { Bot } from "grammy"; import { addReplyParam } from "@roziscoding/grammy-autoquote"; -// import { addReplyParam } from 'https://deno.land/x/grammy_autoquote/mod.ts' +// import { addReplyParam } from "https://deno.land/x/grammy_autoquote/mod.ts" const bot = new Bot(""); From 472fddeeaf1a26c865b8f8c76d23831a5e392625 Mon Sep 17 00:00:00 2001 From: Roz <3948961+roziscoding@users.noreply.github.com> Date: Sun, 24 Jul 2022 23:07:31 -0300 Subject: [PATCH 06/16] Update site/docs/plugins/autoquote.md --- site/docs/plugins/autoquote.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/docs/plugins/autoquote.md b/site/docs/plugins/autoquote.md index b0a73ed93..c4e51caf8 100644 --- a/site/docs/plugins/autoquote.md +++ b/site/docs/plugins/autoquote.md @@ -27,7 +27,7 @@ bot.command("demo", async (ctx) => { bot.start(); ``` -### Usage for every route +### Usage for Every Route Use this if you want absolutelly every possible message sent from your bot to quote the triggering message. From 02510dda61bb5041450df39fb5231d8a97368183 Mon Sep 17 00:00:00 2001 From: KnorpelSenf Date: Fri, 29 Jul 2022 15:29:33 +0200 Subject: [PATCH 07/16] Add missing await keywords to code examples --- site/docs/plugins/autoquote.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/site/docs/plugins/autoquote.md b/site/docs/plugins/autoquote.md index c4e51caf8..289c34fdf 100644 --- a/site/docs/plugins/autoquote.md +++ b/site/docs/plugins/autoquote.md @@ -21,7 +21,7 @@ const bot = new Bot(""); bot.command("demo", async (ctx) => { ctx.api.config.use(addReplyParam(ctx)); - ctx.reply("Demo command!"); // This will quote the user's message + await ctx.reply("Demo command!"); // This will quote the user's message }); bot.start(); @@ -41,11 +41,11 @@ const bot = new Bot(""); bot.use(autoQuote); bot.command("demo", async (ctx) => { - ctx.reply("Demo command!"); // This will quote the user's message + await ctx.reply("Demo command!"); // This will quote the user's message }); bot.command("hello", async (ctx) => { - ctx.reply("Hi there :)"); // Also quotes the user's message + await ctx.reply("Hi there :)"); // Also quotes the user's message }); bot.start(); From 9de22e034ce889ffa100f0b945fd7240ac331c9d Mon Sep 17 00:00:00 2001 From: Roz Date: Thu, 4 Aug 2022 12:18:59 -0300 Subject: [PATCH 08/16] Add javascript and deno code to autoquote page --- site/docs/plugins/autoquote.md | 142 ++++++++++++++++++++++++++------- 1 file changed, 115 insertions(+), 27 deletions(-) diff --git a/site/docs/plugins/autoquote.md b/site/docs/plugins/autoquote.md index 289c34fdf..63b316235 100644 --- a/site/docs/plugins/autoquote.md +++ b/site/docs/plugins/autoquote.md @@ -12,44 +12,132 @@ This plugin sets the value of `reply_to_message_id` param to `ctx.msg.message_id Use this if you want all messages sent from within a specific context (like a specific command) to -```ts -import { Bot } from "grammy"; -import { addReplyParam } from "@roziscoding/grammy-autoquote"; -// import { addReplyParam } from "https://deno.land/x/grammy_autoquote/mod.ts" + + -const bot = new Bot(""); + ```ts + import { Bot } from "grammy"; + import { addReplyParam } from "@roziscoding/grammy-autoquote"; -bot.command("demo", async (ctx) => { - ctx.api.config.use(addReplyParam(ctx)); - await ctx.reply("Demo command!"); // This will quote the user's message -}); + const bot = new Bot(""); -bot.start(); -``` + bot.command("demo", async (ctx) => { + ctx.api.config.use(addReplyParam(ctx)); + await ctx.reply("Demo command!"); // This will quote the user's message + }); -### Usage for Every Route + bot.start(); + ``` -Use this if you want absolutelly every possible message sent from your bot to quote the triggering message. + + + + ```ts + 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 will quote the user's message + }); + + bot.start(); + ``` -```ts -import { Bot } from "grammy"; -import { autoQuote } from "@roziscoding/grammy-autoquote"; -// import { autoQuote } from 'https://deno.land/x/grammy_autoquote/mod.ts' + + -const bot = new Bot(""); + ```ts + import { Bot } from "https://deno.land/x/grammy/mod.ts"; + import { addReplyParam } from "https://deno.land/x/grammy_autoquote/mod.ts"; -bot.use(autoQuote); + const bot = new Bot(""); -bot.command("demo", async (ctx) => { - await ctx.reply("Demo command!"); // This will quote the user's message -}); + bot.command("demo", async (ctx) => { + ctx.api.config.use(addReplyParam(ctx)); + await ctx.reply("Demo command!"); // This will quote the user's message + }); -bot.command("hello", async (ctx) => { - await ctx.reply("Hi there :)"); // Also quotes the user's message -}); + bot.start(); + ``` + + + + +### Usage for Every Route + +Use this if you want absolutelly every possible message sent from your bot to quote the triggering message. -bot.start(); -``` + + + + ```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 will quote the user's message + }); + + bot.command("hello", async (ctx) => { + await ctx.reply("Hi there :)"); // Also quotes the user's message + }); + + bot.start(); + ``` + + + + + ```ts + 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 will quote the user's message + }); + + bot.command("hello", async (ctx) => { + await ctx.reply("Hi there :)"); // Also quotes the user's message + }); + + bot.start(); + ``` + + + + + ```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 will quote the user's message + }); + + bot.command("hello", async (ctx) => { + await ctx.reply("Hi there :)"); // Also quotes the user's message + }); + + bot.start(); + ``` + + + ## Plugin Summary From 90a8f40158bb36157f0730027e9dfdc731d10207 Mon Sep 17 00:00:00 2001 From: Roz Date: Thu, 4 Aug 2022 12:20:13 -0300 Subject: [PATCH 09/16] fix formatting of autoquote page --- site/docs/plugins/autoquote.md | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/site/docs/plugins/autoquote.md b/site/docs/plugins/autoquote.md index 63b316235..54ebe0f7c 100644 --- a/site/docs/plugins/autoquote.md +++ b/site/docs/plugins/autoquote.md @@ -29,7 +29,7 @@ Use this if you want all messages sent from within a specific context (like a sp bot.start(); ``` - + ```ts @@ -46,7 +46,7 @@ Use this if you want all messages sent from within a specific context (like a sp bot.start(); ``` - + ```ts @@ -63,7 +63,7 @@ Use this if you want all messages sent from within a specific context (like a sp bot.start(); ``` - + ### Usage for Every Route @@ -76,67 +76,67 @@ Use this if you want absolutelly every possible message sent from your bot to qu ```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 will quote the user's message }); - + bot.command("hello", async (ctx) => { await ctx.reply("Hi there :)"); // Also quotes the user's message }); - + bot.start(); ``` - + ```ts 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 will quote the user's message }); - + bot.command("hello", async (ctx) => { await ctx.reply("Hi there :)"); // Also quotes the user's message }); - + bot.start(); ``` - + ```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 will quote the user's message }); - + bot.command("hello", async (ctx) => { await ctx.reply("Hi there :)"); // Also quotes the user's message }); - + bot.start(); ``` - + ## Plugin Summary From 46f2c730184b917e635a7b75c8e0b2f2b42e01ed Mon Sep 17 00:00:00 2001 From: Roz <3948961+roziscoding@users.noreply.github.com> Date: Sat, 6 Aug 2022 05:05:47 -0300 Subject: [PATCH 10/16] Apply suggestions from code review Co-authored-by: Roj --- site/docs/plugins/autoquote.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/site/docs/plugins/autoquote.md b/site/docs/plugins/autoquote.md index 54ebe0f7c..13937b154 100644 --- a/site/docs/plugins/autoquote.md +++ b/site/docs/plugins/autoquote.md @@ -1,16 +1,16 @@ # Always Replying to Messages -Sometimes, especially for bots that are meant to be used in groups, it is necessary to always send messages as a reply (or quote) to the message that started the interaction. -Usually, the way to do that is to mannualy add `reply_to_message_id` to the params of the method that sends the message (`sendText` / `reply`, `sendPhoto` / `replyWithPhoto`). -However, if you're doing this for every message, it can get a bit messy and tiring. +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 value of `reply_to_message_id` param to `ctx.msg.message_id` for every `send` method (except for `sendChatAction`, which does not support this parameter), thus making every message a reply to the message that triggered that update. +This plugin sets the `reply_to_message_id` parameter to `ctx.msg.message_id` for `reply` and all `send*` methods that support it to make every message a reply to the message that triggered it. ## Usage -### For a Single Route +### In a Specific Routes -Use this if you want all messages sent from within a specific context (like a specific command) to +If you want all messages sent within a specific context (like a specific command), you can specifically apply the plugin to them: @@ -23,7 +23,7 @@ Use this if you want all messages sent from within a specific context (like a sp bot.command("demo", async (ctx) => { ctx.api.config.use(addReplyParam(ctx)); - await ctx.reply("Demo command!"); // This will quote the user's message + await ctx.reply("Demo command!"); // this is going to quote the user's message }); bot.start(); @@ -40,7 +40,7 @@ Use this if you want all messages sent from within a specific context (like a sp bot.command("demo", async (ctx) => { ctx.api.config.use(addReplyParam(ctx)); - await ctx.reply("Demo command!"); // This will quote the user's message + await ctx.reply("Demo command!"); // this is going to quote the user's message }); bot.start(); @@ -57,7 +57,7 @@ Use this if you want all messages sent from within a specific context (like a sp bot.command("demo", async (ctx) => { ctx.api.config.use(addReplyParam(ctx)); - await ctx.reply("Demo command!"); // This will quote the user's message + await ctx.reply("Demo command!"); // this is going to quote the user's message }); bot.start(); @@ -66,9 +66,9 @@ Use this if you want all messages sent from within a specific context (like a sp -### Usage for Every Route +### In for All Routes -Use this if you want absolutelly every possible message sent from your bot to quote the triggering message. +If you want every sent message to reply the messages that triggered them, you can apply the plugin this way: @@ -82,11 +82,11 @@ Use this if you want absolutelly every possible message sent from your bot to qu bot.use(autoQuote); bot.command("demo", async (ctx) => { - await ctx.reply("Demo command!"); // This will quote the user's message + await ctx.reply("Demo command!"); // this is going to quote the user's message }); bot.command("hello", async (ctx) => { - await ctx.reply("Hi there :)"); // Also quotes the user's message + await ctx.reply("Hi there :)"); // this quotes the user's message, too }); bot.start(); @@ -104,11 +104,11 @@ Use this if you want absolutelly every possible message sent from your bot to qu bot.use(autoQuote); bot.command("demo", async (ctx) => { - await ctx.reply("Demo command!"); // This will quote the user's message + await ctx.reply("Demo command!"); // this is going to quote the user's message }); bot.command("hello", async (ctx) => { - await ctx.reply("Hi there :)"); // Also quotes the user's message + await ctx.reply("Hi there :)"); // this quotes the user's message, too }); bot.start(); @@ -126,11 +126,11 @@ Use this if you want absolutelly every possible message sent from your bot to qu bot.use(autoQuote); bot.command("demo", async (ctx) => { - await ctx.reply("Demo command!"); // This will quote the user's message + await ctx.reply("Demo command!"); // this is going to quote the user's message }); bot.command("hello", async (ctx) => { - await ctx.reply("Hi there :)"); // Also quotes the user's message + await ctx.reply("Hi there :)"); // this quotes the user's message, too }); bot.start(); From b40ad2232d23818f1f427219df089b1b47c5fc62 Mon Sep 17 00:00:00 2001 From: Roz Date: Sat, 6 Aug 2022 05:07:16 -0300 Subject: [PATCH 11/16] fix formatting of autoquote plugin page --- site/docs/plugins/autoquote.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/docs/plugins/autoquote.md b/site/docs/plugins/autoquote.md index 13937b154..adf633b79 100644 --- a/site/docs/plugins/autoquote.md +++ b/site/docs/plugins/autoquote.md @@ -10,7 +10,7 @@ This plugin sets the `reply_to_message_id` parameter to `ctx.msg.message_id` for ### In a Specific Routes -If you want all messages sent within a specific context (like a specific command), you can specifically apply the plugin to them: +If you want all messages sent within a specific context (like a specific command), you can specifically apply the plugin to them: From 9d3692342ccbde56f6375548ef7b728ec7a19c6f Mon Sep 17 00:00:00 2001 From: Roj Date: Sat, 6 Aug 2022 11:35:38 +0300 Subject: [PATCH 12/16] Fix article --- site/docs/plugins/autoquote.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/docs/plugins/autoquote.md b/site/docs/plugins/autoquote.md index adf633b79..d7f3c0001 100644 --- a/site/docs/plugins/autoquote.md +++ b/site/docs/plugins/autoquote.md @@ -8,7 +8,7 @@ This plugin sets the `reply_to_message_id` parameter to `ctx.msg.message_id` for ## Usage -### In a Specific Routes +### 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: From 5b26f2a7aca27c5a798f6bf4e7e50e70c8585c05 Mon Sep 17 00:00:00 2001 From: Roz <3948961+roziscoding@users.noreply.github.com> Date: Sat, 6 Aug 2022 20:53:23 -0300 Subject: [PATCH 13/16] Apply suggestions from code review Co-authored-by: Ciki Momogi --- site/docs/plugins/autoquote.md | 142 ++++++++++++++++----------------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/site/docs/plugins/autoquote.md b/site/docs/plugins/autoquote.md index d7f3c0001..7291c0d09 100644 --- a/site/docs/plugins/autoquote.md +++ b/site/docs/plugins/autoquote.md @@ -1,10 +1,10 @@ # 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. +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 `reply` and all `send*` methods that support it to make every message a reply to the message that triggered it. +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 @@ -15,53 +15,53 @@ If you want all messages sent within a specific context (like a specific command - ```ts - import { Bot } from "grammy"; - import { addReplyParam } from "@roziscoding/grammy-autoquote"; +```ts +import { Bot } from "grammy"; +import { addReplyParam } from "@roziscoding/grammy-autoquote"; - const bot = new Bot(""); +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.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(); - ``` +bot.start(); +``` - ```ts - const { Bot } = require("grammy"); - const { addReplyParam } = require("@roziscoding/grammy-autoquote"); +```js +const { Bot } = require("grammy"); +const { addReplyParam } = require("@roziscoding/grammy-autoquote"); - const bot = new Bot(""); +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.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(); - ``` +bot.start(); +``` - ```ts - import { Bot } from "https://deno.land/x/grammy/mod.ts"; - import { addReplyParam } from "https://deno.land/x/grammy_autoquote/mod.ts"; +```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(""); +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.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(); - ``` +bot.start(); +``` @@ -73,68 +73,68 @@ If you want every sent message to reply the messages that triggered them, you ca - ```ts - import { Bot } from "grammy"; - import { autoQuote } from "@roziscoding/grammy-autoquote"; +```ts +import { Bot } from "grammy"; +import { autoQuote } from "@roziscoding/grammy-autoquote"; - const bot = new Bot(""); +const bot = new Bot(""); - bot.use(autoQuote); +bot.use(autoQuote); - bot.command("demo", async (ctx) => { - await ctx.reply("Demo command!"); // this is going to quote the user's message - }); +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.command("hello", async (ctx) => { + await ctx.reply("Hi there :)"); // this quotes the user's message, too +}); - bot.start(); - ``` +bot.start(); +``` - ```ts - const { Bot } = require("grammy"); - const { autoQuote } = require("@roziscoding/grammy-autoquote"); +```js +const { Bot } = require("grammy"); +const { autoQuote } = require("@roziscoding/grammy-autoquote"); - const bot = new Bot(""); +const bot = new Bot(""); - bot.use(autoQuote); +bot.use(autoQuote); - bot.command("demo", async (ctx) => { - await ctx.reply("Demo command!"); // this is going to quote the user's message - }); +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.command("hello", async (ctx) => { + await ctx.reply("Hi there :)"); // this quotes the user's message, too +}); - bot.start(); - ``` +bot.start(); +``` - ```ts - import { Bot } from "https://deno.land/x/grammy/mod.ts"; - import { autoQuote } from "https://deno.land/x/grammy_autoquote/mod.ts"; +```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(""); +const bot = new Bot(""); - bot.use(autoQuote); +bot.use(autoQuote); - bot.command("demo", async (ctx) => { - await ctx.reply("Demo command!"); // this is going to quote the user's message - }); +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.command("hello", async (ctx) => { + await ctx.reply("Hi there :)"); // this quotes the user's message, too +}); - bot.start(); - ``` +bot.start(); +``` From 089fb0da67453ced348d7c9f8d37261decde1d29 Mon Sep 17 00:00:00 2001 From: Roz <3948961+roziscoding@users.noreply.github.com> Date: Thu, 18 Aug 2022 16:08:48 -0300 Subject: [PATCH 14/16] add grammt_autoquote to modules.json --- site/docs/.vuepress/plugins/current-versions/modules.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/site/docs/.vuepress/plugins/current-versions/modules.json b/site/docs/.vuepress/plugins/current-versions/modules.json index 0f1a8ec49..76ff9a8c5 100644 --- a/site/docs/.vuepress/plugins/current-versions/modules.json +++ b/site/docs/.vuepress/plugins/current-versions/modules.json @@ -11,6 +11,7 @@ "grammy_emoji", "grammy_parse_mode", "grammy_storages", - "grammy_conversations" + "grammy_conversations", + "grammy_autoquote" ] } From 8ccd391cdf4c8768bde26a516bdd5998a33b79d4 Mon Sep 17 00:00:00 2001 From: Roz <3948961+roziscoding@users.noreply.github.com> Date: Sat, 20 Aug 2022 12:05:39 -0300 Subject: [PATCH 15/16] Update site/docs/plugins/autoquote.md Co-authored-by: WingLim <643089849@qq.com> --- site/docs/plugins/autoquote.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/docs/plugins/autoquote.md b/site/docs/plugins/autoquote.md index 7291c0d09..0aa8c53bb 100644 --- a/site/docs/plugins/autoquote.md +++ b/site/docs/plugins/autoquote.md @@ -143,4 +143,4 @@ bot.start(); - Name: Autoquote - Source: -- Reference: +- API Reference: From 0e62b33094a546681f4583d8060acf9a20f49cf6 Mon Sep 17 00:00:00 2001 From: WingLim Date: Sat, 20 Aug 2022 23:06:10 +0800 Subject: [PATCH 16/16] Sync changes to Chinese --- site/docs/.vuepress/config.ts | 4 + site/docs/zh/plugins/autoquote.md | 146 ++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 site/docs/zh/plugins/autoquote.md diff --git a/site/docs/.vuepress/config.ts b/site/docs/.vuepress/config.ts index f95caa06b..fff125791 100644 --- a/site/docs/.vuepress/config.ts +++ b/site/docs/.vuepress/config.ts @@ -976,6 +976,10 @@ export default defineUserConfig({ text: "有用的中间件", link: "/zh/plugins/middlewares.html", }, + { + text: "自动引用", + link: "/zh/plugins/autoquote.html", + }, { text: "[等待你的 PR!]", link: "/zh/plugins/#向文档提交你自己的插件", diff --git a/site/docs/zh/plugins/autoquote.md b/site/docs/zh/plugins/autoquote.md new file mode 100644 index 000000000..6d313c6a3 --- /dev/null +++ b/site/docs/zh/plugins/autoquote.md @@ -0,0 +1,146 @@ +# 总是回复消息 + +有时候有必要总是将消息作为回复发送,特别是对于那些打算要在群组中使用的 bot。 +我们通常通过在发送消息的方法中添加 `reply_to_message_id` 参数来实现这一点:`sendText`, `reply`, `sendPhoto`, `replyWithPhoto` 等等。 +然而,如果你对每一条消息都这样做,这会使得代码变得很无聊和繁琐。 + +这个插件将所有 `reply*` 和 `send*` 方法的 `reply_to_message_id` 参数设置为 `ctx.msg.message_id`,以便每条消息都是对触发这条消息的回复。 + +## 使用方式 + +### 在指定的路由中 + +如果你想让所有在特定上下文的消息进行回复(比如特定的命令),你可以专门应用这个插件到它们上面: + + + + +```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(); +``` + + + + +```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(); +``` + + + + +```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(); +``` + + + + +### 在所有路由中 + +如果你希望每条发送的消息都回复触发它的消息,你可以通过这样的方式应用这个插件: + + + + +```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(); +``` + + + + +```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(); +``` + + + + +```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(); +``` + + + + +## 插件概述 + +- 名字:Autoquote +- 源码: +- API 参考: