PtokaX forum

Archive => Archived 5.0 boards => Request for scripts => Topic started by: imby on 27 February, 2005, 00:40:49

Title: simple !kick script
Post by: imby on 27 February, 2005, 00:40:49
simple !kick script please
Title:
Post by: Jaakko on 27 February, 2005, 00:52:31
And a !warn x 3 = !kick would be nice to have in it too :D
Title:
Post by: bolamix on 27 February, 2005, 09:11:46
If you already have a script doing it in lua4, it shouldn't be too hard to convert using plop's 425 converter (thx plop!). I converted a couple of my own simple scripts and it works. I still fail miserably with file operations though :(

I'll try working on the kick/warn script I use, but Mutor will probably beat me to it :P
Title:
Post by: bolamix on 02 March, 2005, 10:47:05
Here we go:
too many errors in script, scroll down for better version ;)Not tested yet, please give some feedback ;)
Title:
Post by: Pothead on 02 March, 2005, 12:59:31
Missing quote (") in
userToBeKicked:SendPM(Bot, You've been kicked by "..user.sName.." because: "..reason)

change to
[code]userToBeKicked:SendPM(Bot, "You've been kicked by "..user.sName.." because: "..reason)
Title:
Post by: bolamix on 02 March, 2005, 13:03:32
Thx Pothead, I missed that one when I translated the messages from French to English :P Otherwise the script works?
Title:
Post by: Pothead on 02 March, 2005, 14:24:49
Yes, otherwise it works fine.  A few other things you could remove:
the two else in the function NewUserConnected(user, data)  part.

the OpConnected = NewUserConnected  isn't needed either.

user:SendData(Bot, usr.." n'est pas connect?(e)." )   in the kick section could be tranlated to english, like in the warn part.

:)

(Also maybe swap the order of if (user.bOperator) then to before the if (cmd =="    bit , so it's only needed to be called once.

**Edit Oops, forgot, user:NickBan() can be removed as well, because user:Ban() does a nick ban as well :)
Title:
Post by: bolamix on 02 March, 2005, 15:26:04
QuoteOriginally posted by Pothead
Yes, otherwise it works fine.  A few other things you could remove:
the two else in the function NewUserConnected(user, data)  part.

the OpConnected = NewUserConnected  isn't needed either.

user:SendData(Bot, usr.." n'est pas connect?(e)." )   in the kick section could be tranlated to english, like in the warn part.

:)

(Also maybe swap the order of if (user.bOperator) then to before the if (cmd =="    bit , so it's only needed to be called once.

**Edit Oops, forgot, user:NickBan() can be removed as well, because user:Ban() does a nick ban as well :)
Thanks for your comments. True, I didn't pay attention to coding details, the script worked so... But now I've tried to optimize it:
- the 2 "else" have been removed
- OpConnected = NewUserConnected has been commented out...
  Maybe some people would use it for ops, I don't know
- previously non-translated bits are now translated ;)
- user.bOperator is only used once
- about Ban/NickBan: to my knowledge user:Ban() bans the IP and shows the last nick used
with this IP, but it doesn't ban the nickname; hence the user:NickBan() on top of it.
Can someone confirm this?

Here's the script again:--Requested by Hades
--Made by nErBoS
--Mods and conversion to LUA5 by bolamix March 2, 2005

Bot = frmHub:GetHubBotName()

warn = {}
kicked = {}

function NewUserConnected(user, data)
if (warn[user.sName] == 3) then
user:SendData(Bot, "You're going to be kicked because you had 3 warnings.")
user:TempBan()
warn[user.sName] = nil
end
if (kicked[user.sName] == 3) then
user:SendData(Bot, "You've had your 3 kicks, now you're banned. Happy?")
user:Ban()
user:NickBan()
kicked[user.sName] = nil
end
end

-- OpConnected = NewUserConnected --(uncomment this if you don't trust your ops... On the other hand, if you don't trust them, why are they ops? ;))

function ChatArrival(user, data)
s,e,cmd = string.find(data,"%b<>%s+(%S+)")
    if (user.bOperator) then
if (cmd=="!kick") then
local s,e,usr,reason = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if (usr == nil or reason == nil) then
user:SendData(Bot, "Syntax error: must be !kick .")
else
if (GetItemByName(usr) == nil) then
user:SendData(Bot, "The user "..usr.." is not online.")
else
local userToBeKicked = GetItemByName(usr)
SendToAll(Bot, userToBeKicked.sName.." has been kicked by "..user.sName.." because : "..reason)
userToBeKicked:SendPM(Bot, "You've been kicked by "..user.sName.." because: "..reason)
if (kicked[userToBeKicked.sName] == nil) then
kicked[userToBeKicked.sName] = 1
else

kicked[userToBeKicked.sName] = kicked[userToBeKicked.sName] + 1
end
userToBeKicked:TempBan()
end
end
end
return 1
elseif (cmd=="!warn") then
local s,e,usr,reason = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if (usr == nil or reason == nil) then
user:SendData(Bot, "Syntax error, !warn , must have a nick and reason.")
else
if (GetItemByName(usr) == nil) then
user:SendData(Bot, "The user "..usr.." is not online.")
else
local userToBeWarned = GetItemByName(usr)
userToBeWarned:SendPM(Bot, "You are being warned because: "..reason)
user:SendData(Bot, "Your warning has been sent.")
SendToAll(Bot, "User "..userToBeWarned.sName.." was warned by "..Bot.." because of "..reason)
if (warn[userToBeWarned.sName] == nil) then
warn[userToBeWarned.sName] = 1
else
warn[userToBeWarned.sName] = warn[userToBeWarned.sName] + 1
end
userToBeWarned:Disconnect()
end
end
end
return 1
else
user:SendData(Bot, "You don?t have permission to use this command.")
end
end
I'll delete the one a few posts up, to avoid too much confusion
Title:
Post by: Pothead on 02 March, 2005, 15:45:01
Ban() does an IP and nick ban. I test this. It just puts the last IP in the nick column (instead of the text -nickban-)

Might also want to add master protection, something along these lines, in the right place :)
local userToBeKicked = GetItemByName(usr)
if userToBeKicked.iProfile ~= 0 then
SendToAll(Bot, userToBeKicked.sName.." has been kicked by "..user.sName.." because : "..reason)
userToBeKicked:SendPM(Bot, "You've been kicked by "..user.sName.." because: "..reason)
if (kicked[userToBeKicked.sName] == nil) then
kicked[userToBeKicked.sName] = 1
else
kicked[userToBeKicked.sName] = kicked[userToBeKicked.sName] + 1
end
userToBeKicked:TempBan()
else
userToBeKicked:SendPM(Bot, user.sName.." tried to kick you.")
user:SendPM(Bot, userToBeKicked.sName.." is gonna kick your arse.")
end
Title:
Post by: Jaakko on 02 March, 2005, 21:11:38
Kick.lua:73: `end' expected (to close `function' at line 26) near `else' ?(
Title:
Post by: bolamix on 02 March, 2005, 21:26:52
Well I'm confused... I just tested with 0.3.3.0.b16.04.nt.rls: when I type !ban it puts the IP in the left-hand column and the nick in the right-hand column.... To me that means the nickname isn't banned... or is it? On the other hand I'm not sure whether typing "!ban user" in mainchat does exactly the same thing as the "user:Ban()" command in a script... Confused, I'm telling you.
I'll leave the NickBan in the script for now, until I'm less confused at least.

Apart from that, thx for the master protection idea and script-snippet ;)
I didn't think of it cuz I fully trust my ops, but, once again, maybe some people don't... anyway, how about this?--Requested by Hades
--Made by nErBoS
--Mods and (painful)conversion to LUA5 by bolamix with the help of Pothead March 2, 2005

Bot = frmHub:GetHubBotName()

warn = {}
kicked = {}

function NewUserConnected(user, data)
if (warn[user.sName] == 3) then
user:SendData(Bot, "You're going to be kicked because you had 3 warnings.")
user:TempBan()
warn[user.sName] = nil
end
if (kicked[user.sName] == 3) then
user:SendData(Bot, "You've had your 3 kicks, now you're banned. Happy?")
user:Ban()
user:NickBan()
kicked[user.sName] = nil
end
end

-- OpConnected = NewUserConnected --(uncomment this if you don't trust your ops... On the other hand, if you don't trust them, why are they ops? ;))

function ChatArrival(user, data)
s,e,cmd = string.find(data,"%b<>%s+(%S+)")
    if (user.bOperator) then
if (cmd=="!kick") then
local s,e,usr,reason = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if (usr == nil or reason == nil) then
user:SendData(Bot, "Syntax error: must be !kick .")
else
if (GetItemByName(usr) == nil) then
user:SendData(Bot, "The user "..usr.." is not online.")
else
local userToBeKicked = GetItemByName(usr)
if userToBeKicked.iProfile ~= 0 then
   SendToAll(Bot, userToBeKicked.sName.." has been kicked by "..user.sName.." because : "..reason)
   userToBeKicked:SendPM(Bot, "You've been kicked by "..user.sName.." because: "..reason)
   if (kicked[userToBeKicked.sName] == nil) then
  kicked[userToBeKicked.sName] = 1
  else
  kicked[userToBeKicked.sName] = kicked[userToBeKicked.sName] + 1
end
userToBeKicked:TempBan()
else
                        userToBeKicked:SendPM(Bot, user.sName.." tried to kick you.")
                        user:SendPM(Bot, userToBeKicked.sName.." is gonna kick your arse.")
end
end
end
return 1
elseif (cmd=="!warn") then
local s,e,usr,reason = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if (usr == nil or reason == nil) then
user:SendData(Bot, "Syntax error, !warn , must have a nick and reason.")
else
if (GetItemByName(usr) == nil) then
user:SendData(Bot, "The user "..usr.." is not online.")
else
local userToBeWarned = GetItemByName(usr)
userToBeWarned:SendPM(Bot, "You are being warned because: "..reason)

user:SendData(Bot, "Your warning has been sent.")
SendToAll(Bot, "User "..userToBeWarned.sName.." was warned by "..Bot.." because of "..reason)
if (warn[userToBeWarned.sName] == nil) then
warn[userToBeWarned.sName] = 1
else
warn[userToBeWarned.sName] = warn[userToBeWarned.sName] + 1
end
userToBeWarned:Disconnect()
end
end
end
return 1
else
user:SendData(Bot, "You don?t have permission to use this command.")
end
end
@ Jaakko: you sure you haven't missed the last "end" when copy-pasting? The script returns no error on my machine.
Title:
Post by: Hoke on 03 March, 2005, 10:03:01
That one gag my ops :-)

this is how i get it to work

--Requested by Hades
--Made by nErBos
--Mods and (painful)conversion to LUA5 by bolamix with the help of Pothead March 2, 2005

Bot = frmHub:GetHubBotName()

warn = {}
kicked = {}

function NewUserConnected(user, data)
if (warn[user.sName] == 3) then
user:SendPM(Bot, "You're going to be kicked because you had 3 warnings.")
user:TempBan()
warn[user.sName] = nil
end
if (kicked[user.sName] == 3) then
user:SendPM(Bot, "You've had your 3 kicks, now you're banned. Happy?")
user:Ban()
user:NickBan()
kicked[user.sName] = nil
end
end

-- OpConnected = NewUserConnected --(uncomment this if you don't trust your ops... On the other hand, if you don't trust them, why are they ops? ;))


function ChatArrival(user, data)
s,e,cmd = string.find(data,"%b<>%s+(%S+)")
if (user.bOperator) then
if (cmd=="!kick") then
local s,e,usr,reason = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if (usr == nil or reason == nil) then
user:SendData(Bot, "Syntax error: must be !kick .")
else
if (GetItemByName(usr) == nil) then
user:SendData(Bot, "The user "..usr.." is not online.")
else
local userToBeKicked = GetItemByName(usr)
if userToBeKicked.iProfile ~= 0 then
SendToAll(Bot, userToBeKicked.sName.." has been kicked by "..user.sName.." because : "..reason)
userToBeKicked:SendPM(Bot, "You've been kicked by "..user.sName.." because: "..reason)
if (kicked[userToBeKicked.sName] == nil) then
kicked[userToBeKicked.sName] = 1
else
kicked[userToBeKicked.sName] = kicked[userToBeKicked.sName] + 1
end
userToBeKicked:TempBan()
else
userToBeKicked:SendPM(Bot, user.sName.." tried to kick you.")
user:SendPM(Bot, userToBeKicked.sName.." is gonna kick your arse.")
end
end
end
return 1
elseif (cmd=="!warn") then
local s,e,usr,reason = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if (usr == nil or reason == nil) then
user:SendData(Bot, "Syntax error, !warn , must have a nick and reason.")
else
if (GetItemByName(usr) == nil) then
user:SendData(Bot, "The user "..usr.." is not online.")
else
local userToBeWarned = GetItemByName(usr)
if userToBeWarned.iProfile ~= 0 then
userToBeWarned:SendPM(Bot, "You are being warned and disconnected because: "..reason)
user:SendData(Bot, "Your warning has been sent.")
SendToAll(Bot, "User "..userToBeWarned.sName.." was warned by "..Bot.." because of "..reason)
if (warn[userToBeWarned.sName] == nil) then
warn[userToBeWarned.sName] = 1
else
warn[userToBeWarned.sName] = warn[userToBeWarned.sName] + 1
end
userToBeWarned:Disconnect()
else
userToBeWarned:SendPM(Bot, user.sName.." tried to warn you.")
user:SendPM(Bot, userToBeWarned.sName.." is gonna kick your arse.")
end
end
-- user:SendData(Bot, "You don?t have permission to use this command.")
end
return 1
end
end
end

Title:
Post by: Jaakko on 03 March, 2005, 15:51:04
It gags me too.
So you can:
a) Kick pepole or
b) Talk
but not both.

Damn
Title:
Post by: Hoke on 03 March, 2005, 15:56:17
QuoteIt gags me too.
So you can:
a) Kick pepole or
b) Talk
but not both.

Damn

Is my version same ?
Title:
Post by: bolamix on 03 March, 2005, 16:12:34
OK, I think the problem comes from the fact that Hoke added the "master-protection" lines to the "warn" part of the script, and an "else" is missing somewhere... I can't correct it right now (kids are hungry, it's tea-time here ;)), but i'll do it within an hour. Thx for your patience, I'm learning a lot through making mistakes and correcting them ^^
Title:
Post by: Hoke on 03 March, 2005, 16:27:57
For me it is working ok , i  maby mess the code up when i past is here .

now i try to get inbuilt $kick kommand in that same sript
but i can?t get it yet and now i don?t have time  :(
Title:
Post by: bolamix on 03 March, 2005, 17:39:51
Ok, this *should* be working... I hope
--Requested by Hades
--Made by nErBos
--Mods and (painful) conversion to LUA5 by bolamix with help from Pothead March 2/3, 2005

Bot = frmHub:GetHubBotName()

warn = {}
kicked = {}

function NewUserConnected(user, data)
if (warn[user.sName] == 3) then
user:SendPM(Bot, "You're going to be kicked because you had 3 warnings.")
user:TempBan()
warn[user.sName] = nil
end
if (kicked[user.sName] == 3) then
user:SendPM(Bot, "You've had your 3 kicks, now you're banned. Happy?")
user:Ban()
user:NickBan()
kicked[user.sName] = nil
end
end

-- OpConnected = NewUserConnected --(uncomment this if you don't trust your ops... On the other hand, if you don't trust them, why are they ops? ;))

function ChatArrival(user, data)
s,e,cmd = string.find(data,"%b<>%s+(%S+)")
if (user.bOperator) then
if (cmd=="!kick") then
local s,e,usr,reason = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if (usr == nil or reason == nil) then
user:SendData(Bot, "Syntax error: must be !kick .")
else
if (GetItemByName(usr) == nil) then
user:SendData(Bot, "The user "..usr.." is not online.")
else
local userToBeKicked = GetItemByName(usr)
if userToBeKicked.iProfile ~= 0 then
SendToAll(Bot, userToBeKicked.sName.." has been kicked by "..user.sName.." because : "..reason)
userToBeKicked:SendPM(Bot, "You've been kicked by "..user.sName.." because: "..reason)
if (kicked[userToBeKicked.sName] == nil) then
kicked[userToBeKicked.sName] = 1
else
kicked[userToBeKicked.sName] = kicked[userToBeKicked.sName] + 1
end
userToBeKicked:TempBan()
else
userToBeKicked:SendPM(Bot, user.sName.." tried to kick you.")
user:SendPM(Bot, userToBeKicked.sName.." is gonna kick your arse.")
end
end
end
return 1
elseif (cmd=="!warn") then
local s,e,usr,reason = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if (usr == nil or reason == nil) then
user:SendData(Bot, "Syntax error, !warn , must have a nick and reason.")
else
if (GetItemByName(usr) == nil) then
user:SendData(Bot, "The user "..usr.." is not online.")
else
local userToBeWarned = GetItemByName(usr)
if userToBeWarned.iProfile ~= 0 then
userToBeWarned:SendPM(Bot, "You are being warned and disconnected because: "..reason)
user:SendData(Bot, "Your warning has been sent.")
SendToAll(Bot, "User "..userToBeWarned.sName.." was warned by "..Bot.." because: "..reason)
if (warn[userToBeWarned.sName] == nil) then
warn[userToBeWarned.sName] = 1
else
warn[userToBeWarned.sName] = warn[userToBeWarned.sName] + 1
end
userToBeWarned:Disconnect()
else
userToBeWarned:SendPM(Bot, user.sName.." tried to warn you.")
user:SendPM(Bot, userToBeWarned.sName.." is gonna kick your arse.")
end
end
end
return 1
end
else
user:SendData(Bot, "You don't have permission to use this command.")
end
end
@Hoke: what do you mean, "get the inbuilt $kick command in that same script"?
Title:
Post by: Jaakko on 03 March, 2005, 19:56:28
Now the kick script makes my bot say "You don't have permission to use this command" when user talks in mainchat.
Title:
Post by: bolamix on 03 March, 2005, 20:21:52
Yup I just saw that ;( I finally switched to the new Ptokax for my hub (instead of testing it alone on my local machine), so now I get like *lots* of bug reports :P
Please forgive me for all these bugs, I've now rewritten it and will test it, and post it when I'm sure it works correctly.
Title:
Post by: bolamix on 03 March, 2005, 22:38:36
I believe I finally saw the light... In the end I had to make it check if the user is Op before each command is sent...
otherwise the "return 1" blocks everything the ops type, not just the commands. I guess it's due to the new ChatArrival.
Anyway, I tested it on my hub and it works fine. Hope it does for yall out there too ;)
--Requested by Hades
--Made by nErBos
--Mods and (painful)conversion to LUA5 by bolamix with help from Pothead March 2/3, 2005

Bot = frmHub:GetHubBotName()

warn = {}
kicked = {}

function NewUserConnected(user, data)
if (warn[user.sName] == 3) then
user:SendPM(Bot, "You're going to be kicked because you had 3 warnings.")
user:TempBan()
warn[user.sName] = nil
end
if (kicked[user.sName] == 3) then
user:SendPM(Bot, "You've had your 3 kicks, now you're banned. Happy?")
user:Ban()
user:NickBan()
kicked[user.sName] = nil
end
end

-- OpConnected = NewUserConnected --(uncomment this if you don't trust your ops... On the other hand, if you don't trust them, why are they ops? ;))

function ChatArrival(user, data)
s,e,cmd = string.find(data,"%b<>%s+(%S+)")
if (cmd=="!kick") then
if (user.bOperator) then
   local s,e,usr,reason = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if (usr == nil or reason == nil) then
   user:SendData(Bot, "Syntax error: must be !kick .")
else
if (GetItemByName(usr) == nil) then
  user:SendData(Bot, "The user "..usr.." is not online.")
else
local userToBeKicked = GetItemByName(usr)
if userToBeKicked.iProfile ~= 0 then
   SendToAll(Bot, userToBeKicked.sName.." has been kicked by "..user.sName.." because : "..reason)
userToBeKicked:SendPM(Bot, "You've been kicked by "..user.sName.." because: "..reason)
if (kicked[userToBeKicked.sName] == nil) then
   kicked[userToBeKicked.sName] = 1
else
kicked[userToBeKicked.sName] = kicked[userToBeKicked.sName] + 1
end
userToBeKicked:TempBan()
else
userToBeKicked:SendPM(Bot, user.sName.." tried to kick you.")
user:SendPM(Bot, userToBeKicked.sName.." is gonna kick your arse.")
end
end
end
else
user:SendData(Bot, "You don?t have permission to use this command.")
end
return 1
elseif (cmd=="!warn") then
if (user.bOperator) then
   local s,e,usr,reason = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if (usr == nil or reason == nil) then
   user:SendData(Bot, "Syntax error, !warn , must have a nick and reason.")
else
if (GetItemByName(usr) == nil) then
   user:SendData(Bot, "The user "..usr.." is not online.")
else
local userToBeWarned = GetItemByName(usr)
if userToBeWarned.iProfile ~= 0 then
   userToBeWarned:SendPM(Bot, "You are being warned and disconnected because: "..reason)
user:SendData(Bot, "Your warning has been sent.")
SendToAll(Bot, "User "..userToBeWarned.sName.." was warned by "..user.sName.." because: "..reason)
if (warn[userToBeWarned.sName] == nil) then
   warn[userToBeWarned.sName] = 1
else
warn[userToBeWarned.sName] = warn[userToBeWarned.sName] + 1
end
userToBeWarned:Disconnect()
else
userToBeWarned:SendPM(Bot, user.sName.." tried to warn you.")
user:SendPM(Bot, userToBeWarned.sName.." is gonna kick your arse.")
end
end
end
else
user:SendData(Bot, "You don?t have permission to use this command.")
end
return 1
end
end
Title:
Post by: UwV on 04 March, 2005, 12:20:19
hihi,..

I made this one ..
pretty simular in effect...
but done in another way..

click here to check it out.. (http://board.univ-angers.fr/thread.php?threadid=3789&boardid=26&styleid=1)

ps.
 it sure would have saved me an hour if i had read this post ..
it was the " GetItemByName " thingy  i needed to use to make it all work..