Skip to content

Instantly share code, notes, and snippets.

@gc373
Last active June 20, 2017 04:44
Show Gist options
  • Save gc373/369adff6abe891162915c3a4ff6a4e68 to your computer and use it in GitHub Desktop.
Save gc373/369adff6abe891162915c3a4ff6a4e68 to your computer and use it in GitHub Desktop.
mastodon-police
{
"name": "t.co-police",
"version": "1.0.0",
"description": "",
"main": "police.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "gc373",
"license": "MIT",
"dependencies": {
"mastodon-api": "^1.3.0"
}
}
var Masto = require('mastodon-api')
const M = new Masto({
access_token: '***** token *****',
timeout_ms: 60 * 1000,
api_url: 'https://****** your site *******/api/v1/',
})
const MESSAGE = "\r\n動くな、Mastodon警察だ。壁に手をつけ。いまお前が使ったリンクはt.coだな…?"
function post(id, reply_id) {
console.log({ status: "@" + id + MESSAGE, in_reply_to_id: reply_id });
M.post('statuses', { status: "@" + id + MESSAGE, in_reply_to_id: reply_id }, function (err, a, b) {
console.log(JSON.stringify(err, null, "\t"));
})
}
const streamPub = M.stream('streaming/public') // streaming/public でやったら死ぬかも
streamPub.on('message', (msg) => {
if (msg.event == 'update' && msg.data.content.match(/.https:\/\/t\.co./)) {
post(msg.data.account.acct, msg.data.id);
}
})
streamPub.on('error', (err) => {
console.log(err)
})
@gc373
Copy link
Author

gc373 commented Jun 19, 2017

tokenの取得はここ
URLに空白が入ってエラーになるので削除すること!!!

@gc373
Copy link
Author

gc373 commented Jun 20, 2017

mastodon-apiを1.3にしたから空白入らないかも?:innocent:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment