--- --- --- --- --- --- --- Entire Story Below --- --- --- --- --- --- --- 
".PHP_EOL;
if (file_exists($stories_path)==False)
{
  if (file_exists($stories_path_filename)==False)
  {
    privmsg("stories path not found, and stories path filename file not found: \"$stories_path_filename\"");
    return;
  }
  $stories_path_test=file_get_contents($stories_path_filename);
  if ($stories_path_test===False)
  {
    privmsg("error reading stories path file: \"$stories_path_filename\"");
    return;
  }
  $stories_path_test=trim($stories_path_test);
  $stories_path_test=rtrim($stories_path_test,"/");
  if (file_exists($stories_path_test)==False)
  {
    privmsg("stories path not found: \"$stories_path_test\"");
    return;
  }
  if (is_dir($stories_path_test)==False)
  {
    privmsg("stories path isn't a directory: \"$stories_path_test\"");
    return;
  }
  $stories_path=$stories_path_test."/";
}
if (file_exists($stories_path)==False)
{
  privmsg("stories path not found: \"$stories_path\"");
  return;
}
$keep_days=3;
if (in_array(strtolower($nick),$allowed)==True)
{
  if ($trailing=="list")
  {
    refresh_list();
    privmsg("http://wiki.soylentnews.org/wiki/Storybot");
    return;
  }
  if ($cmd<>"INTERNAL")
  {
    $last=get_bucket("<>");
    $d=microtime(True)-$last;
    if ($d<60)
    {
      privmsg("it has been only ".round($d)." seconds since the last submission - please wait");
      return;
    }
    submit_story($trailing);
    return;
  }
}
$bot_nick=get_bot_nick();
if (($bot_nick<>"exec") and ($bot_nick<>"x"))
{
  return;
}
delete_old();
refresh_list();
pm("#exec","http://wiki.soylentnews.org/wiki/Storybot has been updated");
pm("#crutchy","http://wiki.soylentnews.org/wiki/Storybot has been updated");
#####################################################################################################
function url_exists(&$story_list,$url)
{
  $result=False;
  for ($i=0;$i0))
    {
      privmsg("processing files... $i");
    }*/
    $filename=$file_list[$i];
    if (($filename==".") or ($filename==".."))
    {
      continue;
    }
    $fn=$stories_path.$filename;
    $content=file_get_contents($fn);
    if ($content===False)
    {
      continue;
    }
    $url=extract_text($content,"Original URL: ");
    $title=extract_text($content,"Title: ","
");
    if (($url===False) or ($title===False))
    {
      continue;
    }
    if (url_exists($story_list,$url)==True)
    {
      continue;
    }
    $title=clean_title($title);
    $parts=explode($blockquote_delim,$content);
    if (count($parts)<>2)
    {
      continue;
    }
    $summary=$parts[1];
    $record=array();
    $record["filename"]=$filename;
    $record["full_filename"]=$fn;
    $record["url"]=$url;
    $record["title"]=clean_text($title);
    $record["summary"]=clean_text($summary);
    $record["raw_content"]=clean_text($content);
    $record["submit_content"]=$parts[0].$blockquote_delim."".$parts[1]."
".PHP_EOL.PHP_EOL."-- submitted from IRC";
    $story_list[]=$record;
  }
  #privmsg(count($story_list)." stories loaded");
  $id_len=6;
  do
  {
    $ids=array();
    for ($i=0;$icount(array_unique($ids)));
  for ($i=0;$iTO SUBMIT ONE OF THESE STORIES, TYPE \"~submit-story #\" IN SOYLENTNEWS IRC, WHERE # IS THE ID FROM THE LIST BELOW.".PHP_EOL;
  $text=$text."{| class=\"wikitable\"".PHP_EOL;
  $text=$text."|-".PHP_EOL;
  $text=$text."! link !! id !! title".PHP_EOL;
  for ($i=0;$ithis page was autogenerated at ".date("H:i:s, j F Y")."by [[IRC:exec|exec]] irc bot. please don't manually edit this page".PHP_EOL;
  $title="Storybot";
  $summary="scheduled page rewrite by exec bot";
  $wiki_result=sn_wiki_rewrite_page($title,$text,$summary);
  if (is_array($wiki_result)==True)
  {
    var_dump($wiki_result);
    for ($i=0;$i($keep_days*24*60*60))
    {
      if (@unlink($filename)===False)
      {
        term_echo("storybot: ERROR DELETING OLD FILE \"".$filename."\"");
      }
      else
      {
        term_echo("storybot: deleted old file \"".$filename."\"");
      }
    }
  }
}
#####################################################################################################
function clean_title($title)
{
  $title=str_replace("_"," ",$title);
  $i=strpos($title,"--");
  if ($i!==False)
  {
    $title=trim(substr($title,0,$i));
  }
  $i=strpos($title,"|");
  if ($i!==False)
  {
    $title=trim(substr($title,0,$i));
  }
  $i=strpos($title," - ");
  if ($i!==False)
  {
    $title=trim(substr($title,0,$i));
  }
  $i=strpos($title," : ");
  if ($i!==False)
  {
    $title=trim(substr($title,0,$i));
  }
  $i=strpos($title," — ");
  if ($i!==False)
  {
    $title=trim(substr($title,0,$i));
  }
  $i=strpos($title," • ");
  if ($i!==False)
  {
    $title=trim(substr($title,0,$i));
  }
  return $title;
}
#####################################################################################################
function submit_story($id)
{
  global $submit_host;
  $story_list=build_story_list();
  $index=False;
  for ($i=0;$i");
  if ($reskey===False)
  {
    privmsg("error: unable to extract reskey");
    return;
  }
  sleep(30);
  $params=array();
  $params["reskey"]=$reskey;
  $params["name"]=get_bot_nick();
  $params["email"]="";
  $params["subj"]=trim(substr($submit_story["title"],0,100));
  $params["primaryskid"]="1";
  $params["tid"]="6";
  $params["sub_type"]="plain";
  $params["story"]=$submit_story["submit_content"];
  $params["op"]="SubmitStory";
  $response=wpost($submit_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);
  if (strpos($html,"Perhaps you would like to enter an email address or a URL next time.")!==False)
  {
    privmsg("submission successful - https://$submit_host/submit.pl?op=list");
  }
  else
  {
    privmsg("error: something went wrong with your submission - maybe try again in a minute");
    return;
  }
  unlink($submit_story["full_filename"]);
  set_bucket("<>",microtime(True));
  refresh_list();
}
#####################################################################################################
?>