-- [TopicBot] - v0.1 -- Written by bonki -- -- ABOUT: -- Allows you to add a topic to your hub(name) (not shown in hublists!) -- -- AVAILABLE COMMANDS: -- !tb.help: Guess. -- !tb.settopic : Sets a new topic (OP). -- !tb.rmtopic: Removes the current topic (OP). -- -- OTHER FEATURES: -- You may want to edit 'sHubnamePattern' to suits your needs. -- This will be the final string for hubname + topic. -- [hubname] will be replaced with your hub's name. -- [topic] will be replaced with your hub's topic. -- -- BUGS/LIMITATIONS: -- If you change your hubname when a topic is set, you have to reset the topic -- in order to change the displayed hubname to the new one. -- -- CHANGELOG: -- v0.1: General: Initial release -- sName = "TopicBot"; sVer = "0.1"; sAbout = "Allows you to add a topic to your hub." sHubnamePattern = "[hubname] [topic: [topic]]" sTopicFile = "TopicBot.topic"; sTopic = nil; sHubname = ""; sCrLf = "\r\n"; ------------------------------------------------------------------------------- function Main() bot = { sBotName = sName, sBotVer = sVer, sBotTag = "<++ V:"..sVer..",P:bonki>", sBotDescr = "Current topic: [topic]", sBotEmail = "bonki@no-spam.net", sBotSpeed = "Sol", iBotShare = 0 }; LoadTopic(); UpdateBotInfo(); SendBotInfo(); sHelpHeader = sCrLf..sCrLf.."TopicBot v"..bot.sBotVer.." written by bonki 2003"..sCrLf..sAbout..sCrLf; sOpHelpOutput = sCrLf.."OP Commands:"..sCrLf..sCrLf; sHelpOutput = sCrLf.."Commands:"..sCrLf..sCrLf; tCommands = { [ "!tb.help" ] = { CmdShowHelp, 0, nil, "\tDisplays this help message." }, [ "!tb.settopic" ] = { CmdSetTopic, 1, "", "Sets the topic to ." }, [ "!tb.rmtopic" ] = { CmdRemoveTopic, 1, nil, "Removes the current topic." }, }; for sCmd, tCmd in tCommands do if(tCmd[2] == 1) then if (tCmd[3]) then sOpHelpOutput = sOpHelpOutput..sCmd.." "..tCmd[3].."\t\t"..tCmd[4]..sCrLf; else sOpHelpOutput = sOpHelpOutput..sCmd.."\t\t"..tCmd[4]..sCrLf; end hasOpCommands = 1; else if (tCmd[3]) then sHelpOutput = sHelpOutput..sCmd.." "..tCmd[3].."\t"..tCmd[4]..sCrLf; else sHelpOutput = sHelpOutput..sCmd.."\t\t"..tCmd[4]..sCrLf; end end end frmHub:RegBot(bot.sBotName); end ------------------------------------------------------------------------------- function CmdShowHelp(curUser) local sMsg = sHelpHeader; if (curUser.bOperator and hasOpCommands) then sMsg = sMsg..sOpHelpOutput; end sMsg = sMsg..sHelpOutput; curUser:SendData(bot.sBotName, sMsg); end ------------------------------------------------------------------------------- function CmdSetTopic(curUser, args) if (strlen(args) > 0) then SetTopic(args, 1); else curUser:SendData(bot.sBotName, "Syntax error, see help."); end end ------------------------------------------------------------------------------- function CmdRemoveTopic(curUser) if (sTopic) then sHubname = frmHub:GetHubName(); sTopic = nil; remove(sTopicFile); SendHubname(); UpdateBotInfo(); SendBotInfo(); SendToAll(bot.sBotName, "Hub topic removed!"); else curUser:SendData(bot.sBotName, "There's currently no topic set anyway!"); end end ------------------------------------------------------------------------------- function DataArrival(curUser, sData) local _, _, cmd, args = strfind(sData, "%b<>%s+(%S+)%s*([^%|]*)%|$"); if(cmd == nil) then return 0; end if (tCommands[cmd]) then curUser:SendData(sData); if (tCommands[cmd][2] == 0 or curUser.bOperator) then tCommands[cmd][1](curUser, strlower(args)); else curUser:SendData(bot.sBotName, "You do not have sufficient rights to run that command!"); end return 1; end return 0; end ------------------------------------------------------------------------------- function NewUserConnected(curUser) SendHubname(); SendBotInfo(curUser); end ------------------------------------------------------------------------------- OpConnected = NewUserConnected; ------------------------------------------------------------------------------- function SaveTopic(curTopic) flTopicFile = openfile(sTopicFile, "w"); if (flTopicFile) then write(flTopicFile, curTopic); closefile(flTopicFile); end end ------------------------------------------------------------------------------- function LoadTopic() flTopicFile = openfile(sTopicFile, "r"); if (flTopicFile) then sTopic = read(flTopicFile); closefile(flTopicFile); SetTopic(sTopic, 1); end end ------------------------------------------------------------------------------- function SetTopic(curTopic, bSave) curTopic = gsub(curTopic, "%s+", " "); curTopic = gsub(curTopic, "%c+", " "); sTopic = curTopic; local sHubString = gsub(sHubnamePattern, "%[topic%]", sTopic); sHubString = gsub(sHubString, "%[hubname%]", frmHub:GetHubName()); sHubname = sHubString; if (bSave) then SaveTopic(curTopic); end UpdateBotInfo(); SendBotInfo(); SendHubname(); SendToAll(bot.sBotName, "Topic set to: "..curTopic); end ------------------------------------------------------------------------------- function SendHubname(curUser) if (curUser) then curUser:SendData("$HubName "..sHubname); else SendToAll("$HubName "..sHubname); end end ------------------------------------------------------------------------------- function SendBotInfo(curUser) if (curUser) then curUser:SendData(sBotInfo); else SendToAll(sBotInfo); end end ------------------------------------------------------------------------------- function UpdateBotInfo() local sBotDescr = ""; if (sTopic) then sBotDescr = gsub(bot.sBotDescr, "%[topic%]", sTopic); else sBotDescr = gsub(bot.sBotDescr, "%[topic%]", "No topic set."); end sBotInfo = "$MyINFO $ALL "..bot.sBotName.." "..sBotDescr..bot.sBotTag.."$ $"..bot.sBotSpeed..strchar(1).."$"..bot.sBotEmail.."$"..bot.iBotShare.."$"; end -------------------------------------------------------------------------------