This repository was archived by the owner on Mar 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseful.php
More file actions
171 lines (154 loc) · 4.62 KB
/
useful.php
File metadata and controls
171 lines (154 loc) · 4.62 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
ini_set('error_display', 1);
error_reporting(E_ALL);
define("APPNAME_BOT_DIR", __DIR__."/bot");
define("off", false);
define("on", true);
/**
* Pretty colourful version of print, prints text into console
*
* 1st arg is background;
*
* 2nd arg is foreground;
*
* e.g: BLACK+WHITE
*
* Background colours: Black, Red, GREEN, YELLOW, BLUE, MAGENTA, CYAN, LIGHTGRAY
*
* foreground colours: Black, DARKGRAY, RED, LIGHTRED, GREEN, LIGHTGREEN, BROWN, YELLOW, BLUE, LIGHTBLUE, MAGENTA, LIGHTMAGENTA, CAYN, LIGHTCYAN, LIGHTGRAY, WHITE
*/
class log
{
public $string;
public $print;
private $settings = [
0 => [
'where' => 'foreground',
'default' => "1;32;",
],
1 => [
'where' => 'background',
'default' => "48m",
],
];
private $foreground = [
'BLACK' => "0;30;",
'DARKGREY' => "1;30;",
'RED' => "0;31;",
'LIGHTRED' => "0;31;",
'GREEN' => "0;32;",
'LIGHTGREEN' => "1;32;",
'BROWN' => "0;33;",
'YELLOW' => "1;33;",
'BLUE' => "0;34;",
'LIGHTBLUE' => "1;34;",
'MAGENTA' => "0;35;",
'LIGHTMAGENTA' => "1;35;",
'CYAN' => "0;36;",
'LIGHTCYAN' => "1;36;",
'LIGHTGRAY' => "0;37;",
'WHITE' => "1;37;",
];
private $background = [
'BLACK' => "40m",
'RED' => "41m",
'GREEN' => "42m",
'YELLOW' => "43m",
'BLUE' => "44m",
'MAGENTA' => "45m",
'CYAN' => "46m",
'LIGHTGRAY' => "47m",
];
public function __construct($text, $echo = false)
{
$this->string = &$text;
$this->paint();
}
public function formatColours(array $args)
{
foreach ($this->settings as $digit => $surface) {
if (isset($args[$digit]))
if (isset(($this->{$surface['where']})[$args[$digit]])) {
$colours[$surface['where']] = ($this->{$surface['where']})[$args[$digit]];
continue;
}
$colours[$surface['where']] = $surface['default'];
}
$colours['_'] = "\e[".$colours['foreground'].$colours['background']; // uncompleted string
return $colours;
}
public function paint(string $background = null, string $foreground = null, $inline = false)
{
$colours = $this->formatColours([$background, $foreground]);
$this->print = $colours['_']." ".$this->string." "."\e[0m";
if (isset($foreground) || isset($background))
if ($inline) $this->logln(); else $this->log();
else return $this->print;
}
public function log($text = false)
{
if ($text) print($text.PHP_EOL); else print($this->print.PHP_EOL);
}
public function logln($text = false)
{
if ($text) print($text); else print($this->print);
}
public function lnlog($text = false)
{
if ($text) print(PHP_EOL.$text.PHP_EOL); else print(PHP_EOL.$this->print.PHP_EOL);
}
}
/**
* This function resembles JavaScript function 'console'
*/
function console(string $text) : object
{
return new log($text);
}
class useful
{
public static $settings = [
"notice" => on,
];
public $print;
public function __construct()
{
console("Hello, I'm constructed and ready to help you because I'm the most useful class ever!")
->paint("BLACK", "LIGHTGRAY");
}
public static function date_to_words(string $date, $lang = null, $letters = null) {
$date = date_parse_from_format("Y-m-d", $date);
$month = [
"1" => "Января",
"2" => "Февраля",
"3" => "Марта",
"4" => "Апреля",
"5" => "Мая",
"6" => "Июня",
"7" => "Июля",
"8" => "Августа",
"9" => "Сентября",
"10" => "Октября",
"11" => "Ноября",
"12" => "Декабря",
][$date["month"]];
return [
"_" => "{$date["day"]}-{$month}-{$date["year"]}",
"day" => $date["day"],
"month" => $month,
"year" => $date["year"],
];
}
public static function setUp(array $settings)
{
self::$settings = &$settings;
}
public static function getGeo()
{
$ip = shell_exec('curl https://ipinfo.io/ip');
$geo = shell_exec('curl https://ipvigilante.com/'.$ip);
$geo = json_decode($geo);
#print_r($geo->data);
return $geo->data->country_name;
}
}