PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Madman on 03 January, 2005, 13:44:16

Title: Get Topic?
Post by: Madman on 03 January, 2005, 13:44:16
I'm using 0.3.3.0 build 15.25 [debug]
I want when i change topic it sends the topic to main also..
And if the topic is so long that the user can see the whole line, he can use some command to show the complete topic...

Note that i dont want a script to change topic.. i just want a script that tell and show the topic...

And is there somekind of frmhub:GetTheTopic?
Title:
Post by: enema on 03 January, 2005, 14:06:03
got to do something with this
SendToAll("$HubName "..HubName.." - "..Topic)
Title:
Post by: Madman on 03 January, 2005, 15:10:26
Thanks =)
That Helpe.. Kind of slow now in the morning ;p
Title:
Post by: bastya_elvtars on 03 January, 2005, 19:12:01
http://www.plop.nl/ptokaxbots/Bonki/TopicBot.lua

btw ptokax with lua5 will have such option.
Title:
Post by: TTB on 03 January, 2005, 19:41:40
Hi,

I have modified a script what was here somewhere... I made an extra option: -topic will show the whole topic. It has one disadvantage... the text is only smallsized (how do you name that in English... :P) Ow, this is the script above... :)  and now modified... It should be the script u need...

-- [TopicBot] - v0.1
-- Written by bonki
-- Added -topic (VIEW) feat. by TTB
--
-- ABOUT:
--   Allows you to add a topic to your hub(name) (not shown in hublists!)
--
-- AVAILABLE COMMANDS:
--   -topichelp:        Guess.
--   -topic : Sets a new topic.
--   -topic: Shows current topic.
--   -rmtopic  :        Removes the current topic.
--
-- 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  = "[BOT]PLAY";
sVer   = "0.1";
sAbout = "Allows you to add a topic to your hub."

sHubnamePattern = "[hubname] [topic]]"

sTopicFile = "TopicBot.topic";
sTopic     = nil;
sHubname   = "";

sCrLf      = "\r\n";

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

function Main()
  bot = { sBotName  = sName,
          sBotVer   = sVer,
          sBotTag   = "<++ V:"..sVer..",P:DVDhub>",
          sBotDescr = "",
          sBotEmail = "",
          sBotSpeed = "",
          iBotShare = 0 };

  LoadTopic();

  UpdateBotInfo();
  SendBotInfo();


  sHelpHeader   = "";
  sOpHelpOutput = sCrLf.."OP Commands:"..sCrLf..sCrLf;
  sHelpOutput   = sCrLf.."Commands:"..sCrLf..sCrLf;

  tCommands = {
                [ "-topichelp" ]      = { CmdShowHelp,    0, nil,       "Displays this help message." },
                [ "-topic" ]      = { CmdSetTopic,    0, "", "Sets the topic to ."  },
                [ "-rmtopic" ]        = { CmdRemoveTopic, 0, 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);
   elseif (sTopic == nil) then
   curUser:SendData(bot.sBotName, "There is no topic atm!");
   else
    curUser:SendData(bot.sBotName, "Current topic: "..sTopic);
    --"Om de topic te veranderen moet je wel iets achter '-topic' zetten!");
  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);
    tCommands[cmd][1](curUser, strlower(args));
--    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

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


BYE

*EDIT* >> some text was Dutch, changed it to English
*EDIT2* >> I ment with smallsized text -> text without capitals
Title:
Post by: Madman on 03 January, 2005, 22:28:20
thanks for the help but...
i think you missed the line in my first post
QuoteNote that i dont want a script to change topic.. i just want a script that tell and show the topic...
=)
Anyway this is what i wanted....
--//Topic Change Notification Bot Made By Madman
--//Rewriten And Updated
--//Based On A Script From Phatty
--//Also Thanks To enema For The The Help


Bot = "TopicBot"
Topiced = {}

function DataArrival(curUser, data)
if (strsub(data,1,1) == "<") then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if cmd == "!showtopic" then
curUser:SendData(Bot, "The topic is: " ..Topiced)
end
if curUser.iProfile == 0 then
local s,e,cmd,Topic = strfind(data,"%b<>%s+(%S+)%s+(.+)")
if cmd == "!topic" then
if Topic == "off" then
SendToAll(Bot, curUser.sName.." deleted the topic")
else
SendToAll(Bot, curUser.sName.." changed the topic to: "..Topic)
Topiced = Topic
end
end
end
end
end
But i got a problem with it..
After Script/Hub restart the table is emptyed....
So when i try to read the topic i get this error msg

Syntax error: attempt to concat global `Topiced' (a table value)
stack traceback:
   1:  function `DataArrival' at line 15 [file `...ram\Hub\PtokaX-0.330 madhouse\scripts\Topic.lua']

So eiter i need to save the topic somewhere/somehow
or i need it to display a error that the topic couldnt be found... In dc that is...
but i dont manage to to either of them...
So if anyone could do it for me i would be happy =)
Title:
Post by: bastya_elvtars on 03 January, 2005, 22:32:10
Modify to your needs:

function savetopic()
writeto("lawmaker/inifiles/topic.ini")
if topic then
write("topic=\""..topic.."\"")
else
write("topic=nil")
end
writeto()
end

the topic.ini has to be dofiled in start of script.
Title:
Post by: TTB on 04 January, 2005, 00:19:44
Just asking...

the script I posted, is only without capitals... Is it simple to change that (I like CAPITALS!) :)  I don't know how to fix that...  ?(
Title:
Post by: Madman on 04 January, 2005, 01:15:51
--//Topic Change Notification Bot Made By Madman
--//Rewriten And Updated
--//Based On A Script From Phatty
--//Also Thanks To enema For The The Help
--//Thanks To bastya_elvtars For The Save Function


Bot = "TopicBot"

dofile("topic.ini")

function DataArrival(curUser, data)
if (strsub(data,1,1) == "<") then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
-- if cmd == "!showtopic" then ReadTopic() end --Add When fixed save
if curUser.iProfile == 0 then --Make bOperator?
local s,e,cmd,Topic = strfind(data,"%b<>%s+(%S+)%s+(.+)")
if cmd == "!topic" then
if Topic == "off" then
SendToAll(Bot, curUser.sName.." deleted the topic")
else
SendToAll(Bot, curUser.sName.." changed the topic to: "..Topic)
SaveTopic()
end
end
end
end
end

function SaveTopic()
writeto("Topic.ini")
if Topic then
write("Topic=\""..Topic.."\"")
else
write("Topic=nil")
end
writeto()
end

It dont work :/
I type this
!topic 123'
and see this
[01:11:22] *** Topic has been set to '123'.
[01:11:22] Madman changed the topic to: 123
But in the ini file i see
Topic=nil
Title:
Post by: bastya_elvtars on 04 January, 2005, 01:19:10
Again, some code piece, grab what you need. I had this bug too.

function changetopic(user,data,env)
if levtopic~=0 then
if CheckUserLevel(user) >= levtopic then
local _,_,tp = strfind(data,"%b<>%s+%S+%s+(.+)")
if tp then
if topic then
topic=tp
SendToAll(Bot, "Topic has been changed by "..user.sName.." to: "..topic)
SendToAll("$HubName "..frmHub:GetHubName().." - "..topic)
else
topic=tp
SendToAll(Bot, "New topic has been created by "..user.sName..": "..topic)
SendToAll("$HubName "..frmHub:GetHubName().." - "..topic)
end
else
SendToAll(Bot, "Topic has been deleted by "..user.sName)
SendToAll("$HubName "..frmHub:GetHubName())
topic=nil
end
savetopic()
else
user:SendData(parseenv(user,env,Bot).."You do not have sufficient rights to run that command! |")
end
else
user:SendData(parseenv(user,env,Bot).."That command is disabled.")
end
end
Title:
Post by: Madman on 04 January, 2005, 02:10:42
Okey, That Was easy solved....
Thanks =)
Title:
Post by: bastya_elvtars on 04 January, 2005, 02:25:17
QuoteOriginally posted by madman
Okey, That Was easy solved....
Thanks =)

and where is the new script? or i missed something? ;)
Title:
Post by: Madman on 04 January, 2005, 02:46:10
Not at all ;)
Here it is
http://board.univ-angers.fr/thread.php?threadid=1924&boardid=12&sid=562e31968de5e0e632ff5562707c3f53
But wait until i edited the post... i allready writing an update ;)
Title:
Post by: bastya_elvtars on 04 January, 2005, 02:53:07
oh ok :)

i have my own topic in lawmaker ;p

just wanted 2 see how you can implement my code

and maybe that bug comes into my mind... i cant get wtf it was LoL
Title:
Post by: Madman on 04 January, 2005, 03:02:56
Well i found the bug...
SendToAll(Bot, curUser.sName.." changed the topic to: "..Topic)
SaveTopic()
SendToAll(Bot, curUser.sName.." changed the topic to: "..Topic)
[b]Topic2Save = Topic --//"Convert" For SaveTopic()[/b]
SaveTopic()
You have to do like that...
For some reason it cant save with Topic so it has to be "converted" to something else then Topic =)