diff --git a/README.md b/README.md index 7b24977..97b637d 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,3 @@ -# Old-Machine -Old-Machine is a mega simple bot in just one file, without any external libraries +# Old-Machine BREAD Version -Commands: - ->whois - See information of a user! - ->quote - Quote a message - ->ping - Respond with a funny gif! - ->ban - Ban some out-laws, sherrif! (Requires banMember permission) - ->coolness - See coolness of a person! - ->battle - Fight someone! - ->magicball - Speak with a magic ball! - ->time - Reveals the current UNIX time! - ->unwarn - WIP | UnWarn wrong people you warned! (Requires administrator permission) - ->purge - Start a purge to clean the chat! (Requies manageMessages permission) - ->warn - WIP | Warn people before doing a mess! (Requires administrator permission) - -# Dependencies - -Discordia 2.8.4 - -Luvit - -# Installation - -Old machine can be installed from: - -git - ``git clone https://letiulthecode/Old-Machine`` - -lit - ``lit install letiulthecode/Old-Machine``--NOTE: The Old-Machine.lua will stay at deps folder by default, change it to your project folder - -# Contribuing - -I dont accept any donations yet, the max you can do is: - -Report Issues - -Pull requests - -Fork the source - -# Extra info - -This "Software" its under the License M.I.T, see LICENSE for more details - -Invite Original Bot: - -https://discord.com/api/oauth2/authorize?client_id=777887826561335327&permissions=8&scope=bot \ No newline at end of file +I made a command handler and i put the bot code (adpted) inside on that command handler. diff --git a/src/Bread.lua b/src/Bread.lua new file mode 100644 index 0000000..375ea4a --- /dev/null +++ b/src/Bread.lua @@ -0,0 +1,156 @@ +local discordia = require "discordia" +local Bread = {} + +local up = string.upper +local rep = string.rep +local form = string.format +local date = os.date +local time = os.time +local insert = table.insert + +Bread.Color = { + esc = "\027", + reset = "[0m", + black = '[30m', + red = '[31m', + green = '[32m', + yellow = '[33m', + blue = '[34m', + magenta = '[35m', + cyan = '[36m', + white = '[37m', +} + + +local client = discordia.Client() +Bread.__init = Bread +discordia.extensions() + +local function LockArray(tbl) + if not tbl then tbl = {} end + return setmetatable(tbl, { + __newindex = function(table, key, value) + error("Attempt to modify a value in a locked array") + end, + __metatable = false + }) +end + +local function UnLockArray(tbl) + if not tbl then tbl = {} end + return setmetatable(tbl, { + __metatable = false + }) +end + +---Declare token and prefix +function Bread:NewClient(token, prefix) + self.Commands = {} + self.Data = {} + self.Data.Token = token + self.Data.Prefix = prefix + + LockArray(self.Data) + + return self +end + +function Bread.Discordia() + return discordia +end + +function Bread.Client() + return client +end + +--Checks if str starts with ptrn +function Bread.StartsWith(str, ptrn) + return str:sub(1, #ptrn) == ptrn +end + +--Log in the output +function Bread.Log(lvl, lvlcolor, msg) + return form(date("%F %T", time()).." | \27"..lvlcolor.."[%s]\27[0m"..rep(" ", #lvl).."| %s ", up(lvl), msg) +end + +--Easy bulk-delete method +function Bread.BulkDel(message, amount) + local cha = message.guild:getChannel(message.channel.id) + cha:bulkDelete(message.channel:getMessagesBefore(message.id, amount)) +end + +--Wait for some secodns to a callback start +function Bread.WaitFor(seconds, callback) + discordia.Clock():waitFor("", seconds * 1000) + if type(callback) == "function" then + callback() + else + error("Callback must be a function") + end +end + +--Makes a new command +function Bread:Command(cmd, desc, func) + local prefix = self.Data.Prefix + self.Commands[prefix..cmd] = { + desc = desc, + exec = function(message) + if type(func) == "function" then + func(message) + else + error("The func param needs be function type.") + end + end + } + return self +end + +--Makes a Help command +function Bread:Help(embedtoggle) + Bread:Command("help", "Displays all commands", function(message) + if embedtoggle == false then + local output = {} + for word, tbl in pairs(Bread.Commands) do + insert(output, word .. " - " .. tbl.desc .. "\n") + end + + message:reply("Help\n"..table.concat(output, "\n\n")) + elseif embedtoggle == true then + local output = {} + for word, tbl in pairs(Bread.Commands) do + insert(output, word .. " - " .. tbl.desc .. "\n") + end + + message:reply{ + embed = { + title = "Help", + description = table.concat(output, "\n") + } + } + else + error("You need toggle if the help message will be an embed or not.") + end + end) +end + +--Starts Everything +function Bread:Eat() + client:on("ready", function() + print(Bread.Log("info", Bread.Color.green, client.user.username.." Is online!")) + end) + + client:on("messageCreate", function(message) + if message.author.bot then return end + local args = message.content:split(" ") + + local command = self.Commands[args[1]] + if command then + command.exec(message) + end + end) + + client:run("Bot "..self.Data.Token) + LockArray(self) +end + +return Bread \ No newline at end of file diff --git a/src/bot.lua b/src/bot.lua deleted file mode 100644 index d300d08..0000000 --- a/src/bot.lua +++ /dev/null @@ -1,309 +0,0 @@ ---Hello! My name is "Helpful comment", Im Here to help you to use this source to build your ver own bot! ---Everytime you seeing a "--" and in front a text, thats me helping you! - -local discordia = require "discordia"-- We need require the Discordia Lib to use this bot -local client = discordia.Client() -- Also load the client, it will be very important -discordia.extensions()-- Load all helpful extentions - -local warns = 0 -- ignore this -local prefix = ">" -- Define the prefix, like when a members send "!ping" the '!' its the prefix. -local commands = { -- Define commands its a table that will contain our commands - [prefix..'ping'] = { -- Indexes can also be strings! So the string index it will concat our prefix and the command name! - desc = 'Respond with a funny gif!', -- Description of our command... - exec = function (message) -- And a function to our execute it! - message.channel:send('https://tenor.com/view/cats-ping-pong-gif-8942945') --You can use message:reply('message'), its the same as message.channel:send - end - }; --Remember to put colon or semicolor when creating a new var (indenpedent if its a number, string, etc) - --These other commands below i wont explane. - [prefix..'coolness'] = { - desc = 'See coolness of a person!', - exec = function (message) - local msg = prefix..'coolness' - if message.content:sub(1, #msg) == msg then - local mentioned = message.mentionedUsers - if #mentioned == 1 then - message:reply("<@!"..mentioned[1][1].."> is "..math.random(0, 100).."% cool! :sunglasses:") - elseif #mentioned == 0 then - message:reply("<@!"..message.author.id.."> is "..math.random(0, 100).."% cool! :sunglasses:") - end - end - end - }; - [prefix..'ban'] = { - desc = 'Ban some out-laws, sherrif! (Requires banMember permission)', - exec = function (message) - local msg = prefix..'ban' - if message.content:sub(1, #msg) == msg then - local author = message.guild:getMember(message.author.id) - local member = message.mentionedUsers.first - - if not member then - message:reply("Please mention someone to ban!") - return - elseif not author:hasPermission("administrator") then - message:reply("You do not have permissions to ban!") - return - end - - for user in message.mentionedUsers:iter() do - member = message.guild:getMember(user.id) - if author.highestRole.position > member.highestRole.position then - message:reply("Member Banned!") - member:ban() - else - message:reply("That person its an admin or mod, i cant ban it.") - end - end - end - end - }; - [prefix..'warn'] = { - desc = 'WIP | Warn people before doing a mess! (Requires administrator permission)', - exec = function (message) - local msg = prefix..'warn' - if message.content:sub(1, #msg) == msg then - local author = message.guild:getMember(message.author.id) - local member = message.mentionedUsers.first - - if not member then - message:reply("Please mention someone to warn!") - return - elseif not author:hasPermission("administrator") then - message:reply("You do not have permissions to warn!") - return - end - - for user in message.mentionedUsers:iter() do - member = message.guild:getMember(user.id) - if author.highestRole.position > member.highestRole.position then - warns = warns + 1 - message:reply("Member "..user.username.." Warned! (Now "..warns..' Warns.)') - else - message:reply("That person its an admin or mod, i cant warn it.") - end - end - end - end - }; - [prefix..'unwarn'] = { - desc = 'WIP | UnWarn wrong people you warned! (Requires administrator permission)', - exec = function (message) - local msg = prefix..'unwarn' - if message.content:sub(1, #msg) == msg then - local author = message.guild:getMember(message.author.id) - local member = message.mentionedUsers.first - - if not member then - message:reply("Please mention someone to warn!") - return - elseif not author:hasPermission("administrator") then - message:reply("You do not have permissions to warn!") - return - end - - for user in message.mentionedUsers:iter() do - member = message.guild:getMember(user.id) - if author.highestRole.position > member.highestRole.position then - warns = warns - 1 - if warns <= -1 then - warns = 0 - message:reply("This member dont have any warns.") - return - end - message:reply("Member "..user.username.." UnWarned! (Now "..warns..' Warns.)') - end - end - end - end - }; - [prefix..'time'] = { - desc = 'Reveals the current time!', - exec = function (message) - message:reply('Current UNIX Time: '..os.date("%F %T", os.time())) - end - }; - [prefix.."purge"] = { - desc = "Start a purge to clean the chat! (Requies manageMessages permission)", - exec = function(message) - local msg = prefix..'purge' - if message.content:sub(1, #msg) == msg then - if message.member:hasPermission('manageMessages') then - local repla = string.gsub(message.content, prefix.."purge ", "") - local cha = message.guild:getChannel(message.channel.id) - if not cha:bulkDelete(message.channel:getMessagesBefore(message.id, repla)) then - message:delete() - local reply = message:reply("Something went wrong whiling starting a purge...") - discordia.Clock():waitFor("", 3000) - reply:delete() - else - message:delete() - local reply - if repla == "1" then - reply = message:reply("Chat purged by <@!"..message.author.id.."> (Purged "..repla.." Message)!") - else - reply = message:reply("Chat purged by <@!"..message.author.id.."> (Purged "..repla.." Messages)!") - end - discordia.Clock():waitFor("", 3000) - reply:delete() - end - else - message:reply("Sorry <@!"..message.author.id.."> you dont have perms to purge!") - end - end - end - }; - [prefix.."whois"] = { - desc = "See information of a user!", - exec = function(message) - local member = message.mentionedUsers - if #member == 0 then - message:reply("Please, mention someone to check!") - return - elseif #member == 1 then - for user in message.mentionedUsers:iter() do - member = message.guild:getMember(user.id) - message:reply { - embed = { - thumbnail = {url = member.avatarURL}, - fields = { - {name = 'Nick & Tag', value = member.tag, inline = true}, - {name = 'ID', value = member.id, inline = true}, - {name = 'Highest Role', value = member.highestRole.name, inline = true}, - {name = 'Boosted Since', value = member.premiumSince or "Dont Boosted", inline = true}, - {name = 'Joined Server At', value = member.joinedAt and member.joinedAt:gsub('%..*', ''):gsub('T', ' ') or '?', inline = true}, - {name = 'Joined Discord At', value = discordia.Date.fromSnowflake(member.id):toISO(' ', ''), inline = true}, - }, - color = discordia.Color.fromRGB(255, 0, 0).value - } - } - end - elseif #member >= 2 then - message:reply("I cannot check "..#member.." users or more at same time.") - return - end - end - }; - [prefix.."battle"] = { - desc = "Fight someone!", - exec = function(message) - local enemy = message.mentionedUsers - local author = message.author.id - local winner = math.random(1, 100) - - local rounds = math.random(1, 20) - if #enemy == 1 then - for user in message.mentionedUsers:iter() do - enemy = user.id - if enemy == author then - message:reply("You cannot beat yourself!") - return - end - local winnedby= { - 'Punching him to death', - 'Using Shadow clone jutso', - 'Stopping time and throwing knifes', - 'Cutting him with a Powerful Sword', - 'Giving him a head-shot with a sniper', - 'Making him rage-quit', - 'Abusing of bugs', - 'Find and kill him in a manhunt', - 'Using Uno Reverse card', - 'Killing him in front of a crewmate' - } - if winner >= 50 then - message:reply("<@!"..enemy.."> won the battle in "..rounds.." rounds by: "..winnedby[math.random(1, #winnedby)].."!") - elseif winner <= 50 then - message:reply("<@!"..author.."> won the battle in "..rounds.." rounds by: "..winnedby[math.random(1, #winnedby)].."!") - end - end - elseif #enemy >= 2 then - message:reply("I cant make you fight against "..#enemy.." people!") - else - message:reply("Please metion someone to battle!") - end - end - }; - [prefix.."magicball"] = { - desc = "Speak with a magic ball!", - exec = function(message) - local answers = { - 'Yes', - 'No', - 'Maybe', - 'I dont know', - 'Im dont gonna answer this.', - 'I will think.', - 'Probably yes.', - 'Probably no.' - } - message:reply { - embed = { - title = ":8ball: Magic Ball", - description = "Question:\n"..message.content:gsub(prefix.."magicball ", ""), - fields = { - {name = "Answer:", value = answers[math.random(1, #answers)]} - }; - color = discordia.Color.fromRGB(27,26,54).value - } - } - end - }; - [prefix.."quote"] = { - desc = "Quote a message (Needs Message ID)", - exec = function (message) - local MsgID = message.content:gsub(prefix.."quote ", "") - local Msg = message.channel:getMessage(MsgID) - local Channel = message.guild:getChannel(message.channel.id) - if not Msg then - message:reply("Couldn't find the quote you looking for.") - else - message:reply{ - embed = { - author = { - name = Msg.author.username, - icon_url = Msg.author.avatarURL - }, - description = Msg.content, - footer = { - text = string.format("#%s in %s", Channel.name, message.guild.name) - }, - timestamp = Msg.timestamp, - color = discordia.Color.fromRGB(27,26,54).value - } - } - end - end - } -} - -client:on("ready", function() -- Remember we made a client variable? We can use it now! - -- So if the bot its ready, it will prints thats its online! - -- Ignore os.date, os.time, \027[94m etc. its things that just make the message cool! - -- NOTE: Remember every thing related with client, its related to the bot! - print(os.date("%F %T", os.time()).." | \027[94m[BOT]\027[0m | "..client.user.username.." Is online!") - client:setGame("With Code | Shard "..tostring(client.totalShardCount)) -- Status message -end) - -client:on('messageCreate', function(message) -- If someone sends a message, we gonna make a function with param "message". - if message.author.bot then return end -- Prevent the bot to use thier own commands - local args = message.content:split(" ") -- Split all arguments of the message content into a table - - local command = commands[args[1]] -- Use first index of the arguments - if command then -- If one of the commands then execute it - command.exec(message) - end - - --Help command - if args[1] == prefix.."help" then -- If first index of args its the prefix and help, then (bassicaly) display all the commands - local stdout = {} - for w, tbl in pairs(commands) do - table.insert(stdout, w .. " - " .. tbl.desc) - end - - if not message.member:send{embed = {title = "Old-Machine commands", description = table.concat(stdout, "\n\n"), color = discordia.Color.fromRGB(27,26,54).value;}} then --If cant send in the DMs then send on channel - message:reply{embed = {title = "Old-Machine commands", description = table.concat(stdout, "\n\n"), color = discordia.Color.fromRGB(27,26,54).value;}} - end - end -end) - -client:run("Bot TOKEN") --replace TOKEN with the bot token, running a second instance before/after can cause problems, regen the token to solve \ No newline at end of file diff --git a/src/bread-ver-bot.lua b/src/bread-ver-bot.lua new file mode 100644 index 0000000..78f498a --- /dev/null +++ b/src/bread-ver-bot.lua @@ -0,0 +1,265 @@ +local Bread = require "./Bread" +local discordia = Bread.Discordia() +local client = Bread.Client() + +Bread:NewClient("Token.", ">") + +local prefix = Bread.Data.Prefix +local warns = 0 + +Bread:Command("ping", "Responds with a funny gif", function (message) + message:reply('https://tenor.com/view/cats-ping-pong-gif-8942945') +end) + +Bread:Command("coolness", "Check coolness of a user", function (message) + local msg = prefix..'coolness' + if message.content:sub(1, #msg) == msg then + local mentioned = message.mentionedUsers + if #mentioned == 1 then + message:reply("<@!"..mentioned[1][1].."> is "..math.random(0, 100).."% cool! :sunglasses:") + elseif #mentioned == 0 then + message:reply("<@!"..message.author.id.."> is "..math.random(0, 100).."% cool! :sunglasses:") + end + end +end) + +Bread:Command("ban", "Ban some outlaws, sherrif! (Requires banMember permission)", function (message) + local msg = prefix..'ban' + if message.content:sub(1, #msg) == msg then + local author = message.guild:getMember(message.author.id) + local member = message.mentionedUsers.first + + if not member then + message:reply("Please mention someone to ban!") + return + elseif not author:hasPermission("administrator") then + message:reply("You do not have permissions to ban!") + return + end + + for user in message.mentionedUsers:iter() do + member = message.guild:getMember(user.id) + if author.highestRole.position > member.highestRole.position then + message:reply("Member Banned!") + if not member:ban() then + message:reply("Error while trying to ban") + end + else + message:reply("That person its an admin or mod, i cant ban it.") + end + end + end +end) + +Bread:Command("warn", "WIP | Warn people before doing a mess! (Requires administrator permission)", function (message) + local msg = prefix..'warn' + if message.content:sub(1, #msg) == msg then + local author = message.guild:getMember(message.author.id) + local member = message.mentionedUsers.first + + if not member then + message:reply("Please mention someone to warn!") + return + elseif not author:hasPermission("administrator") then + message:reply("You do not have permissions to warn!") + return + end + + for user in message.mentionedUsers:iter() do + member = message.guild:getMember(user.id) + if author.highestRole.position > member.highestRole.position then + warns = warns + 1 + message:reply("Member "..user.username.." Warned! (Now "..warns..' Warns.)') + else + message:reply("That person's role its higher than yours") + end + end + end +end) + +Bread:Command("unwarn", "WIP | UnWarn wrong people you warned! (Requires administrator permission)", function (message) + local msg = prefix..'unwarn' + if message.content:sub(1, #msg) == msg then + local author = message.guild:getMember(message.author.id) + local member = message.mentionedUsers.first + + if not member then + message:reply("Please mention someone to warn!") + return + elseif not author:hasPermission("administrator") then + message:reply("You do not have permissions to warn!") + return + end + + for user in message.mentionedUsers:iter() do + member = message.guild:getMember(user.id) + if author.highestRole.position > member.highestRole.position then + warns = warns - 1 + if warns <= -1 then + warns = 0 + message:reply("This member dont have any warns.") + return + end + message:reply("Member "..user.username.." UnWarned! (Now "..warns..' Warns.)') + end + end + end +end) + +Bread:Command("time", "Reveal current UNIX time", function (message) + message:reply('Current UNIX Time: '..os.date("%F %T", os.time())) +end) + +Bread:Command("purge", "Start a purge to clean the chat! (Requies manageMessages permission)", function (message) + if message.member:hasPermission("manageMessages") then + local msg = prefix..'purge' + if message.content:sub(1, #msg) == msg then + if message.member:hasPermission('manageMessages') then + local repla = string.gsub(message.content, prefix.."purge ", "") + local cha = message.guild:getChannel(message.channel.id) + if not cha:bulkDelete(message.channel:getMessagesBefore(message.id, repla)) then + message:delete() + local reply = message:reply("Something went wrong whiling starting a purge...") + Bread.WaitFor(3, function() + reply:delete() + end) + else + message:delete() + local reply + if repla == "1" then + reply = message:reply("Chat purged by <@!"..message.author.id.."> (Purged "..repla.." Message)!") + else + reply = message:reply("Chat purged by <@!"..message.author.id.."> (Purged "..repla.." Messages)!") + end + Bread.WaitFor(3, function() + reply:delete() + end) + end + else + message:reply("Sorry <@!"..message.author.id.."> you dont have perms to purge!") + end + end + end +end) + +Bread:Command("whois", "Check user information", function(message) + local member = message.mentionedUsers + if #member == 0 then + message:reply("Please, mention someone to check!") + return + elseif #member == 1 then + for user in message.mentionedUsers:iter() do + member = message.guild:getMember(user.id) + message:reply { + embed = { + thumbnail = {url = member.avatarURL}, + fields = { + {name = 'Nick & Tag', value = member.tag, inline = true}, + {name = 'ID', value = member.id, inline = true}, + {name = 'Highest Role', value = member.highestRole.name, inline = true}, + {name = 'Boosted Since', value = member.premiumSince or "Dont Boosted", inline = true}, + {name = 'Joined Server At', value = member.joinedAt and member.joinedAt:gsub('%..*', ''):gsub('T', ' ') or '?', inline = true}, + {name = 'Joined Discord At', value = discordia.Date.fromSnowflake(member.id):toISO(' ', ''), inline = true}, + }, + color = discordia.Color.fromRGB(255, 0, 0).value + } + } + end + elseif #member >= 2 then + message:reply("I cannot check "..#member.." users or more at same time.") + return + end +end) + +Bread:Command("battle", "Battle someone!", function (message) + local enemy = message.mentionedUsers + local author = message.author.id + local winner = math.random(1, 100) + + local rounds = math.random(1, 20) + if #enemy == 1 then + for user in message.mentionedUsers:iter() do + enemy = user.id + if enemy == author then + message:reply("You cannot beat yourself!") + return + end + local winnedby= { + 'Punching him to death', + 'Using Shadow clone jutso', + 'Stopping time and throwing knifes', + 'Cutting him with a Powerful Sword', + 'Giving him a head-shot with a sniper', + 'Making him rage-quit', + 'Abusing of bugs', + 'Find and kill him in a manhunt', + 'Using Uno Reverse card', + 'Killing him in front of a crewmate' + } + if winner >= 50 then + message:reply("<@!"..enemy.."> won the battle in "..rounds.." rounds by: "..winnedby[math.random(1, #winnedby)].."!") + elseif winner <= 50 then + message:reply("<@!"..author.."> won the battle in "..rounds.." rounds by: "..winnedby[math.random(1, #winnedby)].."!") + end + end + elseif #enemy >= 2 then + message:reply("I cant make you fight against "..#enemy.." people!") + else + message:reply("Please metion someone to battle!") + end +end) + +Bread:Command("magicball", "Tell something to the ball!", function(message) + local answers = { + 'Yes', + 'No', + 'Maybe', + 'I dont know', + 'Im dont gonna answer this.', + 'I will think.', + 'Probably yes.', + 'Probably no.' + } + message:reply { + embed = { + title = ":8ball: Magic Ball", + description = "Question:\n"..message.content:gsub(prefix.."magicball ", ""), + fields = { + {name = "Answer:", value = answers[math.random(1, #answers)]} + }; + color = discordia.Color.fromRGB(27,26,54).value + } + } +end) + +Bread:Command("quote", "Quote a message (Needs message ID)", function (message) + local MsgID = message.content:gsub(prefix.."quote ", "") + local Msg = message.channel:getMessage(MsgID) + local Channel = message.guild:getChannel(message.channel.id) + if not Msg then + message:reply("Couldn't find the quote you looking for.") + else + message:reply{ + embed = { + author = { + name = Msg.author.username, + icon_url = Msg.author.avatarURL + }, + description = Msg.content, + footer = { + text = string.format("#%s in %s", Channel.name, message.guild.name) + }, + timestamp = Msg.timestamp, + color = discordia.Color.fromRGB(27,26,54).value + } + } + end +end) + +client:on("ready", function () + client:setGame("With code | Shard "..tostring(client.totalShardCount)) +end) + +Bread:Help(true) + +Bread:Eat() \ No newline at end of file diff --git a/src/package.lua b/src/package.lua deleted file mode 100644 index 4423a67..0000000 --- a/src/package.lua +++ /dev/null @@ -1,16 +0,0 @@ - return { - name = "letiulthecode/Old-Machine", - version = "1.0.3", - description = "A mega simple bot made in discordia withot any other external libraries", - tags = { "discordia", "luvit" }, - license = "MIT", - author = { name = "Git (lethel)", email = "minebuckbr@gmail.com" }, --i created that email with 7 years lol - homepage = "https://github.com/letiulthecode/Old-Machine", - dependencies = { - 'SinisterRectus/discordia' - }, - files = { - "bot.lua", - --"Makefile" - } - } \ No newline at end of file diff --git a/src/test/Machine.lua b/src/test/Machine.lua deleted file mode 100644 index b371b47..0000000 --- a/src/test/Machine.lua +++ /dev/null @@ -1,71 +0,0 @@ --- Machine is a Command Manager, a dependency for this bot - -local discordia = require "discordia" -local class = discordia.class -local client = discordia.Client() -local Machine = class("Machine") -discordia.extensions() - -CMD = {} - -AliasCMD = {} - ---// Method Section ---New Commands -function Machine:__init(name, handle) - self.name = name - self.handle = handle - - return self -end - -function Machine:NewDesc(desc) - self.desc = desc - - return self -end - -function Machine:NewCategory(cat) - self.category = cat - - return self -end - -function Machine:NewAlias(alias) - AliasCMD[alias] = self.name - - return self -end - ---Get Commands - -function Machine:GetName() - return self.name -end - -function Machine:GetDesc() - return (self.desc ~= nil and self.desc or nil) -end - -function Machine:GetCat() - return (self.category ~= nil and self.category or nil) -end - -function Machine:Execute(...) - return self.handle(...) -end - ---// Misc Section -function GetAllCmds() - return CMD -end - -function IsReady() - client:on("ready", function() - print(os.date("%F @ %T", os.time()).."| [MACHINE] | "..client.user.username.." Is online!") - end) -end - -function ExistCmd(cmd) - return (CMD[cmd] ~= nil) -end diff --git a/src/test/framework.lua b/src/test/framework.lua deleted file mode 100644 index c46f33c..0000000 --- a/src/test/framework.lua +++ /dev/null @@ -1,121 +0,0 @@ -local Frame = {} - - -Frame.Settings = { - BotCanUseOwnCmds = false, -} - -Frame.Container = { - Discordia = { - message = nil, - client = nil - }; - Bot = { - prefix = nil, - --token = nil - } -} - -local function IsType(name, val, typ) - if type(val) ~= typ then - error("Type of "..name.." needs be type "..typ.."!") - end -end - - -local client = Frame.Container.Discordia.Client -local prefix = Frame.Container.Bot.prefix - -function Frame.DefineDisc(message, client) - Frame.Container.Discordia.message = message - Frame.Container.Discordia.Client = client -end - -function Frame.DefinePrefix(prefix) - Frame.Container.Bot.prefix = prefix -end - -function Frame.Cooldown(n) - local message = Frame.Container.Discordia.message - for i=1, n do - if i ~= n then - message:reply("Command in cooldown...") - end - end -end - -function Frame.ActivateSettings() - local settings = Frame.Settings - local message = Frame.Container.Discordia.message - if settings.BotCanUseOwnCmds == false then - if message.author.bot then return end - else - end -end - -function Frame.NewCommand(command, func) - IsType("command", command, "string") - IsType("func", func, "function") - local message = Frame.Container.Discordia.message - local prefix = Frame.Container.Bot.prefix - if message.content == prefix..command then - func() - end -end - -function Frame.StartsWithPrefix(sb) - IsType("sub", sb, "string") - local message = Frame.Container.Discordia.message - local prefix = Frame.Container.Bot.prefix - local msg = prefix..sb - return message.content:sub(1, #msg) == msg -end - -function Frame.BulkDelete(msg) - local message = Frame.Container.Discordia.message - local prefix = Frame.Container.Bot.prefix - local ms = prefix..msg - local repla = string.gsub(message.content, ms.." ", "") - if repla:match('1234567890') == false then return false end - if message.member:hasPermission('manageMessages') then - message:delete() - local cha = message.guild:getChannel(message.channel.id) - cha:bulkDelete(message.channel:getMessagesBefore(message.id, repla)) - else - message:reply("Sorry <@!"..message.author.id.."> you dont have perms to clean!") - end -end - -function Frame.NewIfCommand(command, condition, func) - IsType("command", command, "string") - IsType("condition", condition, "string") - IsType("func", func, "function") - local message = Frame.Container.Discordia.message - local prefix = Frame.Container.Bot.prefix - local msg = prefix..command - if condition == "StartsWithPrefix" then - if message.content:sub(1, #msg) == msg then - func() - end - end -end - -function Frame.NewEmbed(title, desc, color, finame, fival, iline) - IsType("title", title, "string") - IsType("description", desc, "string") - IsType("color", color, "number") - IsType("field name", finame, "string") - IsType("field value", fival, "string") - IsType("inline", iline, "boolean") - local embed = { - title = title, - description = desc, - color = color, - fields = { - {name = finame, value = fival, inline = iline} - } - } - return embed -end - -return Frame \ No newline at end of file