gag.lua (1005B)
1 local Gags = { } 2 local AnsiGags = { } 3 4 local ChatGags = { } 5 local AnsiChatGags = { } 6 7 local doGags 8 local doAnsiGags 9 10 local doChatGags 11 local doAnsiChatGags 12 13 local function genericGags( gags ) 14 return 15 function( pattern, disabled ) 16 local gag = { 17 pattern = pattern, 18 19 enabled = not disabled, 20 21 enable = function( self ) 22 self.enabled = true 23 end, 24 disable = function( self ) 25 self.enabled = false 26 end, 27 } 28 29 table.insert( gags, gag ) 30 31 return gag 32 end, 33 34 function( line ) 35 for i = 1, #gags do 36 local gag = gags[ i ] 37 38 if gag.enabled and line:find( gag.pattern ) then 39 return true 40 end 41 end 42 43 return false 44 end 45 end 46 47 mud.gag, doGags = genericGags( Gags ) 48 mud.gagAnsi, doAnsiGags = genericGags( AnsiGags ) 49 50 mud.gagChat, doChatGags = genericGags( ChatGags ) 51 mud.gagAnsiChat, doChatAnsiGags = genericGags( ChatAnsiGags ) 52 53 return { 54 doGags = doGags, 55 doAnsiGags = doAnsiGags, 56 57 doChatGags = doChatGags, 58 doChatAnsiGags = doChatAnsiGags, 59 }