profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/siiibo/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.

siiibo/lp-redirector 0

Landing Page (LP) Redirector for Siiibo domains

siiibo/phoenix_live_reload 0

Provides live-reload functionality for Phoenix

push eventsiiibo/shujinosuke

hi-se

commit sha 090947bbde859bfaad99232403603b8bde4fc9d5

[feat] launch automation (#33) * fix: remove anchor in regexp * fix: change regexp for command * fix: change regexp * tmp: add console.log * fix: change regexp * fix: add \ in regexp * fix: change type of listen arg to string * fix: change regexp * fix: change regexp * refactor: remove unnecessary const * tmp: remove tmp * fix: change regex * refactor: rename argument to commandRegExpString * refactor: add function for ch eck command * feat: add . in commandRegexp for slackbot reminder

view details

push time in 25 days

delete branch siiibo/shujinosuke

delete branch : feature_launch_automation

delete time in 25 days

PR merged siiibo/shujinosuke

[feat] launch automation

Slackの公式Botのリマインダーを利用して自動起動するためのPR.

+17 -13

4 comments

1 changed file

hi-se

pr closed time in 25 days

PullRequestReviewEvent

pull request commentsiiibo/shujinosuke

[feat] launch automation

.(ピリオド)の正規表現への追加は 164bcab3fa4b92f1615b15d57f04f4b937402e2c で行いました。

@ymtszw レビューしていただいて、問題なさそうであればマージします。

hi-se

comment created time in a month

pull request commentsiiibo/shujinosuke

[feat] launch automation

RegExpに渡すためのString型というのを型で表現できなかったので変数名をリネームしました。 db0c87e4399a8e91359f1b8de9cae5721763d5ed

hi-se

comment created time in a month

pull request commentsiiibo/shujinosuke

[feat] launch automation

「正規表現で独自定義のコマンドかどうかチェックしている」ことが分かりやすいように 4817d7d6f24ee25da353c3c265c82d0f612fd242 で関数に切り出しました。

hi-se

comment created time in a month

push eventsiiibo/shujinosuke

hi-se

commit sha db0c87e4399a8e91359f1b8de9cae5721763d5ed

refactor: rename argument to commandRegExpString

view details

hi-se

commit sha 4817d7d6f24ee25da353c3c265c82d0f612fd242

refactor: add function for check command

view details

hi-se

commit sha 164bcab3fa4b92f1615b15d57f04f4b937402e2c

feat: add . in commandRegexp for slackbot reminder

view details

push time in a month

Pull request review commentsiiibo/shujinosuke

[feat] launch automation

 const getChannelStateMessage = (channelId: string) => { const getListen = (client: SlackClient, event: SlackEvent) => {   switch (event.type) {     case 'app_mention':-      return (regExp: RegExp, callback: (client: SlackClient, event: AppMentionEvent) => void) => {-        const messageContent = event.text.replace(/^<@\w+>\s*/, '');-        if (messageContent.match(regExp)) {+      return (command: string, callback: (client: SlackClient, event: AppMentionEvent) => void) => {+        const commandRegExp = new RegExp(`<@\\w+[\\w\\s\|]*>\\s+${command}($|\\s+)`);

リマインダーで勝手に.が補われるパターンもここで対応していいと思います。

hi-se

comment created time in a month

PullRequestReviewEvent

Pull request review commentsiiibo/shujinosuke

[feat] launch automation

 const getChannelStateMessage = (channelId: string) => { const getListen = (client: SlackClient, event: SlackEvent) => {   switch (event.type) {     case 'app_mention':-      return (regExp: RegExp, callback: (client: SlackClient, event: AppMentionEvent) => void) => {-        const messageContent = event.text.replace(/^<@\w+>\s*/, '');-        if (messageContent.match(regExp)) {+      return (command: string, callback: (client: SlackClient, event: AppMentionEvent) => void) => {+        const commandRegExp = new RegExp(`<@\\w+[\\w\\s\|]*>\\s+${command}($|\\s+)`);

ああちょっと勘違いしてた。messageContentはなんか勝手に生成されるものじゃなくて自分で作ってたか。 (Botkitは確かにこんな感じの処理をやってメッセージ先頭のメンション文字列を削ってた記憶)

hi-se

comment created time in a month

PullRequestReviewEvent

Pull request review commentsiiibo/shujinosuke

[feat] launch automation

 const getChannelStateMessage = (channelId: string) => { const getListen = (client: SlackClient, event: SlackEvent) => {   switch (event.type) {     case 'app_mention':-      return (regExp: RegExp, callback: (client: SlackClient, event: AppMentionEvent) => void) => {-        const messageContent = event.text.replace(/^<@\w+>\s*/, '');-        if (messageContent.match(regExp)) {+      return (command: string, callback: (client: SlackClient, event: AppMentionEvent) => void) => {+        const commandRegExp = new RegExp(`<@\\w+[\\w\\s\|]*>\\s+${command}($|\\s+)`);

(messageContentを削除した経緯)

「何をコマンドと認識するか」について、今までは文頭の文字列をコマンドである条件としていました。 (レポート以外のコマンドは、$もつけてそのコマンド文字列しかないことを条件にしていた)

ただ、slackからくるpayloadは <@U010MMQGD96> コマンド文字列という形式だったため、 先頭からメンション分の文字列を削除する処理が必要でした。 (botkitはおそらく似たような処理を内部で行っていた)

それが

const messageContent = event.text.replace(/^<@\w+>\s*/, '');

の部分で、このreplaceの部分を if(...match(command)) に入れ込むと読みづらいかと思い、messageContentの宣言部分に処理を書いていました。

今回の変更でコマンドと見なす条件を「(文頭に関わらず)メンション + 空白 + 文字列 ( +空白 ) とし、 文字列を調べる対象がreplace処理をしないevent.textそのものになったので変数を削除しました。

hi-se

comment created time in a month

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentsiiibo/shujinosuke

[feat] launch automation

 const getChannelStateMessage = (channelId: string) => { const getListen = (client: SlackClient, event: SlackEvent) => {   switch (event.type) {     case 'app_mention':-      return (regExp: RegExp, callback: (client: SlackClient, event: AppMentionEvent) => void) => {-        const messageContent = event.text.replace(/^<@\w+>\s*/, '');-        if (messageContent.match(regExp)) {+      return (command: string, callback: (client: SlackClient, event: AppMentionEvent) => void) => {+        const commandRegExp = new RegExp(`<@\\w+[\\w\\s\|]*>\\s+${command}($|\\s+)`);

app_mentionイベントとして取れてました?

取れていました。

messageContentはどうなってましたか?

リマインダー : <@U010MMQGD96|shujinosuke> 開始 という内容でした。

hi-se

comment created time in a month

Pull request review commentsiiibo/shujinosuke

[feat] launch automation

 const getChannelStateMessage = (channelId: string) => { const getListen = (client: SlackClient, event: SlackEvent) => {   switch (event.type) {     case 'app_mention':-      return (regExp: RegExp, callback: (client: SlackClient, event: AppMentionEvent) => void) => {-        const messageContent = event.text.replace(/^<@\w+>\s*/, '');-        if (messageContent.match(regExp)) {+      return (command: string, callback: (client: SlackClient, event: AppMentionEvent) => void) => {+        const commandRegExp = new RegExp(`<@\\w+[\\w\\s\|]*>\\s+${command}($|\\s+)`);

リマインダーで始まる場合(=@Shujinosukeが先頭に来てないメッセージ)でも、app_mentionイベントとして取れてました? その場合、messageContentはどうなってましたか?(event.textにマッチ対象を変えているが)

hi-se

comment created time in a month

PullRequestReviewEvent

Pull request review commentsiiibo/shujinosuke

[feat] launch automation

 const getChannelStateMessage = (channelId: string) => { const getListen = (client: SlackClient, event: SlackEvent) => {   switch (event.type) {     case 'app_mention':-      return (regExp: RegExp, callback: (client: SlackClient, event: AppMentionEvent) => void) => {-        const messageContent = event.text.replace(/^<@\w+>\s*/, '');-        if (messageContent.match(regExp)) {+      return (command: string, callback: (client: SlackClient, event: AppMentionEvent) => void) => {+        const commandRegExp = new RegExp(`<@\\w+[\\w\\s\|]*>\\s+${command}($|\\s+)`);

一般ユーザーからのメンション@Shujinosuke<@U010MMQGD96>と届くのに対し、Botからのメンションは <@U010MMQGD96|shujinosuke> と届く仕様になっていた。

そのため正規表現が少し複雑になっている。

(もしより完結な書き方があればアドバイスいただきたいです)

hi-se

comment created time in a month

PullRequestReviewEvent

Pull request review commentsiiibo/shujinosuke

[feat] launch automation

 const getChannelStateMessage = (channelId: string) => { const getListen = (client: SlackClient, event: SlackEvent) => {   switch (event.type) {     case 'app_mention':-      return (regExp: RegExp, callback: (client: SlackClient, event: AppMentionEvent) => void) => {-        const messageContent = event.text.replace(/^<@\w+>\s*/, '');-        if (messageContent.match(regExp)) {+      return (command: string, callback: (client: SlackClient, event: AppMentionEvent) => void) => {+        const commandRegExp = new RegExp(`<@\\w+[\\w\\s\|]*>\\s+${command}($|\\s+)`);

SlackBotによるリマインダーは リマインダー : @Shujinosuke 開始 のようにメンションの前に「リマインダー : 」という文字列が入る。 元々週次之介のコマンドは^@Shujinosuke ${command}といった入力を想定した実装になっていたが、文頭以外でも @Shujinosuke ${command} を受け入れるように修正。

hi-se

comment created time in a month

Pull request review commentsiiibo/shujinosuke

[feat] launch automation

 const getChannelStateMessage = (channelId: string) => { const getListen = (client: SlackClient, event: SlackEvent) => {   switch (event.type) {     case 'app_mention':-      return (regExp: RegExp, callback: (client: SlackClient, event: AppMentionEvent) => void) => {-        const messageContent = event.text.replace(/^<@\w+>\s*/, '');-        if (messageContent.match(regExp)) {+      return (command: string, callback: (client: SlackClient, event: AppMentionEvent) => void) => {
  1. メンション + 空白 + コマンド という構成を無視してコマンドの文字列だけで受け入れてしまうと、「業開始」などの言葉にも反応してしまう
  2. RegExpの結合ができない

という理由から、受け取るコマンドの型をstringにして、getListen内で正規表現のコンパイルをするようにした。

hi-se

comment created time in a month

PullRequestReviewEvent

PR opened siiibo/shujinosuke

[feat] launch automation

Slackの公式Botのリマインダーを利用して自動起動するためのPR.

+13 -13

0 comment

1 changed file

pr created time in a month

push eventsiiibo/shujinosuke

hi-se

commit sha ce7950a4296be5597099342db9d3843a533a811b

refactor: remove unnecessary const

view details

hi-se

commit sha 14f730df7aace58507071f814fbaee86e283bc3f

tmp: remove tmp

view details

hi-se

commit sha 5b2c37e0e1da385dc7faef7d624f5aa93df9a756

fix: change regex

view details

push time in a month

push eventsiiibo/shujinosuke

hi-se

commit sha 41a61c85b48564967c557b843603f034fc6ccfe1

fix: change regexp

view details

push time in a month

push eventsiiibo/shujinosuke

hi-se

commit sha a4d9b737ec6e6b8241e8cfa37a828dfb80b36cc4

fix: change type of listen arg to string

view details

hi-se

commit sha 99df8feb4d444f5ebc52f268f5e3e3febac67fd0

fix: change regexp

view details

push time in a month

push eventsiiibo/shujinosuke

hi-se

commit sha aa6ca53ef2d4bb443341d4191fad3793dfa51906

fix: add \ in regexp

view details

push time in a month

push eventsiiibo/shujinosuke

hi-se

commit sha 25de60f5410604e148ab66d34a254e5395d20301

fix: change regexp

view details

push time in a month