# HG changeset patch # User Thomas Mangin # Date 1277398148 -3600 # Node ID 11154ba6cbf682d9933f3e3f4952cb7ec6f49389 # Parent d0d1d88ec0efdc58ffe6382ef87a18846e0c9906 plugins.tell: More validation on inputs, to prevent crashes diff -r d0d1d88ec0ef -r 11154ba6cbf6 plugins/tell.lua --- a/plugins/tell.lua Tue Jun 22 14:52:53 2010 +0100 +++ b/plugins/tell.lua Thu Jun 24 17:49:08 2010 +0100 @@ -3,35 +3,37 @@ function riddim.plugins.tell(bot) bot:hook("commands/tell", function (command) - if command.room then - local s, e = command.param:find(" "); - local nick = command.param:sub(0, s - 1); - local msg = command.param:sub(s + 1); - local found = false; - - for tmp,_ in pairs(command.room.occupants) do - if tmp == nick then - found = true; - break; - end - end - - if not found then - if(tellings[nick] == nil) then - tellings[nick] = {}; - end - tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg}; - return "Ok!"; - else - if nick == command.sender.nick then - return "Tell yourself."; - else - return "" .. nick .. " is currently online!"; - end - end - else + if not command.room then return "This command is only available in groupchats."; end + if not command.param then + return "If you want me to tell someone something then do so"; + end + + local s, e = command.param:find(" "); + + if not s then + return "if you have nothing to say to "..command.param..", then leave me alone, please"; + end + + local nick = command.param:sub(0, s - 1); + local msg = command.param:sub(s + 1); + + if nick == command.sender.nick then + return "Tell yourself."; + end + + for tmp,_ in pairs(command.room.occupants) do + if tmp == nick then + return "" .. nick .. " is currently online!"; + end + end + + if tellings[nick] == nil then + tellings[nick] = {}; + end + tellings[nick][#tellings[nick] + 1] = {from=command.sender.nick, msg=msg}; + return "Ok!"; end); bot:hook("groupchat/joined", function (room)