未验证 提交 f8411162 编写于 作者: 梨子(Riko) 提交者: GitHub

docs: improve ding-dong-bot example (#1904)

It's better to clearly instruct new users that outgoing messages will cause a 'message' event emit in order to prevent infinitely sending messages
Co-authored-by: Huan (李卓桓)'s avatarHuan (李卓桓) <zixia@zixia.net>
上级 6fdc650d
......@@ -113,6 +113,11 @@ function onError (e: Error) {
async function onMessage (msg: Message) {
console.info(msg.toString())
if (msg.self()) {
console.info('Message discarded because its outgoing')
return
}
if (msg.age() > 2 * 60) {
console.info('Message discarded because its TOO OLD(than 2 minutes)')
return
......@@ -120,7 +125,6 @@ async function onMessage (msg: Message) {
if (msg.type() !== bot.Message.Type.Text
|| !/^(ding|ping|bing|code)$/i.test(msg.text())
/* && !msg.self() */
) {
console.info('Message discarded because it does not match ding/ping/bing/code')
return
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册