1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace mpyw\HardBotter\Traits; |
4
|
|
|
|
5
|
|
|
use mpyw\Co\Co; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @method mixed post($endpoint, array $params = []) |
9
|
|
|
* @method \Generator postAsync($endpoint, array $params = []) |
10
|
|
|
*/ |
11
|
|
|
trait TweetManagerTrait |
12
|
|
|
{ |
13
|
|
|
abstract protected static function out($msg); |
14
|
|
|
abstract public function __call($method, array $args); |
15
|
|
|
|
16
|
1 |
|
public function reply($text, \stdClass $original_status, $prepend_screen_name = true) |
17
|
|
|
{ |
18
|
1 |
|
$result = $this->post('statuses/update', [ |
19
|
1 |
|
'status' => $prepend_screen_name ? "@{$original_status->user->screen_name} $text" : $text, |
20
|
1 |
|
'in_reply_to_status_id' => $original_status->id_str, |
21
|
|
|
]); |
22
|
1 |
|
if ($result !== false) { |
23
|
1 |
|
self::out('REPLIED: ' . $result->text); |
24
|
|
|
} |
25
|
1 |
|
return $result; |
26
|
|
|
} |
27
|
|
|
|
28
|
1 |
|
public function replyAsync($text, \stdClass $original_status, $prepend_screen_name = true) |
29
|
|
|
{ |
30
|
1 |
|
$result = (yield $this->postAsync('statuses/update', [ |
31
|
1 |
|
'status' => $prepend_screen_name ? "@{$original_status->user->screen_name} $text" : $text, |
32
|
1 |
|
'in_reply_to_status_id' => $original_status->id_str, |
33
|
|
|
])); |
34
|
1 |
|
if ($result !== false) { |
35
|
1 |
|
self::out('REPLIED: ' . $result->text); |
36
|
|
|
} |
37
|
1 |
|
yield Co::RETURN_WITH => $result; |
38
|
|
|
// @codeCoverageIgnoreStart |
39
|
|
|
} |
40
|
|
|
// @codeCoverageIgnoreEnd |
41
|
|
|
|
42
|
1 |
|
public function tweet($text) |
43
|
|
|
{ |
44
|
1 |
|
$result = $this->post('statuses/update', ['status' => $text]); |
45
|
1 |
|
if ($result !== false) { |
46
|
1 |
|
self::out('TWEETED: ' . $result->text); |
47
|
|
|
} |
48
|
1 |
|
return $result; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
public function tweetAsync($text) |
52
|
|
|
{ |
53
|
1 |
|
$result = (yield $this->postAsync('statuses/update', ['status' => $text])); |
54
|
1 |
|
if ($result !== false) { |
55
|
1 |
|
self::out('TWEETED: ' . $result->text); |
56
|
|
|
} |
57
|
1 |
|
yield Co::RETURN_WITH => $result; |
58
|
|
|
// @codeCoverageIgnoreStart |
59
|
|
|
} |
60
|
|
|
// @codeCoverageIgnoreEnd |
61
|
|
|
|
62
|
1 |
|
public function favorite(\stdClass $status) |
63
|
|
|
{ |
64
|
1 |
|
$result = $this->post('favorites/create', ['id' => $status->id_str]); |
65
|
1 |
|
if ($result !== false) { |
66
|
1 |
|
self::out('FAVORITED @' . $result->user->screen_name . ': ' . $result->text); |
67
|
|
|
} |
68
|
1 |
|
return $result; |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
public function favoriteAsync(\stdClass $status) |
72
|
|
|
{ |
73
|
1 |
|
$result = (yield $this->postAsync('favorites/create', ['id' => $status->id_str])); |
74
|
1 |
|
if ($result !== false) { |
75
|
1 |
|
self::out('FAVORITED @' . $result->user->screen_name . ': ' . $result->text); |
76
|
|
|
} |
77
|
1 |
|
yield Co::RETURN_WITH => $result; |
78
|
|
|
// @codeCoverageIgnoreStart |
79
|
|
|
} |
80
|
|
|
// @codeCoverageIgnoreEnd |
81
|
|
|
|
82
|
1 |
|
public function retweet(\stdClass $status) |
83
|
|
|
{ |
84
|
1 |
|
$result = $this->post('statuses/retweet', ['id' => $status->id_str]); |
85
|
1 |
|
if ($result !== false) { |
86
|
1 |
|
$original = $result->retweeted_status; |
87
|
1 |
|
self::out('RETWEETED @' . $original->user->screen_name . ': ' . $original->text); |
88
|
|
|
} |
89
|
1 |
|
return $result; |
90
|
|
|
} |
91
|
|
|
|
92
|
1 |
|
public function retweetAsync(\stdClass $status) |
93
|
|
|
{ |
94
|
1 |
|
$result = (yield $this->postAsync('statuses/retweet', ['id' => $status->id_str])); |
95
|
1 |
|
if ($result !== false) { |
96
|
1 |
|
$original = $result->retweeted_status; |
97
|
1 |
|
self::out('RETWEETED @' . $original->user->screen_name . ': ' . $original->text); |
98
|
|
|
} |
99
|
1 |
|
yield Co::RETURN_WITH => $result; |
100
|
|
|
// @codeCoverageIgnoreStart |
101
|
|
|
} |
102
|
|
|
// @codeCoverageIgnoreEnd |
103
|
|
|
} |
104
|
|
|
|