From f214e7f2f6d9be8f1c79876ad9253de6bae07bad Mon Sep 17 00:00:00 2001 From: Damian Zaremba Date: Sat, 24 Jul 2021 07:35:22 +0200 Subject: [PATCH] Add UDP relay support This adds back a stripped down version of the UDP relay support. --- cluebot-ng.config.php.dist | 1 + db_functions.php | 20 ++++++++++---------- feed_functions.php | 4 +++- irc_functions.php | 26 ++++++++++++++++++++++++++ process_functions.php | 16 ++++++++-------- 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/cluebot-ng.config.php.dist b/cluebot-ng.config.php.dist index 2a26fc7..e4ea5be 100644 --- a/cluebot-ng.config.php.dist +++ b/cluebot-ng.config.php.dist @@ -36,6 +36,7 @@ namespace CluebotNG; public static $cb_mysql_user = ''; public static $cb_mysql_pass = ''; public static $cb_mysql_db = 'cb'; + public static $udpport = 3334; public static $coreport = 3565; public static $fork = true; public static $dry = false; diff --git a/db_functions.php b/db_functions.php index 4d427e6..092b7d5 100644 --- a/db_functions.php +++ b/db_functions.php @@ -24,9 +24,9 @@ class Db { public static $coreNodeCache = 0; - public static $relayNodeCache = 0; + public static $ircRelayNodeCache = 0; public static $coreNode = null; - public static $relayNode = null; + public static $ircRelayNode = null; // Returns the edit it for the vandalism public static function detectedVandalism($user, $title, $heuristic, $reason, $url, $old_rev_id, $rev_id) @@ -95,22 +95,22 @@ public static function getCurrentCoreNode() return null; } - // Returns the hostname of the current relay node - public static function getCurrentRelayNode() + // Returns the hostname of the current IRC relay node + public static function getCurrentIrcRelayNode() { - if (self::$relayNodeCache > time() - 10 && self::$relayNode != null) { - return self::$relayNode; + if (self::$ircRelayNodeCache > time() - 10 && self::$ircRelayNode != null) { + return self::$ircRelayNode; } checkMySQL(); - self::$relayNodeCache = time(); - $res = mysqli_query(Globals::$cb_mysql, 'SELECT `node` from `cluster_node` where type="relay"'); + self::$ircRelayNodeCache = time(); + $res = mysqli_query(Globals::$cb_mysql, 'SELECT `node` from `cluster_node` where type="irc_relay"'); if ($res !== false) { $d = mysqli_fetch_assoc($res); - self::$relayNode = $d['node']; + self::$ircRelayNode = $d['node']; return $d['node']; } - self::$relayNode = null; + self::$ircRelayNode = null; return null; } } diff --git a/feed_functions.php b/feed_functions.php index f749400..5b77f1f 100644 --- a/feed_functions.php +++ b/feed_functions.php @@ -154,6 +154,8 @@ public static function bail($change, $why = '', $score = 'N/A', $reverted = fals } $logger->addInfo($change['rawline'] . " # " . $score . - ' # ' . $why . ' # ' . ($reverted ? 'Reverted' : 'Not reverted')); + ' # ' . $why . ' # ' . ($reverted ? 'Reverted' : 'Not reverted')); + IRC::spam($change['rawline'] . "\003 # " . $score . ' # ' . $why . + ' # ' . ($reverted ? 'Reverted' : 'Not reverted')); } } diff --git a/irc_functions.php b/irc_functions.php index 834a532..874e420 100644 --- a/irc_functions.php +++ b/irc_functions.php @@ -104,4 +104,30 @@ public static function init() } self::$chans = $tmp; } + + public static function spam($message) + { + return self::message('#wikipedia-en-cbngfeed', $message); + } + + public static function revert($message) + { + return self::message('#wikipedia-en-cbngrevertfeed', $message); + } + + private static function message($channel, $message) + { + global $logger; + $relay_node = Db::getCurrentIrcRelayNode(); + if (!isset($relay_node)) { + $logger->addError("Could not get relay node. Failed to send: " . $message); + return; + } + $logger->addInfo('Saying to ' . $channel . ': ' . $message); + $udp = fsockopen('udp://' . $relay_node, Config::$udpport); + if ($udp !== false) { + fwrite($udp, $channel . ':' . $message); + fclose($udp); + } + } } diff --git a/process_functions.php b/process_functions.php index df5030d..0cf6fab 100644 --- a/process_functions.php +++ b/process_functions.php @@ -105,8 +105,8 @@ public static function processEditThread($change) } $oftVand[$change['title']][] = time(); file_put_contents('oftenvandalized.txt', serialize($oftVand)); - $ircreport = "[[" . $change['title'] . "]] by \"" . $change['user'] . - "\" (" . $change['url'] . " )" . $s . " ("; + $ircreport = "\x0315[[\x0307" . $change['title'] . "\x0315]] by \"\x0303" . $change['user'] . + "\x0315\" (\x0312 " . $change['url'] . " \x0315) \x0306" . $s . "\x0315 ("; $change['mysqlid'] = Db::detectedVandalism( $change['user'], $change['title'], @@ -123,9 +123,9 @@ public static function processEditThread($change) $rbret = Action::doRevert($change); if ($rbret !== false) { $change['edit_status'] = 'reverted'; - $logger->addInfo( - $ircreport . "Reverted) (" . $revertReason . - ") (" . (microtime(true) - $change['startTime']) . " s)" + IRC::revert( + $ircreport . "\x0304Reverted\x0315) (\x0313" . $revertReason . + "\x0315) (\x0302" . (microtime(true) - $change['startTime']) . " \x0315s)" ); Action::doWarn($change, $report); Db::vandalismReverted($change['mysqlid']); @@ -134,9 +134,9 @@ public static function processEditThread($change) $change['edit_status'] = 'beaten'; $rv2 = Api::$a->revisions($change['title'], 1); if ($change['user'] != $rv2[0]['user']) { - $logger->addInfo( - $ircreport . "Not Reverted) (Beaten by " . - $rv2[0]['user'] . ") (" . (microtime(true) - $change['startTime']) . " s)" + IRC::revert( + $ircreport . "\x0303Not Reverted\x0315) (\x0313Beaten by " . + $rv2[0]['user'] . "\x0315) (\x0302" . (microtime(true) - $change['startTime']) . " \x0315s)" ); Db::vandalismRevertBeaten($change['mysqlid'], $change['title'], $rv2[0]['user'], $change['url']); Feed::bail($change, 'Beaten by ' . $rv2[0]['user'], $s);