-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunreal_updates.php
131 lines (120 loc) · 3.32 KB
/
unreal_updates.php
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
<?php
/*
// (C) 2021 DalekIRC Services
\\
// dalek.services
\\
// GNU GENERAL PUBLIC LICENSE
\\ v3
//
\\
//
\\ Title: bbServ
//
\\ Desc: Post to the chat whenever something new goes on the forum
//
\\ Expects an "forumschan" setting in wordpress.conf
//
\\ Version: 1.0
//
\\ Author: Valware
//
*/
class unreal_updates {
/* Module handle */
/* $name needs to be the same name as the class and file lol */
public $name = "unreal_updates";
public $description = "Post to channel whenever there is a new version of UnrealIRCd";
public $author = "Valware";
public $version = "1.0";
/* To run when this class is created/when the module is loaded */
/* Construction: Here's where you'll wanna initialise any globals or databases or anything */
function __construct()
{
$conn = sqlnew();
$conn->query("CREATE TABLE IF NOT EXISTS dalek_unreal_version (
id int AUTO_INCREMENT NOT NULL,
version varchar(255) NOT NULL,
PRIMARY KEY (id)
)");
$conn->close();
}
/* To run when the class is destroyed/when the module is unloaded */
/* Destruction: Here's where to clear up your globals or databases or anything */
function __destruct()
{
hook::del("chanmsg", 'unreal_updates::fantasy');
}
function __init()
{
$error = NULL;
Events::Add(servertime() + 600, 0, 600, 'unreal_updates::check_for_new_version', [], $error, 'unreal_updates');
hook::func("chanmsg", 'unreal_updates::fantasy');
return true;
}
static function fantasy($u)
{
global $chanserv;
$cs = Client::find($chanserv['nick']);
$parv = split($u['params']);
if (strcasecmp(mb_substr($parv[1],1),"!unreal") || $u['dest'] !== "#PossumsOnly")
return;
$json = (array)json_decode(file_get_contents("https://www.unrealircd.org/downloads/list.json"));
if ($json)
{
foreach($json as $latest)
{
if (!isset($latest->Stable))
continue;
$cs->msg("#PossumsOnly",bold("Latest UnrealIRCd version:")." ".$latest->Stable->version);
$cs->msg("#PossumsOnly",bold("Download link:")." ".$latest->Stable->downloads->src);
}
}
}
static function check_for_new_version()
{
$latest = NULL;
$json = (array)json_decode(file_get_contents("https://www.unrealircd.org/downloads/list.json"));
if ($json)
{
foreach($json as $lates)
{
if (!isset($lates->Stable))
continue;
$version = $lates->Stable->version;
$latest = $lates;
}
}
else return;
if ($version > $v = self::get_last())
{
self::set_last($version);
global $chanserv;
$cs = Client::find($chanserv['nick']);
if ($v)
$cs->msg("#PossumsOnly","UnrealIRCd v$version released! - $latest->Stable->downloads->src");
else
$cs->msg("#PossumsOnly","First run: Got UnrealIRCd version $version. I'll let you know when there's a new version released!");
}
}
static function set_last($id)
{
$conn = sqlnew();
if (!unreal_updates::get_last())
{
$conn->query("TRUNCATE TABLE dalek_unreal_version");
$conn->query("INSERT INTO dalek_unreal_version (version) VALUES ('$id')");
}
else
$conn->query("UPDATE dalek_unreal_version SET version = '$id' WHERE id = 1");
}
static function get_last()
{
$conn = sqlnew();
$result = $conn->query("SELECT * FROM dalek_unreal_version WHERE id = 1");
if (!$result || $result->num_rows < 1)
return 0;
$row = $result->fetch_assoc();
return $row['version'];
}
}