Skip to content

Commit

Permalink
v0.4
Browse files Browse the repository at this point in the history
Added commands:
- pickrandom (picks a random word from supplied arguments, split by spaces)
- ynm (ask a question and get a reply ranging from yes, no or maybe)
- checklove (ping two users and get their love value calculated based on their discord IDs)
- checktruth (provide a string of text after the command name and get the string's objective, inrefutable and correct truth value)

Changes:
- Help command is now more compact
- added a "Playing" status message
  • Loading branch information
nirokay committed Jul 30, 2022
1 parent e7e288a commit e04b4c6
Show file tree
Hide file tree
Showing 11 changed files with 368 additions and 25 deletions.
12 changes: 12 additions & 0 deletions data/BotProfile.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BotProfile = {
playing = "=help"
}

BotProfile.status = string.format([[
%s is a general-purpose bot written in Lua.
My default prefix is %s, see %shelp for more information about me!
My source code can be viewed here: %s
]], info.name, info.prefix, info.prefix ,info.repository)

return BotProfile
12 changes: 12 additions & 0 deletions data/Changelog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,16 @@ Added command:
- convert (converts units of measurements)
]]

Changelog['v0.4'] = [[
Added commands:
- pickrandom (picks a random word from supplied arguments, split by spaces)
- ynm (ask a question and get a reply ranging from yes, no or maybe)
- checklove (ping two users and get their love value calculated based on their discord IDs)
- checktruth (provide a string of text after the command name and get the string's objective, inrefutable and correct truth value)
Changes:
- Help command is now more compact
- added a "Playing" status message
]]

return Changelog
109 changes: 101 additions & 8 deletions data/CommandList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ local commandType = {
add("info", "Displays info about the bot.", commandType.technical, function(Message, Caller, ...)
local output = "Hi, I'm " .. info.name .. "\nI am a general-purpose bot, written in Lua!\n"
local prefix = "My prefix is: " .. info.prefix
local source = "Check out my source code: " .. info.repository
local source = "Check out my source code: `" .. info.repository .. "`"

output = output .. string.format("%s\n%s\n", prefix, source)
Message.channel:send(output)
Expand All @@ -48,13 +48,13 @@ add("help", "Displays a help message about all commands.", commandType.technical

-- Add one by one by types to output:
for i, v in pairs(sorted) do
output = output .. "\n\n**__" .. tostring(i) .. "__**"
output = output .. "\n**__" .. tostring(i) .. "__**:"

-- Add each command to output:
for _, l in pairs(v) do
local cmd_name = "**" .. tostring(l.name) .. "**"
local desc = "" .. tostring(l.desc) .. ""
output = output .. "\n " .. cmd_name .. "\n " .. desc .. ""
local desc = "*" .. tostring(l.desc) .. "*"
output = output .. "\n> " .. cmd_name .. " " .. desc
end
end

Expand All @@ -74,7 +74,6 @@ add("changelog", "Shows the changelog for the current or a specific version of t
else
showVersion = arg[1]
end


if Changelog[showVersion] == nil then
local tab = {}
Expand All @@ -99,7 +98,7 @@ add("echo", "I will echo back whatever you said to me.", commandType.chat, funct
return
end
local str = table.concat(tab, " ")

Message.channel:send(Message.author.mentionString .. " said: '" .. str .. "'")
end)

Expand All @@ -120,6 +119,100 @@ add("flip", "Flip a coin.", commandType.math, function(Message, Caller, ...)
Message.channel:send(Message.author.mentionString .. " flipped a coin:\n**" .. flip .. "**")
end)

add("ynm", "Yes? No? Maybe? Ask me a question!", commandType.math, function(Message, Caller, ...)
local args = ...
local temp = string.format(YesNoMaybe.askMeSomethingPrompt, Message.author.mentionString)
if args == nil then
Message.channel:send(temp)
return
end
if #args < 1 then
Message.channel:send(temp)
return
end
local vals = {}

for i,v in pairs(YesNoMaybe.weight) do
for _=0, v do
table.insert(vals, i)
end
end

local out = easy.string.firstUppercase(easy.table.randomIn(vals))
Message.channel:send(string.format(YesNoMaybe.responsePrompt, out, Message.author.mentionString))
end)

add("pickrandom", "Pick a random word from a string input (seperated by spaces).", commandType.math, function(Message, Caller, ...)
local args = ...
local usage = "\nUsage: pickrandom option1 option2 option3 long_option_four option.5 ( -> randomly chosen)"

local function handleErrorMessage(txt, ...)
Message.channel:send(string.format(txt, ...) .. usage)
end
if args == nil then
handleErrorMessage("Please provide a string from which words can be randomly picked.")
return
end
if #args < 1 then
handleErrorMessage("Please provide a string from which words can be randomly picked.")
return
end

local pick = easy.table.randomIn(args)
Message.channel:send("Your randomly chosen word is:\n**" .. pick .. "**")
end)

add("checklove", "Check the love value between two members.", commandType.math, function(Message, Caller, ...)
local mentioned = Message.mentionedUsers
local usage = "\nUsage: checklove @FirstMember @SecondMember"
if #mentioned < 2 then
Message.channel:send("You need to provide two users as input!" .. usage)
end

-- Member IDs:
mentioned = {mentioned[1][1], mentioned[1][2]}

local percentage = (mentioned[1]%1000 + mentioned[2]%1000) % 101
Message.channel:send(string.format("%s x %s = %d%s", "<@"..mentioned[1]..">", "<@"..mentioned[2]..">", percentage, "%"))
end)

add("checktruth", "Check the truth-value of a given statement.", commandType.math, function(Message, Caller, ...)
local args = ...
local usage = "\nUsage: checktruth This String Will Be Evaluated For The Truth Value"
local function handleErrorMessage(txt, ...)
Message.channel:send(string.format(txt, ...) .. usage)
end

-- Check if string provided:
if args == nil then
handleErrorMessage("Faulty Syntax. You need to provide a string to evaluate after the command name!")
return
end
if #args < 1 then
handleErrorMessage("Faulty Syntax. You need to provide a string to evaluate after the command name!")
return
end

local fullString = table.concat(args, " ")
local fullEncoded = base64.encode(tostring(fullString))
local percentage = 0

-- Emergency Break-Out:
if fullEncoded == nil then
Message.channel:send("There was an error calculating the truth value...")
return
end

-- Calculate Percentage:
for i=1, #fullEncoded do
local char = string.sub(fullEncoded, i, i)
percentage = percentage + string.byte(char)
end
percentage = percentage % 101

Message.channel:send(string.format("The truth value for... `%s`... is %d%s!", fullString, percentage, "%"))
end)

add("roll", "Roll a die. (Supports `roll int int` and `roll string`(-> String: '2d6', '4d20') )", commandType.math, function(Message, Caller, ...)
local arg = ...
local default = "1d6"
Expand Down Expand Up @@ -192,7 +285,7 @@ add("convert", "Convert units of measurement.", commandType.math, function(Messa
for j,k in pairs(v) do
table.insert(concat, j)
end
local cat_name = (string.sub(i, 1, 1)):upper()..string.sub(i, 2, -1):lower()
local cat_name = easy.string.firstUppercase(i)
usage = usage .. "\n" .. cat_name .. ":\n> " .. table.concat(concat, ", ")
end
local function handleErrorMessage(txt, ...)
Expand Down Expand Up @@ -273,7 +366,7 @@ local function handleSocialEvent(Message, Caller, type, textAction, emojis)
local text = textAction .. " you"
local emoji = emojis[1]
local gifs = Gifs[type]
local gif = gifs[math.random(1, #gifs)]
local gif = easy.table.randomIn(gifs)

-- User @'ed themselves:
if active == passive then
Expand Down
10 changes: 0 additions & 10 deletions data/ReactionList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,4 @@ local function add(id, reactionType, reaction, trigger)
ReactionList[id] = MessageSubstring:init(id, reactionType, reaction, trigger)
end

-- Add Reactions here:
add("general_kenobi", "reply",
{"General Kenobi!"},
{"hello there", "hello there!"}
)
add("hi_dad", "reply",
{"Hi, I'm dad!"},
{"i am", "i'm", "im"}
)

return ReactionList
2 changes: 1 addition & 1 deletion data/Units.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Units.list = {
['pint'] = 0.4731765,
['drop'] = 0.00005
},
['weigth'] = {
['mass'] = {
['mg'] = 0.001,
['g'] = 1,
['kg'] = 1000,
Expand Down
17 changes: 17 additions & 0 deletions data/YesNoMaybe.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- This file contains the weight values for yes, no and maybe for the ynm command:
-- Notice: Numbers are not percentages!

YesNoMaybe = {}
YesNoMaybe.weight = {
['yes'] = 5,
['no'] = 5,
['maybe'] = 2
}

-- This string will be fed through string.format(), %s is Message.author.mentionString (Ping)
YesNoMaybe.askMeSomethingPrompt = "I don't know, how about you ask me something, %s?"

-- This is the answer string, it will be fed through string.format() as well: (first is out, second is Message.author.mentionString)
YesNoMaybe.responsePrompt = "%s, %s."

return YesNoMaybe
3 changes: 2 additions & 1 deletion globalInfo.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- Information considered to be global: (can be modified, but has nothing secret or config-related in it)
globalInfo = {
version = 'v0.3'
version = 'v0.4'
}

return globalInfo
5 changes: 4 additions & 1 deletion import.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ bot = require "src/bot"
easy = require "src/easy"

-- Libraries:
Class = require "lib/class" -- https://github.com/vrld/hump/blob/master/class.lua
Class = require "lib/class" -- https://github.com/vrld/hump/blob/master/class.lua
Switch = require "lib/Switch" -- https://github.com/NiroUwU/Lua-Utils/blob/main/Switch.lua
base64 = require "lib/base64" -- https://github.com/iskolbin/lbase64/blob/master/base64.lua

-- Import General Data About the Bot
globalInfo = require "globalInfo"
Expand All @@ -22,7 +23,9 @@ require "data/ReactionList"
require "data/BannedIDs"

-- Data required for Commands:
require "data/BotProfile"
require "data/Units"
require "data/HelloResponse"
require "data/Gifs"
require "data/Changelog"
require "data/YesNoMaybe"
Loading

0 comments on commit e04b4c6

Please sign in to comment.