Skip to content

Commit

Permalink
Merge pull request #1 from cluebotng/add-simple-relay
Browse files Browse the repository at this point in the history
Add UDP relay support
  • Loading branch information
DamianZaremba authored Jul 24, 2021
2 parents e385a62 + f214e7f commit b4fb824
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 deletions.
1 change: 1 addition & 0 deletions cluebot-ng.config.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions db_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
4 changes: 3 additions & 1 deletion feed_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
26 changes: 26 additions & 0 deletions irc_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
16 changes: 8 additions & 8 deletions process_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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']);
Expand All @@ -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);
Expand Down

0 comments on commit b4fb824

Please sign in to comment.