Last active
April 21, 2017 12:17
-
-
Save SwadicalRag/88fa1163c96f75965ab3 to your computer and use it in GitHub Desktop.
Repeat after me
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function ParseStatement(msg,repper) | |
if(msg:match("^repeat[ \n\r\t]-after[ \n\r\t]-.-[ \n\r\t]-.+[ \n\r\t]-ty")) then | |
local to_repeat = msg:match("^repeat[ \n\r\t]-after[ \n\r\t]-.-[ \n\r\t]-[\"'](.+)[\"'][ \n\r\t]-x[ \n\r\t]-%d-[ \n\r\t]-ty") | |
local n = msg:match("^repeat[ \n\r\t]-after[ \n\r\t]-.-[ \n\r\t]-[\"'].+[\"'][ \n\r\t]-x[ \n\r\t]-(%d+)[ \n\r\t]-ty") | |
local person = msg:match("^repeat[ \n\r\t]-after[ \n\r\t]-([^ ]+)[ \n\r\t]-[\"'].+[\"'][ \n\r\t]-x[ \n\r\t]-%d+[ \n\r\t]-ty") | |
if not (to_repeat and tonumber(n) and person) then return end | |
local out = "" | |
local repper = (repper or "\n") | |
for i=1,tonumber(n) do | |
out = out..to_repeat..repper | |
end | |
return out:sub(1,-1-#repper),person | |
end | |
end | |
--print(ParseStatement[[repeat after me 'hi' x10 ty]]) | |
local cache = {} | |
hook.Add("Message","Repeat",function(_,__,msg,name) | |
for name_q,msgs in pairs(cache) do | |
if(name:match(name_q)) then | |
for i,msg in ipairs(msgs) do | |
print(msg) | |
cache[name_q][i] = nil | |
end | |
end | |
end | |
local st,person = ParseStatement(msg) | |
if st then | |
if(person == "me") then | |
print(st) | |
else | |
cache[person] = cache[person] or {} | |
cache[person][#cache[person]+1] = st | |
end | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment