Example #1
0
function shorten_url($url, $mode = "title")
{
    if ($url == "") {
        return False;
    }
    $params = array();
    $params["url"] = $url;
    if ($mode != "") {
        $params["mode"] = $mode;
        # optional
    }
    $response = wpost("o.my.to", "/", "80", ICEWEASEL_UA, $params, "", 30);
    $short_url = trim(strip_headers($response));
    if ($short_url != "") {
        return $short_url;
    } else {
        return False;
    }
}
Example #2
0
function youtube_search($query)
{
    $agent = ICEWEASEL_UA;
    $host = "www.youtube.com";
    $uri = "/results";
    $port = 443;
    $params = array();
    $params["search_query"] = $query;
    $response = wpost($host, $uri, $port, $agent, $params);
    $html = strip_headers($response);
    strip_all_tag($html, "head");
    strip_all_tag($html, "script");
    strip_all_tag($html, "style");
    $delim1 = "class=\"item-section\">";
    $delim2 = "</ol>";
    $html = extract_text_nofalse($html, $delim1, $delim2);
    $results = explode("<li><div class=\"yt-lockup yt-lockup-tile yt-lockup-video vve-check clearfix yt-uix-tile\"", $html);
    array_shift($results);
    if (count($results) == 0) {
        return False;
    }
    for ($i = 0; $i < count($results); $i++) {
        $parts = explode(">", $results[$i]);
        array_shift($parts);
        $results[$i] = implode(">", $parts);
        $delim1 = "<h3 class=\"yt-lockup-title \">";
        $delim2 = "</h3>";
        $results[$i] = extract_text_nofalse($results[$i], $delim1, $delim2);
        $delim1 = "<a href=\"";
        $delim2 = "\" ";
        $url = "https://www.youtube.com" . extract_text_nofalse($results[$i], $delim1, $delim2);
        $delim1 = "dir=\"ltr\">";
        $delim2 = "</a>";
        $title = extract_text_nofalse($results[$i], $delim1, $delim2);
        $title = html_decode($title);
        $title = html_decode($title);
        $delim1 = "> - Duration: ";
        $delim2 = ".</span>";
        $time = extract_text_nofalse($results[$i], $delim1, $delim2);
        $results[$i] = $url . " - " . $title . " - " . $time;
    }
    return $results;
}
Example #3
0
function wiki_spamctl($nick, $trailing)
{
    $account = users_get_account($nick);
    $allowed = array("wikirc", "crutchy", "chromas", "mrcoolbp", "paulej72", "juggs", "martyb");
    if (in_array($account, $allowed) == False) {
        privmsg("  error: not authorized");
        return;
    }
    $title = trim(substr($trailing, strlen(".spamctl")));
    if ($title == "last") {
        $wikirc_last = get_bucket("last_wikirc_#wiki");
        $delim1 = chr(3) . "14[[" . chr(3) . "07";
        $delim2 = chr(3) . "14]]";
        $title = extract_text_nofalse($wikirc_last, $delim1, $delim2);
    }
    if ($title == "") {
        privmsg("  syntax: .spamctl <page title>");
        return;
    }
    if (strtolower(substr($title, 0, 4)) == "http") {
        # TODO: ACCEPT WIKI URLS
    }
    if ($nick == "wikirc") {
        $text = "{{spam}}<br>if this automated spam flag is wrong, please join #wiki @ http://chat.soylentnews.org/ and let us know";
    } else {
        $text = "{{spam}}<br>if this spam flag is wrong, please join #wiki @ http://chat.soylentnews.org/ and let us know";
    }
    if (login($nick, True) == False) {
        return;
    }
    $cookieprefix = get_bucket("wiki_login_cookieprefix");
    $sessionid = get_bucket("wiki_login_sessionid");
    if ($cookieprefix == "" or $sessionid == "") {
        privmsg("  not logged in");
        return;
    }
    $headers = array("Cookie" => login_cookie($cookieprefix, $sessionid));
    $uri = "/w/api.php?action=tokens&format=php";
    $response = wget(WIKI_HOST, $uri, 80, WIKI_USER_AGENT, $headers);
    $data = unserialize(strip_headers($response));
    if (isset($data["tokens"]["edittoken"]) == False) {
        privmsg("  error getting edittoken");
        logout(True);
        return;
    }
    $token = $data["tokens"]["edittoken"];
    $uri = "/w/api.php?action=edit";
    $params = array("format" => "php", "title" => $title, "text" => $text, "contentformat" => "text/x-wiki", "contentmodel" => "wikitext", "bot" => "", "token" => $token);
    $response = wpost(WIKI_HOST, $uri, 80, WIKI_USER_AGENT, $params, $headers);
    $data = unserialize(strip_headers($response));
    if (isset($data["error"]) == True) {
        privmsg("  error: " . $data["error"]["code"]);
    } else {
        $msg = $data["edit"]["result"];
        if ($data["edit"]["result"] == "Success") {
            if (isset($data["edit"]["oldrevid"]) == True and isset($data["edit"]["newrevid"]) == True) {
                $msg = $msg . ", oldrevid=" . $data["edit"]["oldrevid"] . ", newrevid=" . $data["edit"]["newrevid"];
            }
        }
        privmsg("  {$msg}");
        $title = str_replace(" ", "_", $title);
        privmsg("  http://wiki.soylentnews.org/wiki/" . urlencode($title));
    }
    logout(True);
}
Example #4
0
    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);
var_dump($html);
# TODO: extract success/error message and output to IRC
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");
} else {
    privmsg("error: something went wrong with your submission");
}
# TODO: testing... much more testing
Example #5
0
 $params["mode"] = "improvedthreaded";
 $params["startat"] = "";
 $params["threshold"] = "-1";
 $params["commentsort"] = "0";
 $params["formkey"] = $formkey;
 $params["postersubj"] = $subject;
 $params["postercomment"] = $comment;
 $params["nobonus_present"] = "1";
 #$params["nobonus"]="";
 $params["postanon_present"] = "1";
 #$params["postanon"]="";
 $params["posttype"] = "1";
 # Plain Old Text
 $params["op"] = "Submit";
 sleep(8);
 $response = wpost($host, $uri, $port, ICEWEASEL_UA, $params, $extra_headers);
 $delim = "start template: ID 104";
 if (strpos($response, $delim) !== False) {
     privmsg("SoylentNews requires you to wait between each successful posting of a comment to allow everyone a fair chance at posting.");
 }
 $delim = "start template: ID 274";
 if (strpos($response, $delim) !== False) {
     privmsg("This exact comment has already been posted. Try to be more original.");
 }
 $delim = "start template: ID 180";
 if (strpos($response, $delim) !== False) {
     privmsg("Comment submitted successfully. There will be a delay before the comment becomes part of the static page.");
 }
 #term_echo($response);
 sn_logout();
 return;
Example #6
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;
    }
}
Example #7
0
        for ($i = 0; $i < count($request_ids); $i++) {
            $id = $request_ids[$i];
            $request_params = array();
            $request_params["exec_key"] = $key;
            $response = wpost("irciv.us.to", "/?exec&request_id={$id}", 80, "", $request_params);
            $content = trim(strip_headers($response));
            var_dump($content);
            if (strpos(strtoupper($content), "ERROR") !== False) {
                output_message($content);
            } elseif ($content != "") {
                $content = unserialize($content);
                output_message($content["request_uri"]);
                $data = get_bucket($content["data"]);
                $response_params = array();
                $response_params["exec_key"] = $key;
                $response_params["request_id"] = $id;
                $response_params["data"] = $data;
                $response = wpost("irciv.us.to", "/?exec", 80, "", $response_params);
                $content = trim(strip_headers($response));
                output_message($content);
            }
        }
    }
    sleep(10);
}
#####################################################################################################
function output_message($msg)
{
    privmsg($msg);
}
#####################################################################################################
Example #8
0
        $repo = "rehash";
    } else {
        $username = "******";
        $repo = "exec-irc-bot";
    }
    $uri = "/repos/{$username}/{$repo}/issues";
    $tok = trim(file_get_contents("../pwd/gh_tok"));
    $headers = array();
    $headers["Authorization"] = "token {$tok}";
    $headers["Content-Type"] = "application/json";
    $headers["Accept"] = "application/vnd.github.v3+json";
    $params = array();
    $params["title"] = $title;
    $params["body"] = $body . "\n\nsubmitted by exec on behalf of {$nick} from {$dest} @ irc.sylnt.us";
    $json = json_encode($params, JSON_PRETTY_PRINT);
    $response = wpost($host, $uri, $port, ICEWEASEL_UA, $json, $headers, 60, True, False);
    $content = strip_headers($response);
    $data = json_decode($content, True);
    if (isset($data["html_url"]) == True) {
        privmsg($data["html_url"]);
    } else {
        privmsg("there was an error submitting the issue");
    }
    return;
}
$list = exec_file_read("github_feed_repos");
sort($list, SORT_STRING);
if ($alias == "~epoch-feed") {
    $list = array("Subsentient/epoch");
    define("FEED_CHAN", "#epoch");
} else {