Chat Bot

Discussion in 'Lua Discussions' started by fooBrew, Nov 12, 2019.

Thread Status:
Not open for further replies.
  1. fooBrew

    fooBrew Avatar

    Messages:
    34
    Likes Received:
    31
    Trophy Points:
    8
    Gender:
    Male
    Location:
    San Diego, CA
    This is a simple chat bot style template I use to provide an interface to the commands I want to run. You just need to change PLAYER_NAME and BOT_NAME. I use it by whispering to myself, for example:

    Code:
    /w westmalle, bishop get virtues
    
    You could easily change it to listen to other chat channels by changing the line with 'Private' in it. You could then change it to listen to anyone or a list of people other than just PLAYER_NAME.

    Code:
    local PLAYER_NAME = "Westmalle"
    local BOT_NAME = "bishop"
    
    local function ShowVirtues()
       ConsoleLog(string.format("Courage: %s", GetStatValueByNumber(317)))
       ConsoleLog(string.format("Love: %s", GetStatValueByNumber(318)))
       ConsoleLog(string.format("Truth: %s", GetStatValueByNumber(319)))
    end
    
    local last_msg = ""
    function ShroudOnConsoleInput(type, player, message)
       if player == PLAYER_NAME and message ~= last_msg then
          local _, _, cmd = string.find(message, "^.*%[Private%]: "..BOT_NAME.." (.*)")
          if cmd == "numstats" then
             ConsoleLog(string.format("Number of stats: %d", GetStatCount()))
          elseif cmd == "dumpstats" then
             ConsoleLog(string.format("dump list of stats"))
             for i = 1, GetStatCount() do
                ConsoleLog(string.format("%d - %s = %s", i, GetStatNameByNumber(i),
                                         GetStatValueByNumber(i)))
             end
          elseif cmd == "get scene" then
             ConsoleLog(ShroudGetCurrentSceneName())
          elseif cmd == "get clock" then
             ConsoleLog(os.time())
          elseif cmd == "get virtues" then
             ShowVirtues()
          end
    
          last_msg = message
       end
    end
     
    Drake Aedus, Jaesun and FrostII like this.
Thread Status:
Not open for further replies.