Yessiest
2 years ago
9 changed files with 480 additions and 480 deletions
-
368libraries/air.lua
-
92libraries/fake_message.lua
-
166libraries/file.lua
-
64libraries/import.lua
-
2libraries/luaqalc
-
170libraries/markov.lua
-
44libraries/purify.lua
-
40libraries/table-utils.lua
-
14libraries/unixToString.lua
@ -1,48 +1,48 @@ |
|||
return function(message,overrides) |
|||
assert(type(message) == "table","table expected, got "..type(message)) |
|||
assert(type(overrides) == "table","table expected for arg#2, got "..type(overrides)) |
|||
local fake = {content = message.content, |
|||
author = message.author, |
|||
member = message.guild:getMember(message.author.id), |
|||
channel = message.channel, |
|||
client = message.client, |
|||
guild = message.guild, |
|||
delete = function() message:delete() end, |
|||
reply = function(thing,...) |
|||
message.channel:send(...) |
|||
end, |
|||
createdAt = message.createdAt, |
|||
_parent = message.parent, |
|||
parent = message.parent, |
|||
id = message.id, |
|||
attachment = message.attachment, |
|||
attachments = message.attachments, |
|||
cleanContent = message.cleanContent, |
|||
editedTimestamp = message.editedTimestamp, |
|||
embed = message.embed, |
|||
embeds = message.embeds, |
|||
link = message.link, |
|||
mentionedChannels = message.mentionedChannels, |
|||
mentionedEmojis = message.mentionedEmojis, |
|||
mentionedRoles = message.mentionedRoles, |
|||
mentionedUsers = message.mentionedUsers, |
|||
nonce = message.nonce, |
|||
oldContent = message.oldContent, |
|||
pinned = message.pinned, |
|||
reactions = message.reactions, |
|||
tts = message.tts, |
|||
type = message.type, |
|||
webhookId = message.webhookId, |
|||
addReaction = function(self,...) |
|||
message:addReaction(...) |
|||
end, |
|||
removeReaction = function(self,...) |
|||
message:removeReaction(...) |
|||
end, |
|||
emulated = true |
|||
} |
|||
for k,v in pairs(overrides) do |
|||
fake[k] = v |
|||
end |
|||
return fake |
|||
assert(type(message) == "table","table expected, got "..type(message)) |
|||
assert(type(overrides) == "table","table expected for arg#2, got "..type(overrides)) |
|||
local fake = {content = message.content, |
|||
author = message.author, |
|||
member = message.guild:getMember(message.author.id), |
|||
channel = message.channel, |
|||
client = message.client, |
|||
guild = message.guild, |
|||
delete = function() message:delete() end, |
|||
reply = function(thing,...) |
|||
message.channel:send(...) |
|||
end, |
|||
createdAt = message.createdAt, |
|||
_parent = message.parent, |
|||
parent = message.parent, |
|||
id = message.id, |
|||
attachment = message.attachment, |
|||
attachments = message.attachments, |
|||
cleanContent = message.cleanContent, |
|||
editedTimestamp = message.editedTimestamp, |
|||
embed = message.embed, |
|||
embeds = message.embeds, |
|||
link = message.link, |
|||
mentionedChannels = message.mentionedChannels, |
|||
mentionedEmojis = message.mentionedEmojis, |
|||
mentionedRoles = message.mentionedRoles, |
|||
mentionedUsers = message.mentionedUsers, |
|||
nonce = message.nonce, |
|||
oldContent = message.oldContent, |
|||
pinned = message.pinned, |
|||
reactions = message.reactions, |
|||
tts = message.tts, |
|||
type = message.type, |
|||
webhookId = message.webhookId, |
|||
addReaction = function(self,...) |
|||
message:addReaction(...) |
|||
end, |
|||
removeReaction = function(self,...) |
|||
message:removeReaction(...) |
|||
end, |
|||
emulated = true |
|||
} |
|||
for k,v in pairs(overrides) do |
|||
fake[k] = v |
|||
end |
|||
return fake |
|||
end |
@ -1 +1 @@ |
|||
Subproject commit 9e6f09050f9ebecc4ffcea1234b920468254a79b |
|||
Subproject commit 23fcea17c2eb380b6a6b1ba848d5bc7ebdc38b05 |
@ -1,123 +1,123 @@ |
|||
local markov = {} |
|||
|
|||
local function node(relations) |
|||
local node = {} |
|||
local total = 0 |
|||
for k,v in pairs(relations) do |
|||
total = total + v.occurences |
|||
end |
|||
for k,v in pairs(relations) do |
|||
node[k] = {probability = v.occurences/total,occurences = v.occurences} |
|||
end |
|||
return node |
|||
local node = {} |
|||
local total = 0 |
|||
for k,v in pairs(relations) do |
|||
total = total + v.occurences |
|||
end |
|||
for k,v in pairs(relations) do |
|||
node[k] = {probability = v.occurences/total,occurences = v.occurences} |
|||
end |
|||
return node |
|||
end |
|||
|
|||
local function escape(str) |
|||
return str:gsub("([%%%*%(%)%^%.%[%]%+%-%$%?])","%%%1") |
|||
return str:gsub("([%%%*%(%)%^%.%[%]%+%-%$%?])","%%%1") |
|||
end |
|||
|
|||
local function register_words(str,word_list) |
|||
local word_list = word_list or {} |
|||
str:gsub("%S+",function(word) |
|||
if not word_list[word] then |
|||
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 |
|||
if not current_word[word2].occurences then |
|||
current_word[word2].occurences = 1 |
|||
else |
|||
current_word[word2].occurences = current_word[word2].occurences + 1 |
|||
local word_list = word_list or {} |
|||
str:gsub("%S+",function(word) |
|||
if not word_list[word] then |
|||
word_list[word] = {} |
|||
end |
|||
end) |
|||
end) |
|||
for k,v in pairs(word_list) do |
|||
word_list[k] = node(v) |
|||
end |
|||
return word_list |
|||
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 |
|||
if not current_word[word2].occurences then |
|||
current_word[word2].occurences = 1 |
|||
else |
|||
current_word[word2].occurences = current_word[word2].occurences + 1 |
|||
end |
|||
end) |
|||
end) |
|||
for k,v in pairs(word_list) do |
|||
word_list[k] = node(v) |
|||
end |
|||
return word_list |
|||
end |
|||
|
|||
local table_length = function(tab) |
|||
local len = 0 |
|||
for k,v in pairs(tab) do |
|||
len = len + 1 |
|||
end |
|||
return len |
|||
local len = 0 |
|||
for k,v in pairs(tab) do |
|||
len = len + 1 |
|||
end |
|||
return len |
|||
end |
|||
|
|||
function markov.walk(self,start) |
|||
if not self.init then |
|||
error("Attempted to use an instance method on an uninitialized instance") |
|||
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) |
|||
if not self.init then |
|||
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 |
|||
random = math.random(0,1e7)/1e7 |
|||
end |
|||
end |
|||
if words.count > 0 then |
|||
word = words[math.random(1,#words)] |
|||
end |
|||
return word |
|||
if words.count > 0 then |
|||
word = words[math.random(1,#words)] |
|||
end |
|||
return word |
|||
end |
|||
|
|||
function markov.expand_vocabulary(self,source) |
|||
if not self.init then |
|||
error("Attempted to use an instance method on an uninitialized instance") |
|||
end |
|||
self.net = register_words(source,self.net) |
|||
if not self.init then |
|||
error("Attempted to use method on uninitialized instances") |
|||
end |
|||
self.net = register_words(source,self.net) |
|||
end |
|||
|
|||
function markov.save_state(self) |
|||
return self.net |
|||
return self.net |
|||
end |
|||
|
|||
function markov.load_state(self,new_state) |
|||
self.net = new_state |
|||
self.net = new_state |
|||
end |
|||
|
|||
function markov.run(self,start,count) |
|||
if not self.init then |
|||
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 |
|||
if not self.init then |
|||
error("Attempted to use an instance method on an uninitialized instance") |
|||
end |
|||
end |
|||
local 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 |
|||
if not start then |
|||
for k,v in pairs(self.net) do |
|||
start = k |
|||
break |
|||
end |
|||
end |
|||
local 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 |
|||
end |
|||
return sequence |
|||
return sequence |
|||
end |
|||
|
|||
function markov.new(str) |
|||
local self = setmetatable({},{__index = markov}) |
|||
self.net = register_words(str or "") |
|||
self.init = true |
|||
return self |
|||
local self = setmetatable({},{__index = markov}) |
|||
self.net = register_words(str or "") |
|||
self.init = true |
|||
return self |
|||
end |
|||
|
|||
return markov |
@ -1,32 +1,32 @@ |
|||
--string purifier library |
|||
local purify = {} |
|||
purify.purify_pings = function(msg,input) |
|||
local text = input |
|||
while text:match("<@(%D*)(%d*)>") do |
|||
local obj,id = text:match("<@(%D*)(%d*)>") |
|||
local substitution = "" |
|||
if obj:match("!") then |
|||
local member = msg.guild:getMember(id) |
|||
if member then |
|||
substitution = "@"..member.name |
|||
end |
|||
elseif obj:match("&") then |
|||
local role = msg.guild:getRole(id) |
|||
if role then |
|||
substitution = "@"..role.name |
|||
end |
|||
local text = input |
|||
while text:match("<@(%D*)(%d*)>") do |
|||
local obj,id = text:match("<@(%D*)(%d*)>") |
|||
local substitution = "" |
|||
if obj:match("!") then |
|||
local member = msg.guild:getMember(id) |
|||
if member then |
|||
substitution = "@"..member.name |
|||
end |
|||
elseif obj:match("&") then |
|||
local role = msg.guild:getRole(id) |
|||
if role then |
|||
substitution = "@"..role.name |
|||
end |
|||
end |
|||
if substitution == "" then |
|||
substitution = "<\\@"..obj..id..">" |
|||
end |
|||
text = text:gsub("<@(%D*)"..id..">",substitution) |
|||
end |
|||
if substitution == "" then |
|||
substitution = "<\\@"..obj..id..">" |
|||
end |
|||
text = text:gsub("<@(%D*)"..id..">",substitution) |
|||
end |
|||
return text |
|||
return text |
|||
end |
|||
|
|||
purify.purify_escapes = function(text) |
|||
local match = "([%(%)%.%%%+%-%*%?%[%]%^%$])" |
|||
return text:gsub(match,"%%%1") |
|||
local match = "([%(%)%.%%%+%-%*%?%[%]%^%$])" |
|||
return text:gsub(match,"%%%1") |
|||
end |
|||
|
|||
return purify |
@ -1,9 +1,9 @@ |
|||
return function(sec) |
|||
local hours = math.floor(sec/3600) |
|||
local minutes = math.floor((sec - hours*3600)/60) |
|||
local seconds = sec - (hours*3600) - (minutes*60) |
|||
hours = ((hours < 10) and ("0"..hours)) or hours |
|||
minutes = ((minutes < 10) and ("0"..minutes)) or minutes |
|||
seconds = ((seconds < 10) and ("0"..seconds)) or seconds |
|||
return ((tonumber(hours) > 0 and hours..":") or "")..minutes..":"..seconds |
|||
local hours = math.floor(sec/3600) |
|||
local minutes = math.floor((sec - hours*3600)/60) |
|||
local seconds = sec - (hours*3600) - (minutes*60) |
|||
hours = ((hours < 10) and ("0"..hours)) or hours |
|||
minutes = ((minutes < 10) and ("0"..minutes)) or minutes |
|||
seconds = ((seconds < 10) and ("0"..seconds)) or seconds |
|||
return ((tonumber(hours) > 0 and hours..":") or "")..minutes..":"..seconds |
|||
end |
Write
Preview
Loading…
Cancel
Save
Reference in new issue