1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sovereign\Plugins\onMessage; |
4
|
|
|
|
5
|
|
|
use Discord\Discord; |
6
|
|
|
use Discord\Parts\Channel\Message; |
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 porn extends \Threaded implements \Collectable |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var Message |
20
|
|
|
*/ |
21
|
|
|
private $message; |
22
|
|
|
/** |
23
|
|
|
* @var Discord |
24
|
|
|
*/ |
25
|
|
|
private $discord; |
26
|
|
|
/** |
27
|
|
|
* @var Logger |
28
|
|
|
*/ |
29
|
|
|
private $log; |
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
private $channelConfig; |
34
|
|
|
/** |
35
|
|
|
* @var Config |
36
|
|
|
*/ |
37
|
|
|
private $config; |
38
|
|
|
/** |
39
|
|
|
* @var Db |
40
|
|
|
*/ |
41
|
|
|
private $db; |
42
|
|
|
/** |
43
|
|
|
* @var cURL |
44
|
|
|
*/ |
45
|
|
|
private $curl; |
46
|
|
|
/** |
47
|
|
|
* @var Settings |
48
|
|
|
*/ |
49
|
|
|
private $settings; |
50
|
|
|
/** |
51
|
|
|
* @var Permissions |
52
|
|
|
*/ |
53
|
|
|
private $permissions; |
54
|
|
|
/** |
55
|
|
|
* @var ServerConfig |
56
|
|
|
*/ |
57
|
|
|
private $serverConfig; |
58
|
|
|
/** |
59
|
|
|
* @var Users |
60
|
|
|
*/ |
61
|
|
|
private $users; |
62
|
|
|
/** |
63
|
|
|
* @var array |
64
|
|
|
*/ |
65
|
|
|
private $extras; |
66
|
|
|
|
67
|
|
View Code Duplication |
public function __construct($message, $discord, $channelConfig, $log, $config, $db, $curl, $settings, $permissions, $serverConfig, $users, $extras) |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$this->message = $message; |
70
|
|
|
$this->discord = $discord; |
71
|
|
|
$this->channelConfig = $channelConfig; |
72
|
|
|
$this->log = $log; |
73
|
|
|
$this->config = $config; |
74
|
|
|
$this->db = $db; |
75
|
|
|
$this->curl = $curl; |
76
|
|
|
$this->settings = $settings; |
77
|
|
|
$this->permissions = $permissions; |
78
|
|
|
$this->serverConfig = $serverConfig; |
79
|
|
|
$this->users = $users; |
80
|
|
|
$this->extras = $extras; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function run() |
84
|
|
|
{ |
85
|
|
|
$pornConfig = @$this->channelConfig->porn; |
86
|
|
|
|
87
|
|
|
// This is one of those plugins that need to be allowed before it works |
88
|
|
|
if (isset($pornConfig->allowedChannels) && in_array($this->message->channel_id, $pornConfig->allowedChannels)) { |
89
|
|
|
$explode = explode(" ", $this->message->content); |
90
|
|
|
unset($explode[0]); |
91
|
|
|
$type = implode(" ", $explode); |
92
|
|
|
$categoryNames = array(); |
93
|
|
|
$url = ""; |
94
|
|
|
|
95
|
|
|
$categories = array( |
96
|
|
|
"redheads" => array( |
97
|
|
|
"https://api.imgur.com/3/gallery/r/redheads/time/all/", |
98
|
|
|
"https://api.imgur.com/3/gallery/r/ginger/time/all/", |
99
|
|
|
"https://api.imgur.com/3/gallery/r/FireCrotch/time/all/" |
100
|
|
|
), |
101
|
|
|
"blondes" => "https://api.imgur.com/3/gallery/r/blondes/time/all/", |
102
|
|
|
"asians" => "https://api.imgur.com/3/gallery/r/AsiansGoneWild/time/all/", |
103
|
|
|
"gonewild" => "https://api.imgur.com/3/gallery/r/gonewild/time/all/", |
104
|
|
|
"realgirls" => "https://api.imgur.com/3/gallery/r/realgirls/time/all/", |
105
|
|
|
"palegirls" => "https://api.imgur.com/3/gallery/r/palegirls/time/all/", |
106
|
|
|
"gif" => "https://api.imgur.com/3/gallery/r/NSFW_GIF/time/all/", |
107
|
|
|
"lesbians" => "https://api.imgur.com/3/gallery/r/lesbians/time/all/", |
108
|
|
|
"tattoos" => "https://api.imgur.com/3/gallery/r/Hotchickswithtattoos/time/all/", |
109
|
|
|
"mgw" => "https://api.imgur.com/3/gallery/r/MilitaryGoneWild/time/all/", |
110
|
|
|
"amateur" => "https://api.imgur.com/3/gallery/r/AmateurArchives/time/all/", |
111
|
|
|
"college" => "https://api.imgur.com/3/gallery/r/collegesluts/time/all/", |
112
|
|
|
"bondage" => "https://api.imgur.com/3/gallery/r/bondage/time/all/", |
113
|
|
|
"milf" => "https://api.imgur.com/3/gallery/r/milf/time/all/", |
114
|
|
|
"freckles" => "https://api.imgur.com/3/gallery/r/FreckledGirls/time/all/", |
115
|
|
|
"cosplay" => "https://api.imgur.com/3/gallery/r/cosplay/time/all/", |
116
|
|
|
"tits" => "https://api.imgur.com/3/gallery/r/boobs/time/all/", |
117
|
|
|
"ass" => "https://api.imgur.com/3/gallery/r/ass/time/all/", |
118
|
|
|
"food" => "https://api.imgur.com/3/gallery/r/foodporn/time/all/", |
119
|
|
|
"gifrecipes" => "https://api.imgur.com/3/gallery/r/gifrecipes/time/all/", |
120
|
|
|
"bbw" => "https://api.imgur.com/3/gallery/r/bbw/time/all/", |
121
|
|
|
"dongs" => "https://api.imgur.com/3/gallery/r/penis/time/all/", |
122
|
|
|
"innie" => "https://api.imgur.com/3/gallery/r/innie/time/all/", |
123
|
|
|
); |
124
|
|
|
|
125
|
|
|
foreach($categories as $catName => $catURL) { |
126
|
|
|
$categoryNames[] = ucfirst($catName); |
127
|
|
|
if(strtolower($type) == strtolower($catName)) { |
128
|
|
|
if(is_array($catURL)) |
129
|
|
|
$url = $catURL[array_rand($catURL)]; |
130
|
|
|
else |
131
|
|
|
$url = $catURL; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
if (!empty($url)) { |
136
|
|
|
// Select a random url |
137
|
|
|
$clientID = $this->config->get("clientID", "imgur"); |
138
|
|
|
$headers = array(); |
139
|
|
|
$headers[] = "Content-type: application/json"; |
140
|
|
|
$headers[] = "Authorization: Client-ID {$clientID}"; |
141
|
|
|
$data = $this->curl->get($url, $headers); |
142
|
|
|
|
143
|
|
|
if ($data) { |
144
|
|
|
$json = json_decode($data, true)["data"]; |
145
|
|
|
$img = $json[array_rand($json)]; |
146
|
|
|
$imageURL = $img["link"]; // gifv doesn't embed properly in discord, yet.. |
147
|
|
|
$msg = "**Title:** {$img["title"]} | **Section:** {$img["section"]} | **url:** {$imageURL}"; |
148
|
|
|
$this->message->reply($msg); |
149
|
|
|
} |
150
|
|
|
} else { |
151
|
|
|
$msg = "No endpoint selected. Currently available are: " . implode(", ", $categoryNames); |
152
|
|
|
$this->message->reply($msg); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
} else { |
156
|
|
|
$this->message->reply("Sorry, this plugin is not allowed in this channel, speak to your admin to get it allowed (To enable, use {$this->channelConfig->prefix}config enablePorn)"); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
// Mark this as garbage |
160
|
|
|
$this->isGarbage(); |
161
|
|
|
} |
162
|
|
|
} |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: