Changeset 3494

Show
Ignore:
Timestamp:
03/12/10 11:06:53 (5 months ago)
Author:
trichards
Message:

Adding support for loading and saving channels (by Dun1031)

Location:
Scripts/branches/0180_TM_ENHANCE_MUDBOT_QUESTING/Lua/experiments/mudbot
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • Scripts/branches/0180_TM_ENHANCE_MUDBOT_QUESTING/Lua/experiments/mudbot/irc.lua

    r3445 r3494  
    11local base = _G 
    22require "socket" 
     3require "save" 
    34 
    45module(..., package.seeall) 
     
    119120                    if words[1] == "PING" then 
    120121                        c:send("PONG :indiezen") 
    121                     else 
     122                        print("PONG") 
     123                                        else 
    122124                        print(words[1]) 
    123125                        print("ERR: Couldn't parse " .. value) 
     
    161163     
    162164    local channels = {} 
    163  
     165         
     166        local setChannels = function(newChannels) 
     167         
     168                bot.reload("savedChannels.lua"); 
     169                                 
     170                -- Set the channels to be the new channels (possibly temporarily save the current channels table 
     171                local oldChannels = channels; 
     172                channels = newChannels; 
     173                 
     174                -- Iterate through the new channels and join them if not already joined. 
     175                for channelName, channel in channels do 
     176                        -- Check to see if the channel has already been joined 
     177                        -- We've already joined if the channel exists in the original channels table. 
     178                        if oldChannels[channelName] == nil then 
     179                                -- Join the channel because it wasn't in the old list. 
     180                                connection.join(channelName); 
     181                        else 
     182                                -- We're already in the channel, so remove it from the old list. 
     183                                -- This will make it so that when we're done, everything still 
     184                                -- in the old list we need to leave. 
     185                                oldChannels[channelName] = nil; 
     186                        end 
     187                end 
     188                 
     189                 
     190                -- Once you're done, any channels that remain in the old channels table you need to "leave". 
     191                for channelName, channel in oldChannels do 
     192                        connection.part(channelName); 
     193                end 
     194        end 
     195         
     196        local saveChannels = function() 
     197                local file = io.open("savedChannels.lua", "w"); 
     198 
     199                file:write("channels = {}\n"); 
     200     
     201                for channelIndex, channel in pairs(channels) do 
     202                        file:write("channels[\"" .. channelIndex .. "\"] = channel(\"" .. channel .. "\");\n"); 
     203        end 
     204 
     205                file:close(); 
     206        end 
     207         
    164208    local login = function(_nickname) 
    165209        nickname = _nickname 
     
    214258            getCmd = getCmd, getText = getText, quit = quit, login = login, join = join, 
    215259            sendMessage = sendMessage, errHandler = errHandler, say = say, broadcast = broadcast, 
    216             setLogHandler = setLogHandler 
     260            setLogHandler = setLogHandler, saveChannels = saveChannels, setChannels = setChannels 
    217261        } 
    218262     
  • Scripts/branches/0180_TM_ENHANCE_MUDBOT_QUESTING/Lua/experiments/mudbot/playerCommands.lua

    r3225 r3494  
    2525end 
    2626 
    27 playerCommands["leave"] = function (connection, channel, nick, command, words) 
     27playerCommands["part"] = function (connection, channel, nick, command, words) 
    2828    if operators[nick] ~= nil then 
    2929        --connection.leave(words[2]..words[3]) 
    30         connection.say("This needs fixed! :(") 
     30                connection.part(words[2]..words[3]) 
     31        --connection.say("This needs fixed! :(") 
     32                connection.say("words[2]"..words[2].."words[3]"..words[3]) 
     33                connection.say("I'm leavin'") 
    3134    else 
    3235        connection.say("You can't do that!")