Commit c4b4a7884ccb6c847cd557e3133e392b0141fd33

Added "8ball" command

Added a magic 8-ball command, accessible with 8ball or 8-ball,
42 random responses.
  
1DEFINITION MODULE EightBall;
2
3IMPORT Message;
4
5PROCEDURE EightBall(parse: Message.Parse);
6
7END EightBall.
obj/Handler.o
(65 / 62)
Binary files differ
obj/Mention.o
(28 / 29)
Binary files differ
obj/gaze.o
(27 / 25)
Binary files differ
obj/m.o
(24 / 20)
Binary files differ
Binary files differ
obj/t.o
(2 / 2)
Binary files differ
obj/u.o
(4 / 4)
Binary files differ
obj/users.o
(28 / 23)
Binary files differ
obj/w.o
(6 / 7)
Binary files differ
  
1IMPLEMENTATION MODULE EightBall;
2
3FROM RandCard IMPORT RandInt, seed;
4FROM TimeConv IMPORT millisecs;
5IMPORT Message, FormStr;
6
7PROCEDURE EightBall(parse: Message.Parse);
8VAR
9 result : Message.strType;
10 answers : ARRAY [0..42] OF ARRAY [0..29] OF CHAR;
11 choice : INTEGER;
12BEGIN
13 seed := millisecs(); (* re-seed the random number generator *)
14 (* There is probably a better way of doing this *)
15 answers[0] := 'Yes.';
16 answers[1] := 'No.';
17 answers[2] := 'Outlook not so good.';
18 answers[3] := 'All signs point to yes.';
19 answers[4] := 'All signs point to no';
20 answers[5] := 'Ask again later.';
21 answers[6] := 'The answer is unclear.';
22 answers[7] := 'A definite maybe.';
23 answers[8] := 'Signs point to yes.';
24 answers[9] := 'Yes.';
25 answers[10] := 'Reply hazy, try again.';
26 answers[11] := 'Without a doubt.';
27 answers[12] := 'My sources say no.';
28 answers[13] := 'As I see it, yes.';
29 answers[14] := 'You may rely on it.';
30 answers[15] := 'Concentrate and ask again.';
31 answers[16] := 'Outlook not so good.';
32 answers[17] := 'It is decidedly so.';
33 answers[18] := 'Better not tell you now.';
34 answers[19] := 'Very doubtful.';
35 answers[20] := 'Yes - definitely.';
36 answers[21] := 'It is certain.';
37 answers[22] := 'Cannot predict now.';
38 answers[23] := 'Most likely.';
39 answers[24] := 'Ask again later.';
40 answers[25] := 'My reply is no.';
41 answers[26] := 'Outlook good.';
42 answers[27] := "Don't count on it";
43 answers[28] := 'Yes, in due time.';
44 answers[29] := 'My sources say no.';
45 answers[30] := 'Definitely not.';
46 answers[31] := 'Yes.';
47 answers[32] := 'You will have to wait.';
48 answers[33] := 'I have my doubts.';
49 answers[34] := 'Outlook so so.';
50 answers[35] := 'Looks good to me!';
51 answers[36] := 'Who knows?';
52 answers[37] := 'Looking good!';
53 answers[38] := 'Probably.';
54 answers[39] := 'Are you kidding?';
55 answers[40] := 'Go for it!';
56 answers[41] := "Don't bet on it.";
57 answers[42] := 'Forget about it.';
58
59 choice := RandInt(0, 42);
60 FormStr.print(result, "%s shakes the magic 8-ball... %s", parse.botname, answers[choice]);
61 Message.PrintLine(parse.chan, result);
62EXCEPT
63 RETURN
64END EightBall;
65
66END EightBall.
  
4848IMPORT users;
4949IMPORT WholeStr, RegComp, FormStr;
5050
51IMPORT b, d, c, f, google, k, m, Mention, n, o, p, q, r, s, t, u, v, w;
51IMPORT b, d, c, EightBall, f, google, k, m, Mention, n, o, p, q, r, s, t, u, v, w;
5252IMPORT Timers, tracker, bugcheckState, bugsearch, conversions, util;
5353FROM Setup IMPORT ChannelT, checkChans, check;
5454
282282 cmd := parse.cmd;
283283 Capitalize(cmd);
284284
285
285(* Misc *)
286(* 8 <><><><><><><><><><> *)
287(* 8ball - Magic 8-ball *)
288 IF Left("8BALL", cmd) OR Left("8-BALL", cmd) THEN EightBall.EightBall(parse) END;
286289(* A <><><><><><><><><><> *)
287290(* B <><><><><><><><><><> *)
288291(* Backup - back up the program source to timestorm (will later backup settings files) *)
  
213213 BEGIN
214214 alreadyFound := mentionFound;
215215 (* Second loop. Process entire log, if mentionFound=FALSE, do search, otherwise just transfer matches *)
216 (* IF NOT mentionFound THEN (* Process returned FALSE, checking whole log *); *)
217216 FormStr.print (command, "tac %s/log/irclog | grep -i '%s' > %stemporary.log", p6datPath, string, p6tmpPath);
218217 status := ProgExec.Command(command, exit);
219218
235235 ELSE
236236 output(out, "No mentions were found");
237237 END;
238 (*
239 IF mentionFound AND NOT FileSys.Exists(p6tmpPath+"alreadyFound") THEN
240 Message.PrintLine(line.chan, outputStr);
241 output(out, outputStr);
242 SeqFile.OpenWrite(file, p6tmpPath+"alreadyFound", writeFlags, iores);
243 TextIO.WriteString(file, "found");
244 SeqFile.Close(file);
245 END;
246 *)
247238 HALT;
248239 ELSE
249240 END;
250
251241
252242 END SecondStep;
253243
  
147147 modDepends = "| sed s/\(depends\)//g "; (* modify (depends) *)
148148 modOptional = "| sed s/\ \(optional\)/*/g "; (* Modify (optional) *)
149149 modSub = "| sed s/-sub//g "; (* Modify -sub *)
150 FILTER = noColors+modDepends+modOptional+modSub;
150 modSpaces = "| sed 's/^ *//;s/ *$//;s/ \{1,\}/ /g' "; (* delete extra spaces *)
151 FILTER = noColors+modDepends+modOptional+modSub+modSpaces;
151152
152153 writeFIFO = p6Fifo.writeFIFO;
153154 readFIFO = p6Fifo.readFIFO;
  
2222 stat.mkfifo(fifoName, 777B);
2323 END;
2424 FormStr.append(command, " > %s &", fifoName);
25 Done := ProgExec.Command(command, return);
25 done := ProgExec.Command(command, return);
2626END writeFIFO;
2727
2828PROCEDURE readFIFO(VAR string : ARRAY OF CHAR);
3030 found : BOOLEAN;
3131 pos : CARDINAL;
3232BEGIN
33 buffer := "";
34 Strings.Assign("", string);
33 buffer := ""; Strings.Assign("", string);
3534 pipeFd := fcntl.open(fifoName, openRead);
3635 IF (pipeFd <> -1) THEN
3736 REPEAT
5151 bufAdr := string.memset(buffer, 0, SIZE(buffer));
5252
5353FINALLY
54 FileSys.Remove(fifoname, done);
54 FileSys.Remove(fifoName, done);
5555END p6Fifo.
src/u.mod
(4 / 4)
  
1414
1515IMPLEMENTATION MODULE u;
1616
17IMPORT FileSys, Message, ProgExec, StreamFile, Strings, TextIO, IOResult, util;
17IMPORT FileSys, Message, ProgExec, StreamFile, Strings, TextIO, IOResult, util, p6Fifo;
1818
1919 PROCEDURE Uptime(parse : Message.Parse);
2020 (* Uptime: How long has the computer that the bot is running on *)
2626 iores : StreamFile.OpenResults;
2727 file : StreamFile.ChanId;
2828 BEGIN
29 util.CmdUsed(parse);
29 util.CmdUsed(parse);
3030 exit := 0; result := ""; str := "";
3131 done := ProgExec.Command("uptime > /home/terry/p6dat/tmp/uptime", exit);
3232 StreamFile.Open(file, "/home/terry/p6dat/tmp/uptime", StreamFile.read, iores);
3434 TextIO.SkipLine(file);
3535 StreamFile.Close(file);
3636 FileSys.Remove("/home/terry/p6dat/tmp/uptime",done);
37 Strings.Assign("Uptime: ",str);
38 Strings.Concat(str, result, str);
37 Strings.Assign("Uptime: ",str);
38 Strings.Concat(str, result, str);
3939 Message.PrintLine(parse.chan, result);
4040 END Uptime;
4141
  
2626
2727CONST
2828 debugging = FALSE;
29 tempfile = "/usr/share/httpd/htdocs/users/temp.png"; (* old file, used with diff command *)
30 difffile = "/usr/share/httpd/htdocs/users/visual-diff.pam"; (* graphic output *)
31 difftext = "/usr/share/httpd/htdocs/users/visual-diff.txt"; (* readable output *)
32 notefile = "/usr/share/httpd/htdocs/users/note"; (* file for email *)
29 webDir = '/usr/local/www/server/page6.shlrm.org/pages/';
30
31 tempfile = webDir+"users/temp.png"; (* old file, used with diff command *)
32 difffile = webDir+"users/visual-diff.pam"; (* graphic output *)
33 difftext = webDir+"users/visual-diff.txt"; (* readable output *)
34 notefile = webDir+"users/note"; (* file for email *)
3335
3436PROCEDURE generateImage(lat, long : REAL; rad : CARDINAL; name : ARRAY OF CHAR; parse: Message.Parse): Message.strType ;
3537VAR
6363 ** or: pamarith -difference <(pngtopnm smgl-us.png) <(pngtopnm smgl-us-nov06.png) | pamsumm -maxx > file
6464 *)
6565
66 file := "/usr/share/httpd/htdocs/users/smgl-FN.png"; (* new file for potential upload to Flickr *)
66 file := webDir+"users/smgl-FN.png"; (* new file for potential upload to Flickr *)
6767 StringParse.Replace(file, "FN", name);
6868 filepng := file;
6969
7474 ** really works in relation to images created after I changed to this method.
7575 ** create the file note, which will contain the description and tags
7676 *)
77 command := "echo 'Source Mage GNU/Linux users centered over NAME DATE TIME http://www.sourcemage.org tags: smgl users' > /usr/share/httpd/htdocs/users/note";
77 command := "echo 'Source Mage GNU/Linux users centered over NAME DATE TIME http://www.sourcemage.org tags: smgl users' > /usr/local/www/servers/page6.shlrm.org/pages/users/note";
7878 StringParse.Replace(command, "NAME", name);
7979 StringParse.Replace(command, "DATE", util.Date(parse));
8080 StringParse.Replace(command, "TIME", util.Time(parse));
8181 done := ProgExec.Command(command, res);
82 command := "mail -s 'smgl users in NAM' -a FILE eight06looked@photos.flickr.com < /usr/share/httpd/htdocs/users/note";
82 command := "mail -s 'smgl users in NAM' -a FILE eight06looked@photos.flickr.com < /usr/local/www/servers/page6.shlrm.org/pages/users/note";
8383 StringParse.Replace(command, "FILE", filepng);
8484 StringParse.Replace(command, "NAM", name);
8585 IF debugging THEN
100100 ** compare -metric AE
101101 ** this is done by a bash script in the directory, and creates the file visual-diff.txt
102102 *)
103 command := '/usr/share/httpd/htdocs/users/test.sh "PNGf"';
103 command := '/usr/local/www/servers/page6.shlrm.org/pages/users/test.sh "PNGf"';
104104 StringParse.Replace(command, "PNGf", filepng);
105105 IF debugging THEN
106106 Message.Notice("qnr", command);
src/w.mod
(3 / 2)
  
8585 target := str; (* get rid of the the formatting changes *)
8686 (* Check string for Humidity, or Current, if it's there, then the return is valid *)
8787 IF StringParse.InString("Humidity", result) THEN
88 (* Error in my code somewhere isn't clearing the previous line, so I'm
88 (* Error in my code somewhere. It isn't clearing the previous line returned, so I'm
8989 manually trimming everything after the %. Must be in the FIFO, but I can't see where. *)
9090 Strings.FindNext("%", result, 0, found, pos);
9191 IF found THEN Strings.Delete(result, pos+1, LENGTH(result)) END;
9393 ELSE
9494 FormStr.print(str, "I'm sorry, I couldn't find any weather for %s", target);
9595 END;
96
9796 Message.PrintLine(parse.chan, str);
9897EXCEPT
98 (* Flesh this out, find out what the exceptions are and write code to keep
99 them from occurring *)
99100 Message.PrintLine(parse.chan, "For what location?");
100101 RETURN;
101102END Weather;
sym/w.sym
(9 / 3)
Binary files differ
tmp.mkf
(2 / 0)
  
2222
2323OBJ= \
2424 obj/Connect.o \
25 obj/EightBall.o \
2526 obj/FloodProtect.o \
2627 obj/Handler.o \
2728 obj/Logging.o \
2829 obj/Mention.o \
2930 obj/Message.o \
3031 obj/PageSix.o \
32 obj/RandCard.o \
3133 obj/Setup.o \
3234 obj/Stack.o \
3335 obj/StringParse.o \