Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(discord): support webhook message #75

Merged
merged 15 commits into from
Apr 1, 2023
Merged

feat(discord): support webhook message #75

merged 15 commits into from
Apr 1, 2023

Conversation

XxLittleCxX
Copy link
Member

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Feb 17, 2023

Codecov Report

Merging #75 (2fdb599) into master (9f7f6c7) will not change coverage.
The diff coverage is n/a.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@           Coverage Diff           @@
##           master      #75   +/-   ##
=======================================
  Coverage   82.14%   82.14%           
=======================================
  Files           1        1           
  Lines         420      420           
  Branches       86       86           
=======================================
  Hits          345      345           
  Misses         75       75           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@XxLittleCxX XxLittleCxX linked an issue Feb 17, 2023 that may be closed by this pull request
@XxLittleCxX
Copy link
Member Author

<message forward>
  <message id="114514">
    <author
      nickname={"_custom_ nickname"}
      avatar={
        "https://s.gravatar.com/avatar/1dc454fa994913deea45584c0ea74084.png"
      }
    />
    <image url="https://koishi.chat/logo.png" />
    我是<b>笨蛋</b> **你是笨蛋**
  </message>
  <message id="7355608">
    <author avatar={"https://koishi.chat/logo.png"} />
    消息
  </message>
  <message>
    <quote id={session.messageId}></quote>
    <image url="https://s.gravatar.com/avatar/1dc454fa994913deea45584c0ea74084.png" />
    quote 到原 channel, 带图片 quote
  </message>
  <message>
    <quote id="114514" />
    <author nickname={"aaaa"} />
    quote 到原 channel 的第一条
  </message>
  <message>
    <author nickname={"bbbb"} />
    <at id={session.userId} />
    <quote id="7355608" />
    quote 到内子区
    @everyone
  </message>
  <message>没 author 的普通消息</message>
</message>

@XxLittleCxX XxLittleCxX marked this pull request as ready for review February 17, 2023 12:39
Copy link
Contributor

@shigma shigma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有没有什么改动总结(

adapters/discord/src/message.ts Outdated Show resolved Hide resolved
adapters/discord/src/message.ts Outdated Show resolved Hide resolved
adapters/discord/src/message.ts Outdated Show resolved Hide resolved
adapters/discord/src/message.ts Outdated Show resolved Hide resolved
adapters/discord/src/utils.ts Outdated Show resolved Hide resolved
@shigma
Copy link
Contributor

shigma commented Feb 26, 2023

草,怎么还有个 conflict

@XxLittleCxX
Copy link
Member Author

if (msg.application_id === bot.selfId) {
return
}

不加这里的话,如果发一条链接,discord 会抓取预览信息,加到 embed,然后发一个 MESSAGE_UPDATE

payload 和 channel message
{
  id: '1083765668144500856',
  embeds: [
    {
      url: 'https://google.com/?123',
      type: 'link',
      title: 'Google',
      description: "Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for."       
    }
  ],
  channel_id: '816619123890716694',
  guild_id: '814065827053043743'
}
{
  id: '1083765668144500856',
  type: 0,
  content: 'https://google.com/?123',
  channel_id: '816619123890716694',
  author: {
      url: 'https://google.com/?123',
      title: 'Google',
      description: "Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for."       
    }
  ],
  mentions: [],
  mention_roles: [],
  pinned: false,
  mention_everyone: false,
  tts: false,
  timestamp: '2023-03-10T14:57:50.678000+00:00',
  edited_timestamp: null,
  flags: 0,
  components: [],
  application_id: '814066234282475520',
  webhook_id: '1083763306390638693'
}

@XxLittleCxX
Copy link
Member Author

不知道作为 adapter 要不要处理掉,上面 MESSAGE_CREATE 是允许单独出现 embeds 的,先删了看看(

adapters/discord/src/message.ts Outdated Show resolved Hide resolved
adapters/discord/src/message.ts Outdated Show resolved Hide resolved
Comment on lines 54 to 55
if (this.webhookLock[channelId]) return this.webhookLock[channelId]
return this.webhookLock[channelId] = this._ensureWebhook(channelId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this.webhookLock[channelId]) return this.webhookLock[channelId]
return this.webhookLock[channelId] = this._ensureWebhook(channelId)
return this.webhookLock[channelId] ||= this._ensureWebhook(channelId)

} catch (e) {
if (Quester.isAxiosError(e) && e.response?.data.code === 10015) {
logger.debug('webhook has been deleted, recreating..., %o, lock %o', e.response.data, this.bot.webhookLock[this.channelId])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你给 lock 打印了个 promise。

Suggested change
logger.debug('webhook has been deleted, recreating..., %o, lock %o', e.response.data, this.bot.webhookLock[this.channelId])
logger.debug('webhook has been deleted, recreating..., %o', e.response.data)

adapters/discord/src/message.ts Show resolved Hide resolved
adapters/discord/src/bot.ts Show resolved Hide resolved
@shigma
Copy link
Contributor

shigma commented Mar 27, 2023

上面修完合一下主分支跑下 lint 就差不多了。

@shigma shigma changed the title feat(discord): webhook message feat(discord): support webhook message Apr 1, 2023
@shigma shigma merged commit 3eb23f4 into master Apr 1, 2023
@shigma shigma deleted the forward branch April 1, 2023 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: support discord webhook
3 participants