Exemplo n.º 1
0
function set_fs()
{
    global $fs;
    if ($fs["modified"] == False) {
        return;
    }
    $fs["modified"] = False;
    set_array_bucket($fs, BUCKET_FS, True);
    echo "/IRC :" . get_bot_nick() . " INTERNAL :~execfs sync\n";
}
Exemplo n.º 2
0
function register_all_events($alias, $privmsg = False)
{
    register_event_handler("JOIN", ":" . get_bot_nick() . " INTERNAL :{$alias} event-join %%nick%% %%params%%");
    register_event_handler("KICK", ":" . get_bot_nick() . " INTERNAL :{$alias} event-kick %%params%%");
    register_event_handler("NICK", ":" . get_bot_nick() . " INTERNAL :{$alias} event-nick %%nick%% %%trailing%%");
    register_event_handler("PART", ":" . get_bot_nick() . " INTERNAL :{$alias} event-part %%nick%% %%params%%");
    register_event_handler("QUIT", ":" . get_bot_nick() . " INTERNAL :{$alias} event-quit %%nick%%");
    if ($privmsg == True) {
        register_event_handler("PRIVMSG", ":" . get_bot_nick() . " INTERNAL :{$alias} event-privmsg %%nick%% %%dest%% %%trailing%%");
    }
}
Exemplo n.º 3
0
} */
$host = "soylentnews.org";
$port = 443;
$uri = "/submit.pl";
$response = wget($host, $uri, $port, ICEWEASEL_UA);
$html = strip_headers($response);
$reskey = extract_text($html, "<input type=\"hidden\" id=\"reskey\" name=\"reskey\" value=\"", "\">");
if ($reskey === False) {
    privmsg("error: unable to extract reskey");
    return;
}
sleep(25);
$params = array();
$params["reskey"] = $reskey;
#$params["name"]=trim(substr($nick,0,50));
$params["name"] = get_bot_nick();
$params["email"] = "";
$params["subj"] = trim(substr($source_title, 0, 100));
$params["primaryskid"] = "1";
$params["tid"] = "6";
$params["sub_type"] = "plain";
$params["story"] = $source_body . "\n\n" . $url . "\n\n-- submitted from IRC";
$params["op"] = "SubmitStory";
$response = wpost($host, $uri, $port, ICEWEASEL_UA, $params);
$html = strip_headers($response);
strip_all_tag($html, "head");
strip_all_tag($html, "script");
strip_all_tag($html, "style");
strip_all_tag($html, "a");
$html = strip_tags($html);
$html = clean_text($html);
Exemplo n.º 4
0
- the bot could keeep track of irc comments and if you type something like
  "~comment Bytram, i think you're right" the bot could tack it to the end of Bytram's last comment posting
- if two people are having an irc discussion about tfa, and they are triggering comment posting,
  the bot would prolly just treat it like they were replying to each other's comments
- if they wanted to start a new thread it might need some kind of separate trigger
*/
#####################################################################################################
require_once "sn_lib.php";
$trailing = $argv[1];
$dest = $argv[2];
$nick = $argv[3];
$alias = $argv[4];
define("BUCKET_VERIFIER_NICK", "<<verifier_nick>>");
switch ($alias) {
    case "~sn-internal":
        register_event_handler("NICK", ":" . get_bot_nick() . " INTERNAL :~verifier-nick-change %%nick%% %%trailing%%");
        return;
    case "~uid":
        $host = "www.soylentnews.org";
        $port = 443;
        $uri = "/zoo.pl?op=max";
        $response = wget($host, $uri, $port, ICEWEASEL_UA);
        $delim1 = "<p class='bender'>";
        $delim2 = "</p>";
        $uid = extract_text($response, $delim1, $delim2);
        if ($uid !== False) {
            privmsg($uid);
        } else {
            var_dump($response);
            privmsg(" uid: an error occurred");
        }
Exemplo n.º 5
0
function authenticate($items)
{
    global $exec_list;
    global $admin_data;
    global $admin_is_sock;
    global $admin_accounts;
    global $admin_aliases;
    global $operator_aliases;
    term_echo("detected cmd 330: {$admin_data}");
    $parts = explode(" ", $items["params"]);
    if ($admin_data != "") {
        if (count($parts) == 3 and $parts[0] == get_bot_nick()) {
            $nick = $parts[1];
            $account = $parts[2];
            $admin_items = parse_data($admin_data);
            $args = explode(" ", $admin_items["trailing"]);
            $alias = $args[0];
            if ($admin_items["nick"] == $nick) {
                if (is_operator_alias($alias) == True) {
                    if ($account != OPERATOR_ACCOUNT) {
                        term_echo("authentication failure: \"{$account}\" attempted to run \"{$alias}\" but is not authorized");
                    } else {
                        $tmp_data = $admin_data;
                        $tmp_is_sock = $admin_is_sock;
                        $admin_data = "";
                        $admin_is_sock = "";
                        handle_data($tmp_data, $tmp_is_sock, True);
                        return;
                    }
                } elseif (in_array($alias, $admin_aliases) == True) {
                    if ($account != OPERATOR_ACCOUNT and in_array($account, $admin_accounts) == False) {
                        term_echo("authentication failure: \"{$account}\" attempted to run \"{$alias}\" but is not authorized");
                    } else {
                        $tmp_data = $admin_data;
                        $tmp_is_sock = $admin_is_sock;
                        $admin_data = "";
                        $admin_is_sock = "";
                        handle_data($tmp_data, $tmp_is_sock, True);
                        return;
                    }
                } elseif (has_account_list($alias) == True) {
                    if ($account != OPERATOR_ACCOUNT and in_array($account, $exec_list[$alias]["accounts"]) == False and $exec_list[$alias]["accounts_wildcard"] != "*" and in_array($account, $admin_accounts) == False) {
                        term_echo("authentication failure: \"{$account}\" attempted to run \"{$alias}\" but is not authorized");
                    } else {
                        $tmp_data = $admin_data;
                        $tmp_is_sock = $admin_is_sock;
                        $admin_data = "";
                        $admin_is_sock = "";
                        handle_data($tmp_data, $tmp_is_sock, True);
                        return;
                    }
                }
            }
        }
    }
    $admin_data = "";
    $admin_is_sock = "";
}
Exemplo n.º 6
0
array_shift($parts);
array_shift($parts);
$trailing = trim(implode(" ", $parts));
return;
define("PREVIOUS_MSG_TRACK", 5);
if (get_bucket("<<IRC_CONNECTION_ESTABLISHED>>") != "1") {
    return;
}
$items = unserialize($argv[1]);
$nick = $items["nick"];
if (users_get_account($nick) == get_bot_nick()) {
    return;
}
$trailing = $items["trailing"];
$dest = strtolower($items["destination"]);
$exec = users_get_data(get_bot_nick());
if (isset($exec["channels"][$dest]) == True) {
    if (strpos($exec["channels"][$dest], "@") === False) {
        return;
    }
} else {
    return;
}
$user = users_get_data($nick);
if (isset($user["channels"][$dest]) == False) {
    return;
}
var_dump($items);
return;
$timestamp = $items["time"];
$index = "ANTISPAM_DATA_" . $dest . "_" . $nick;
Exemplo n.º 7
0
function handle_switch($alias, $dest, $nick, $trailing, $channels_bucket, $switch_alias, $internal_alias, &$msg)
{
    $channels = get_bucket($channels_bucket);
    if ($channels != "") {
        $channels = unserialize($channels);
        if ($channels === False) {
            $channels = array();
            save_channels($channels, $channels_bucket);
        }
    } else {
        $channels = array();
        save_channels($channels, $channels_bucket);
    }
    if ($alias == $switch_alias) {
        switch (strtolower($trailing)) {
            case "on":
                if (in_array($dest, $channels) == False) {
                    $channels[] = $dest;
                    save_channels($channels, $channels_bucket);
                    return 1;
                } else {
                    return 2;
                }
                break;
            case "off":
                if (channel_off($channels, $dest, $channels_bucket) == True) {
                    return 3;
                } else {
                    return 4;
                }
                break;
            default:
                return 11;
        }
    } elseif ($alias == $internal_alias) {
        $parts = explode(" ", $trailing);
        $command = strtolower($parts[0]);
        array_shift($parts);
        $msg = implode(" ", $parts);
        switch ($command) {
            case "kick":
                if (count($parts) == 2) {
                    if ($parts[1] == get_bot_nick()) {
                        channel_off($channels, $parts[0], $channels_bucket);
                        return 5;
                    }
                }
                break;
            case "part":
                if ($nick == get_bot_nick()) {
                    channel_off($channels, $msg, $channels_bucket);
                    return 6;
                }
                break;
            case "privmsg":
                if (in_array($dest, $channels) == True and $nick != get_bot_nick()) {
                    return 7;
                }
                return 8;
            case "join":
                if (in_array($dest, $channels) == True and $nick != get_bot_nick()) {
                    return 9;
                }
                return 10;
        }
    }
    return 0;
}
Exemplo n.º 8
0
function sn_submit($url)
{
    if ($url == "") {
        return False;
    }
    $url = get_redirected_url($url);
    if ($url === False) {
        privmsg("error: unable to download source (get_redirected_url)");
        return False;
    }
    $host = "";
    $uri = "";
    $port = 80;
    if (get_host_and_uri($url, $host, $uri, $port) == False) {
        privmsg("error: unable to download source (get_host_and_uri)");
        return False;
    }
    $response = wget($host, $uri, $port);
    if (get_host_and_uri($url, $host, $uri, $port) == False) {
        privmsg("error: unable to download source (wget)");
        return False;
    }
    $source_html = strip_headers($response);
    $source_title = extract_raw_tag($source_html, "title");
    $delimiters = array("--", "|", " - ", " : ", " — ", " • ");
    for ($i = 0; $i < count($delimiters); $i++) {
        $j = strpos($source_title, $delimiters[$i]);
        if ($j !== False) {
            $source_title = trim(substr($source_title, 0, $j));
        }
    }
    if ($source_title === False or $source_title == "") {
        privmsg("error: title not found or empty");
        return False;
    }
    $source_title = html_decode($source_title);
    $source_title = html_decode($source_title);
    $source_body = extract_meta_content($source_html, "description");
    if ($source_body === False or $source_body == "") {
        $source_body = extract_meta_content($source_html, "og:description", "property");
        if ($source_body === False or $source_body == "") {
            privmsg("error: description meta content not found or empty");
            return False;
        }
    }
    $html = $source_html;
    $article = extract_raw_tag($html, "article");
    if ($article !== False) {
        $html = $article;
    }
    strip_all_tag($html, "head");
    strip_all_tag($html, "script");
    strip_all_tag($html, "style");
    #strip_all_tag($html,"a");
    strip_all_tag($html, "strong");
    $html = strip_tags($html, "<p>");
    $html = lowercase_tags($html);
    $html = explode("<p", $html);
    $source_body = array();
    for ($i = 0; $i < count($html); $i++) {
        $parts = explode(">", $html[$i]);
        if (count($parts) >= 2) {
            array_shift($parts);
            $html[$i] = implode(">", $parts);
        }
        $html[$i] = strip_tags($html[$i]);
        $html[$i] = clean_text($html[$i]);
        $host_parts = explode(".", $host);
        for ($j = 0; $j < count($host_parts); $j++) {
            if (strlen($host_parts[$j]) > 3) {
                if (strpos(strtolower($html[$i]), strtolower($host_parts[$j])) !== False) {
                    continue 2;
                }
            }
        }
        if (filter($html[$i], "0123456789") != "") {
            continue;
        }
        if (strlen($html[$i]) > 1) {
            if ($html[$i][strlen($html[$i]) - 1] != ".") {
                continue;
            }
            while (True) {
                $j = strlen($html[$i]) - 1;
                if ($j < 0) {
                    break;
                }
                $c = $html[$i][$j];
                if ($c == ".") {
                    break;
                }
                $html[$i] = substr($html[$i], 0, $j);
            }
        }
        if (strlen($html[$i]) > 100) {
            $source_body[] = $html[$i];
        }
    }
    $source_body = implode("\n\n", $source_body);
    $source_body = html_decode($source_body);
    $source_body = html_decode($source_body);
    $host = "dev.soylentnews.org";
    $port = 443;
    $uri = "/submit.pl";
    $response = wget($host, $uri, $port, ICEWEASEL_UA);
    $html = strip_headers($response);
    $reskey = extract_text($html, "<input type=\"hidden\" id=\"reskey\" name=\"reskey\" value=\"", "\">");
    if ($reskey === False) {
        privmsg("error: unable to extract reskey");
        return False;
    }
    sleep(25);
    $params = array();
    $params["reskey"] = $reskey;
    #$params["name"]=trim(substr($nick,0,50));
    $params["name"] = get_bot_nick();
    $params["email"] = "";
    $params["subj"] = trim(substr($source_title, 0, 100));
    $params["primaryskid"] = "1";
    $params["tid"] = "6";
    $params["sub_type"] = "plain";
    $params["story"] = $source_body . "\n\n" . $url . "\n\n-- submitted from IRC";
    $params["op"] = "SubmitStory";
    $response = wpost($host, $uri, $port, ICEWEASEL_UA, $params);
    $html = strip_headers($response);
    strip_all_tag($html, "head");
    strip_all_tag($html, "script");
    strip_all_tag($html, "style");
    strip_all_tag($html, "a");
    $html = strip_tags($html);
    $html = clean_text($html);
    if (strpos($html, "Perhaps you would like to enter an email address or a URL next time. Thanks for the submission.") !== False) {
        privmsg("submission successful - https://{$host}/submit.pl?op=list");
        return True;
    } else {
        privmsg("error: something went wrong with your submission");
        return False;
    }
}
Exemplo n.º 9
0
        }
        break;
    case "~invite":
        if ($trailing != "") {
            rawmsg("INVITE {$trailing} :{$dest}");
        }
        break;
        /*case ".kick":
          if (($target==$nick) and ($target<>get_bot_nick()))
          {
            rawmsg("KICK $dest $target :$nick kicked self");
          }
          break;*/
    /*case ".kick":
      if (($target==$nick) and ($target<>get_bot_nick()))
      {
        rawmsg("KICK $dest $target :$nick kicked self");
      }
      break;*/
    case "~kick":
        if ($target != $nick and $target != get_bot_nick()) {
            rawmsg("KICK {$dest} {$target} :commanded by {$nick}");
        }
        break;
    case "~topic":
        if ($trailing != "") {
            rawmsg("TOPIC {$dest} :{$trailing}");
        }
        break;
}
#####################################################################################################
Exemplo n.º 10
0
     register_event_handler("PRIVMSG", ":" . get_bot_nick() . " INTERNAL :~x event-privmsg %%nick%% %%dest%% %%trailing%%");
     break;
 case "event-privmsg":
     # trailing = crutchy # test
     if ($global_execute != "enabled") {
         return;
     }
     $parts = explode(" ", $trailing);
     if (count($parts) > 2) {
         $nick = $parts[0];
         $dest = $parts[1];
         array_shift($parts);
         array_shift($parts);
         $trailing = trim(implode(" ", $parts));
     }
     if ($dest == get_bot_nick()) {
         return;
     }
     foreach ($scripts as $script_name => $data) {
         if (isset($data["enabled"]) == False) {
             continue;
         }
         if ($data["enabled"] != True) {
             continue;
         }
         $code = trim(base64_decode($data["code"]));
         if ($code == "") {
             continue;
         }
         $code = implode(" ", explode("\n", $code));
         term_echo("*** LIVE SCRIPT: " . $code);
Exemplo n.º 11
0
function privmsg($destination, $nick, $msg)
{
    global $dest_overrides;
    if ($destination == "") {
        term_echo("PRIVMSG: DESTINATION NOT SPECIFIED: nick=\"{$nick}\", msg=\"{$msg}\"");
        return;
    }
    if ($msg == "") {
        term_echo("PRIVMSG: NO TEXT TO SEND: nick=\"{$nick}\", destination=\"{$destination}\"");
        return;
    }
    $msg = substr($msg, 0, MAX_MSG_LENGTH);
    if (isset($dest_overrides[$nick][$destination]) == True) {
        $data = ":" . get_bot_nick() . " PRIVMSG " . $dest_overrides[$nick][$destination] . " :{$msg}";
        rawmsg($data);
    } else {
        if (substr($destination, 0, 1) == "#") {
            $data = ":" . get_bot_nick() . " PRIVMSG {$destination} :{$msg}";
            rawmsg($data);
        } else {
            $data = ":" . get_bot_nick() . " PRIVMSG {$nick} :{$msg}";
            rawmsg($data);
        }
    }
}
Exemplo n.º 12
0
function handle_macros($nick, $channel, $trailing)
{
    $reserved_triggers = array(".macro", ".macro-list");
    $reserved_commands = array("~restart-internal", "~q", "~ps", "~kill", "~killall", "~restart", "~rehash", "~dest-override", "~dest-clear", "~ignore", "~unignore", "~ignore-list", "~buckets-dump", "~eval", "~say", "~bucket", "~buckets-save", "~buckets-load", "~buckets-flush", "~buckets-list", "~exec-conflicts", "~exec-list", "~exec-timers", "~exec-errors", "~op", "~deop", "~voice", "~devoice", "~invite", "~kick", "~topic", "~exec-add", "~exec-del", "~exec-save", "<init>", "<quit>", "<startup>");
    $allowed = array("crutchy", "chromas", "TheMightyBuzzard", "Bytram", "arti", "paulej72", "mrcoolbp", "juggs");
    if ($nick == "" or $channel == "" or $trailing == "") {
        return;
    }
    if ($trailing == ".macro") {
        pm($channel, chr(3) . "02" . "  syntax to add: .macro <trigger> <chanlist> PRIVMSG|INTERNAL <command_template>");
        pm($channel, chr(3) . "02" . "  syntax to delete: .macro <trigger> -");
        #pm($channel,chr(3)."02"."  <chanlist> is comma-separated or * for any");
    }
    $macro_file = DATA_PATH . "exec_macros.txt";
    $macros = load_settings($macro_file, "=");
    if ($macros !== False and $trailing == ".macro-list") {
        foreach ($macros as $trigger => $data) {
            $data = unserialize($data);
            $cmd = "INTERNAL";
            if (isset($data["cmd"]) == True) {
                $cmd = $data["cmd"];
            }
            pm($channel, chr(3) . "13" . "  {$trigger} [" . $data["chanlist"] . "] {$cmd} " . $data["command"]);
        }
    }
    if ($macros === False) {
        $macros = array();
    }
    $parts = explode(" ", $trailing);
    delete_empty_elements($parts);
    if (count($parts) == 0) {
        return;
    }
    if (trim($parts[0]) == ".macro" and count($parts) > 2) {
        $account = users_get_account($nick);
        if (in_array($account, $allowed) == False) {
            return;
        }
        $trigger = trim($parts[1]);
        if (in_array($trigger, $reserved_triggers) == True) {
            privmsg(chr(3) . "02" . "  *** macro with trigger \"{$trigger}\" not permitted");
            return;
        }
        if (in_array($trigger, $reserved_commands) == True) {
            privmsg(chr(3) . "02" . "  *** macro with trigger \"{$trigger}\" not permitted");
            return;
        }
        $exec_list = unserialize(base64_decode(trim(get_bucket("<<EXEC_LIST>>"))));
        if (isset($exec_list[$trigger]) == True) {
            privmsg(chr(3) . "02" . "  *** error: macro with trigger that is the same as existing alias is not permitted");
            return;
        }
        $chanlist = trim($parts[2]);
        if ($chanlist == "-") {
            unset($macros[$trigger]);
            privmsg(chr(3) . "02" . "  *** macro with trigger \"{$trigger}\" deleted");
        } elseif (count($parts) >= 5) {
            array_shift($parts);
            array_shift($parts);
            array_shift($parts);
            $cmd = strtoupper(trim($parts[0]));
            if ($cmd != "PRIVMSG" and $cmd != "INTERNAL") {
                privmsg(chr(3) . "02" . "  *** error: invalid cmd (must be either INTERNAL or PRIVMSG)");
                return;
            }
            array_shift($parts);
            if (isset($macros[$parts[0]]) == True) {
                privmsg(chr(3) . "02" . "  *** error: triggering other macros is not permitted");
                return;
            }
            $command = implode(" ", $parts);
            for ($i = 0; $i < count($reserved_commands); $i++) {
                if (strtolower(substr($command, 0, strlen($reserved_commands[$i]))) == strtolower($reserved_commands[$i])) {
                    privmsg(chr(3) . "02" . "  *** macro with command \"{$command}\" not permitted");
                    return;
                }
            }
            $data = array();
            $data["chanlist"] = $chanlist;
            $data["command"] = $command;
            $data["cmd"] = $cmd;
            $macros[$trigger] = serialize($data);
            privmsg(chr(3) . "02" . "  *** macro with trigger \"{$trigger}\" and {$cmd} command template \"{$command}\" saved");
        }
        save_settings($macros, $macro_file, "=");
    } else {
        foreach ($macros as $trigger => $data) {
            if (trim($parts[0]) == $trigger) {
                $data = unserialize($data);
                if ($data["chanlist"] == "*" or in_array(strtolower($channel), explode(",", strtolower($data["chanlist"]))) == True) {
                    $account = users_get_account($nick);
                    if ($account != "") {
                        $cmd = "INTERNAL";
                        if (isset($data["cmd"]) == True) {
                            $cmd = $data["cmd"];
                        }
                        $trailing = trim(substr($trailing, strlen($trigger)));
                        # TODO: MAKE MORE TRAILING PARSING REPLACE ARGS
                        $command = str_replace("%%channel%%", $channel, $data["command"]);
                        $command = str_replace("%%nick%%", $nick, $command);
                        $command = str_replace("%%trailing%%", $trailing, $command);
                        echo "/IRC :" . get_bot_nick() . " {$cmd} {$channel} :{$command}\n";
                    }
                }
                return;
            }
        }
    }
}
Exemplo n.º 13
0
exec:~title|60|0|0|0|||||php scripts/title.php %%trailing%% %%alias%% %%dest%% %%nick%%
exec:~sizeof|60|0|0|0|*||#journals,#test,#Soylent,#,#exec,#dev||php scripts/title.php %%trailing%% %%alias%% %%dest%% %%nick%%
init:~title-internal register-events
*/
#####################################################################################################
# TODO: PICK UP ON www. LINKS THAT OMIT A SCHEME PREFIX (ASSUME HTTP)
# TODO: META HTTP-EQUIV=REFRESH URL REDIRECTS
ini_set("display_errors", "on");
require_once "lib.php";
require_once "title_lib.php";
require_once "translate_lib.php";
$trailing = trim($argv[1]);
$alias = trim($argv[2]);
$dest = $argv[3];
$nick = $argv[4];
if ($nick == get_bot_nick() and $alias != "~title-internal" and $trailing != "register-events") {
    return;
}
$bucket = get_bucket("<exec_title_{$dest}>");
if ($alias == "~title-internal") {
    $parts = explode(" ", $trailing);
    $action = strtolower($parts[0]);
    array_shift($parts);
    switch ($action) {
        case "register-events":
            register_event_handler("PRIVMSG", ":%%nick%% INTERNAL %%dest%% :~title-internal event-privmsg %%nick%% %%dest%% %%trailing%%");
            return;
        case "event-privmsg":
            # trailing = <nick> <channel> <trailing>
            $nick = strtolower($parts[0]);
            $channel = strtolower($parts[1]);
Exemplo n.º 14
0
function users_broadcast($msg)
{
    $channels = users_get_channels(get_bot_nick());
    for ($i = 0; $i < count($channels); $i++) {
        pm($channels[$i], chr(3) . "13" . $msg);
    }
}