Author Topic: Area Script [NEW API]  (Read 3232 times)

0 Members and 1 Guest are viewing this topic.

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Area Script [NEW API]
« on: 23 January, 2008, 12:52:55 »
Hi guys, this is one of my favourite scripts, so converted it to the NEW API. I have changed the script structure so might contain bugs, if you get any then post them over here....

Code: [Select]
--[[
Area script by Hungarista
If the user add him/herself to the database, his/her area will be shown in the description.
2oo6.1o.o6.

- Some code bits taken from jiten's scripts
- Thanks to CrazyGuy for making script case insensitive
- Revised script structure by speedX
- Added Profile tables by speedX
- Converted to NEW API by speedX
]]


sBot = SetMan.GetString(21) -- The botname who send us the messages

function OnStartup()
local file = io.open("userareas.dat", "r")
if (file) then -- if we can open the file, the script runs at least once, we should read the values
tUserAreas = {}
local line = file:read()
while line do
local _,_,nick,area = string.find(line,"^(%S+)?(.*)$")
tUserAreas[string.lower(nick)] = area
line = file:read()
end
file:close()
else -- else this is the first time we use the script, so we need an empty table
tUserAreas = {}
end
local file2 = io.open("userareas.tbl", "r")
if (file2) then
tAreas = {}
local line = file2:read()
while line do
local _,_,area = string.find(line,"(.*)")
table.insert(tAreas,area)
line = file2:read()
end
file2:close()
table.sort(tAreas,  function(a,b) return a<b end)
else
tAreas = {}
end
update = TmrMan.AddTimer(60000) -- Update the MyINFO-s in every minute
end

ChatArrival = function(user,data)
local _,_,to = string.find(data,"^$To:%s(%S+)%s+From:")
local _,_,data = string.find(data,"%b<>%s*(.*)|$")
if (to and to == sBot) or not to then
local _,_,cmd = string.find(data,"%p(%S+)")
if cmd and tCommands[cmd:lower()] then
cmd = cmd:lower()
if tCommands[cmd].tLevels[user.iProfile] == 1 then
if to and to == sBot then
return Core.SendPmToNick(user.sNick,sBot,tCommands[cmd].sFunction(user,data)), true
else
  return Core.SendToNick(user.sNick,"<"..sBot.."> "..tCommands[cmd].sFunction(user,data)), true
end
else
if to and to == sBot then
return Core.SendPmToNick(user.sNick,sBot, "*** Error: You are not allowed to use this command!"), true
else
return Core.SendToNick(user.sNick,"<"..sBot.."> Error: You are not allowed to use this command!"), true
end
end
end
end
end
ToArrival = ChatArrival 
 
tCommands = { 
areaadd = {
      sFunction = function(user,data)
local _,_,area = string.find(data,"%p%S+%s*(.*)$")
for i in ipairs(tAreas) do
if string.lower(tAreas[i]) == string.lower(area) then
bIsExist = true
end
end
if bIsExist then
bIsExist = nil
return "This value is still in the database."
else
area = string.gsub(area," "," ")
table.insert(tAreas,area)
table.sort(tAreas,  function(a,b) return a<b end)
return ""..area.." has been successfully added to the database with index "..table.getn(tAreas)..""
end
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 0, }
},
areadel = {
  sFunction = function(user,data)
local _,_,area = string.find(data,"%p%S+%s*(%S+)$")
if area then
if tonumber(area) <= table.getn(tAreas) then
table.remove(tAreas,area)
table.sort(tAreas,  function(a,b) return a<b end)
bIsExist = nil
return tAreas[tonumber(area)].." has been successfully deleted from the list."
else
return "There is no area with index '"..area.."' on the list. Use the !arealist command."
end
else
return "Usage: !areadel <index>"
end
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 0, }
},
arealist = {
      sFunction = function(user,data)
local msg = "Currently avaible areas are:\r\n"
for i in ipairs(tAreas) do
msg = msg..i.." - "..tAreas[i].."\r\n"
end
if msg == "Currently avaible areas are:\r\n" then msg = "The list is empty." end
return msg
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 0, }
},
addarea = {
  sFunction = function(user,data)
    local _,_,nick,area = string.find(data,"%p%S+%s*(%S*)%s*(%d+)$")
if nick then
if tUserAreas[string.lower(nick)] then
return nick.." is already in the database from "..tUserAreas[string.lower(nick)]
else
if RegMan.GetReg(nick) then
if tonumber(area) <= table.getn(tAreas) then
tUserAreas[string.lower(nick)] = tAreas[tonumber(area)]
return nick.." has been successfully added to the database with area "..tAreas[tonumber(area)]
else
return "Ooops, you wrote too high value, the currently max is "..table.getn(tAreas)..". To list"..
" the areas, use !areas command."
end
else
return "This user isn't registered in this hub. Please register him/her first."
end
end
else
return "Usage: !addarea <nick> <areaindex>"
end
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 0, }
},
delarea = {
      sFunction = function(user,data)
local _,_,nick = string.find(data,"%p%S+%s*(%S+)$")
if tUserAreas[string.lower(nick)] then
tUserAreas[string.lower(nick)] = nil
return nick.." has been successfully deleted from the database."
else
return "This user is not in my database, please check your syntax. Use the !listareas command"
end
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 0, }
},
chgarea = {
  sFunction = function(user,data)
    local _,_,nick,area = string.find(data,"%p%S+%s*(%S+)%s*(%d+)$")
if nick then
if not tUserAreas[string.lower(nick)] then
return nick.." is not in the database, so you can't change his/her area."
else
if tonumber(area) <= table.getn(tAreas) then
tUserAreas[string.lower(nick)] = tAreas[area]
return nick.." has been successfully modified in the database with new area: "..tAreas[tonumber(area)]
else
return "Ooops, you wrote too high value, the currently max is "..table.getn(tAreas)..". To list"..
" the areas, use !areas command."
end
end
else
return "Usage: !addarea <nick> <area>"
end
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 0, }
},
listareas = {
  sFunction = function(user,data)
  local _,_,opt = string.find(data,"%p%S+%s*(.*)$")
if opt == "" then
local msg = "Currently users whoes added to the database:\r\n"
for k in pairs(tUserAreas) do
msg = msg..k.." - "..tUserAreas[k].."\r\n"
end
if msg == "Currently users whoes added to the database:\r\n" then
return "The database is empty yet..."
else
return msg
end
else
local msg = "Users from "..opt.." are:\r\n"
for k in pairs(tUserAreas) do
if string.lower(tUserAreas[k]) == string.lower(opt) then
msg = msg..k.."\r\n"
end
end
if msg == "Users from "..opt.." are:\r\n" then
return "Check your syntax! There is nobody from "..opt
else
return "..msg.."
end
end
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 0, [5] = 0, }
},
areastat = {
  sFunction = function(user,data)
    local tCount = {}
for k in pairs(tUserAreas) do
table.insert(tCount,k)
end
local iACounter = table.getn(tCount)
local iRCounter = table.getn(RegMan.GetRegs())
return "There are "..iACounter.." users in the area-database, and there are "..
iRCounter.." registered users in the hub-database ("..iRCounter-iACounter.." users "..
"are remaining)! Totally "..math.floor((iACounter/iRCounter)*100).."% of registered users in the database."
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 0, }
}
}

function OnTimer(update)
for i,v in ipairs(Core.GetOnlineUsers(true)) do
if tUserAreas[string.lower(v.sNick)] then
local myinfo = "$MyINFO $ALL "..v.sNick.." "..tUserAreas[string.lower(v.sNick)].." - "..(v.sDescription or "")..(v.sTag or "").."$ $"..(v.sConnection or "")..string.char(v.iMagicByte or "").."$"..(v.sEmail or "").."$"..(v.iShareSize or "").."$"
Core.SendToAll(myinfo)
end
end
end

function OnExit()
local file = io.open("userareas.dat", "w")
if file then
for key, value in pairs(tUserAreas) do
file:write(key.."?"..value.."\r\n")
end
end
file:close()
local file2 = io.open("userareas.tbl", "w")
if file2 then
for index, value in ipairs(tAreas) do
file2:write(value.."\r\n")
end
end
file2:close()
end
« Last Edit: 23 January, 2008, 18:22:23 by speedX »
Thanking You,

speedX

PtokaX forum

Area Script [NEW API]
« on: 23 January, 2008, 12:52:55 »

Offline Yahoo

  • Triple Ace
  • **
  • Posts: 225
  • Karma: +32/-14
  • People Say "I Dont Know English"
    • Yahoo
Re: Area Script [NEW API]
« Reply #1 on: 26 April, 2008, 07:36:57 »
just a small modification if possible if a user havent added his area he must get a message to add his area
"BoRN FIGhTEr"

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: Area Script [NEW API]
« Reply #2 on: 28 April, 2008, 11:31:53 »
Code: [Select]
--[[
Area script by Hungarista
If the user add him/herself to the database, his/her area will be shown in the description.
2oo6.1o.o6.

- Some code bits taken from jiten's scripts
- Thanks to CrazyGuy for making script case insensitive
- Revised script structure by speedX
- Added Profile tables by speedX
- Converted to NEW API by speedX

Version 1.1 by speedX
  - Message is sent to users with no area in description    - Requested by Yahoo

]]


sBot = SetMan.GetString(21) -- The botname who send us the messages

-- Message to be sent to users with no area
sMsg = "Please PM your area name to any operator of this hub"

----------------------------------------------------------------------------------------------------
function OnStartup()
local file = io.open("userareas.dat", "r")
if (file) then -- if we can open the file, the script runs at least once, we should read the values
tUserAreas = {}
local line = file:read()
while line do
local _,_,nick,area = string.find(line,"^(%S+)?(.*)$")
tUserAreas[string.lower(nick)] = area
line = file:read()
end
file:close()
else -- else this is the first time we use the script, so we need an empty table
tUserAreas = {}
end
local file2 = io.open("userareas.tbl", "r")
if (file2) then
tAreas = {}
local line = file2:read()
while line do
local _,_,area = string.find(line,"(.*)")
table.insert(tAreas,area)
line = file2:read()
end
file2:close()
table.sort(tAreas,  function(a,b) return a<b end)
else
tAreas = {}
end
update = TmrMan.AddTimer(60000) -- Update the MyINFO-s in every minute
end

ChatArrival = function(user,data)
local _,_,to = string.find(data,"^$To:%s(%S+)%s+From:")
local _,_,data = string.find(data,"%b<>%s*(.*)|$")
if (to and to == sBot) or not to then
local _,_,cmd = string.find(data,"%p(%S+)")
if cmd and tCommands[cmd:lower()] then
cmd = cmd:lower()
if tCommands[cmd].tLevels[user.iProfile] == 1 then
if to and to == sBot then
return Core.SendPmToNick(user.sNick,sBot,tCommands[cmd].sFunction(user,data)), true
else
  return Core.SendToNick(user.sNick,"<"..sBot.."> "..tCommands[cmd].sFunction(user,data)), true
end
else
if to and to == sBot then
return Core.SendPmToNick(user.sNick,sBot, "*** Error: You are not allowed to use this command!"), true
else
return Core.SendToNick(user.sNick,"<"..sBot.."> Error: You are not allowed to use this command!"), true
end
end
end
end
end
ToArrival = ChatArrival 
 
tCommands = { 
areaadd = {
      sFunction = function(user,data)
local _,_,area = string.find(data,"%p%S+%s*(.*)$")
for i in ipairs(tAreas) do
if string.lower(tAreas[i]) == string.lower(area) then
bIsExist = true
end
end
if bIsExist then
bIsExist = nil
return "This value is still in the database."
else
area = string.gsub(area," "," ")
table.insert(tAreas,area)
table.sort(tAreas,  function(a,b) return a<b end)
return ""..area.." has been successfully added to the database with index "..table.getn(tAreas)..""
end
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 0, }
},
areadel = {
  sFunction = function(user,data)
local _,_,area = string.find(data,"%p%S+%s*(%S+)$")
if area then
if tonumber(area) <= table.getn(tAreas) then
table.remove(tAreas,area)
table.sort(tAreas,  function(a,b) return a<b end)
bIsExist = nil
return tAreas[tonumber(area)].." has been successfully deleted from the list."
else
return "There is no area with index '"..area.."' on the list. Use the !arealist command."
end
else
return "Usage: !areadel <index>"
end
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 0, }
},
arealist = {
      sFunction = function(user,data)
local msg = "Currently avaible areas are:\r\n"
for i in ipairs(tAreas) do
msg = msg..i.." - "..tAreas[i].."\r\n"
end
if msg == "Currently avaible areas are:\r\n" then msg = "The list is empty." end
return msg
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 0, }
},
addarea = {
  sFunction = function(user,data)
    local _,_,nick,area = string.find(data,"%p%S+%s*(%S*)%s*(%d+)$")
if nick then
if tUserAreas[string.lower(nick)] then
return nick.." is already in the database from "..tUserAreas[string.lower(nick)]
else
if RegMan.GetReg(nick) then
if tonumber(area) <= table.getn(tAreas) then
tUserAreas[string.lower(nick)] = tAreas[tonumber(area)]
return nick.." has been successfully added to the database with area "..tAreas[tonumber(area)]
else
return "Ooops, you wrote too high value, the currently max is "..table.getn(tAreas)..". To list"..
" the areas, use !areas command."
end
else
return "This user isn't registered in this hub. Please register him/her first."
end
end
else
return "Usage: !addarea <nick> <areaindex>"
end
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 0, }
},
delarea = {
      sFunction = function(user,data)
local _,_,nick = string.find(data,"%p%S+%s*(%S+)$")
if tUserAreas[string.lower(nick)] then
tUserAreas[string.lower(nick)] = nil
return nick.." has been successfully deleted from the database."
else
return "This user is not in my database, please check your syntax. Use the !listareas command"
end
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 0, }
},
chgarea = {
  sFunction = function(user,data)
    local _,_,nick,area = string.find(data,"%p%S+%s*(%S+)%s*(%d+)$")
if nick then
if not tUserAreas[string.lower(nick)] then
return nick.." is not in the database, so you can't change his/her area."
else
if tonumber(area) <= table.getn(tAreas) then
tUserAreas[string.lower(nick)] = tAreas[area]
return nick.." has been successfully modified in the database with new area: "..tAreas[tonumber(area)]
else
return "Ooops, you wrote too high value, the currently max is "..table.getn(tAreas)..". To list"..
" the areas, use !areas command."
end
end
else
return "Usage: !addarea <nick> <area>"
end
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 0, }
},
listareas = {
  sFunction = function(user,data)
  local _,_,opt = string.find(data,"%p%S+%s*(.*)$")
if opt == "" then
local msg = "Currently users whoes added to the database:\r\n"
for k in pairs(tUserAreas) do
msg = msg..k.." - "..tUserAreas[k].."\r\n"
end
if msg == "Currently users whoes added to the database:\r\n" then
return "The database is empty yet..."
else
return msg
end
else
local msg = "Users from "..opt.." are:\r\n"
for k in pairs(tUserAreas) do
if string.lower(tUserAreas[k]) == string.lower(opt) then
msg = msg..k.."\r\n"
end
end
if msg == "Users from "..opt.." are:\r\n" then
return "Check your syntax! There is nobody from "..opt
else
return "..msg.."
end
end
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 0, [5] = 0, }
},
areastat = {
  sFunction = function(user,data)
    local tCount = {}
for k in pairs(tUserAreas) do
table.insert(tCount,k)
end
local iACounter = table.getn(tCount)
local iRCounter = table.getn(RegMan.GetRegs())
return "There are "..iACounter.." users in the area-database, and there are "..
iRCounter.." registered users in the hub-database ("..iRCounter-iACounter.." users "..
"are remaining)! Totally "..math.floor((iACounter/iRCounter)*100).."% of registered users in the database."
end,
tLevels = { [-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 0, }
}
}

function OnTimer(update)
for i,v in ipairs(Core.GetOnlineUsers(true)) do
if tUserAreas[string.lower(v.sNick)] then
local myinfo = "$MyINFO $ALL "..v.sNick.." "..tUserAreas[string.lower(v.sNick)].." - "..(v.sDescription or "")..(v.sTag or "").."$ $"..(v.sConnection or "")..string.char(v.iMagicByte or "").."$"..(v.sEmail or "").."$"..(v.iShareSize or "").."$"
Core.SendToAll(myinfo)
else
  Core.SendPmToNick(v.sNick,sBot,sMsg)
end
end
end

function OnExit()
local file = io.open("userareas.dat", "w")
if file then
for key, value in pairs(tUserAreas) do
file:write(key.."?"..value.."\r\n")
end
end
file:close()
local file2 = io.open("userareas.tbl", "w")
if file2 then
for index, value in ipairs(tAreas) do
file2:write(value.."\r\n")
end
end
file2:close()
end
-----------------------------------------------------------------------------------------------------
« Last Edit: 28 April, 2008, 11:41:09 by speedX »
Thanking You,

speedX

Offline reaper

  • Junior Member
  • **
  • Posts: 14
  • Karma: +2/-2
Re: Area Script [NEW API]
« Reply #3 on: 16 November, 2008, 18:05:27 »
plz can you explain what this script are for ????

Offline ?StIfFLEr??

  • Triple Ace
  • **
  • Posts: 241
  • Karma: +17/-63
Re: Area Script [NEW API]
« Reply #4 on: 17 November, 2008, 01:30:15 »
Add right click function to it if possible.


PtokaX forum

Re: Area Script [NEW API]
« Reply #4 on: 17 November, 2008, 01:30:15 »