PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: D-J Valhala on 14 May, 2004, 08:37:32

Title: +eban (Stand-alone)
Post by: D-J Valhala on 14 May, 2004, 08:37:32
hi all :)
need one more script :)
+eban = E-Mail Ban
it will kick him from the hub but the user will never know the his e-mail is banned he will think the IP or Nick he can change the nick + ip but will not can connect coz the e-mail is banned :P
10x :D
Title:
Post by: nErBoS on 14 May, 2004, 12:31:07
Hi,

Added also a cmd to unban the email, hope it helps..

--Requested by D-J Valhala
--Made by nErBoS

sBot = "eBanner"
eban = {}
ebansv = "eban.dat"

function Main()
frmHub:RegBot(sBot)
LoadFromFile(ebansv)
end

function OnExit()
SaveToFile(ebansv , eban , "eban")
end

function NewUserConnected(user)
if (CheckForMailBan(user) == 1) then
user:SendPM(sBot, "You are banned from this HUB.")
user:Ban()
end
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "!eban" and user.bOperator) then
local s,e,email = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (email == nil) then
user:SendPM(sBot, "Syntax Error, !eban , you must write a email.")
else
if (eban[strlower(email)] ~= nil) then
user:SendPM(sBot, "This email is already banned.")
else
eban[strlower(email)] = 1
user:SendPM(sBot, "The email "..email.." has been banned.")
end
end
return 1
elseif (cmd == "!deleban" and user.bOperator) then
local s,e,email = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (email == nil) then
user:SendPM(sBot, "Syntax Error, !deleban , you must write a email.")
else
if (eban[strlower(email)] == nil) then
user:SendPM(sBot, "This email is not banned.")
else
eban[strlower(email)] = nil
user:SendPM(sBot, "The email "..email.." has been unbanned.")
end
end
return 1
end
end
end

function CheckForMailBan(user)
local found = 0
local s,e,usrMail = strfind(user.sMyInfoString, "$MyINFO $ALL [^$]+$ $[^$]*$([^$]*)$[^$]+")
if (usrMail ~= nil and usrMail ~= "") then
for mail, aux in eban do
if (strlower(mail) == strlower(usrMail)) then
found = 1
break
end
end
end
return found
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS
Title:
Post by: D-J Valhala on 14 May, 2004, 13:20:13
nope not working...
Title:
Post by: nErBoS on 14 May, 2004, 21:01:38
Hi,

Sorry i has comparing the wrong mail, the script above have been edited and fixed.

Best regards, nErBoS
Title:
Post by: D-J Valhala on 15 May, 2004, 09:32:00
nope steel not working...
and maybe you can add on the script
!ebanlist?
and it will show it like that...
"aaa@aaa.com" (Username)
10x :D
Title:
Post by: nErBoS on 15 May, 2004, 14:30:19
Hi,

I have tested the script and its working, are you trying with to enter the Hub as a OP or User ?? If you are entering as a OP will not check if the mail is ban.

Here is the script with your request...

--Requested by D-J Valhala
--Made by nErBoS

sBot = "eBanner"
eban = {}
ebansv = "eban.dat"

function Main()
frmHub:RegBot(sBot)
LoadFromFile(ebansv)
end

function OnExit()
SaveToFile(ebansv , eban , "eban")
end

function NewUserConnected(user)
if (CheckForMailBan(user) == 1) then
user:SendPM(sBot, "You are banned from this HUB.")
user:Ban()
end
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "!eban" and user.bOperator) then
local s,e,email = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (email == nil) then
user:SendPM(sBot, "Syntax Error, !eban , you must write a email.")
else
if (eban[strlower(email)] ~= nil) then
user:SendPM(sBot, "This email is already banned.")
else
eban[strlower(email)] = 1
user:SendPM(sBot, "The email "..email.." has been banned.")
end
end
return 1
elseif (cmd == "!deleban" and user.bOperator) then
local s,e,email = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (email == nil) then
user:SendPM(sBot, "Syntax Error, !deleban , you must write a email.")
else
if (eban[strlower(email)] == nil) then
user:SendPM(sBot, "This email is not banned.")
else
eban[strlower(email)] = nil
user:SendPM(sBot, "The email "..email.." has been unbanned.")
end
end
return 1
elseif (cmd == "!ebanlist" and user.bOperator) then
MailBanList(user)
return 1
end
end
end

function CheckForMailBan(user)
local found = 0
local s,e,usrMail = strfind(user.sMyInfoString, "$MyINFO $ALL [^$]+$ $[^$]*$([^$]*)$[^$]+")
if (usrMail ~= nil and usrMail ~= "") then
for mail, aux in eban do
if (strlower(mail) == strlower(usrMail)) then
found = 1
break
end
end
end
return found
end

function MailBanList(user)
local sTmp = "The Mails that are ban in this Hub:\r\n\r\n"
for mail, aux in eban do
sTmp = sTmp..mail.."\r\n"
end
user:SendPM(sBot, sTmp)
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS
Title:
Post by: D-J Valhala on 15 May, 2004, 17:17:05
damm you are good man! :D
the script work PERFECT!!! like all your scripts :)
thank you mate keep up the GooD work !:)
Title:
Post by: D-J Valhala on 15 May, 2004, 17:23:37
lil bug...
if the hub soft stop runing the hub or whan i restarted the scripts it dont saves the e-mail banneds
Title:
Post by: nErBoS on 16 May, 2004, 21:28:21
Hi,

I have tested and is saving if you restart the Hub or scripts, or shuting down the Hub.

Best regards, nErBoS
Title:
Post by: D-J Valhala on 24 May, 2004, 10:57:58
it wont save the banned Emails man look i ban a@a.com
1 restart the scripts and the hub and...

<-=<[LsD_-_BoT]>=-> The email a@a.com has been banned.
<-=<[LsD_-_BoT]>=-> The Mails that are ban in this Hub:


^^^^ you see it wont save it...
Title:
Post by: nErBoS on 24 May, 2004, 12:44:29
Hi,

I have tested this script by restarting the Hub , the script and is saving the mails. Did you modified anything on the script ???

Best regards, nErBoS
Title:
Post by: D-J Valhala on 24 May, 2004, 13:44:27
nope
Title:
Post by: nErBoS on 24 May, 2004, 15:31:14
Hi,

Ban some mails and then shut down the HUB them go to the folder script and open the eban.dat and see if the mails that you banned is there. If yes the BOT is working OK.

Best regards, nErBoS
Title:
Post by: D-J Valhala on 24 May, 2004, 17:31:24
i dont have eban.dat...
Title:
Post by: nErBoS on 24 May, 2004, 22:37:48
Hi,

So that is what is bugging your script, what version of ptokax are you using ??? The eban.dat should appear in "...ptokax\scripts\eban.dat".

Best regards, nErBoS
Title:
Post by: D-J Valhala on 25 May, 2004, 10:11:08
i use PtokaX-0.326.TestDrive4
and i know it should appear but i dont know why he not appear...
Title:
Post by: nErBoS on 25 May, 2004, 12:27:25
Hi,

OK, its explain you are using TD4, doesn't have the function OnExit that saves the ebans when restarting or closing the Hub.

Try out this on...

--Requested by D-J Valhala
--Made by nErBoS
--For TD4

sBot = "eBanner"
eban = {}
ebansv = "eban.dat"

function Main()
frmHub:RegBot(sBot)
LoadFromFile(ebansv)
end

function NewUserConnected(user)
if (CheckForMailBan(user) == 1) then
user:SendPM(sBot, "You are banned from this HUB.")
user:Ban()
end
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "!eban" and user.bOperator) then
local s,e,email = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (email == nil) then
user:SendPM(sBot, "Syntax Error, !eban , you must write a email.")
else
if (eban[strlower(email)] ~= nil) then
user:SendPM(sBot, "This email is already banned.")
else
SaveToFile(ebansv , eban , "eban")
eban[strlower(email)] = 1
user:SendPM(sBot, "The email "..email.." has been banned.")
end
end
return 1
elseif (cmd == "!deleban" and user.bOperator) then
local s,e,email = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (email == nil) then
user:SendPM(sBot, "Syntax Error, !deleban , you must write a email.")
else
if (eban[strlower(email)] == nil) then
user:SendPM(sBot, "This email is not banned.")
else
SaveToFile(ebansv , eban , "eban")
eban[strlower(email)] = nil
user:SendPM(sBot, "The email "..email.." has been unbanned.")
end
end
return 1
elseif (cmd == "!ebanlist" and user.bOperator) then
MailBanList(user)
return 1
end
end
end

function CheckForMailBan(user)
local found = 0
local s,e,usrMail = strfind(user.sMyInfoString, "$MyINFO $ALL [^$]+$ $[^$]*$([^$]*)$[^$]+")
if (usrMail ~= nil and usrMail ~= "") then
for mail, aux in eban do
if (strlower(mail) == strlower(usrMail)) then
found = 1
break
end
end
end
return found
end

function MailBanList(user)
local sTmp = "The Mails that are ban in this Hub:\r\n\r\n"
for mail, aux in eban do
sTmp = sTmp..mail.."\r\n"
end
user:SendPM(sBot, sTmp)
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS
Title:
Post by: D-J Valhala on 25 May, 2004, 12:44:05
there is now eban.dat but whan i stop the hub it wont save the email...
Title:
Post by: nErBoS on 25 May, 2004, 12:46:00
Hi,

The script will save the mails when added and removed. Try to add some mails then close the software hub and then check out eban.dat.

Best regards, nErBoS
Title:
Post by: D-J Valhala on 25 May, 2004, 12:58:49
<-=<[LsD_-_BoT]>=-> The email a@a.com has been banned.


FROM eban.dat

eban = {
}
it wont save
Title:
Post by: nErBoS on 25 May, 2004, 23:29:15
Hi,

Sorry my bad, fixed...

--Requested by D-J Valhala
--Made by nErBoS
--For TD4

sBot = "eBanner"
eban = {}
ebansv = "eban.dat"

function Main()
frmHub:RegBot(sBot)
LoadFromFile(ebansv)
end

function NewUserConnected(user)
if (CheckForMailBan(user) == 1) then
user:SendPM(sBot, "You are banned from this HUB.")
user:Ban()
end
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "!eban" and user.bOperator) then
local s,e,email = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (email == nil) then
user:SendPM(sBot, "Syntax Error, !eban , you must write a email.")
else
if (eban[strlower(email)] ~= nil) then
user:SendPM(sBot, "This email is already banned.")
else
eban[strlower(email)] = 1
user:SendPM(sBot, "The email "..email.." has been banned.")
SaveToFile(ebansv , eban , "eban")
end
end
return 1
elseif (cmd == "!deleban" and user.bOperator) then
local s,e,email = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (email == nil) then
user:SendPM(sBot, "Syntax Error, !deleban , you must write a email.")
else
if (eban[strlower(email)] == nil) then
user:SendPM(sBot, "This email is not banned.")
else
eban[strlower(email)] = nil
user:SendPM(sBot, "The email "..email.." has been unbanned.")
SaveToFile(ebansv , eban , "eban")
end
end
return 1
elseif (cmd == "!ebanlist" and user.bOperator) then
MailBanList(user)
return 1
end
end
end

function CheckForMailBan(user)
local found = 0
local s,e,usrMail = strfind(user.sMyInfoString, "$MyINFO $ALL [^$]+$ $[^$]*$([^$]*)$[^$]+")
if (usrMail ~= nil and usrMail ~= "") then
for mail, aux in eban do
if (strlower(mail) == strlower(usrMail)) then
found = 1
break
end
end
end
return found
end

function MailBanList(user)
local sTmp = "The Mails that are ban in this Hub:\r\n\r\n"
for mail, aux in eban do
sTmp = sTmp..mail.."\r\n"
end
user:SendPM(sBot, sTmp)
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS