PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: kepp on 21 December, 2003, 09:08:34

Title: Simple Topic Bot
Post by: kepp on 21 December, 2003, 09:08:34
I was bored so i made myself a little Topic bot for my bot :)

And now i took it out of there..
This one will show up in Public list aswell.
Enjoy...

--// Topic Bot
--// Made by Kepp

BotName = "T0pic"  --// What ever you want
HubOName = "Your_Hub_Name_Here"

function DataArrival(user, data)
   if (strsub(data,1,1) == "<") then
--// Bye bye
    data=strsub(data,1,strlen(data)-1)
    local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
       if user.iProfile == 0 then
   
             if (cmd=="+topic") then
                local s,e,cmd,arg = strfind(data,"%b<>%s+(%S+)%s+(.+)")
                local HubName = frmHub:GetHubName()
                local Topic = HubName.." - [Topic: "..arg.." ]"
                      frmHub:SetHubName(Topic)
                      SendToAll("$HubName "..Topic)
                      SendToAll(BotName, user.sName.." Changed the topic to: "..arg)


             elseif (cmd=="+removetopic") then
                      frmHub:SetHubName(HubOName)
                      SendToAll("$HubName "..HubOName)
                   end
             end
      end
end
Title:
Post by: kepp on 21 December, 2003, 09:11:21
Oups.... Don't take untill i can locate some copy 'n' paste missatkes :)
Title:
Post by: kepp on 21 December, 2003, 09:21:17
Nevermind, Anyway, before you set a new topic after another, don't forget to delete the first one.
else you will end up with multiple topics!!  :rolleyes:
Title:
Post by: IceCoder on 21 December, 2003, 20:43:48
hehe :)
good one
Title:
Post by: BlazeXxX on 22 December, 2003, 08:06:07
Good one kepp :) there is another version of topicbot done by Skrolster i think ? which even updates the current topic to the public hub list and changes the hub description with the topic that is set?

So feel free to try both :) still a good script kepp  :D
Title:
Post by: kepp on 22 December, 2003, 18:56:14
Well, there's one by Bonki! Actually got the idea from this one

-- [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

-------------------------------------------------------------------------------

Only diference between this one and mine is that Bonki's will update The bot's description aswell, And yea, there's some help too!
But this one won't show up in public,
And therefore i took abit of another approach!

So, credits goes to Bonki as i got the idea from his script :)
Title:
Post by: pHaTTy on 03 January, 2004, 19:42:31
QuoteOriginally posted by kepp
I was bored so i made myself a little Topic bot for my bot :)

And now i took it out of there..
This one will show up in Public list aswell.
Enjoy...

--// Topic Bot
--// Made by Kepp

BotName = "T0pic"  --// What ever you want
HubOName = "Your_Hub_Name_Here"

function DataArrival(user, data)
   if (strsub(data,1,1) == "<") then
--// Bye bye
    data=strsub(data,1,strlen(data)-1)
    local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
       if user.iProfile == 0 then
   
             if (cmd=="+topic") then
                local s,e,cmd,arg = strfind(data,"%b<>%s+(%S+)%s+(.+)")
                local HubName = frmHub:GetHubName()
                local Topic = HubName.." - [Topic: "..arg.." ]"
                      frmHub:SetHubName(Topic)
                      SendToAll("$HubName "..Topic)
                      SendToAll(BotName, user.sName.." Changed the topic to: "..arg)


             elseif (cmd=="+removetopic") then
                      frmHub:SetHubName(HubOName)
                      SendToAll("$HubName "..HubOName)
                   end
             end
      end
end

actually this will update on pubby list ;)
Title:
Post by: pHaTTy on 03 January, 2004, 19:50:06
but here you go ;)


--// Topic Bot
--// Made by Kepp
--// Update by Phatty

SetCommand = "+topic" --// anything u want
KillCommand = "+removetopic" --// anything u want

Bot = "Kepp" --// he he he ;)
HubName = "YouHubName"
Topic = ""

function DataArrival(user, data)
if (strsub(data,1,1) == "<") then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")  

      if user.iProfile == 0 then
if cmd == SetCommand then
s,e,cmd,arg = strfind(data,"%b<>%s+(%S+)%s+(.+)")
Topic = arg
frmHub:SetHubName(HubName.." - "..Topic)
SendToAll("$HubName "..HubName.." - "..Topic)
SendToAll(Bot, user.sName.." Changed the topic to: "..arg)
elseif cmd == KillCommand then
frmHub:SetHubName(HubName)
SendToAll("$HubName "..HubName)
end
end
end
end


l8rr
Title:
Post by: kepp on 10 January, 2004, 02:18:06
Nice :D
Title:
Post by: Pieltre on 12 March, 2004, 22:45:31
Hi,

I've tried the first bot posted by Keep and it works fine, except for a few details.   I wanted to get the OPs to change the topics too, so I change the
line        if user.iProfile == 0 then to        if user.iProfile == 1 then   The problem now is that I can't, as a master, change the topic... I tried a few ways to include to status, but failed.  Another thing I wanted to do was remove the "Topic: " in the topic line... removing that from the line local Topic = HubName.." - [Topic: "..arg.." ]"  just got the script not to work anymore...  
How can I get this to work


cheers,
pieltre
Title:
Post by: plop on 13 March, 2004, 00:36:04
by using this.
if user.iProfile <= 1 thenplop