LoginSignup
2
3

More than 5 years have passed since last update.

Slackの豆腐をころすマンをHubotで実装する(暫定版)

Last updated at Posted at 2017-05-31

最近Macのクライアントを使ってSlackを打つと結構な確率でバックスペースが入り豆腐になるので、ちまたで流行りの豆腐殺すマンをHubotで実装。

tofu_korosu.png

nodeのBufferの使い方がいまいち分からなかったのでRubyで書いてる部分が暫定だよ。
一応Botに引用っぽく発言させて会話を阻害しないようにしてます。

no_more_tofu.coffee
# Description:
#   Mac版のエージェントで発生する豆腐を人間語に翻訳しなおします
#
# Author:
#   miyay

exec = require('child_process').exec

module.exports = (robot) ->
  robot.hear /.*/, (msg) ->
    exec "ruby -e 'puts [%q(#{msg.message.text}).unpack(%(H*)).first.each_char.each_slice(2).map(&:join).map{|a| a == %(08) ? nil : a}.tap{|t| exit if t.all?}.join].pack(%(H*))'", (error, stdout, stderr) ->
      if stdout
        data =
          content:
            text: stdout
            mrkdwn_in: ["text"]
          channel: msg.envelope.room
          username: "tofu_changer"
          icon_emoji: ":black_medium_square:"
        robot.emit "slack.attachment", data

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3