ain't afraid of no sleep,

This commit is contained in:
Yessiest 2022-05-20 22:20:49 +04:00
parent 38c9e580b9
commit ca17b716ba
9 changed files with 481 additions and 481 deletions

View File

@ -2,202 +2,202 @@
--P.S: air stands for Advanced Input Recognition, although technically it's not all that advanced --P.S: air stands for Advanced Input Recognition, although technically it's not all that advanced
air = {} air = {}
air.match_strings = function(string) air.match_strings = function(string)
local strings = {} local strings = {}
string = string:gsub("\"(.-[^\\])\"",function(capt) string = string:gsub("\"(.-[^\\])\"",function(capt)
string_id = string_id + 1 string_id = string_id + 1
strings["%str"..string_id] = capt:gsub("\\\"","\"") strings["%str"..string_id] = capt:gsub("\\\"","\"")
return " %str"..string_id return " %str"..string_id
end) end)
return string,strings return string,strings
end end
local function parse_strings(thing,strings) local function parse_strings(thing,strings)
--find all strings and replace them with string ids with no spaces --find all strings and replace them with string ids with no spaces
local strings = strings or {} local strings = strings or {}
local string_count = 0 local string_count = 0
local function get_string(text) local function get_string(text)
string_count = string_count + 1 string_count = string_count + 1
local id = "&;"..tostring(string_count)..";&" local id = "&;"..tostring(string_count)..";&"
strings[string_count] = text strings[string_count] = text
return id return id
end end
thing = thing:gsub("(\")\"",get_string) thing = thing:gsub("(\")\"",get_string)
thing = thing:gsub("(\".-[^\\])\"",get_string) thing = thing:gsub("(\".-[^\\])\"",get_string)
thing = thing:gsub("(\')\'",get_string) thing = thing:gsub("(\')\'",get_string)
thing = thing:gsub("(\'.-[^\\])\'",get_string) thing = thing:gsub("(\'.-[^\\])\'",get_string)
return thing,strings return thing,strings
end end
--this table will look up special types --this table will look up special types
special_case = { special_case = {
["voiceChannel"] = function(id,client,guild_id) ["voiceChannel"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id) local guild = client:getGuild(guild_id)
local channel = guild:getChannel(id:match("(%d+)[^%d]*$")) local channel = guild:getChannel(id:match("(%d+)[^%d]*$"))
if tostring(channel):match("^GuildVoiceChannel: ") then if tostring(channel):match("^GuildVoiceChannel: ") then
return true,channel return true,channel
else else
return false return false
end
end,
["textChannel"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id)
local channel = guild:getChannel(id:match("(%d+)[^%d]*$"))
if tostring(channel):match("^GuildTextChannel: ") then
return true,channel
else
return false
end
end,
["messageLink"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id)
local channelId,messageId = id:match("(%d+)/(%d+)[^%d]*$")
channel = guild:getChannel(channelId)
if tostring(channel):find("GuildTextChannel") then
message = channel:getMessage(messageId)
if message then
return true,message
end
end
return false
end,
["role"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id)
local role = guild:getRole(id:match("(%d+)[^%d]*$"))
if role then
return true,role
else
return false
end
end,
["member"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id)
local member = guild:getMember(id:match("(%d+)[^%d]*$"))
if member then
return true,member
else
return false
end
end,
["emoji"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id)
local emoji = guild:getEmoji(id:match("(%d+)[^%d]*$"))
if emoji then
return true,emoji
else
return false
end
end,
["ban"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id)
local ban = guild:getBan(id:match("(%d+)[^%d]*$"))
if ban then
return true,ban
else
return false
end
end,
["channel"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id)
local channel = guild:getChannel(id:match("(%d+)[^%d]*$"))
if channel then
return true,channel
else
return false
end
end,
["user"] = function(id,client,guild_id)
local user = client:getUser(id:match("(%d+)[^%d]*$"))
if user then
return true,user
end
return false
end,
["id"] = function(id)
if tonumber(id:match("(%d+)[^%d]*$")) and tostring(id:match("(%d+)[^%d]*$")):len() > 10 then
return true,id
end
return false
end end
end,
["textChannel"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id)
local channel = guild:getChannel(id:match("(%d+)[^%d]*$"))
if tostring(channel):match("^GuildTextChannel: ") then
return true,channel
else
return false
end
end,
["messageLink"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id)
local channelId,messageId = id:match("(%d+)/(%d+)[^%d]*$")
channel = guild:getChannel(channelId)
if tostring(channel):find("GuildTextChannel") then
message = channel:getMessage(messageId)
if message then
return true,message
end
end
return false
end,
["role"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id)
local role = guild:getRole(id:match("(%d+)[^%d]*$"))
if role then
return true,role
else
return false
end
end,
["member"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id)
local member = guild:getMember(id:match("(%d+)[^%d]*$"))
if member then
return true,member
else
return false
end
end,
["emoji"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id)
local emoji = guild:getEmoji(id:match("(%d+)[^%d]*$"))
if emoji then
return true,emoji
else
return false
end
end,
["ban"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id)
local ban = guild:getBan(id:match("(%d+)[^%d]*$"))
if ban then
return true,ban
else
return false
end
end,
["channel"] = function(id,client,guild_id)
local guild = client:getGuild(guild_id)
local channel = guild:getChannel(id:match("(%d+)[^%d]*$"))
if channel then
return true,channel
else
return false
end
end,
["user"] = function(id,client,guild_id)
local user = client:getUser(id:match("(%d+)[^%d]*$"))
if user then
return true,user
end
return false
end,
["id"] = function(id)
if tonumber(id:match("(%d+)[^%d]*$")) and tostring(id:match("(%d+)[^%d]*$")):len() > 10 then
return true,id
end
return false
end
} }
air.parse = function(string,argmatch,client,guild_id) air.parse = function(string,argmatch,client,guild_id)
local args,opts = {},{} local args,opts = {},{}
local string_id = 0 local string_id = 0
local strings = {} local strings = {}
string = string:gsub("[%s\n]+\"\"",function(capt) string = string:gsub("[%s\n]+\"\"",function(capt)
string_id = string_id + 1 string_id = string_id + 1
strings["%str"..string_id] = "" strings["%str"..string_id] = ""
return " %str"..string_id return " %str"..string_id
end) end)
string = string:gsub("[%s\n]+\"(.-[^\\])\"",function(capt) string = string:gsub("[%s\n]+\"(.-[^\\])\"",function(capt)
string_id = string_id + 1 string_id = string_id + 1
strings["%str"..string_id] = capt:gsub("\\\"","\"") strings["%str"..string_id] = capt:gsub("\\\"","\"")
return " %str"..string_id return " %str"..string_id
end) end)
string = string:gsub("[%s\n]+%-%-(%w+)=\"\"",function(name) string = string:gsub("[%s\n]+%-%-(%w+)=\"\"",function(name)
opts[name] = "" opts[name] = ""
return "" return ""
end) end)
string = string:gsub("[%s\n]+%-%-(%w+)=\"(.-[^\\])\"",function(name,value) string = string:gsub("[%s\n]+%-%-(%w+)=\"(.-[^\\])\"",function(name,value)
opts[name] = value:gsub("\\\"","\"") opts[name] = value:gsub("\\\"","\"")
return "" return ""
end) end)
string = string:gsub("[%s\n]+%-%-(%w+)=(%S+)",function(name,value) string = string:gsub("[%s\n]+%-%-(%w+)=(%S+)",function(name,value)
opts[name] = value opts[name] = value
return "" return ""
end) end)
string = string:gsub("[%s\n]+%-%-(%w+)",function(name) string = string:gsub("[%s\n]+%-%-(%w+)",function(name)
opts[name] = true opts[name] = true
return "" return ""
end) end)
string = string:gsub("[%s\n]+%-(%w+)",function(args) string = string:gsub("[%s\n]+%-(%w+)",function(args)
args:gsub(".",function(key) args:gsub(".",function(key)
opts[key] = true opts[key] = true
end)
return ""
end)
string:gsub("([^%s\n]+)",function(match)
table.insert(args,match)
end) end)
return ""
end)
string:gsub("([^%s\n]+)",function(match)
table.insert(args,match)
end)
for k,v in pairs(args) do
if v:match("%%str%d+") then
if strings[v] then
args[k] = strings[v]
end
end
end
if argmatch and #argmatch > 0 then
local match,err = false
local new_args = {}
for k,v in pairs(argmatch) do
if not args[k] then
match = false
err = "Missing arguments: "..table.concat(argmatch,", ",k)
break
end
if v == "number" and tonumber(args[k]) then
match = true
new_args[k] = tonumber(args[k])
elseif v == "string" then
match = true
new_args[k] = args[k]
elseif special_case[v] then
match,new_args[k] = special_case[v](args[k],client,guild_id)
else
match = false
end
if match == false then
err = "Type mismatch for argument "..k..": "..argmatch[k].." expected."
break
end
end
for k,v in pairs(args) do for k,v in pairs(args) do
if not new_args[k] then if v:match("%%str%d+") then
new_args[k] = v if strings[v] then
end args[k] = strings[v]
end
end
end
if argmatch and #argmatch > 0 then
local match,err = false
local new_args = {}
for k,v in pairs(argmatch) do
if not args[k] then
match = false
err = "Missing arguments: "..table.concat(argmatch,", ",k)
break
end
if v == "number" and tonumber(args[k]) then
match = true
new_args[k] = tonumber(args[k])
elseif v == "string" then
match = true
new_args[k] = args[k]
elseif special_case[v] then
match,new_args[k] = special_case[v](args[k],client,guild_id)
else
match = false
end
if match == false then
err = "Type mismatch for argument "..k..": "..argmatch[k].." expected."
break
end
end
for k,v in pairs(args) do
if not new_args[k] then
new_args[k] = v
end
end
return match,new_args,opts,err
else
return true,args,opts
end end
return match,new_args,opts,err
else
return true,args,opts
end
end end
return air return air

View File

@ -1,48 +1,48 @@
return function(message,overrides) return function(message,overrides)
assert(type(message) == "table","table expected, got "..type(message)) assert(type(message) == "table","table expected, got "..type(message))
assert(type(overrides) == "table","table expected for arg#2, got "..type(overrides)) assert(type(overrides) == "table","table expected for arg#2, got "..type(overrides))
local fake = {content = message.content, local fake = {content = message.content,
author = message.author, author = message.author,
member = message.guild:getMember(message.author.id), member = message.guild:getMember(message.author.id),
channel = message.channel, channel = message.channel,
client = message.client, client = message.client,
guild = message.guild, guild = message.guild,
delete = function() message:delete() end, delete = function() message:delete() end,
reply = function(thing,...) reply = function(thing,...)
message.channel:send(...) message.channel:send(...)
end, end,
createdAt = message.createdAt, createdAt = message.createdAt,
_parent = message.parent, _parent = message.parent,
parent = message.parent, parent = message.parent,
id = message.id, id = message.id,
attachment = message.attachment, attachment = message.attachment,
attachments = message.attachments, attachments = message.attachments,
cleanContent = message.cleanContent, cleanContent = message.cleanContent,
editedTimestamp = message.editedTimestamp, editedTimestamp = message.editedTimestamp,
embed = message.embed, embed = message.embed,
embeds = message.embeds, embeds = message.embeds,
link = message.link, link = message.link,
mentionedChannels = message.mentionedChannels, mentionedChannels = message.mentionedChannels,
mentionedEmojis = message.mentionedEmojis, mentionedEmojis = message.mentionedEmojis,
mentionedRoles = message.mentionedRoles, mentionedRoles = message.mentionedRoles,
mentionedUsers = message.mentionedUsers, mentionedUsers = message.mentionedUsers,
nonce = message.nonce, nonce = message.nonce,
oldContent = message.oldContent, oldContent = message.oldContent,
pinned = message.pinned, pinned = message.pinned,
reactions = message.reactions, reactions = message.reactions,
tts = message.tts, tts = message.tts,
type = message.type, type = message.type,
webhookId = message.webhookId, webhookId = message.webhookId,
addReaction = function(self,...) addReaction = function(self,...)
message:addReaction(...) message:addReaction(...)
end, end,
removeReaction = function(self,...) removeReaction = function(self,...)
message:removeReaction(...) message:removeReaction(...)
end, end,
emulated = true emulated = true
} }
for k,v in pairs(overrides) do for k,v in pairs(overrides) do
fake[k] = v fake[k] = v
end end
return fake return fake
end end

View File

@ -2,112 +2,112 @@
local file = {} local file = {}
local json local json
if pcall(import,"json") then if pcall(import,"json") then
json = import("json") json = import("json")
elseif pcall(require,"json") then elseif pcall(require,"json") then
json = require("json") json = require("json")
end end
file.safe = true file.safe = true
file.read = function(filename,mode) file.read = function(filename,mode)
assert(type(filename) == "string","string expected, got "..type(filename)) assert(type(filename) == "string","string expected, got "..type(filename))
local mode = mode or "*a" local mode = mode or "*a"
local temp_file,err = io.open(filename,r) local temp_file,err = io.open(filename,r)
if err then if err then
if not file.safe then error(err) else if not file.safe then error(err) else
ret_string = "" ret_string = ""
end
else
ret_string = temp_file:read(mode)
temp_file:close()
end end
else return ret_string,err
ret_string = temp_file:read(mode)
temp_file:close()
end
return ret_string,err
end end
file.write = function(filename,write) file.write = function(filename,write)
assert(type(filename) == "string", "string expected, got "..type(filename)) assert(type(filename) == "string", "string expected, got "..type(filename))
assert(type(write) == "string", "string expected for argument #2, got "..type(write)) assert(type(write) == "string", "string expected for argument #2, got "..type(write))
local temp_file,err = io.open(filename,"w+") local temp_file,err = io.open(filename,"w+")
local status = false local status = false
if err then if err then
if not file.safe then error(err) else if not file.safe then error(err) else
status = false status = false
end
else
temp_file:write(write)
temp_file:close()
status = true
end end
else return status,err
temp_file:write(write)
temp_file:close()
status = true
end
return status,err
end end
file.exists = function(filename) file.exists = function(filename)
local file = io.open(filename,"r") local file = io.open(filename,"r")
if file then if file then
file:close() file:close()
return true return true
else else
return false return false
end end
end end
file.existsDir = function(filename) file.existsDir = function(filename)
local file = io.open(filename.."/stuff","w") local file = io.open(filename.."/stuff","w")
if file then if file then
file:close() file:close()
os.remove(filename.."/stuff") os.remove(filename.."/stuff")
return true return true
else else
return false return false
end end
end end
file.ls = function(path) file.ls = function(path)
if file.existsDir(path) then if file.existsDir(path) then
local ls_handle = io.popen("ls -1 "..path,"r") local ls_handle = io.popen("ls -1 "..path,"r")
local ls_data = ls_handle:read("*a") local ls_data = ls_handle:read("*a")
ls_handle:close() ls_handle:close()
return ls_data return ls_data
else else
return false, "No such file or directory" return false, "No such file or directory"
end end
end end
if json then if json then
file.readJSON = function(filename,default) file.readJSON = function(filename,default)
assert(type(filename) == "string","string expected, got "..type(filename)) assert(type(filename) == "string","string expected, got "..type(filename))
local json_data,err = file.read(filename,"*a") local json_data,err = file.read(filename,"*a")
local table_data, status local table_data, status
if err then if err then
if not file.safe then error(err) else if not file.safe then error(err) else
status = err status = err
table_data = default or {} table_data = default or {}
end end
else else
table_data,_,err = json.decode(json_data) table_data,_,err = json.decode(json_data)
if not table_data then if not table_data then
if not file.safe then error(err) else if not file.safe then error(err) else
status = err status = err
table_data = default or {} table_data = default or {}
end
end
end end
end return table_data, status
end end
return table_data, status file.writeJSON = function(filename,table_data)
end assert(type(filename) == "string","string expected, got "..type(filename))
file.writeJSON = function(filename,table_data) assert(type(table_data) == "table","table expected, got "..type(table_data))
assert(type(filename) == "string","string expected, got "..type(filename)) local status = false
assert(type(table_data) == "table","table expected, got "..type(table_data)) local status,json_object,_,err = pcall(function() return json.encode(table_data) end)
local status = false if not status then
local status,json_object,_,err = pcall(function() return json.encode(table_data) end) if not file.safe then error(err) else
if not status then status = false
if not file.safe then error(err) else err = json_object
status = false end
err = json_object else
end if json_object then
else status,err = file.write(filename,json_object)
if json_object then end
status,err = file.write(filename,json_object) end
end return status, err
end end
return status, err
end
end end
return file return file

View File

@ -1,39 +1,39 @@
--Luvit's deadly sin - a library that fixes the dumbest problem in luvit --Luvit's deadly sin - a library that fixes the dumbest problem in luvit
--That is, unability to load core modules from the files that were required --That is, unability to load core modules from the files that were required
return function(reqfunc) return function(reqfunc)
local function import(path) local function import(path)
local paths = { } local paths = {}
package.path:gsub("[^;]+",function(path) package.path:gsub("[^;]+",function(path)
table.insert(paths,path) table.insert(paths,path)
end) end)
local filename = path:gsub("%.","/") local filename = path:gsub("%.","/")
local file = io.open(filename..".lua","r") local file = io.open(filename..".lua","r")
local iterator = 0 local iterator = 0
local last_filename = "" local last_filename = ""
while not file do while not file do
iterator = iterator + 1 iterator = iterator + 1
if paths[iterator] then if paths[iterator] then
file = io.open(paths[iterator]:gsub("%?",filename),"r") file = io.open(paths[iterator]:gsub("%?",filename),"r")
last_filename = paths[iterator] last_filename = paths[iterator]
else else
break break
end end
end
if not file then
return reqfunc(path)
else
content = file:read("*a")
local f,err = load(content,"import: "..filename,nil,setmetatable({
require = reqfunc,
import = import,
},{__index = _G}))
if err then
error("[import: "..filname.."] "..tostring(err))
end
return f()
end
end end
if not file then return import
return reqfunc(path)
else
content = file:read("*a")
local func,err = load(content,"import: "..filename,nil,setmetatable({
require = reqfunc,
import = import,
},{__index = _G}))
if err then
error(err)
end
return func()
end
end
return import
end end
--[[ --[[
Usage: Usage:

@ -1 +1 @@
Subproject commit 9e6f09050f9ebecc4ffcea1234b920468254a79b Subproject commit 23fcea17c2eb380b6a6b1ba848d5bc7ebdc38b05

View File

@ -1,123 +1,123 @@
local markov = {} local markov = {}
local function node(relations) local function node(relations)
local node = {} local node = {}
local total = 0 local total = 0
for k,v in pairs(relations) do for k,v in pairs(relations) do
total = total + v.occurences total = total + v.occurences
end end
for k,v in pairs(relations) do for k,v in pairs(relations) do
node[k] = {probability = v.occurences/total,occurences = v.occurences} node[k] = {probability = v.occurences/total,occurences = v.occurences}
end end
return node return node
end end
local function escape(str) local function escape(str)
return str:gsub("([%%%*%(%)%^%.%[%]%+%-%$%?])","%%%1") return str:gsub("([%%%*%(%)%^%.%[%]%+%-%$%?])","%%%1")
end end
local function register_words(str,word_list) local function register_words(str,word_list)
local word_list = word_list or {} local word_list = word_list or {}
str:gsub("%S+",function(word) str:gsub("%S+",function(word)
if not word_list[word] then if not word_list[word] then
word_list[word] = {} word_list[word] = {}
end
local current_word = word_list[word]
local escaped_word = escape(word)
str:gsub("%s+" .. escaped_word .. "%s+(%S+)",function(word2)
if not current_word[word2] then
current_word[word2] = {}
end end
if not current_word[word2].occurences then local current_word = word_list[word]
current_word[word2].occurences = 1 local escaped_word = escape(word)
else str:gsub("%s+" .. escaped_word .. "%s+(%S+)",function(word2)
current_word[word2].occurences = current_word[word2].occurences + 1 if not current_word[word2] then
end current_word[word2] = {}
end) end
end) if not current_word[word2].occurences then
for k,v in pairs(word_list) do current_word[word2].occurences = 1
word_list[k] = node(v) else
end current_word[word2].occurences = current_word[word2].occurences + 1
return word_list end
end)
end)
for k,v in pairs(word_list) do
word_list[k] = node(v)
end
return word_list
end end
local table_length = function(tab) local table_length = function(tab)
local len = 0 local len = 0
for k,v in pairs(tab) do for k,v in pairs(tab) do
len = len + 1 len = len + 1
end end
return len return len
end end
function markov.walk(self,start) function markov.walk(self,start)
if not self.init then if not self.init then
error("Attempted to use an instance method on an uninitialized instance") error("Attempted to use method on uninitialized instances")
end
local random = math.random(0,1e7)/1e7
local words = {}
words.count = 0
local word = nil
if self.net[start] then
while (words.count < 1) and (table_length(self.net[start]) > 0) do
for k,v in pairs(self.net[start]) do
if (random <= v.probability) then
words.count = words.count + 1
table.insert(words,k)
end
end
random = math.random(0,1e7)/1e7
end end
end local random = math.random(0,1e7)/1e7
if words.count > 0 then local words = {}
word = words[math.random(1,#words)] words.count = 0
end local word = nil
return word if self.net[start] then
while (words.count < 1) and (table_length(self.net[start]) > 0) do
for k,v in pairs(self.net[start]) do
if (random <= v.probability) then
words.count = words.count + 1
table.insert(words,k)
end
end
random = math.random(0,1e7)/1e7
end
end
if words.count > 0 then
word = words[math.random(1,#words)]
end
return word
end end
function markov.expand_vocabulary(self,source) function markov.expand_vocabulary(self,source)
if not self.init then if not self.init then
error("Attempted to use an instance method on an uninitialized instance") error("Attempted to use method on uninitialized instances")
end end
self.net = register_words(source,self.net) self.net = register_words(source,self.net)
end end
function markov.save_state(self) function markov.save_state(self)
return self.net return self.net
end end
function markov.load_state(self,new_state) function markov.load_state(self,new_state)
self.net = new_state self.net = new_state
end end
function markov.run(self,start,count) function markov.run(self,start,count)
if not self.init then if not self.init then
error("Attempted to use an instance method on an uninitialized instance") error("Attempted to use an instance method on an uninitialized instance")
end
if not start then
for k,v in pairs(self.net) do
start = k
break
end end
end if not start then
local sequence = "" for k,v in pairs(self.net) do
local current_word = start start = k
while current_word do break
sequence = sequence..current_word.." " end
local _,counter = sequence:gsub("(%S+)","%1")
current_word = self:walk(current_word)
if counter > (count or 200) then
sequence = sequence:sub(1,-2).."..."
break
end end
end local sequence = ""
return sequence local current_word = start
while current_word do
sequence = sequence..current_word.." "
local _,counter = sequence:gsub("(%S+)","%1")
current_word = self:walk(current_word)
if counter > (count or 200) then
sequence = sequence:sub(1,-2).."..."
break
end
end
return sequence
end end
function markov.new(str) function markov.new(str)
local self = setmetatable({},{__index = markov}) local self = setmetatable({},{__index = markov})
self.net = register_words(str or "") self.net = register_words(str or "")
self.init = true self.init = true
return self return self
end end
return markov return markov

View File

@ -1,32 +1,32 @@
--string purifier library --string purifier library
local purify = {} local purify = {}
purify.purify_pings = function(msg,input) purify.purify_pings = function(msg,input)
local text = input local text = input
while text:match("<@(%D*)(%d*)>") do while text:match("<@(%D*)(%d*)>") do
local obj,id = text:match("<@(%D*)(%d*)>") local obj,id = text:match("<@(%D*)(%d*)>")
local substitution = "" local substitution = ""
if obj:match("!") then if obj:match("!") then
local member = msg.guild:getMember(id) local member = msg.guild:getMember(id)
if member then if member then
substitution = "@"..member.name substitution = "@"..member.name
end end
elseif obj:match("&") then elseif obj:match("&") then
local role = msg.guild:getRole(id) local role = msg.guild:getRole(id)
if role then if role then
substitution = "@"..role.name substitution = "@"..role.name
end end
end
if substitution == "" then
substitution = "<\\@"..obj..id..">"
end
text = text:gsub("<@(%D*)"..id..">",substitution)
end end
if substitution == "" then return text
substitution = "<\\@"..obj..id..">"
end
text = text:gsub("<@(%D*)"..id..">",substitution)
end
return text
end end
purify.purify_escapes = function(text) purify.purify_escapes = function(text)
local match = "([%(%)%.%%%+%-%*%?%[%]%^%$])" local match = "([%(%)%.%%%+%-%*%?%[%]%^%$])"
return text:gsub(match,"%%%1") return text:gsub(match,"%%%1")
end end
return purify return purify

View File

@ -15,42 +15,42 @@ utilities.deepcopy = function(orig)
return copy return copy
end end
utilities.slice = function(list,start,list_end) utilities.slice = function(list,start,list_end)
local output = {} local output = {}
for I = (start or 1),(list_end or #table) do for I = (start or 1),(list_end or #table) do
table.insert(output,list[I]) table.insert(output,list[I])
end end
return output return output
end end
utilities.shallowcopy = function(orig) utilities.shallowcopy = function(orig)
local copy = {} local copy = {}
for k,v in pairs(orig) do for k,v in pairs(orig) do
copy[k] = v copy[k] = v
end end
return copy return copy
end end
--overwrite the original table's properties with new properties --overwrite the original table's properties with new properties
utilities.overwrite = function(original,overwrite) utilities.overwrite = function(original,overwrite)
local new = utilities.shallowcopy(original) local new = utilities.shallowcopy(original)
for k,v in pairs(overwrite) do for k,v in pairs(overwrite) do
new[k] = v new[k] = v
end end
return new return new
end end
--merge all objects passed as arguments into a table. --merge all objects passed as arguments into a table.
--if the object is a table, merge all of it's contents with the table --if the object is a table, merge all of it's contents with the table
utilities.merge = function(...) utilities.merge = function(...)
local args = {...} local args = {...}
local new = {} local new = {}
for k,v in pairs(args) do for k,v in pairs(args) do
if type(v) == "table" then if type(v) == "table" then
for k2,v2 in pairs(v) do for k2,v2 in pairs(v) do
table.insert(new,v2) table.insert(new,v2)
end end
else else
table.insert(new,v) table.insert(new,v)
end end
end end
return new return new
end end
utilities.remove_value = function(tb,v) utilities.remove_value = function(tb,v)
local id_to_remove = nil local id_to_remove = nil

View File

@ -1,9 +1,9 @@
return function(sec) return function(sec)
local hours = math.floor(sec/3600) local hours = math.floor(sec/3600)
local minutes = math.floor((sec - hours*3600)/60) local minutes = math.floor((sec - hours*3600)/60)
local seconds = sec - (hours*3600) - (minutes*60) local seconds = sec - (hours*3600) - (minutes*60)
hours = ((hours < 10) and ("0"..hours)) or hours hours = ((hours < 10) and ("0"..hours)) or hours
minutes = ((minutes < 10) and ("0"..minutes)) or minutes minutes = ((minutes < 10) and ("0"..minutes)) or minutes
seconds = ((seconds < 10) and ("0"..seconds)) or seconds seconds = ((seconds < 10) and ("0"..seconds)) or seconds
return ((tonumber(hours) > 0 and hours..":") or "")..minutes..":"..seconds return ((tonumber(hours) > 0 and hours..":") or "")..minutes..":"..seconds
end end