# Wrapper for GAgent, adding user commands to modify the score, etc. # This class can function both as a command-line program and # as an IRC bot when it is loaded by the RedTurnip IRC bot framework. begin require 'gagent' # for when we start from the command line rescue LoadError require 'mod/bot/gagent' # for when we start from RedTurnip end class GAgentBot def initialize print "Hello\n" @agent = MyAgent.new @THRESHHOLD = 1 #@SCORE_MOD = 0 @SCORE_MOD = 1 # 2008-04-29: try raising the default score... @MAX_RESPONSE = 10000 @MY_NAME = "(?i)(?:gagentbot|gabot|gagent)" end def getResponse(input) input = input.to_s #print 'INPUT==' + input + "\n" # Set threshhold. if input =~ /^what is your name?/ return @MY_NAME.to_s end if input =~ /^#{@MY_NAME}[:,!]* (quiet|be quiet|stfu|shut.*up|soft)/ @THRESHHOLD = @THRESHHOLD + 1 @SCORE_MOD -= 1 return "My threshhold is now " << @THRESHHOLD.to_s << ", and my score_mod is #{@SCORE_MOD}." end if input =~ /^#{@MY_NAME}[:,!]* (speak.*up|loud|louder|i can't hear you)/ @THRESHHOLD = @THRESHHOLD - 1 @SCORE_MOD += 1 return "My threshhold is now " << @THRESHHOLD.to_s << ", and my score_mod is #{@SCORE_MOD}." end # Return threshhold if input =~ /^#{@MY_NAME}[:,!]* what is your (threshhold|threshold|volume)/ or input =~ /^#{@MY_NAME}[:,!]* (?:threshold|threshhold|volume)/ return "My threshhold is currently " << @THRESHHOLD.to_s end # Provide help message. if input =~ /^#{@MY_NAME}[:,!]* help/ return "I make logical inferences using the Aristotelian syllogism." end # trap restart case input when /^#{@MY_NAME}[:,!]* restart/, /^restart/ return "That command is disabled." # for safety end # Get the agent's response. if input =~ /^#{@MY_NAME}[:,! ]*(.*)/ then input = $1 end r, s = @agent.getResponse(input) if s == nil then s = 1 end #begin; s = @agent.getScore; rescue NoMethodError; s = 1; end s += @SCORE_MOD if r.to_s.size > @MAX_RESPONSE r = r[0..@MAX_RESPONSE] end if r != 'quit' #puts "\n[gagentbot] score==#{s}; threshhold==#{@THRESHHOLD}" end if s > @THRESHHOLD if $0 == __FILE__ then return postprocess(r) end return [postprocess(r), s] else print 'r==' + postprocess(r) end return "" end def postprocess input r = input return r end # Respond to natural language method calls. def method_missing input return getResponse(input.to_s) end end if $0 == __FILE__ b = GAgentBot.new print("\n> "); $stdout.flush quitwords = [":q", "quit", "exit", "bye"] while (line = gets)# !~ /^#{quitwords.join('|')}$/ and line !~ /^$/ response = b.send(line); if response.to_s.strip == 'quit' then break end print "\n" + response.to_s + "\n" print("\n> "); $stdout.flush end print "Bye!" end