Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 2 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
I made a command handler and i put the bot code (adpted) inside on that command handler.
156 changes: 156 additions & 0 deletions src/Bread.lua
Original file line number Diff line number Diff line change
@@ -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
Loading