FoobarBazbot

sedbot

Feb 28th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 1.58 KB | None | 0 0
  1. #!/usr/bin/gawk -f
  2. function lineout(old,new,nouser) {
  3.   if(old!=new) print (nouser?"":"<" user "> ") new >outfile; close(outfile);
  4. }
  5. BEGIN {
  6.  outfile=( ENVIRON["HOME"] "/sedbotirc/irc.sylnt.us/#soylent/in");
  7.  line_re="^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2} <([^>]*)> (.*)$";
  8.  blag_re="world wide web|internet|interweb|intersphere|intertubes|interblag|blogosphere|blagonet|blagosphere|blagoblag|webnet|webweb";
  9.  blag_n=split(blag_re,blag_word,/\|/);
  10.  srand();
  11. }
  12. $0 ~ line_re {
  13.   user=gensub(line_re,"\\1",1);
  14.   line=gensub(line_re,"\\2",1);
  15.   regex=0;
  16. }
  17. line ~ /^s/ {
  18.   sep=substr(line,2,1);
  19.   if(sep ~ /[\.\^\$\[\]\|\+\*\(\)\{\}]/) sep="\\"sep;
  20.   desep="\\\\("sep")";
  21.   s_re = "^s" sep "(([^" sep "]|\\\\" sep ")+)" sep "(([^" sep "]|\\\\" sep ")*)" sep "(([0-9]+|g)|([iI]))*$";
  22.   if(line ~ s_re) {
  23.     regex=1;
  24.     search=gensub(desep,"\\1","g",gensub(s_re,"\\1", 1, line));
  25.     repl  =gensub(desep,"\\1","g",gensub(s_re,"\\3", 1, line));
  26.     count =gensub(desep,"\\1","g",gensub(s_re,"\\6", 1, line));
  27.     casein=gensub(desep,"\\1","g",gensub(s_re,"\\7", 1, line));
  28.     print user ": " line "\n" s_re "\n" search "\n" repl "\n" count "\n" casein >"/dev/stderr";
  29.     if(!count) count=1;
  30.     if(casein) IGNORECASE=1; else IGNORECASE=0;
  31.     newline=gensub(search,repl,count,last_line[user]);
  32.     lineout(last_line[user],gensub(blag_re,blag_word[int(rand()*blag_n+1)],"g",newline));
  33.   }
  34. }
  35. line ~ /^[sS][eE][dD][bB][oO][tT]/ {lineout("","\001ACTION is a 36-line awk script, http://pastebin.com/Gq02WTJb \001",1);}
  36. !regex {last_line[user]=gensub(/\001ACTION (.*)\001/,"\\1",1,line);}
Add Comment
Please, Sign In to add comment