Factoids ======== .. highlight:: irc Factoids are one of the most important Ibid plugins. They are what give a bot most of its personality, and after a few years on IRC, it can expect to pick up a few thousand of them from its users. While it can store simple factoids like:: Ibid is an awesome bot written in Python If you say so Ibid Ibid is an awesome bot written in Python It can also allow for some basic behaviour programming:: slap $arg is slaps $1 and runs for his life Got it slap Bob * ibid slaps Bob and runs for his life Basics ------ Factoids start out pretty basic, as a way of the bot remembering things, such as:: ibid: Ibid is an awesome bot framework Alice: One learns a new thing every day Now I can ask him about that:: ibid: what is ibid? Alice: Ibid is an awesome bot framework Or even:: ibid: Ibid Alice: Ibid is an awesome bot framework They can also store multiple values. On retrieval, a value is picked at random:: ibid: Ibid is also your father Alice: I'll remember that ibid: Ibid Alice: ibid is your father ibid: Ibid Alice: ibid is an awesome bot framework You can request a specific one:: ibid: Ibid /frame/ Alice: ibid is an awesome bot framework ibid: literal ibid Alice: 1: is an awesome bot framework, 2: is your father ibid: Ibid #2 Alice: ibid is your father Fancy factoids -------------- Factoids don't just have to be like a dictionary, they can have some basic behaviour attached. This example also shows how you can trivially replace factoids (assuming you have permission to do so):: ibid: hi is Hi there Alice: One learns a new thing every day ibid: hi Hi there ibid: no, hi is waves Alice: Got it ibid: hi * ibid waves ibid: no, hi is Hello $who Alice: If you say so ibid: hi Hello Alice The ``$who`` substitutes the speaker's name. Other substitutions possible are: * ``$channel``, ``$source`` * ``$year``, ``$month``, ``$mon``, ``$month1``, ``$month2``, ``$day``, ``$day2``, ``$hour``, ``$minute``, ``$second``, ``$date``, ``$time``, ``$weekday``, ``$unixtime`` ``$month``, ``$mon``, ``$month1`` and ``$month2`` substitute, respectively, the month name, abbreviated month name, month number and zero-padded month number; ``$day2`` substitutes the zero-padded day number. And factoids can have multiple names. Our greeting only responds to "hi", it should respond to more greetings:: ibid: hello is the same as hi Alice: Yessir ibid: good day is the same as hi Alice: Alrighty ibid: good day Hello Alice Finally, factoids can take basic arguments:: ibid: slap $arg is slaps $1 Alice: Got it ibid: slap Alice * ibid slaps Alice ibid: run from $arg to $arg is starts running at $1 and stops at $2 Alice: One learns a new thing every day ibid: run from here to there * ibid starts running at here and stops at there Searching --------- Factoids aren't very useful if we can't remember what they are called:: ibid: search slap Alice: slap $arg [1] ibid: search father Alice: Ibid [2] The first example tells us about a factoid mentioning slap. The second shows what happens when a multi-valued factoid is found. The result we are after may be one of two values, so we can't simply say "``ibid: ibid``", we should rather use say:: ibid: ibid /father/ Alice: Ibid is your father You can specify which part of the factoid you are searching in:: ibid: search for values containing awesome Alice: Ibid [2] ibid: search for names containing awesome Alice: I couldn't find anything with that name Modification ------------ Factoids aren't set in stone. While they can be replaced with "``no, name is newvalue``", sometimes you just want to make a small change:: ibid: ibid Alice: Ibid is an awesome bot framework ibid: ibid += , written in python Alice: Pattern matches multiple factoids, please be more specific ibid: ibid /awesome/ += , written in python Alice: Done ibid: ibid /awesome/ Alice: Ibid is an awesome bot framework, written in python ibid: ibid /python/ ~= s/awesome // Alice: Yessir ibid: ibid /python/ Alice: Ibid is an bot framework, written in python .. note:: The replacement is a simple search & replace. If you want to use a regular expression, you must add an ``r`` flag. E.g. s/fo+/bar/r The ``i`` and ``g`` flags are also supported, as is the ``y/x/y/`` operation. And finally, removal:: ibid: forget ibid Alice: Sure ibid: ibid Alice: What? Or only one of the values:: ibid: literal ibid Alice: 0: is your father, 1: is an awesome bot framework ibid: forget ibid /framework/ Alice: Sure ibid: literal ibid Alice: 0: is your father .. vi: set et sta sw=3 ts=3: