Esempio n. 1
0
function output($record, $msg, $show_filter = True)
{
    global $filters;
    pm(MAIN_FEED_CHANNEL, $msg);
    if ($record === False) {
        return;
    }
    foreach ($filters as $id => $filter) {
        # $filter["id"]
        # $filter["target"]
        # $filter["field"]
        # $filter["pattern"]
        # %id% = unique name to identify filter
        # %target% = channel or nick to send filtered comments to
        # %field% = user|uid|score|score_num|subject|title|comment_body
        # %pattern% = regexp pattern for use with preg_match
        # $record["user"]
        # $record["uid"]
        # $record["score"]
        # $record["score_num"]
        # $record["subject"]
        # $record["title"]
        # $record["comment_body"]
        if (isset($filter["cid"]) == True) {
            $filter_cid = trim($filter["cid"]);
            $parent_cid = trim($record["cid"]);
            do {
                $params = array("cid" => $parent_cid);
                $result = fetch_prepare("SELECT * FROM exec_irc_bot.sn_comments WHERE (cid=:cid)", $params);
                if (count($result) != 1) {
                    break;
                }
                $parent_cid = trim($result[0]["parent_cid"]);
                if ($parent_cid == $filter_cid) {
                    if ($show_filter == True) {
                        $msg = "[" . $filter["id"] . "] " . $msg;
                    }
                    pm($filter["target"], $msg);
                    return;
                }
            } while ($parent_cid != "");
        } else {
            if (isset($record[$filter["field"]]) == False) {
                return;
            }
            if ($record[$filter["field"]] == $filter["pattern"]) {
                if ($show_filter == True) {
                    $msg = "[" . $filter["id"] . "] " . $msg;
                }
                pm($filter["target"], $msg);
                return;
            } elseif (preg_match("#" . trim($filter["pattern"]) . "#", $record[$filter["field"]]) == 1) {
                if ($show_filter == True) {
                    $msg = "[" . $filter["id"] . "] " . $msg;
                }
                pm($filter["target"], $msg);
                return;
            }
        }
    }
}
Esempio n. 2
0
<?php

#####################################################################################################
/*
exec:~seen|10|0|0|1|||||php scripts/seen.php %%items%% %%trailing%%
*/
#####################################################################################################
require_once "lib.php";
require_once "lib_mysql.php";
$items = unserialize(base64_decode($argv[1]));
$trailing = trim($argv[2]);
$params = array("nick" => $trailing, "dest" => $items["destination"], "serv" => $items["server"]);
$sql = "SELECT * FROM " . BOT_SCHEMA . "." . LOG_TABLE . " WHERE ((`cmd`=\"PRIVMSG\") AND (`nick`=:nick) AND (`destination`=:dest) AND (`server`=:serv)) ORDER BY id DESC LIMIT 1";
$records = fetch_prepare($sql, $params);
if (count($records) == 0) {
    privmsg(chr(3) . $items["nick"] . ", {$trailing} not seen in " . $items["destination"]);
} else {
    $delta = microtime(True) - $records[0]["microtime"];
    if ($delta <= 0.5) {
        privmsg(chr(3) . $items["nick"] . ", {$trailing} was last seen in " . $items["destination"] . " just now with message: " . $records[0]["trailing"]);
    } else {
        $delta_d = floor($delta / (24 * 60 * 60));
        if ($delta_d > 0) {
            if ($delta_d > 1) {
                $delta_d = "{$delta_d} days";
            } else {
                $delta_d = "{$delta_d} day";
            }
        } else {
            $delta_d = "";
        }
Esempio n. 3
0
$trailing = trim($argv[1]);
$dest = $argv[2];
$nick = $argv[3];
$alias = $argv[4];
$parts = explode(" ", $trailing);
$action = strtolower($parts[0]);
array_shift($parts);
$trailing = trim(implode(" ", $parts));
switch ($action) {
    case "count":
        $records = fetch_query("SELECT COUNT(*) FROM " . BOT_SCHEMA . "." . LOG_TABLE);
        privmsg($records[0]["COUNT(*)"]);
        break;
    case "last":
        $params = array("destination" => $dest);
        $records = fetch_prepare("SELECT * FROM " . BOT_SCHEMA . "." . LOG_TABLE . " WHERE ((cmd='PRIVMSG') and (destination=:destination)) ORDER BY id DESC LIMIT 1", $params);
        privmsg($records[0]["data"]);
        break;
    case "query":
        # ~sql query select comment_body from exec_irc_bot.sn_comments where (comment_body like '%fart%') order by rand() limit 1
        $records = fetch_query($trailing);
        $error = get_last_error();
        if ($error != "") {
            privmsg($error);
            return;
        }
        for ($i = 0; $i < min(3, count($records)); $i++) {
            if (is_array($records[$i]) == True) {
                privmsg(implode("|", $records[$i]));
            } else {
                privmsg($records[$i]);