Skip to content

Commit

Permalink
whatever i changed
Browse files Browse the repository at this point in the history
  • Loading branch information
crutchy committed Mar 21, 2015
1 parent 803a12b commit 05cf3f0
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 37 deletions.
5 changes: 1 addition & 4 deletions irc_lib.php
Expand Up @@ -370,10 +370,7 @@ function log_items($items)
{
return;
}
$fieldnames=array_keys($items);
$placeholders=array_map("callback_prepare",$fieldnames);
$fieldnames=array_map("callback_quote",$fieldnames);
execute_prepare("INSERT INTO ".BOT_SCHEMA.".".LOG_TABLE." (".implode(",",$fieldnames).") VALUES (".implode(",",$placeholders).")",$items);
sql_insert($items,LOG_TABLE);
}

#####################################################################################################
Expand Down
1 change: 1 addition & 0 deletions scripts/chromas_log.php
Expand Up @@ -6,6 +6,7 @@
exec:~first|20|0|0|1|||||php scripts/chromas_log.php %%trailing%% %%dest%% %%nick%% %%alias%%
exec:~last|20|0|0|1|||||php scripts/chromas_log.php %%trailing%% %%dest%% %%nick%% %%alias%%
exec:~random|20|0|0|1|||||php scripts/chromas_log.php %%trailing%% %%dest%% %%nick%% %%alias%%
exec:~count|20|0|0|1|||||php scripts/chromas_log.php %%trailing%% %%dest%% %%nick%% %%alias%%
*/

#####################################################################################################
Expand Down
6 changes: 6 additions & 0 deletions scripts/cmd.php
Expand Up @@ -13,6 +13,8 @@
# #
#####################################################################################################

require_once("lib.php");

$items=unserialize(base64_decode($argv[1]));

$cmd=$items["cmd"];
Expand Down Expand Up @@ -68,6 +70,10 @@
case "PRIVMSG":
echo "/INTERNAL ~sed-internal PRIVMSG $trailing\n";
#echo "/INTERNAL ~antispam ".$argv[1]."\n";
if ($trailing=="~💩")
{
pm_action($dest,"chucks a nasty sloppy dogshit at aqu4");
}
break;
case "QUIT":
break;
Expand Down
128 changes: 95 additions & 33 deletions scripts/comment_feed.php
Expand Up @@ -25,14 +25,17 @@

ini_set("display_errors","on");
require_once("lib.php");
require_once("lib_mysql.php");
require_once("feeds_lib.php");
#require_once("copyright_lib.php");

define("COMMENTS_FEED_FILE","../data/comments_feed.txt");
#define("COMMENTS_FEED_FILE","../data/comments_feed.txt");
define("COMMENTS_CID_FILE","../data/comments_cid.txt");
define("COMMENTS_TOP_FILE","../data/comments_top.txt");
define("COMMENTS_FILTERS_FILE","../data/comments_filters.txt");

define("COMMENTS_TABLE","sn_comments");

define("MAIN_FEED_CHANNEL","#comments");

$trailing=trim($argv[1]);
Expand All @@ -51,6 +54,12 @@
$trailing=trim(implode(" ",$parts));
switch ($action)
{
case "feed":
if (users_get_account($nick)=="crutchy")
{
break;
}
return;
case "test":
if (users_get_account($nick)=="crutchy")
{
Expand All @@ -70,9 +79,17 @@
$filter=unserialize(base64_decode($filter));
$id=$filter["id"];
$target=$filter["target"];
$field=$filter["field"];
$pattern=$filter["pattern"];
privmsg(" $id => target=$target field=$field pattern=\"$pattern\"");
if (isset($filter["cid"])==False)
{
$field=$filter["field"];
$pattern=$filter["pattern"];
privmsg(" $id => target=$target field=$field pattern=\"$pattern\"");
}
else
{
$cid=$filter["cid"];
privmsg(" $id => target=$target cid=$cid");
}
}
return;
case "filter-add":
Expand All @@ -83,26 +100,35 @@
# %pattern% = regexp pattern for use with preg_match
$parts=explode(" ",$trailing);
delete_empty_elements($parts);
if (count($parts)<4)
if (count($parts)<3)
{
privmsg(" syntax: ~comments filter-add %id% %target% %field% %pattern%");
return;
}
$id=$parts[0];
$target=$parts[1];
$field=$parts[2];
array_shift($parts);
array_shift($parts);
array_shift($parts);
$pattern=trim(implode(" ",$parts));
$filter=array();
$filter["id"]=$id;
$filter["target"]=$target;
$filter["field"]=$field;
$filter["pattern"]=$pattern;
if (count($parts)==3)
{
$cid=$parts[2];
$filter["cid"]=$cid;
privmsg(" comments feed filter ".chr(3)."04$id".chr(3)." added [target=$target, cid=$cid]");
}
else
{
$field=$parts[2];
array_shift($parts);
array_shift($parts);
array_shift($parts);
$pattern=trim(implode(" ",$parts));
$filter["field"]=$field;
$filter["pattern"]=$pattern;
privmsg(" comments feed filter ".chr(3)."04$id".chr(3)." added [target=$target, field=$field, pattern=\"$pattern\"]");
}
$filters[$id]=base64_encode(serialize($filter));
save_settings($filters,COMMENTS_FILTERS_FILE," ");
privmsg(" comments feed filter \"$id\" added [target = \"$target\", field=\"$field\", pattern=\"$pattern\"]");
return;
case "filter-delete":
# ~comments filter-delete %id%
Expand All @@ -116,11 +142,11 @@
{
unset($filters[$id]);
save_settings($filters,COMMENTS_FILTERS_FILE," ");
privmsg(" comments feed filter \"$id\" deleted");
privmsg(" comments feed filter ".chr(3)."04$id".chr(3)." deleted");
}
else
{
privmsg(" comments feed filter \"$id\" not found");
privmsg(" comments feed filter ".chr(3)."04$id".chr(3)." not found");
}
return;
default:
Expand Down Expand Up @@ -180,16 +206,16 @@
continue;
}
sleep(5);
$url=$items[$i]["url"]."&threshold=-1&highlightthresh=-1&mode=flat&commentsort=0";
$story_url=$items[$i]["url"]."&threshold=-1&highlightthresh=-1&mode=flat&commentsort=0";
$title=$items[$i]["title"];
$title_output=chr(3)."06".$title.chr(3);
$host="";
$uri="";
$port="";
if (get_host_and_uri($url,$host,$uri,$port)==True)
if (get_host_and_uri($story_url,$host,$uri,$port)==True)
{
$k=$i+1;
term_echo("[$k/$item_count] $url");
term_echo("[$k/$item_count] $story_url");
$response=wget($host,$uri,$port,ICEWEASEL_UA,"",60);
$html=strip_headers($response);
$sid=extract_text($html,"<input type=\"hidden\" name=\"sid\" value=\"","\">");
Expand Down Expand Up @@ -262,7 +288,6 @@
$comment_body=str_replace(" "," ",$comment_body);
$comment_body=html_decode($comment_body);
$comment_body=html_decode($comment_body);

$record=array();
$record["user"]=$user;
$record["uid"]=$uid;
Expand All @@ -271,7 +296,12 @@
$record["subject"]=$subject;
$record["title"]=$title;
$record["comment_body"]=$comment_body;

$record["cid"]=$cid;
$record["sid"]=$sid;
$record["url"]=$url;
$record["parent_cid"]=$pid;
$record["parent_url"]=$parent_url;
$record["story_url"]=$story_url;
$comment_body_len=strlen($comment_body);
$max_comment_length=300;
if (strlen($comment_body)>$max_comment_length)
Expand All @@ -281,8 +311,9 @@
if ($cid>$last_cid)
{
$cids[]=$cid;
$line="$cid\t$sid\t$user\t$uid\t$score\t$score_num\t$subject\t$title\t$url\t".time()."\t$pid\t$parent_url\t$comment_body_len\n";
file_put_contents(COMMENTS_FEED_FILE,$line,FILE_APPEND);
#$line="$cid\t$sid\t$user\t$uid\t$score\t$score_num\t$subject\t$title\t$url\t".time()."\t$pid\t$parent_url\t$comment_body_len\n";
#file_put_contents(COMMENTS_FEED_FILE,$line,FILE_APPEND);
sql_insert($record,COMMENTS_TABLE);
}
$user_uid=chr(3)."03".$user.chr(3);
if ($uid>0)
Expand Down Expand Up @@ -323,7 +354,7 @@
}
$msg=clean_text($msg);
output($record,$msg);
output($record,chr(3)."08└─".$comment_body);
output($record,chr(3)."08└─".$comment_body,False);
}
}
}
Expand All @@ -350,7 +381,7 @@

#####################################################################################################

function output($record,$msg)
function output($record,$msg,$show_filter=True)
{
global $filters;
pm(MAIN_FEED_CHANNEL,$msg);
Expand All @@ -375,18 +406,49 @@ function output($record,$msg)
# $record["subject"]
# $record["title"]
# $record["comment_body"]
if (isset($record[$filter["field"]])==False)
if (isset($filter["cid"])==True)
{
return;
}
var_dump($record);
if ($record[$filter["field"]]==$filter["pattern"])
{
pm($filter["target"],$msg);
$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);
break;
}
}
while ($parent_cid<>"");
}
elseif (preg_match("#".trim($filter["pattern"])."#",$record[$filter["field"]])==1)
else
{
pm($filter["target"],$msg);
if (isset($record[$filter["field"]])==False)
{
return;
}
if ($show_filter==True)
{
$msg="[".$filter["id"]."] ".$msg;
}
if ($record[$filter["field"]]==$filter["pattern"])
{
pm($filter["target"],$msg);
}
elseif (preg_match("#".trim($filter["pattern"])."#",$record[$filter["field"]])==1)
{
pm($filter["target"],$msg);
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions scripts/lib_mysql.php
Expand Up @@ -13,6 +13,16 @@

#####################################################################################################

function sql_insert($items,$table)
{
$fieldnames=array_keys($items);
$placeholders=array_map("callback_prepare",$fieldnames);
$fieldnames=array_map("callback_quote",$fieldnames);
execute_prepare("INSERT INTO ".BOT_SCHEMA.".$table (".implode(",",$fieldnames).") VALUES (".implode(",",$placeholders).")",$items);
}

#####################################################################################################

function callback_quote($field)
{
return "`$field`";
Expand Down
29 changes: 29 additions & 0 deletions scripts/mysql/schema_comments.sql
@@ -0,0 +1,29 @@
CREATE TABLE `exec_irc_bot`.`sn_comments` (
`id` integer unsigned NOT NULL AUTO_INCREMENT,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`user` varchar(255) NOT NULL,
`uid` varchar(255) NOT NULL,
`score` varchar(255) NOT NULL,
`score_num` varchar(255) NOT NULL,
`subject` varchar(500) NOT NULL,
`title` varchar(255) NOT NULL,
`comment_body` varchar(3000) NOT NULL,
`cid` varchar(255) NOT NULL,
`sid` varchar(255) NOT NULL,
`url` varchar(255) NOT NULL,
`parent_cid` varchar(255) NOT NULL,
`parent_url` varchar(500) NOT NULL,
`story_url` varchar(500) NOT NULL,
PRIMARY KEY (`id`),
INDEX `timestamp` (`timestamp` ASC),
INDEX `user` (`user` ASC),
INDEX `uid` (`uid` ASC),
INDEX `score` (`score` ASC),
INDEX `score_num` (`score_num` ASC),
INDEX `subject` (`subject` ASC),
INDEX `title` (`title` ASC),
INDEX `comment_body` (`comment_body` ASC),
INDEX `cid` (`cid` ASC),
INDEX `sid` (`sid` ASC),
INDEX `parent_cid` (`parent_cid` ASC)
) ENGINE=InnoDB AUTO_INCREMENT=1;
36 changes: 36 additions & 0 deletions scripts/mysql/setup_comments.php
@@ -0,0 +1,36 @@
<?php

define("DB_HOST","localhost");
define("DB_USER","root");
define("DB_PASSWORD",trim(file_get_contents("../../../pwd/mysql_root_cs")));

$pdo=new PDO("mysql:host=".DB_HOST,DB_USER,DB_PASSWORD);
if ($pdo===False)
{
die("ERROR CONNECTING TO MYSQL SERVER\n");
}
else
{
echo "CONNECTED\n";
}
$sql=file_get_contents("schema_comments.sql");
$result=$pdo->exec($sql);
if ($result===False)
{
die("ERROR CREATING DATABASE\n");
}
else
{
echo "DATABASE CREATED\n";
}
$result=$pdo->exec("GRANT SELECT, INSERT, UPDATE, DELETE ON exec_irc_bot.* TO www@'%';");
if ($result===False)
{
die("ERROR GRANTING PRIVILEGES\n");
}
else
{
die("PRIVILEGES GRANTED\n");
}

?>
File renamed without changes.
2 changes: 2 additions & 0 deletions scripts/startup.php
Expand Up @@ -18,6 +18,8 @@
rawmsg("MODE #comments -o crutchy");
rawmsg("MODE #github -o crutchy");
rawmsg("MODE #feeds -o crutchy");
rawmsg("MODE #freenode -o crutchy");
echo "/INTERNAL ~freenode\n";

echo "################# END STARTUP #################\n";

Expand Down

0 comments on commit 05cf3f0

Please sign in to comment.