#// bot4.awk #// The bot to post frames to the OTT #// 19.06.2018- #// #// Copyright (C) 2015, 2018 Balthasar Szczepański #// #// This program is free software: you can redistribute it and/or modify #// it under the terms of the GNU Affero General Public License as #// published by the Free Software Foundation, either version 3 of the #// License, or (at your option) any later version. #// #// This program is distributed in the hope that it will be useful, #// but WITHOUT ANY WARRANTY; without even the implied warranty of #// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #// GNU Affero General Public License for more details. #// #// You should have received a copy of the GNU Affero General Public License #// along with this program. If not, see . BEGIN{ FS="" # noticepath="/eizm/mem/aftertime/mpost/" # framepath="/eizm/www/time/" datapath="/eizm/data/aftertime/" timecmd="date" timecmd2="date -u +%N%s" lastpath ="/eizm/mem/aftertime/lastong/" temppath ="/eizm/tmp/aftertime/" ott_address="http://forums.xkcd.com/viewtopic.php?f=7&t=101043&start=" tto_address="http://1190.bicyclesonthemoon.info/ott/view?start=" mstd_address="http://1190.bicyclesonthemoon.info/ott/mview?start=" lastpost_address="http://forums.xkcd.com/viewtopic.php?f=7&t=101043&sd=d" wget="/usr/bin/wget" rm="/bin/rm" perl="/usr/bin/perl" mawk="/usr/bin/mawk" automome="/eizm/pro/ong1/mome.pl" memedef="/eizm/mem/ong1/mome.txt" postawk="/eizm/pro/aftertime/post.awk" mpostawk="/eizm/pro/aftertime/mpost.awk" # timecmd2="date +\"%H%M%S\"" botcastleurl="http://1190.bicyclesonthemoon.info" if(enhance!="" && int(enhance)!="0") { enh=int(enhance) ext="-"enh } else { ext="" enh=0 } f=int(frame) timecmd | getline thistime close(timecmd) timecmd2 | getline ID close(timecmd2) ID=int(ID/3600) ID =int(ID%9999) for(i=0;i<256;++i) { ch=sprintf("%c",i) hex=sprintf("%02X",i); ch2hex[ch]=hex } statefile= datapath story"/ongstate" getline temp < statefile close(statefile) split(temp, temptab, " ") state=int(temptab[1]) last=int(temptab[2]) if(frame=="") f=last # srand(ID + f) # for(i=0;i0) { if(temp ~ regexp) { print "Newpage "page" - already ONGed." system(rm" -f "tempfile) print page" "f > lasttime close(lasttime) exit 1 } gsub(/<[^<>]*>/,"",temp) gsub(/ +/," ",temp) temp2=tolower(temp) if((i=match(temp2,/page [0-9]+ of [0-9]+/))!=0) { temp2=substr(temp2,i) temp2=substr(temp2,index(temp2,"of")+3)" " temp2=substr(temp2,1,index(temp2," ")-1) lastpage=int(temp2) } temp2=tolower(temp) if((i=match(temp2,/[0-9]+ posts/))!=0) { temp2=substr(temp2,index(temp2,"")-1) posts=int(temp2) if(posts%40==0) pope=1 else pope="" } } close(tempfile) print "Newpage "page" - nothing found." } mlastpage=1 for(mpage=1;mpage<=mlastpage;++mpage) { url= "\""mstd_address (mpage-1)*40"\"" cmd= wget " -q -O "tempfile" -U "useragent" "url if(system(cmd)!=0) { print "Mustardtime newpage "mpage" not downloaded." break } for(j=0;(getline temp < tempfile)>0;++j) { if(temp ~ regexp) { print "Newpage "mpage" - already ONGed." system(rm" -f "tempfile) #writeout exit 1 } gsub(/<[^<>]*>/,"",temp) gsub(/ +/," ",temp) temp2=tolower(temp) if((i=match(temp2,/page [0-9]+ of [0-9]+/))!=0) { temp2=substr(temp2,i) temp2=substr(temp2,index(temp2,"of")+3) temp2=substr(temp2,1,index(temp2," ")-1) mlastpage=int(temp2) } temp2=tolower(temp) if((i=match(temp2,/[0-9]+ posts/))!=0) { temp2=substr(temp2,index(temp2,"")-1) posts=int(temp2) if(posts%40==0) pope=1 else pope="" } } close(tempfile) print "Mustradtime newpage "mpage" - nothing found." } } if(argtab["nomeme"]=="") { print "Ok, can ONG. Now generate ONGtext" cmd = perl" "automome" -lc 150 -n 67 -d "memedef (pope!=""?" -t \"[decrall]\"":"") while ((cmd | getline temp)>0) { if(sub(/[AEIOUY]-N-G/,"[b]O-N-G[/b]",temp)>0) { ongtext= prepare(temp) break } if(sub(/O+N+G+/,"[b]&[/b]",temp)>0) { ongtext= prepare(temp) break } if(sub(/DON'T/,"D[b]ON'G[/b]T",temp)>0) { ongtext= prepare(temp) break } if(sub(/[AEIOUY]NG/,"[b]ONG[/b]",temp)>0) { if($0!~/TH\[b\]ONG/) { ongtext= prepare(temp) break } } if(sub(/ON G/,"[b]ON G[/b] ",temp)>0) { ongtext= prepare(temp) break } if(sub(/ON /,"[b]ONG[/b] ",temp)>0) { ongtext= prepare(temp) break } if(sub(/O\.?$/,"[b]ONG[/b] ",temp)>0) { ongtext= prepare(temp) break } } close(cmd) if(ongtext=="") ongtext="ONG" print ongtext } else ongtext="ONG" cmd= wget " -q -O "tempfile" -U "useragent" \""lastpost_address"\"" if(system(cmd)!=0) { print "Can't check last post" # system(rm" -f "tempfile) # exit 1 } else { while((getline temp < tempfile)>0) { if ((i=match(temp, /id=\"p[0-9]+\"/))!=0) #" { temp2=substr(temp, i+5) lastpostid=substr(temp2, 1, index(temp2,"\"")-1) } if (temp ~ /class=\"postprofile\"/) #" postprofile = "1" else if (postprofile=="") continue if(temp ~ /memberlist\.php.*mode=viewprofile[^<>]*>[^<>]+<\/a/) { temp2=substr(temp, index(temp, ">")+1) lastusername=substr(temp2, 1, index(temp2,"<")-1) break } } close(tempfile) if(lastusername=="" || lastpostid=="") { print "Can't check last post" # system(rm" -f "tempfile) # exit 1 } } srand(ID+lastpostid+f) if(rand()<(argtab["npbprob"]+0)) { print "Also, let's do some NewpixbOTTification!" npbsel="npbframe"ext } else npbsel="frame"ext framedir= (argtab["framedir"]!="" ? argtab["framedir"] : "/aftertime/"argtab["story"]"/") print "username="urlencode(username) > tempfile print "password="urlencode(password,1) >> tempfile print "subject="urlencode(sprintf(argtab["subject"ext],f)) >> tempfile print "message="urlencode(ongtext"\n[url="botcastleurl"/aftertime/viewer?story="argtab["story"]"&f="f((enh>0)?"&e="enh:"")"][img]"botcastleurl framedir sprintf(argtab[npbsel],f)"[/img][/url][spoiler]"alt"[/spoiler]\n[right][size=80] -- posted by "botname"[/size][/right]") >> tempfile print "Send post" cmd= mawk" -f "postawk" -v postfile="tempfile_p" -v cookiefile="tempfile_c" -v tempfile="tempfile_t((lastpostid!="" && lastusername!="")?" -v edit="lastpostid" -v user=\""lastusername"\"":"")" "tempfile cmd2= mawk" -f "mpostawk" -v postfile="tempfile_p" -v cookiefile="tempfile_c" -v tempfile="tempfile_t" "tempfile if(system(cmd)!=0) { print "Can't post, try again from mirror" if(system(cmd2)!=0) { print "CAN'T POST EITHER!" system(rm" -f "tempfile) system(rm" -f "tempfile_t) system(rm" -f "tempfile_c) system(rm" -f "tempfile_p) exit 1 } } print "ONGed" system(rm" -f "tempfile) system(rm" -f "tempfile_t) system(rm" -f "tempfile_c) system(rm" -f "tempfile_p) if(force=="") { print lastpage" "f > lasttime close(lasttime) } } function urlencode(name, all, len,iii,escaped,ch) { len=length(name) escaped="" for(iii=1;iii<=len;++iii) { ch=substr(name,iii,1); if (ch ~ /[a-z]|[A-Z]|[0-9]/ && all=="") escaped = escaped ch else escaped = escaped "%" ch2hex[ch] } return escaped }; function prepare(rh) { gsub(/\*\*/,"¤",rh) gsub(/\*[^\*]+\*/,"±&±",rh) gsub(/±\*/,"[i]",rh) gsub(/\*±/,"[/i]",rh) gsub(/¤/,"*",rh) gsub(/__/,"¤",rh) gsub(/_[^_]+_/,"±&±",rh) gsub(/±_/,"[u]",rh) gsub(/_±/,"[/u]",rh) gsub(/¤/,"_",rh) gsub(/\$\$/,"¤",rh) gsub(/\$[^\$]+\$/,"±&±",rh) gsub(/±\$/,"[size=80]",rh) gsub(/\$±/,"[/size]",rh) gsub(/¤/,"$",rh) return rh " -- [url=http://1190.bicyclesonthemoon.info/ongtext?b=on][b]ong[/b]o[/url][url=http://mrob.com/time/automome/]mome[/url]" }