hubot 설치, 스크립팅, 외부 명령 실행
17115 단어 Hubot
참고
설치
# sudo apt-get install -y redis-server
sudo npm install -g npm nodejs
sudo npm install -g coffee-script yo generator-hubot
mkdir k
cd k
yo hubot --defaults
external-scripts.json
[
...
- "hubot-heroku-keepalive",
- "hubot-redis-brain",
...
]
비어 있으므로 삭제
rm hubot-scripts.json
시작
시작
bin/hubot
콘솔
k> k ping
k> PONG
k> k help
k> Shell: k adapter - Reply with the adapter
k animate me <query> - The same thing as `image me`, except adds a few parameters to try to return an animated GIF instead.
k echo <text> - Reply back with <text>
k help - Displays all of the help commands that Hubot knows about.
k help <query> - Displays all help commands that match <query>.
k image me <query> - The Original. Queries Google Images for <query> and returns a random top result.
k map me <query> - Returns a map view of the area returned by `query`.
k mustache me <url|query> - Adds a mustache to the specified URL or query result.
k ping - Reply with pong
k pug bomb N - get N pugs
k pug me - Receive a pug
k the rules - Make sure hubot still knows the rules.
k time - Reply with current time
k translate me <phrase> - Searches for a translation for the <phrase> and then prints that bad boy out.
k translate me from <source> into <target> <phrase> - Translates <phrase> from <source> into <target>. Both <source> and <target> are optional
ship it - Display a motivation squirrel
PING 응답을 변경해 봅니다.
~.coffee is using deprecated documentation syntax
Description은 필요하다고.
scripts/ping.coffee
# Description:
# Example scripts for you to examine and try out.
module.exports = (robot) ->
robot.respond /PING$/i, (res) ->
res.reply "何ですか?"
bin/hubot
k> k ping
k> Shell: 何ですか?
PONG
외부 명령 실행
핑
# Description:
# Commands:
# hubot ping <hostname>
module.exports = (robot) ->
robot.respond /ping (.*)$/i, (msg) ->
hostname = msg.match[1]
@exec = require('child_process').exec
command = "ping -c5 #{hostname}"
msg.send command
@exec command, (error, stdout, stderr) ->
#msg.send error
msg.send stdout
#msg.send stderr
k> k ping 8.8.8.8
ping -c5 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=54 time=5.12 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=54 time=4.83 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=54 time=3.07 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=54 time=4.05 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=54 time=5.26 ms
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 3.074/4.472/5.263/0.814 ms
날씨(curl)
英和/和英(trans)
sudo apt-get install -y gawk
wget git.io/trans
chmod +x ./trans
sudo mv trans /usr/local/bin/
trans 명령의 동작 확인
$ trans :ja binary
$ trans :en 変える
scripts/trans.coffee
# Description:
# Commands:
# hubot trans :(ja|en) <word>
module.exports = (robot) ->
robot.respond /trans :(ja|en) (.*)$/i, (msg) ->
lang = msg.match[1]
word = msg.match[2]
@exec = require('child_process').exec
command = "trans :#{lang} #{word}"
msg.send command
@exec command, (error, stdout, stderr) ->
#msg.send error
msg.send stdout
#msg.send stderr
trans 명령의 동작 확인
k> @k trans :ja binary
wget
scripts/wget.coffee
# Description:
# Commands:
# hubot wget <url>
module.exports = (robot) ->
robot.respond /wget (.*)$/i, (msg) ->
url = msg.match[1]
@exec = require('child_process').exec
command = "wget -P ./Downloads/ #{url}"
msg.send command
@exec command, (error, stdout, stderr) ->
msg.send stdout
준비
mkdir Downloads
동작 확인
k wget https://pbs.twimg.com/media/Civ07I7UgAAXLOC.jpg
ls
scripts/ls.coffee
# Description:
# Commands:
# hubot ls
module.exports = (robot) ->
robot.respond /ls$/i, (msg) ->
@exec = require('child_process').exec
command = "ls -lh ./Downloads/"
msg.send command
@exec command, (error, stdout, stderr) ->
#msg.send error
msg.send stdout
#msg.send stderr
youtube-dl
scripts/
scripts/youtube-dl.coffee
# Description:
# Commands:
# hubot youtube-dl <url>
module.exports = (robot) ->
robot.respond /youtube-dl (.*)$/i, (msg) ->
url = msg.match[1]
@exec = require('child_process').exec
command = "(cd ./Downloads/ && youtube-dl #{url})"
msg.send command
@exec command, (error, stdout, stderr) ->
msg.send stdout
hubot의 이름을 바꾸고 싶다면
sed -i -e 's/myhubot/k/g' package.json
sed -i -e 's/myhubot/k/g' README.md
sed -i -e 's/myhubot/k/g' bin/hubot
sed -i -e 's/myhubot/k/g' bin/hubot.cmd
Reference
이 문제에 관하여(hubot 설치, 스크립팅, 외부 명령 실행), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/tukiyo3/items/b3f20e188302ce65fe81텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)