add 8ball and refactor some code

This commit is contained in:
abbie 2022-11-03 21:08:59 +00:00
parent f8225512ea
commit 575307c013
No known key found for this signature in database
GPG key ID: A575D2415E5E5B6D

67
bot.lua
View file

@ -3,12 +3,23 @@ local client = discordia.Client()
local http = require("simple-http") local http = require("simple-http")
local json = require('json') local json = require('json')
local prefix = "." local prefix = "."
math.randomseed(os.time())
--- https://stackoverflow.com/a/22843701 --- https://stackoverflow.com/a/22843701
string.startswith = function(self, str) string.startswith = function(self, str)
return self:find('^' .. str) ~= nil return self:find('^' .. str) ~= nil
end end
function getnick(str, guild)
local b = str:gsub("<@",""):gsub(">","")
local user = guild:getMember(b)
if user.nickname == nil then
return user.name
else
return user.nickname
end
end
client:on('ready', function() client:on('ready', function()
print('Logged in as '.. client.user.username) print('Logged in as '.. client.user.username)
end) end)
@ -18,27 +29,61 @@ client:on('messageCreate', function(message)
message.channel:send({embed = {title = "Ping?",description = "Pong!",color = 0x00FFFF}}) message.channel:send({embed = {title = "Ping?",description = "Pong!",color = 0x00FFFF}})
end end
if message.content:startswith(prefix .. 'hug <@') then if message.content:startswith(prefix .. 'hug <@') then
local body, res = http.request("GET", "https://nekos.life/api/v2/img/hug") local action = "hug"
message.channel:send({embed = {title = "Aww! " .. message.guild:getMember(message.author.id).username .. " hugged " .. message.guild:getMember(message.content:gsub(prefix .. 'hug <@', ''):gsub('>', '')).username .. "!",color = 0x00FFFF, image = {url = body.url, height = 0, width = 0}}}) local actioner = " hugged "
local body, res = http.request("GET", "https://nekos.life/api/v2/img/" .. action)
message.channel:send({embed = {title = "Aww! " .. getnick(message.author.id, message.guild) .. actioner .. getnick(message.content:gsub(prefix .. action .. ' ', ''), message.guild) .. "!",color = 0x00FFFF, image = {url = body.url, height = 0, width = 0}}})
end end
if message.content:startswith(prefix .. 'cuddle <@') then if message.content:startswith(prefix .. 'cuddle <@') then
local body, res = http.request("GET", "https://nekos.life/api/v2/img/cuddle") local action = "cuddle"
message.channel:send({embed = {title = "Aww! " .. message.guild:getMember(message.author.id).username .. " cuddled " .. message.guild:getMember(message.content:gsub(prefix .. 'cuddle <@', ''):gsub('>', '')).username .. "!",color = 0x00FFFF, image = {url = body.url, height = 0, width = 0}}}) local actioner = " cuddled "
local body, res = http.request("GET", "https://nekos.life/api/v2/img/" .. action)
message.channel:send({embed = {title = "Aww! " .. getnick(message.author.id, message.guild) .. actioner .. getnick(message.content:gsub(prefix .. action .. ' ', ''), message.guild) .. "!",color = 0x00FFFF, image = {url = body.url, height = 0, width = 0}}})
end end
if message.content:startswith(prefix .. 'kiss <@') then if message.content:startswith(prefix .. 'kiss <@') then
local body, res = http.request("GET", "https://nekos.life/api/v2/img/kiss") local action = "kiss"
message.channel:send({embed = {title = "Aww! " .. message.guild:getMember(message.author.id).username .. " kissed " .. message.guild:getMember(message.content:gsub(prefix .. 'kiss <@', ''):gsub('>', '')).username .. "!",color = 0x00FFFF, image = {url = body.url, height = 0, width = 0}}}) local actioner = " kissed "
local body, res = http.request("GET", "https://nekos.life/api/v2/img/" .. action)
message.channel:send({embed = {title = "Aww! " .. getnick(message.author.id, message.guild) .. actioner .. getnick(message.content:gsub(prefix .. action .. ' ', ''), message.guild) .. "!",color = 0x00FFFF, image = {url = body.url, height = 0, width = 0}}})
end end
if message.content:startswith(prefix .. 'slap <@') then if message.content:startswith(prefix .. 'slap <@') then
local body, res = http.request("GET", "https://nekos.life/api/v2/img/slap") local action = "slap"
message.channel:send({embed = {title = "Aww! " .. message.guild:getMember(message.author.id).username .. " slapped " .. message.guild:getMember(message.content:gsub(prefix .. 'slap <@', ''):gsub('>', '')).username .. "!",color = 0x00FFFF, image = {url = body.url, height = 0, width = 0}}}) local actioner = " slapped "
local body, res = http.request("GET", "https://nekos.life/api/v2/img/" .. action)
message.channel:send({embed = {title = "Woah! " .. getnick(message.author.id, message.guild) .. actioner .. getnick(message.content:gsub(prefix .. action .. ' ', ''), message.guild) .. "!",color = 0x00FFFF, image = {url = body.url, height = 0, width = 0}}})
end end
if message.content:startswith(prefix .. 'pat <@') then if message.content:startswith(prefix .. 'pat <@') then
local body, res = http.request("GET", "https://nekos.life/api/v2/img/pat") local action = "pat"
message.channel:send({embed = {title = "Aww! " .. message.guild:getMember(message.author.id).username .. " patted " .. message.guild:getMember(message.content:gsub(prefix .. 'pat <@', ''):gsub('>', '')).username .. "!",color = 0x00FFFF, image = {url = body.url, height = 0, width = 0}}}) local actioner = " patted "
local body, res = http.request("GET", "https://nekos.life/api/v2/img/" .. action)
message.channel:send({embed = {title = "Aww! " .. getnick(message.author.id, message.guild) .. actioner .. getnick(message.content:gsub(prefix .. action .. ' ', ''), message.guild) .. "!",color = 0x00FFFF, image = {url = body.url, height = 0, width = 0}}})
end
if message.content:startswith(prefix .. '8ball') then
local array = {"As I see it, yes.", "Ask again later.", "Better not tell you now.", "Cannot predict now.", "Concentrate and ask again.","Dont count on it.", "It is certain.", "It is decidedly so.", "Most likely.", "My reply is no.", "My sources say no.","Outlook not so good.", "Outlook good.", "Reply hazy, try again.", "Signs point to yes.", "Very doubtful.", "Without a doubt.","Yes.", "Yes definitely.", "You may rely on it."}
local r = math.random(1,20)
if message.content:gsub(prefix..'8ball','') == "" or message.content:gsub(prefix..'8ball','') == " " then
message.channel:send("The 8-ball requires a question!")
else
message.channel:send("**" .. getnick(message.author.id,message.guild).. "** has asked the magic 8-ball: **"..message.content:gsub(prefix..'8ball ','').."**\n\nThe magic 8-ball replies: **"..array[r].."**")
end
end
if message.content == prefix .. 'hug' then
message.channel:send("You gotta hug someone!")
end
if message.content == prefix .. 'cuddle' then
message.channel:send("You gotta cuddle someone!")
end
if message.content == prefix .. 'slap' then
message.channel:send("You gotta slap someone!")
end
if message.content == prefix .. 'kiss' then
message.channel:send("You gotta kiss someone!")
end
if message.content == prefix .. 'pat' then
message.channel:send("You gotta pat someone!")
end end
if message.content == prefix .. 'help' then if message.content == prefix .. 'help' then
message.channel:send("**Need help? Refer to my handy dandy help sheet!**\n\n```diff\n+ Action\nhug kiss pat cuddle slap\n\n+ Info\nping help\n```") message.channel:send("**Need help? Refer to my handy dandy help sheet!**\n\n```diff\n+ Action\nhug kiss pat cuddle slap\n\n+ Fun\n8ball\n\n+ Info\nping help\n```")
end end
if message.content == prefix .. 'shutdown' then if message.content == prefix .. 'shutdown' then
if message.author.id == "867901290336223242" then if message.author.id == "867901290336223242" then