From b4d0f9ea541b1c85b3a00044030b594e70448fc0 Mon Sep 17 00:00:00 2001 From: Yessiest Date: Sat, 21 May 2022 20:46:02 +0400 Subject: [PATCH] Updated guide on self-hosting the bot --- README.md | 8 +++++--- bot.lua | 2 +- plugins/cron/events.lua | 33 +++++++++------------------------ plugins/cron/init.lua | 7 +++++-- plugins/meta/init.lua | 2 +- plugins/security/help.lua | 18 ++++++++++++++++++ plugins/security/init.lua | 28 ++++++++++++++++++++++++++++ 7 files changed, 67 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index ab2bc14..34a6b23 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ [![forthebadge](https://forthebadge.com/images/badges/powered-by-black-magic.svg)](https://forthebadge.com) [![made-with-luvit.svg](https://512mb.org/git/Yessiest/badges/raw/branch/master/badges/made-with-luvit.svg)](https://forthebadge.com/generator/) # 512mb.org-bot -yet another 512mb bot. it's running on a discord library for the luvit framework called [Discordia](https://github.com/SinisterRectus/discordia) +Yet another 512mb bot. It's running on a discord library for the luvit framework called [Discordia](https://github.com/SinisterRectus/discordia). For guides on using particular features of the bot check out the [wiki](https://github.com/512mb-org/512mb.org-bot/wiki). # Self-hosting -place the bot token in the "./token" file, change server id in bot.lua to the id of your server. -compile [luvit](https://luvit.io) and run bot.lua. +1. Get a bot token and place it in ./token +2. Install libqalculate and compile luaqalc +3. Place the ``libqalculator.so`` in ./libraries/ +4. Get [luvit](https://luvit.io) and run ``bot.lua`` using the ``luvit`` binary # License ``` diff --git a/bot.lua b/bot.lua index 19742a6..394e2d7 100644 --- a/bot.lua +++ b/bot.lua @@ -46,4 +46,4 @@ if not tempfile then end local nstr = tempfile:read("*l") tempfile:close() -client:run('Bot '..nstr) +client:run('Bot '..nstr:match("^%s*(.+)%s*$")) diff --git a/plugins/cron/events.lua b/plugins/cron/events.lua index 5f4b71c..43012e9 100644 --- a/plugins/cron/events.lua +++ b/plugins/cron/events.lua @@ -26,10 +26,7 @@ local triggerOnce = function(evname,args,vars) end end -client:on("messageCreate",function(msg) - if (not msg.guild) or (tostring(msg.guild.id) ~= tostring(id)) then - return - end +event_emitter:on("messageCreate",function(msg) local content = msg.content local user = msg.author.id local channelid = msg.channel.id @@ -45,10 +42,7 @@ client:on("messageCreate",function(msg) triggerOnce("messageOnce",{content,user,channelid},args) end) -client:on("userBan",function(user,guild) - if tostring(guild.id) ~= tostring(id) then - return - end +event_emitter:on("userBan",function(user,guild) args = { ["%$USER"] = user.id, ["%$USERNAME"] = user.name @@ -59,10 +53,7 @@ client:on("userBan",function(user,guild) triggerOnce("banOnce",{user.id},args) end) -client:on("userUnban",function(user,guild) - if tostring(guild.id) ~= tostring(id) then - return - end +event_emitter:on("userUnban",function(user,guild) args = { ["%$USER"] = user.id, ["%$USERNAME"] = user.name @@ -73,14 +64,11 @@ client:on("userUnban",function(user,guild) triggerOnce("unbanOnce",{user.id},args) end) -client:on("memberJoin", function(member) - if tostring(member.guild.id) ~= tostring(id) then - return - end +event_emitter:on("memberJoin", function(member) args = { ["%$USER"] = member.id, ["%$USERNAME"] = member.name, - ["%$AGE"] = member.user.createdAt, + ["%$AGE"] = discordia.Date():toSeconds()-member.user.createdAt, ["%$DISCRIM"] = member.user.discriminator, ["%$TAG"] = member.user.tag } @@ -88,24 +76,21 @@ client:on("memberJoin", function(member) trigger("join",{ member.id, member.name, - member.user.createdAt + discordia.Date():toSeconds()-member.user.createdAt },args) -- @joinOnce: userid, username, age, $USER, $USERNAME, $AGE, $DISCRIM, $TAG triggerOnce("joinOnce",{ member.id, member.name, - member.user.createdAt + discordia.Date():toSeconds()-member.user.createdAt },args) end) -client:on("memberLeave", function(member) - if tostring(member.guild.id) ~= tostring(id) then - return - end +event_emitter:on("memberLeave", function(member) args = { ["%$USER"] = member.id, ["%$USERNAME"] = member.name, - ["%$AGE"] = member.user.createdAt, + ["%$AGE"] = discordia.Date():toSeconds()-member.user.createdAt, ["%$DISCRIM"] = member.user.discriminator, ["%$TAG"] = member.user.tag, ["%$GUILDTIME"] = member.joinedAt, diff --git a/plugins/cron/init.lua b/plugins/cron/init.lua index e5ce839..ec725da 100644 --- a/plugins/cron/init.lua +++ b/plugins/cron/init.lua @@ -4,6 +4,8 @@ local plugin = pluginc("cron") local cron = import("cron") local fake_message = import("fake_message") local md5 = import("md5") +local discordia = import("discordia") +local event_emitter = events local events = { timer = {}, event = {} @@ -332,10 +334,11 @@ local data = fhandler:read("*a") fhandler:close() local eventfunc = load(data,"event loader: "..plugin_path.."/events.lua",nil,setmetatable({ id = id, - client = client, + event_emitter = event_emitter, exec = exec, events = events, - config = config + config = config, + discordia = discordia },{__index = _G})) eventfunc() timer:start(true) diff --git a/plugins/meta/init.lua b/plugins/meta/init.lua index 3a99516..c4eca35 100644 --- a/plugins/meta/init.lua +++ b/plugins/meta/init.lua @@ -172,7 +172,7 @@ local c_aliases = command("aliases", { return fields end)(), footer = { - text = "Events "..tostring(page-4).." - "..tostring(page).." | Total: "..tostring(#events) + text = "Aliases "..tostring(page-4).." - "..tostring(page).." | Total: "..tostring(#events) } }}) end diff --git a/plugins/security/help.lua b/plugins/security/help.lua index 23419f7..6bc69e5 100644 --- a/plugins/security/help.lua +++ b/plugins/security/help.lua @@ -43,4 +43,22 @@ return { {name = "Options: ", value = "`--regex (regex)` - match content against regex; \n`--user (user)` - match user against id/name; \n`-w` - match webhook messages"} } }}, + ["ban"] = { embed = { + title = "Ban members", + description = "nuff said.", + fields = { + {name = "Usage: ", value = "ban "}, + {name = "Perms: ", value = "banMembers"}, + {name = "Options: ", value = "--reason=\"\""}, + }, + }}, + ["kick"] = { embed = { + title = "Ban members", + description = "nuff said.", + fields = { + {name = "Usage: ", value = "kick "}, + {name = "Perms: ", value = "kickMembers"}, + {name = "Options: ", value = "--reason=\"\""}, + }, + }}, } diff --git a/plugins/security/init.lua b/plugins/security/init.lua index 8fb1c3b..bcb6093 100644 --- a/plugins/security/init.lua +++ b/plugins/security/init.lua @@ -48,6 +48,34 @@ local revokerole = command("revoke-role",{ }) plugin:add_command(revokerole) +local ban = command("ban",{ + category = "Security", + perms = { + "banMembers" + }, + args = { + "member" + }, + exec = function(msg,args,opts) + return args[1]:ban(opts["reason"]) + end +}) +plugin:add_command(ban) + +local kick = command("kick", { + category = "Security", + perms = { + "kickMembers", + }, + args = { + "member" + }, + exec = function(msg,args,opts) + return args[1]:ban(opts["reason"]) + end +}) +plugin:add_command(kick) + local warn = command("warn",{ category = "Security", perms = {