|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sovereign\Plugins\onTimer; |
|
4
|
|
|
|
|
5
|
|
|
use Discord\Discord; |
|
6
|
|
|
use Discord\Parts\Channel\Channel; |
|
7
|
|
|
use Monolog\Logger; |
|
8
|
|
|
use Sovereign\Lib\Config; |
|
9
|
|
|
use Sovereign\Lib\cURL; |
|
10
|
|
|
use Sovereign\Lib\Db; |
|
11
|
|
|
use Sovereign\Lib\Permissions; |
|
12
|
|
|
use Sovereign\Lib\ServerConfig; |
|
13
|
|
|
use Sovereign\Lib\Settings; |
|
14
|
|
|
use Sovereign\Lib\Users; |
|
15
|
|
|
|
|
16
|
|
|
class jabberPingsTheCulture extends \Threaded implements \Collectable |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var Discord |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $discord; |
|
22
|
|
|
/** |
|
23
|
|
|
* @var Logger |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $log; |
|
26
|
|
|
/** |
|
27
|
|
|
* @var Config |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $config; |
|
30
|
|
|
/** |
|
31
|
|
|
* @var Db |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $db; |
|
34
|
|
|
/** |
|
35
|
|
|
* @var cURL |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $curl; |
|
38
|
|
|
/** |
|
39
|
|
|
* @var Settings |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $settings; |
|
42
|
|
|
/** |
|
43
|
|
|
* @var Permissions |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $permissions; |
|
46
|
|
|
/** |
|
47
|
|
|
* @var ServerConfig |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $serverConfig; |
|
50
|
|
|
/** |
|
51
|
|
|
* @var Users |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $users; |
|
54
|
|
|
/** |
|
55
|
|
|
* @var array |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $extras; |
|
58
|
|
|
|
|
59
|
|
|
public function __construct($discord, $log, $config, $db, $curl, $settings, $permissions, $serverConfig, $users, $extras) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->discord = $discord; |
|
62
|
|
|
$this->log = $log; |
|
63
|
|
|
$this->config = $config; |
|
64
|
|
|
$this->db = $db; |
|
65
|
|
|
$this->curl = $curl; |
|
66
|
|
|
$this->settings = $settings; |
|
67
|
|
|
$this->permissions = $permissions; |
|
68
|
|
|
$this->serverConfig = $serverConfig; |
|
69
|
|
|
$this->users = $users; |
|
70
|
|
|
$this->extras = $extras; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function run() |
|
74
|
|
|
{ |
|
75
|
|
|
$handle = fopen("/tmp/discord.db", "r+"); |
|
76
|
|
|
flock($handle, LOCK_EX); |
|
77
|
|
|
|
|
78
|
|
|
$message = ""; |
|
79
|
|
|
while ($row = fgets($handle)) { |
|
80
|
|
|
if (!empty($row)) { |
|
81
|
|
|
$row = str_replace("\n", "", str_replace("\r", "", str_replace("^@", "", $row))); |
|
82
|
|
|
if ($row == "" || $row == " ") { |
|
83
|
|
|
continue; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$message .= $row . " | "; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
flock($handle, LOCK_UN); |
|
91
|
|
|
fclose($handle); |
|
92
|
|
|
$handle = fopen("/tmp/discord.db", "w+"); |
|
93
|
|
|
fclose($handle); |
|
94
|
|
|
chmod("/tmp/discord.db", 0777); |
|
95
|
|
|
$data = null; |
|
|
|
|
|
|
96
|
|
|
$handle = null; |
|
|
|
|
|
|
97
|
|
|
clearstatcache(); |
|
98
|
|
|
|
|
99
|
|
|
if (!empty($message)) { |
|
100
|
|
|
// Strip out the last | |
|
101
|
|
|
$message = trim(substr($message, 0, -2)); |
|
102
|
|
|
$channelID = 154221481625124864; |
|
103
|
|
|
/** @var Channel $channel */ |
|
104
|
|
|
$channel = Channel::find($channelID); |
|
105
|
|
|
$this->log->addInfo("Sending ping to #pings on The Culture"); |
|
106
|
|
|
$channel->sendMessage("@everyone " . $message, false); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.