-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhellotwitter
60 lines (45 loc) · 2.68 KB
/
hellotwitter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# ============================================================================================================
# YOU need to fill out the target twitter account and your auto-reply message
target=''
message=''
# ============================================================================================================
# YOU need to fill this out using https://developer.twitter.com/en/portal/dashboard
oauth_bearer_token=''
oauth_consumer_key=''
oauth_consumer_secret=''
oauth_token=''
oauth_token_secret=''
# ============================================================================================================
# Code starts here
oauth_consumer_key=`urlencode $oauth_consumer_key`
oauth_consumer_secret=`urlencode $oauth_consumer_secret`
oauth_signature_method=`urlencode HMAC-SHA1`
oauth_token=`urlencode $oauth_token`
oauth_token_secret=`urlencode $oauth_token_secret`
oauth_version=`urlencode 1.0`
signature_key="$oauth_consumer_secret&$oauth_token_secret"
url='https://api.twitter.com/1.1/statuses/update.json'
lastid=`tail -1 lastids.log`
list=`curl -X GET "https://api.twitter.com/2/tweets/search/recent?query=from:$target&since_id=$lastid&tweet.fields=referenced_tweets&expansions=entities.mentions.username" -H "Authorization: Bearer $oauth_bearer_token"`
list=`echo $list | jq '.data[] | {ref:.referenced_tweets, name:.entities.mentions[0].username, id:.id} | if .ref != null then (if [.ref[] | .type == "retweeted"] | any then { id:.ref[] | select("retweeted") | .id, name:.name } else { id:.id } end ) else { id:.id } end | .id + "-" + .name'`
list=`echo $list | sed s/\"//g | tr ' ' '\n' | sort | tr '\n' ' '`
for v in $list; do
id=`echo $v | cut -d '-' -f 1`
data2=`urlencode $id`
data1="@$target $message"
mention=`echo $v | cut -d '-' -f 2`
if [ "$mention" != "" ]; then
data1="@$mention $data1"
fi
data1=`urlencode $data1`
oauth_nonce=`date +%s%N`
oauth_timestamp=`date +%s`
params="oauth_consumer_key=$oauth_consumer_key,oauth_nonce=$oauth_nonce,oauth_signature_method=$oauth_signature_method,oauth_timestamp=$oauth_timestamp,oauth_token=$oauth_token,oauth_version=$oauth_version"
params_anded=`echo $params | sed 's/,/\&/g'`
base_string='POST&'`urlencode $url`'&'`urlencode in_reply_to_status_id=$data2\&$params_anded\&status=$data1` #alphebetical order!!!
oauth_signature=`echo -n $base_string | openssl sha1 -hmac $signature_key -binary | base64`
oauth_signature=`urlencode $oauth_signature`
curl -X POST $url -H "Authorization: OAuth $params,oauth_signature=$oauth_signature" -H "Content-Type: application/x-www-form-urlencoded" --data "status=$data1&in_reply_to_status_id=$data2"
echo $id >>lastids.log
done