PtokaX forum

Development Section => Your Developing Problems => Topic started by: Themaster on 31 December, 2004, 17:41:13

Title: Bot Problem
Post by: Themaster on 31 December, 2004, 17:41:13
Hey Ppl

I got a problem in main chat when i type something
[17:37:13] hello TheMaster? look on the function +help
[17:37:14] l
[17:37:15] hello TheMaster? look on the function +help
[17:37:15] k
[17:37:16] hello TheMaster? look on the function +help
[17:37:16] h

function DataArrival(user, data)
   if (strsub(data, 1, 1) == "<" ) then
      local data=strsub(data,1,strlen(data)-1)
      local _,_,cmd=strfind(data, "%b<>%s+(%S+)")
      local Commands = (UserCommands(user, data, cmd))
      return Commands
   elseif (strsub(data, 1, 12) == "$OpForceMove") or (strsub(data, 1, 10) == "$ForceMove") and (user.iProfile < 0 or user.iProfile > 0) then
      return 1
   elseif (strsub(data,1,4) == "$To:") then
      data = strsub(data,1,-2);
      local s,e,whoTo,from,arg = strfind(data,"%$To:%s+(%S+)%s+From:%s+(%S+)%s+%$%b<>%s+(.*)")
      local s,e,cmd = strfind(arg,"(%S+)")
      if (whoTo == Bot) and UserCommands(user,data,cmd) then
         return UserCommands(user,data,cmd)
      else
         for i=1,getn(ChatBots) do
            if (( whoTo == ChatBots[i].Name )) then
               if (( ChatBots[i].Allowed[user.iProfile] == 1 )) then
                  sChat = ChatBots[i].Name;
                  for b,v in ChatBots[i].Allowed do
                     if (( v == 1 )) then
                        ChatRoom(sChat,user,arg,b)
                     end
                  end
               end
            end
         end
      end
   end
end


Happy New year
Title:
Post by: bastya_elvtars on 31 December, 2004, 17:51:02
replace

local _,_,cmd=strfind(data, "%b<>%s+(%S+)")
to

local _,_,cmd=strfind(data, "%b<>%s+[%!%#%+%?%$%-](%S+)")
it will only check words that start with

Title:
Post by: Themaster on 31 December, 2004, 17:54:37
it still there :s
Title:
Post by: bastya_elvtars on 31 December, 2004, 17:55:26
post the UserCommands function plz
Title:
Post by: Themaster on 31 December, 2004, 17:56:10
function UserCommands(user,data,cmd)
   if cmd == "+myip" then
      user:SendData(Bot, " Your Ip is -=-=> "..user.sIP)
      return 1
   elseif cmd == "+rules" then
      user:SendPM(Bot, filecontents)
      Readtextfile(user, "rules.txt")
      return 1
   elseif cmd == "+network" then
      user:SendData(Bot, filecontents)
      Readtextfile(user, "network.txt")
      return 1
   elseif cmd == "+version" then
      user:SendData(Bot, ""..Version..Build..Creator)
      return 1
   elseif cmd == "+away" then
      s,e,cmd,arg = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
      if (not (arg)) then
      arg = "Default away msg"
      end
      SendToAll(Bot,date("The "..user.sName.." told us at %T that he or shee is away! He or she left this message: ")..arg.." .")
      awayArray[user.sName]=arg
      return 1
   elseif cmd == "+back" then
      if (awayArray[user.sName] == nil) then
      else
      SendToAll(Bot, date("The "..user.sName.." Returned at %T!"))
      awayArray[user.sName]=nil
      end
      return 1
   elseif cmd == "+newdk" then
      user:SendPM(Bot, filecontents)
      Readtextfile(user, "new dk.txt")
      return 1
   elseif cmd == "+newen" then
      user:SendPM(Bot,filecontents)
      Readtextfile(user, "new en.txt")
      return 1
   elseif cmd == "+adduser" and user.bOperator then
      local s,e,cmd,mode,AddName,AddPass = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)" )
      local usr=GetItemByName(AddName)
      if mode == "reg" then
      level = 3
      level1 = "REG"
      elseif mode == "vip" then
      level = 2
      level1 = "VIP"
      elseif mode == "op" then
      level = 1
      level1 = "Operator"
      elseif mode =="net" then
      level = 4
      level1= "NetFounder"
      elseif mode == "adm" then
      level = 0
      level1= "Master"
      elseif mode == "svip" then
      level = 5
      level1 = "SVIP"
      end
      if AddPass == nil or mode == nil then
         user:SendData(Bot,"Wrong Syntax read the help menu before you try to use commands !")
elseif not strfind(AddPass, "%d") then
user:SendData(Bot,"Hello "..user.sName.." ,For security issues , please use some numbers in the password ! !")
      elseif strfind(AddPass, "?") then
user:SendData(Bot,"Hello "..user.sName.." ,The password can not be with spaces ! !")
      elseif strlen(AddPass) < 3 then
         user:SendData(Bot,"Hello "..user.sName.." the inserted password is to short, below 3 characters is not allowed")
      else
      for i = 1, getn(Symbol) do
    pass = gsub(AddPass, Symbol[i], "")
end
         AddRegUser(AddName, pass, level)
        SendToOps(Bot,"Op-Msg : "..user.sName.." *** have succesfully registered the user > "..AddName.." <  as "..level1.."!! ***")
            local user=GetItemByName(AddName)
        if user ~= nil then
user:SendPM(Bot," "..
"\r\nWelcome to "..frmHub:GetHubName().."\r\n\r\n"..
"Please add these details to your favourites:\r\n\r\n"..
"Hub Name:\t "..frmHub:GetHubName().."\r\n"..
"User Name:\t"..AddName.."\r\n"..
"Password:\t"..pass.."\r\n\r\n"..
"Enjoy your stay .......")
SendToAll(Bot,"We have a new "..level1.." in the hub and it is "..AddName)
end
      end        
return 1
   elseif cmd == "+myhubtime" then
local tmp = UserHubTime[user.sName]
local months, days, hours, minutes = floor(tmp/43200), floor(mod(tmp/1440, 30)), floor(mod(tmp/60, 24)), floor(mod(tmp/1, 60))
user:SendData(Bot, "You have been online : "..months.." months, "..days.." days, "..hours.." hours, "..minutes.." minutes ( "..tmp.." min ). That is "..format("%.2f",tmp/UserHubTime["HubUpTime"]*100).." % of the total HubUpTime.")
return 1
   elseif cmd == "+allhubtime"then
      user:SendData(Bot, "   -= The Top "..Max.." Campers =-\r\n"..
GetUserMaxTime().."\r\n")
return 1
   elseif cmd == "+hubtime" then
      local tmp = UserHubTime["HubUpTime"]
local months, days, hours, minutes = floor(tmp/43200), floor(mod(tmp/1440, 30)), floor(mod(tmp/60, 24)), floor(mod(tmp/1, 60))
user:SendData(Bot, "The hub has now been online : "..months.." months, "..days.." days, "..hours.." hours, "..minutes.." minutes ( "..tmp.." min ).")
return 1
   elseif cmd == "+ip" and user.bOperator then
local sTmp,count,usr,ip = "Connected User's and their IP's:\r\n\r\n",0
for usr, ip in arrIP do
count = count + 1
sTmp = sTmp.."("..count..") User: "..usr.."\tIP: "..ip.." ("..count..")\r\n"
end
user:SendPM(sBot, sTmp)
return 1
elseif cmd == "+getip" and user.bOperator then
local s,e,usr = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (usr == nil) then
user:SendPM(sBot, "Syntax Error, +getip , you must write a nick.")
elseif (GetItemByName(usr) == nil) then
user:SendPM(sBot, "The user "..usr.." isn't online.")
else
user:SendPM(sBot, "The user "..GetItemByName(usr).sName.." ip is: "..GetItemByName(usr).sIP)
end
return 1
   elseif cmd == "+mute" and user.bOperator then
      DoMute(user, data)
      return 1
   elseif cmd == "+unmute" and user.bOperator then
      DoUnMute(user, data)
      return 1
   elseif cmd == "+showmute" and user.bOperator then
      ShowMutes(user)
      return 1
   elseif cmd == "+delmute" and user.bOperator then
      MUTE={}
      SendToAll(Bot, " All the Mute's are gone ")
      return 1
   elseif cmd == "+kenny" and user.bOperator then
      kenylize(user, data)
      return 1
   elseif cmd == "+unkenny" and user.bOperator then
      Unkenylize(user, data)
return 1
   elseif cmd=="+showkenny" and user.bOperator then
ShowKennys(user)
return 1
   elseif cmd== "+unkennyall" and user.bOperator then
Kennylizednicks = {}
      SendToAll(Bot, " all kennys have gone ! ! !")
return 1
   elseif cmd == "+funhelp" then
      FunHelp(user)
      return 1
   elseif cmd == "+mypass" then
if (user.iProfile ~= -1) then
if (tPassword[user.sName]) then
user:SendData(sBot, "Hello "..user.sName.."\tYour password is : \""..tPassword[user.sName].Password.."\",\tKeep it in a safe place!")
return 1
else
user:SendData(sBot,"For some reason you could not be found!")
return 1
end
end
   elseif cmd == "+repass" and user.bOperator then
if (user.iProfile ~= -1) then
local s,e,sPass = strfind(data,"^%b<>%s+%S+%s+(%S+)")
if sPass and strlen(sPass) >= 4 then
AddRegUser(user.sName,sPass,3)
user:SendData(sBot,"Sucessfully changed your password!")
return 1
else
user:SendData(sBot,"Either you didn't enter a password or it was too short, Password must be atleast 4 characters!")
return 1
end
else
user:SendData(sBot,"You are not registered!")
return 1
end
   elseif cmd == "+changepass" and user.bOperator then
      if (user.iProfile == 0) then
         local s,e,Name,Pass = strfind(data,"^%b<>%s+%S+%s+(%S+)%s*(%S+)")
if Name then
if Pass and strlen(Pass) >= 4 then
if tPassword[Name] then
Profile = tonumber(tPassword[Name].Profile)
AddRegUser(Name,Pass,Profile)
user:SendData(sBot,"You have sucessfully changed password of "..Name.." to \""..Pass.."\"")
return 1
else
user:SendData(sBot,"\""..Name.."\" is not registered on this hub!")
                  return 1
end
else
user:SendData(sBot,"Either you didn't enter a password or it was too short, Password must be atleast 4 characters!")
return 1
end
else
user:SendData(sBot,"Please enter a name that you will change password for!")
return 1
end
end
   elseif cmd == "+getpass" and user.bOperator then
if (user.iProfile == 0) then
local s,e,Name = strfind(data,"^%b<>%s+%S+%s+(%S+)")
if Name then
if (tPassword[Name]) then
user:SendData(sBot,"\""..Name.."\"'s Password is : \""..tPassword[Name].Password.."\"")
return 1
else
user:SendData(sBot,"\""..Name.."\" is not registered in this hub!")
return 1
end
else
user:SendData(sBot,"Please enter a name to get his / hers password!")
return 1
end
end
   elseif cmd == "+passlist" and user.bOperator then
if (user.iProfile == 0) then
local s,e,sPro = strfind(data,"^%b<>%s+%S+%s+(%S+)")
if sPro then
if (tProfiles[sPro]) then
Idx = GetProfileIdx(sPro)
Profiles = GetUsersByProfile(sPro)
sMsg = ""
for i,v in Profiles do
sMsg = sMsg.."( "..v.." )\r\nPassword : "..tPassword[v].Password.."\r\n\r\n"
end
user:SendData(sBot,"\r\n\r\n"..sMsg)
return 1
else
user:SendData(sBot,"\""..sPro.."\" is not a valid profile name!")
return 1
end
else
user:SendData(sBot,"Please enter a profile name, etc : ..+passwordlist  VIP")
return 1
end
end
   elseif cmd == "+uptime" then
      local sec = clock()
local days = floor(sec/86400)
local hrs = floor((sec-(days*86400))/3600)
local min = floor((sec-(days*86400)-(hrs*3600))/60)
sec = floor(sec-(days*86400)-(hrs*3600)-(min*60))
SendToAll(Bot, "Hubben Has been Online in  "..days.." days, "..hrs.." hours "..min.." minutes and "..sec.." seconds")
return 1
   elseif cmd == "+addlink" then
      local s,e,sLink,sDesc = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(.+)")
      if (sLink == nil or sDesc == nil) then
user:SendPM(Bot, "Syntax Error, +addlink , you must write a link and a description.")
elseif (arrLink[strlower(sLink)] ~= nil) then
user:SendPM(Bot, "The Link "..sLink.." is already in our Link List.")
else
arrLink[strlower(sLink)] = {["BY"] = user.sName, ["DESC"] = sDesc}
user:SendPM(Bot, "The Link "..sLink.." has been added to our Link List, thank you.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
   elseif cmd == "+dellink" and user.bOperator then
local s,e,sLink = strfind(data, "%b<>%s+%S+%s+(.+)")
if (sLink == nil) then
user:SendPM(Bot, "Syntax Error, +dellink , you must write a link.")
elseif (arrLink[strlower(sLink)] == nil) then
user:SendPM(Bot, "The Link "..sLink.."isn't in our Link List.")
else
arrLink[strlower(sLink)] = nil
user:SendPM(Bot, "The Link "..sLink.." has been removed from our Link List.")
if (uLaterPtokax == 1) then
OnExit()
end
end
return 1
elseif cmd == "+showlink" then
local sTmp,sLink,arrTable = " -=-=-=-=-= The Link List of our HUB =-=-=-=-=- \r\n\r\n"
for sLink, arrTable in arrLink do
sTmp = sTmp.."LINK: "..sLink.." POSTED BY: "..arrTable["BY"].." DESCRIPTION: "..arrTable["DESC"].."\r\n"
end
user:SendPM(Bot, sTmp)
return 1
   elseif cmd== "+warn" and user.bOperator then
local s,e,cmd,Name,reason = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s*(.*)" )
local victim = GetItemByName(Name)
if victim ~= nil then
victim:SendPM(user.sName, "You are being warned because: "..reason)
SendToAll(Bot, user.sName.." is warning <"..Name.."> because: "..reason)
return 1
else
user:SendData(Bot, " No such nick in the userlist !! ")
end
      return 1
   elseif cmd == "+help" then
      if user.iProfile == 0 then
         MasterHelp(user)
      elseif user.iProfile == 1 then
         OpHelp(user)
      elseif user.iProfile == 4 then
         NetHelp(user)
      elseif user.iProfile == -1 then
         GuestHelp(user)
      else
         AlmHelp(user)
         return 1
      end
      return 1
   else
      user:SendData(Bot, "hello "..user.sName.." look on the function +help")
   end
end
Title:
Post by: bastya_elvtars on 31 December, 2004, 18:03:18
  else

      user:SendData(Bot, "hello "..user.sName.." look on the function +help")

delete this just confuses
Title:
Post by: Themaster on 31 December, 2004, 18:14:48
Thx
happy new year to you all
Title:
Post by: Themaster on 02 January, 2005, 00:47:54
i still got a small problem with the bot....it pass thing's dobbelt in main or a pm

function DataArrival(user, data)
   if (strsub(data, 1, 1) == "<" ) then
      local data=strsub(data,1,strlen(data)-1)
      local _,_,cmd=strfind(data, "%b<>%s+(%S+)")
      local Commands = (UserCommands(user, data, cmd))
      return Commands
   elseif (strsub(data, 1, 12) == "$OpForceMove") and (user.iProfile < 0 or user.iProfile > 0) then
      return 1
   elseif (strsub(data,1,4) == "$To:") then
      data = strsub(data,1,-2);
      local s,e,whoTo,from,arg = strfind(data,"%$To:%s+(%S+)%s+From:%s+(%S+)%s+%$%b<>%s+(.*)")
      local s,e,cmd = strfind(arg,"(%S+)")
      if (whoTo == Bot) and UserCommands(user,data,cmd) then
         return UserCommands(user,data,cmd)
      else
         for i=1,getn(ChatBots) do
            if (( whoTo == ChatBots[i].Name )) then
               if (( ChatBots[i].Allowed[user.iProfile] == 1 )) then
                  sChat = ChatBots[i].Name;
                  for b,v in ChatBots[i].Allowed do
                     if (( v == 1 )) then
                        ChatRoom(sChat,user,arg,b)
                     end
                  end
               end
            end
         end
      end
      if (strsub(data,1,7) == "$MyINFO") then
      Tag,Speed,Share = Parse(data)
      TagCheck(Tag,Speed,Share,user)
      end
      if Kennylizednicks[user.sName] == 1 then
text=kennytext[random(1, getn(kennytext))]
SendToAll(user.sName, text)
return 1
end
      if strsub(data,1,1) == "<" then
         if MUTE[user.sName] == 1 then return 1
         end
      end
      local tmp = strsub(data,1,1)
if tmp == "<" then
local s, e, str = strfind(data,"%b<> (.*)|")
if not iscommand(str) then
if (user.bOperator) then
DoUpdOpStats(user,str)
else
DoUpdUserStats(user,str)
end
end
end
if (strsub(data,1,1) == "<" ) then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind( data,"%b<>%s+(%S+)" )
if (cmd=="+stats")then
pm = 0
ShowTop15(user)
         end
      end
   end
end

Title:
Post by: bastya_elvtars on 02 January, 2005, 01:19:44
the commands function should return 1 but only in the case if a real usable command has been typed.

Hope this suggestion helps.