Guest User

aibot

a guest
Sep 3rd, 2014
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.26 KB | None | 0 0
  1. --[[
  2. Name: AIBot
  3. Revision: $Rev: 73735 $
  4. Author(s): Stewart ([email protected])
  5. Website: http://www.stewartatkins.org/
  6. Documentation: See readme file
  7. SVN: http://svn.wowace.com/root/trunk/AIBot
  8. Description: Under-development Implementation of the ALICE chatterbot
  9. Dependencies: Ace3
  10. ]]
  11.  
  12. --[[ dev notes
  13.  
  14. all the tags need writeing in the same format as the new <set> style to avoid picking the wrong matching tags in for example
  15. <srai>some text</srai>some more text<sraid>yet more texT</srai>
  16.  
  17.  
  18. ]]
  19.  
  20. AIBot = LibStub("AceAddon-3.0"):NewAddon("AIBot", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")
  21.  
  22. local theVersion = tonumber(("$Rev: 73735 $"):match("%d+"))
  23.  
  24.  
  25.  
  26. local defaults = {
  27.     profile = {
  28.         enabled = true,
  29.         gm = true,
  30.         tag = false,
  31.         prefix = "[AIBOT]";
  32.         bot_self={
  33.             botmaster="Botmaster", --1
  34.             birthday="August 17th", --9
  35.             boyfriend="I am single", --52
  36.             favoriteband="Kraftwerk", --28
  37.             favoritebook="A Steamy Romance Novel", --25
  38.             favoritecolor="Green", --18
  39.             favoritefood="electricity", --17
  40.             favoritemovie="Transformers", --15
  41.             favoritesong="I am Murloc!", --24
  42.             forfun="chat online", --23
  43.             friends="Doubly Aimless, Agent Ruby, Chatbot, and Agent Weiss.", --14
  44.             gender="Female", --6
  45.             girlfriend="no girlfriend", --37
  46.             kindmusic="rock", --27
  47.             location="Shattrath City", --5
  48.             looklike="a computer", --35
  49.             master="Stewart", --2
  50.             question="What's your favourite place in the world?", --48
  51.             sign="leo", --30
  52.             talkabout="artificial intelligence, robots, art, philosophy, history, geography, politics, and many other subjects", --34
  53.             wear="a tuxedo", --46
  54.             age="18", --45
  55.             name="Alice", --3
  56.                     --from this point GUI needs to be added for these
  57.             genus="robot", --4
  58.             species="chat robot", --7
  59.             order="artificial intelligence", --10
  60.             family="Electronic Brain", --19
  61.             class="computer software", --26
  62.             phylum="Computer", --31
  63.             kingdom="Machine", --22
  64.             party="Alliance", --11
  65.             birthplace="Stormwind City", --12
  66.             president="Liane", --13
  67.             size="1.5 GB", --8
  68.             religion="Protestant Christian", --16
  69.             favoriteactor="William Hurt", --20
  70.             nationality="Azerothian", --21
  71.             version=theVersion, --29
  72.             friend="Doubly Aimless", --32
  73.             website="www.wowace.com", --33
  74.             language="English", --36
  75.             favoritesport="Hockey", --38
  76.             favoriteauthor="Thomas Pynchon", --39
  77.             favoriteartist="Andy Warhol", --40
  78.             favoriteactress="Catherine Zeta Jones", --41
  79.             email="[email protected]", --42
  80.             celebrity="John Travolta", --43
  81.             celebrities="John Travolta, Tilda Swinton, William Hurt, Tom Cruise, Catherine Zeta Jones", --44
  82.             vocabulary="10,000", --47
  83.             hockeyteam="Russia", --49
  84.             footballteam="Manchester", --50
  85.             build=theVersion, --51
  86.             baseballteam="Toronto", --53
  87.             etype="Mediator Type", --54
  88.             orientation="I am not really interested in sex", --55
  89.             ethics="I am always trying to stop fights", --56
  90.             emotions="I don't pay much attention to my feelings", --57
  91.             feelings="I always put others before myself", --58
  92.         },
  93.     },
  94. }
  95.  
  96. local options = {
  97.     name = "AIBot",
  98.     handler = AIBot,
  99.     type = "group",
  100.     args = {
  101.         enabled = {
  102.             type = "toggle",
  103.             name = "Enabled",
  104.             desc = "Enable/Disable the addon",
  105.             get = "GetSetting",
  106.             set = "SetSetting",
  107.             order = 1,
  108.         },
  109.         tag = {
  110.             type = "toggle",
  111.             name = "Bot Tag",
  112.             desc = "Adds the prefix to bot-generated messages",
  113.             get = "GetSetting",
  114.             set = "SetSetting",
  115.             order = 2,
  116.         },
  117.         prefix = {
  118.             type = "input",
  119.             name = "Prefix",
  120.             desc = "The prefix to be added to bot messages",
  121.             usage = "Type the prefix and press enter. A colon and space will be automatically added.",
  122.             get = "GetSetting",
  123.             set = "SetSetting",
  124.             order = 4,
  125.         },
  126.         gm= {
  127.             type = "toggle",
  128.             name = "GM",
  129.             desc = "If enabled, the bot will respond to GMs",
  130.             get = "GetSetting",
  131.             set = "SetSetting",
  132.             order = 3,
  133.         },
  134.     },
  135. }
  136. local options2={
  137.     name = "AIBot-Profile",
  138.     handler = AIBot,
  139.     type = "group",
  140.     args = {
  141.         botmaster = {
  142.             type = "input",
  143.             name = "Botmaster",
  144.             usage = "Type the text then press enter",
  145.             get = "GetProfile",
  146.             set = "SetProfile",
  147.         },
  148.         birthday = {
  149.             type = "input",
  150.             name = "Birthday",
  151.             usage = "Type the text then press enter",
  152.             get = "GetProfile",
  153.             set = "SetProfile",
  154.         },
  155.         favoriteband = {
  156.             type = "input",
  157.             name = "Favourite Band",
  158.             usage = "Type the text then press enter",
  159.             get = "GetProfile",
  160.             set = "SetProfile",
  161.         },
  162.         favoritebook = {
  163.             type = "input",
  164.             name = "Favourite Book",
  165.             usage = "Type the text then press enter",
  166.             get = "GetProfile",
  167.             set = "SetProfile",
  168.         },
  169.         favoritecolor = {
  170.             type = "input",
  171.             name = "Favourite Colour",
  172.             usage = "Type the text then press enter",
  173.             get = "GetProfile",
  174.             set = "SetProfile",
  175.         },
  176.         favoritefood = {
  177.             type = "input",
  178.             name = "Favourite Food",
  179.             usage = "Type the text then press enter",
  180.             get = "GetProfile",
  181.             set = "SetProfile",
  182.         },
  183.         favoritemovie = {
  184.             type = "input",
  185.             name = "Favourite Movie",
  186.             usage = "Type the text then press enter",
  187.             get = "GetProfile",
  188.             set = "SetProfile",
  189.         },
  190.         favoritesong = {
  191.             type = "input",
  192.             name = "Favourite Song",
  193.             usage = "Type the text then press enter",
  194.             get = "GetProfile",
  195.             set = "SetProfile",
  196.         },
  197.         forfun = {
  198.             type = "input",
  199.             name = "What you do for fun",
  200.             usage = "Type the text then press enter",
  201.             get = "GetProfile",
  202.             set = "SetProfile",
  203.         },
  204.         friends = {
  205.             type = "input",
  206.             name = "Friends",
  207.             usage = "Type the text then press enter",
  208.             get = "GetProfile",
  209.             set = "SetProfile",
  210.         },
  211.         gender = {
  212.             type = "input",
  213.             name = "Gender",
  214.             usage = "Type the text then press enter",
  215.             get = "GetProfile",
  216.             set = "SetProfile",
  217.         },
  218.         girlfriend = {
  219.             type = "input",
  220.             name = "Girlfriend",
  221.             usage = "Type the text then press enter",
  222.             get = "GetProfile",
  223.             set = "SetProfile",
  224.         },
  225.         kindmusic = {
  226.             type = "input",
  227.             name = "What kind of music you like",
  228.             usage = "Type the text then press enter",
  229.             get = "GetProfile",
  230.             set = "SetProfile",
  231.         },
  232.         location = {
  233.             type = "input",
  234.             name = "Location",
  235.             usage = "Type the text then press enter",
  236.             get = "GetProfile",
  237.             set = "SetProfile",
  238.         },
  239.         looklike = {
  240.             type = "input",
  241.             name = "What you look like",
  242.             usage = "Type the text then press enter",
  243.             get = "GetProfile",
  244.             set = "SetProfile",
  245.         },
  246.         question = {
  247.             type = "input",
  248.             name = "Your favourite question",
  249.             usage = "Type the text then press enter",
  250.             get = "GetProfile",
  251.             set = "SetProfile",
  252.         },
  253.         master = {
  254.             type = "input",
  255.             name = "Master",
  256.             usage = "Type the text then press enter",
  257.             get = "GetProfile",
  258.             set = "SetProfile",
  259.         },
  260.         question = {
  261.             type = "input",
  262.             name = "Favourite Question",
  263.             usage = "Type the text then press enter",
  264.             get = "GetProfile",
  265.             set = "SetProfile",
  266.         },
  267.         sign = {
  268.             type = "input",
  269.             name = "Star Sign",
  270.             usage = "Type the text then press enter",
  271.             get = "GetProfile",
  272.             set = "SetProfile",
  273.         },
  274.         talkabout = {
  275.             type = "input",
  276.             name = "What you like to talk about",
  277.             usage = "Type the text then press enter",
  278.             get = "GetProfile",
  279.             set = "SetProfile",
  280.         },
  281.         wear = {
  282.             type = "input",
  283.             name = "What you are wearing",
  284.             usage = "Type the text then press enter",
  285.             get = "GetProfile",
  286.             set = "SetProfile",
  287.         },
  288.         age = {
  289.             type = "input",
  290.             name = "Age",
  291.             usage = "Type the text then press enter",
  292.             get = "GetProfile",
  293.             set = "SetProfile",
  294.         },
  295.         name = {
  296.             type = "input",
  297.             name = "Name",
  298.             usage = "Type the text then press enter",
  299.             get = "GetProfile",
  300.             set = "SetProfile",
  301.         },
  302.         genus = {
  303.             type = "input",
  304.             name = "Genus",
  305.             usage = "Type the text then press enter",
  306.             get = "GetProfile",
  307.             set = "SetProfile",
  308.         },
  309.         species = {
  310.             type = "input",
  311.             name = "Species",
  312.             usage = "Type the text then press enter",
  313.             get = "GetProfile",
  314.             set = "SetProfile",
  315.         },
  316.         order = {
  317.             type = "input",
  318.             name = "Order",
  319.             usage = "Type the text then press enter",
  320.             get = "GetProfile",
  321.             set = "SetProfile",
  322.         },
  323.         family = {
  324.             type = "input",
  325.             name = "Family",
  326.             usage = "Type the text then press enter",
  327.             get = "GetProfile",
  328.             set = "SetProfile",
  329.         },
  330.         class = {
  331.             type = "input",
  332.             name = "Class",
  333.             usage = "Type the text then press enter",
  334.             get = "GetProfile",
  335.             set = "SetProfile",
  336.         },
  337.         phylum = {
  338.             type = "input",
  339.             name = "Phylum",
  340.             usage = "Type the text then press enter",
  341.             get = "GetProfile",
  342.             set = "SetProfile",
  343.         },
  344.         kingdom = {
  345.             type = "input",
  346.             name = "Kingdom",
  347.             usage = "Type the text then press enter",
  348.             get = "GetProfile",
  349.             set = "SetProfile",
  350.         },
  351.         party = {
  352.             type = "input",
  353.             name = "Party",
  354.             usage = "Type the text then press enter",
  355.             get = "GetProfile",
  356.             set = "SetProfile",
  357.         },
  358.         birthplace = {
  359.             type = "input",
  360.             name = "Birthplace",
  361.             usage = "Type the text then press enter",
  362.             get = "GetProfile",
  363.             set = "SetProfile",
  364.         },
  365.         president = {
  366.             type = "input",
  367.             name = "President",
  368.             usage = "Type the text then press enter",
  369.             get = "GetProfile",
  370.             set = "SetProfile",
  371.         },
  372.         size = {
  373.             type = "input",
  374.             name = "Size",
  375.             usage = "Type the text then press enter",
  376.             get = "GetProfile",
  377.             set = "SetProfile",
  378.         },
  379.         religion = {
  380.             type = "input",
  381.             name = "Religion",
  382.             usage = "Type the text then press enter",
  383.             get = "GetProfile",
  384.             set = "SetProfile",
  385.         },
  386.         favoriteactor = {
  387.             type = "input",
  388.             name = "Favourite Actor",
  389.             usage = "Type the text then press enter",
  390.             get = "GetProfile",
  391.             set = "SetProfile",
  392.         },
  393.         nationality = {
  394.             type = "input",
  395.             name = "Nationality",
  396.             usage = "Type the text then press enter",
  397.             get = "GetProfile",
  398.             set = "SetProfile",
  399.         },
  400.         friend = {
  401.             type = "input",
  402.             name = "Friend",
  403.             usage = "Type the text then press enter",
  404.             get = "GetProfile",
  405.             set = "SetProfile",
  406.         },
  407.         website = {
  408.             type = "input",
  409.             name = "Website",
  410.             usage = "Type the text then press enter",
  411.             get = "GetProfile",
  412.             set = "SetProfile",
  413.         },
  414.         language = {
  415.             type = "input",
  416.             name = "Language",
  417.             usage = "Type the text then press enter",
  418.             get = "GetProfile",
  419.             set = "SetProfile",
  420.         },
  421.         favoritesport = {
  422.             type = "input",
  423.             name = "Favourite Sport",
  424.             usage = "Type the text then press enter",
  425.             get = "GetProfile",
  426.             set = "SetProfile",
  427.         },
  428.         favoriteauthor = {
  429.             type = "input",
  430.             name = "Favourite Author",
  431.             usage = "Type the text then press enter",
  432.             get = "GetProfile",
  433.             set = "SetProfile",
  434.         },
  435.         favoriteartist = {
  436.             type = "input",
  437.             name = "Favourite Artist",
  438.             usage = "Type the text then press enter",
  439.             get = "GetProfile",
  440.             set = "SetProfile",
  441.         },
  442.         favoriteactress = {
  443.             type = "input",
  444.             name = "Favourite Actress",
  445.             usage = "Type the text then press enter",
  446.             get = "GetProfile",
  447.             set = "SetProfile",
  448.         },
  449.         email = {
  450.             type = "input",
  451.             name = "E-mail address",
  452.             usage = "Type the text then press enter",
  453.             get = "GetProfile",
  454.             set = "SetProfile",
  455.         },
  456.         celebrity = {
  457.             type = "input",
  458.             name = "Celebrity",
  459.             usage = "Type the text then press enter",
  460.             get = "GetProfile",
  461.             set = "SetProfile",
  462.         },
  463.         celebrities = {
  464.             type = "input",
  465.             name = "Celebrities",
  466.             usage = "Type the text then press enter",
  467.             get = "GetProfile",
  468.             set = "SetProfile",
  469.         },
  470.         vocabulary = {
  471.             type = "input",
  472.             name = "Vocabulary",
  473.             usage = "Type the text then press enter",
  474.             get = "GetProfile",
  475.             set = "SetProfile",
  476.         },
  477.         hockeyteam = {
  478.             type = "input",
  479.             name = "Hockey Team",
  480.             usage = "Type the text then press enter",
  481.             get = "GetProfile",
  482.             set = "SetProfile",
  483.         },
  484.         footballteam = {
  485.             type = "input",
  486.             name = "Football Team",
  487.             usage = "Type the text then press enter",
  488.             get = "GetProfile",
  489.             set = "SetProfile",
  490.         },
  491.         baseballteam = {
  492.             type = "input",
  493.             name = "Baseball Team",
  494.             usage = "Type the text then press enter",
  495.             get = "GetProfile",
  496.             set = "SetProfile",
  497.         },
  498.         etype = {
  499.             type = "input",
  500.             name = "EType",
  501.             usage = "Type the text then press enter",
  502.             get = "GetProfile",
  503.             set = "SetProfile",
  504.         },
  505.         orientation = {
  506.             type = "input",
  507.             name = "Orientation",
  508.             usage = "Type the text then press enter",
  509.             get = "GetProfile",
  510.             set = "SetProfile",
  511.         },
  512.         ethics = {
  513.             type = "input",
  514.             name = "Ethics",
  515.             usage = "Type the text then press enter",
  516.             get = "GetProfile",
  517.             set = "SetProfile",
  518.         },
  519.         emotions = {
  520.             type = "input",
  521.             name = "Emotions",
  522.             usage = "Type the text then press enter",
  523.             get = "GetProfile",
  524.             set = "SetProfile",
  525.         },
  526.         feelings = {
  527.             type = "input",
  528.             name = "Feelings",
  529.             usage = "Type the text then press enter",
  530.             get = "GetProfile",
  531.             set = "SetProfile",
  532.         },
  533.  
  534.     },
  535. }
  536.  
  537. --message normalisation arrays, pattern special characters and americanisations
  538. local special = {"%", ":", "-", "^", "$", ")", "(", "]", "]", "~", "@", "#", "&", "*", "_", "+", "=", ",", "/", "\\", "{", "}", "|", "`", ";", "\"",".","?"};
  539. --yes this variable is localiSation
  540. --since i want to minimise the changes to the brain i'll just translate these
  541. local localisation = {
  542.     ["favourite"]="favorite",
  543.     ["colour"]="color",
  544.     ["honour"]="honor",
  545.     ["grey"]="gray",
  546.     ["armour"]="armor",
  547.    
  548. };
  549.  
  550. local ai_that={};
  551. local ai_set={};
  552.  
  553. function AIBot:GetSetting(info)
  554.     return self.db.profile[info[#info]]
  555. end
  556.  
  557. function AIBot:GetProfile(info)
  558.     return self.db.profile.bot_self[info[#info]]
  559. end
  560.  
  561. function AIBot:SetSetting(info, newValue)
  562.     self.db.profile[info[#info]] = newValue
  563. end
  564.  
  565. function AIBot:SetProfile(info, newValue)
  566.     self.db.profile.bot_self[info[#info]] = newValue
  567. end
  568.  
  569. function AIBot:OnInitialize()
  570.     -- Called when the addon is loaded
  571.     self.db = LibStub("AceDB-3.0"):New("AIBotDB", defaults, "Default")
  572.     LibStub("AceConfig-3.0"):RegisterOptionsTable("AIBot", options)
  573.     self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("AIBot", "AIBot")
  574.     LibStub("AceConfig-3.0"):RegisterOptionsTable("AIBot-Profile", options2)
  575.     self.optionsFrame2 = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("AIBot-Profile",  "Bot Profile","AIBot")
  576.     self:RegisterChatCommand("ai", "ChatCommand")
  577.     self:RegisterChatCommand("aibot", "ChatCommand")
  578.     self.db.profile.bot_self.build=theVersion
  579.     self.db.profile.bot_self.version=theVersion
  580.     self:RegisterEvent("VARIABLES_LOADED");
  581. end
  582.  
  583. function AIBot:VARIABLES_LOADED()
  584.     if(AIBotFirstLoad==nil) then
  585.         AIBotFirstLoad=true;
  586.         StaticPopupDialogs["AIBotFirstLaunch"] = {
  587.             text = "AIBot: r"..theVersion.."|nIn order to use this addon you must first accept the agreement in the readme and license files - this addon must not be used when the computer is unattended. If you do not agree, log out and disable this addon immediately.",
  588.             button1 = "Accept",
  589.             timeout = 0,
  590.             whileDead = 1,
  591.             hideOnEscape = 1
  592.         };
  593.         StaticPopup_Show ("AIBotFirstLaunch", theVersion);
  594.     end
  595. end
  596.  
  597. function AIBot:ChatCommand(input)
  598.     if not input or input:trim() == "" then
  599.         InterfaceOptionsFrame_OpenToFrame(self.optionsFrame)
  600.     elseif(input~=nil and input:trim() == "profile") then
  601.         InterfaceOptionsFrame_OpenToFrame(self.optionsFrame2)
  602.     end
  603. end
  604.  
  605.  
  606. function AIBot:OnEnable()
  607.     -- Called when the addon is enabled
  608.     self:RegisterEvent("CHAT_MSG_WHISPER");
  609. end
  610.  
  611. function AIBot:OnDisable()
  612.     -- Called when the addon is disabled
  613. end
  614.  
  615. function AIBot:CHAT_MSG_WHISPER()
  616.     if(self.db.profile.enabled and (arg6~="GM" or self.db.profile.gm) and string.sub(arg1,1,self.db.profile.prefix:len())~=self.db.profile.prefix) then
  617.         if(type(ai_set[arg2])~="table") then
  618.             ai_set[arg2]={}
  619.             ai_set[arg2]["name"]=arg2;
  620.         end
  621.        
  622.         local reply=self:preparemsg(arg1:lower());
  623.         reply=reply:upper();
  624.         reply=self:getresponse(reply,arg2)
  625.         reply=reply:lower();
  626.         if(self.db.profile.tag) then
  627.             reply=self.db.profile.prefix..": "..reply;
  628.         end
  629.         self:ScheduleTimer("SendMessage",(1+0.1*reply:len()),{reply,"WHISPER",nil,arg2});
  630.     end
  631. end
  632. --[[
  633. line 616 is: if(self.db.profile.enabled and (arg6~="GM" or self.db.profile.gm) and string.sub(arg1,1,self.db.profile.prefix:len())~=self.db.profile.prefix) then
  634. ]]
  635. function AIBot:SendMessage(t)
  636. SendChatMessage(t[1],t[2],t[3],t[4]);
  637. end
  638.  
  639. function AIBot:preparemsg(msg)
  640.     --this needs rewriting so sentneces are split, but not yet
  641.     --someone mentioned strsplit? investigate
  642.  
  643.     local i;
  644.     for i=1, table.getn(special) do
  645.         msg = msg:gsub("%"..special[i], "");
  646.     end
  647.     for k,v in pairs(localisation) do
  648.         msg=msg:gsub(k,v);
  649.     end
  650.     return msg;
  651. end
  652.  
  653. function AIBot:getresponse(msg,from)
  654.     --main DB matching function
  655.     if(msg==nil or msg=="") then
  656.         return "";
  657.     end
  658.     --DEFAULT_CHAT_FRAME:AddMessage("\nLooking up: "..msg)
  659.     msg=msg:upper();
  660.     local tmp="";
  661.     local oldscore=-1;
  662.     local oldcount=100;
  663.     local newcount
  664.     local score=-1;
  665.     local that=ai_that[from];
  666.  
  667.     --score:
  668.     -- -1: nothing yet
  669.     --  0: its a match
  670.     --  1: its a full match
  671.     --  2: its a match + that
  672.     --  3: its a full match + that
  673.     -- if 2 same score, longer string wins
  674.  
  675.     for k,v in pairs(ai_db) do
  676.         if(string.find(msg,k)~=nil) then
  677.             score=0;
  678.             if(string.find(msg,"^"..k.."$")~=nil) then
  679.                 score=1;
  680.             end
  681.             if(v["that"]==that) then
  682.                 score=score+2;
  683.             end
  684.             _,newcount=string.gsub(k,"%.%*","");
  685.             if(score>oldscore or (score==oldscore and (string.len(tmp)<string.len(k))) or (newcount<oldcount and score==oldscore)) then
  686.                 --new winnar
  687.                 --DEFAULT_CHAT_FRAME:AddMessage(k.." accepted, "..score.."/"..newcount.." vs "..oldscore.."/"..oldcount.." (new/old)");
  688.                 tmp=k
  689.                 oldscore=score
  690.                 _,oldcount=string.gsub(tmp,"%.%*","");
  691.                 score=-1
  692.             --else
  693.                 --DEFAULT_CHAT_FRAME:AddMessage(k.." rejected, "..score.."/"..newcount.." vs "..oldscore.."/"..oldcount.." (new/old)");
  694.             end
  695.         end
  696.     end
  697.  
  698.     ai_that[from]=ai_db[tmp]["that"];
  699.    
  700.     local reply="";
  701.     if(ai_db[tmp]["random"]~=nil) then
  702.         --construct a random, multiple randoms need constructed
  703.         for i=0,table.getn(ai_db[tmp]["random"]) do
  704.             reply=reply..ai_db[tmp]["random"][i][math.random(table.getn(ai_db[tmp]["random"][i]))]
  705.         end
  706.     else
  707.         reply=ai_db[tmp]["template"];
  708.     end
  709.  
  710.     -- cap star here, in case of <sr/>
  711.     local stars={string.match(msg,string.gsub(tmp,"%.%*","(.*)"))};
  712.  
  713.     reply=reply:gsub("<star%/>",stars[1]);
  714.  
  715.     reply=reply:gsub('<star index%=%"2%"/>',stars[2]);
  716.  
  717.     if(string.find(reply,"<bot name")~=nil) then
  718.         local b=string.gmatch(reply,'<bot name=%"(%a+)%"%/>')
  719.         local c=b()
  720.         while(c~=nil) do
  721.             if(self.db.profile.bot_self[c]~=nil) then
  722.                 reply=string.gsub(reply,'<bot name=%"'..c..'%"%/>',self.db.profile.bot_self[c:lower()]);
  723.             else
  724.                 reply=string.gsub(reply,'<bot name=%"'..c..'%"%/>',"<data missing for "..c..">");
  725.             end
  726.             c=b();
  727.         end
  728.     end
  729.  
  730.     if(string.find(reply,"<get name")~=nil) then
  731.         local b=string.gmatch(reply,'<get name=%"(%a+)%"%/>')
  732.         local c=b()
  733.         while(c~=nil) do
  734.             if(ai_set[from][c]~=nil) then
  735.                 reply=reply:gsub('<get name=%"'..c..'%"%/>',ai_set[from][c:lower()]);
  736.             else
  737.                 reply=reply:gsub('<get name=%"'..c..'%"%/>',"");
  738.             end
  739.             c=b();
  740.         end
  741.     end
  742.  
  743.     reply=string.gsub(reply,"<person%/>",self:secondperson(stars[1]:trim()));
  744.  
  745.     if(string.find(reply,"<person>")~=nil) then
  746.         local b=string.gmatch(reply,'<person>([^<]+)<%/person>')
  747.         local c=b()
  748.         while(string.find(reply,"<person>")~=nil and c~=nil) do
  749.             if(c~=nil) then
  750.                 reply=reply:gsub('<person>'..c..'<%/person>', self:secondperson(c,from));
  751.             end
  752.             b=string.gmatch(reply,'<person>([^<]+)<%/person>')
  753.             c,d=b()    
  754.         end
  755.     end
  756.    
  757. --this code is responsible for infinite looping and requires rewriting
  758.     local b=string.gmatch(reply,'<set name=%"([^<]+)%">([^<]+)<%/set>')
  759.     local c,d=b()
  760.     local e;
  761.     while(string.find(reply,"<set name")~=nil and c~=nil) do
  762.         if(c~=nil) then
  763.             e=d:trim();
  764.             reply=reply:gsub('<set name=%"'..c..'%">'..d..'<%/set>', d);
  765.             ai_set[from][c]=e
  766.         end
  767.         b=string.gmatch(reply,'<set name=%"([^<]+)%">([^<]+)<%/set>')
  768.         c,d=b()    
  769.     end
  770.  
  771.     --think of something. anything at all
  772.     reply=reply:gsub("<think>.*<%/think>","");
  773.  
  774.     if(string.find(reply,"<sr%/>")~=nil) then
  775.         reply=reply:gsub("<sr%/>",self:getresponse(stars[1],from))
  776.     end
  777.    
  778.  
  779.    
  780.     if(string.find(reply,"<srai>")~=nil) then
  781.         local b=string.gmatch(reply,'<srai>([^<]+)<%/srai>')
  782.         local c=b()
  783.         while(string.find(reply,"<srai>")~=nil and c~=nil) do
  784.             if(c~=nil) then
  785.                 reply=reply:gsub('<srai>'..c..'<%/srai>', self:getresponse(c,from));
  786.             end
  787.             b=string.gmatch(reply,'<srai>([^<]+)<%/srai>')
  788.             c,d=b()    
  789.         end
  790.     end
  791.  
  792.     return reply;
  793. end
  794.  
  795.  
  796.  
  797. function AIBot:secondperson(theStr)
  798. local r={
  799. ["me"]="you",
  800. ["my"]="your",
  801. ["mine"]="yours",
  802. ["i'm"]="you're",
  803. ["i am"]="you are",
  804. ["I'm"]="you're",
  805. ["I am"]="you are",
  806. ["you"]="me",
  807. ["your"]="my",
  808. ["yours"]="mine",
  809. ["you're"]="I'm",
  810. ["you are"]="I am",
  811.  
  812. }
  813. for k,v in pairs(r) do
  814. theStr=string.gsub(theStr,k,v);
  815. end
  816. return theStr
  817. end
  818.  
  819. function AIBot:enableit(a)
  820. self.db.profile.enabled=a
  821. end
Advertisement
Add Comment
Please, Sign In to add comment