From db5b99ed7ea562291cb050ff588a47699fe6f7b8 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Wed, 8 Jan 2020 20:06:57 -0800 Subject: [PATCH] doc/CodeFactoids.md: deleted because outdated --- doc/CodeFactoids.md | 94 --------------------------------------------- 1 file changed, 94 deletions(-) delete mode 100644 doc/CodeFactoids.md diff --git a/doc/CodeFactoids.md b/doc/CodeFactoids.md deleted file mode 100644 index 43893b3e..00000000 --- a/doc/CodeFactoids.md +++ /dev/null @@ -1,94 +0,0 @@ -### code-factoids -Code-factoids are a special type of factoid whose text is executed as Perl instructions. The return value from these instructions is the final text of the factoid. This final text is then parsed and treated like any other factoid text. - - -* [code-factoids](#code-factoids) - * [Special variables](#special-variables) - * [testargs example](#testargs-example) - * [rtfm example](#rtfm-example) - * [poll example](#poll-example) - - -By default, the variables created within code-factoids do not persist between factoid invocations. This behavior can be overridden by factsetting a persist-key with a unique value. - -To create a code-factoid, simply wrap the factoid text with curly braces. - - factadd keyword { code here } - -#### Special variables - -There are some special variables available to code-factoids. - -* `@args` - any arguments passed to the factoid (note that invoker's nick is passed if no arguments are specified) -* `$nick` - nick of the person invoking the factoid -* `$channel` - channel in which the factoid is being invoked - -#### testargs example - - factadd global testargs { return "/say No arguments!" if not @args; - if (@args == 1) { return "/say One argument: $args[0]!" } elsif - (@args == 2) { return "/say Two arguments: $args[0] and $args[1]!"; } - my $results = join ', ', @args; return "/say $results"; } - testargs added to the global channel. - testargs - One argument: pragma-! - testargs "abc 123" xyz - Two arguments: abc 123 and xyz! - -#### rtfm example - -Remember that `rtfm` factoid from earlier? Let's modify it so that it doesn't attack Zhivago. - - forget rtfm - rtfm removed from the global channel. - factadd global rtfm { return "/say Nonsense! Zhivago is a gentleman and - a scholar." if $nick eq "Zhivago" or "@args" =~ /zhivago/i; return "/me - $attacks $args[0] with a $sizes $colors manual." } - rtfm added to the global channel. - rtfm luser - * PBot smacks luser with a huge blue manual. - rtfm Zhivago - Nonsense! Zhivago is a gentleman and a scholar. - -#### poll example - -An extremely basic aye/nay poll system. All code-factoids sharing the same persist-key will share the same persisted variables. - -First we add the factoids: - - factadd global startpoll { %aye = (); %nay = (); $question = "@args"; - "/say Starting poll: $question" } - startpoll added to the global channel. - factadd global aye { $aye{$nick} = 1; delete $nay{$nick}; "" } - aye added to the global channel. - factadd global nay { $nay{$nick} = 1; delete $aye{$nick}; "" } - nay added to the global channel. - factadd global pollresults { $ayes = keys %aye; $nays = keys %nay; - "/say Results for poll \"$question\": ayes: $ayes, nays: $nays" } - pollresults added to the global channel. - -Then we set their persist-key to the same value: - - factset global startpoll persist-key pragma-poll - [global] startpoll: 'persist-key' set to 'pragma-poll' - factset global aye persist-key pragma-poll - [global] aye: 'persist-key' set to 'pragma-poll' - factset global nay persist-key pragma-poll - [global] nay: 'persist-key' set to 'pragma-poll' - factset global pollresults persist-key pragma-poll - [global] pollresults: 'persist-key' set to 'pragma-poll' - -And action: - - startpoll Isn't this cool? - Starting poll: Isn't this cool? - aye - nay - aye - pollresults - Results for poll "Isn't this cool?": ayes: 2, nays: 1 - -* Exercise for the reader: extend this poll system to be per-channel using `$channel`. - -* Experts: extend this to use a `vote ` factoid, and adjust `pollresults` to show a tally for each keyword. -