Bolodefchoco_LUAXML

[cmd] bdays

Oct 21st, 2020 (edited)
704
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local currentDay = tonumber(os.date("%d"))
  2. local currentMonth = os.date("%m")
  3. local past, upcoming, today = { }, { }, { }
  4. local pastIndex, upcomingIndex, todayIndex = 0, 0, 0
  5.  
  6. local day, get
  7. for memberId, memberData in next, memberProfiles do
  8.     if memberData.bday and string.sub(memberData.bday, 4, 5) == currentMonth then
  9.         day = tonumber(string.sub(memberData.bday, 1, 2))
  10.         get = #memberData.bday == 10
  11.  
  12.         memberId = "<@" .. memberId .. "> [" .. discord.getMemberName(memberId) .. "] - " .. memberData.bday
  13.         if day < currentDay then
  14.             pastIndex = pastIndex + 1
  15.             past[pastIndex] = memberId .. (get and (" - is " .. getAge(memberData.bday) .. " years old.") or '')
  16.         elseif day > currentDay then
  17.             upcomingIndex = upcomingIndex + 1
  18.             upcoming[upcomingIndex] = memberId .. (get and (" - will be " .. (getAge(memberData.bday) + 1) .. " years old.") or '')
  19.         else
  20.             todayIndex = todayIndex + 1
  21.             today[todayIndex] = memberId .. (get and (" - " .. getAge(memberData.bday) .. " years old.") or '')
  22.         end
  23.     end
  24. end
  25.  
  26. local fields, fieldsIndex = { }, 0
  27.  
  28. if todayIndex > 0 then
  29.     fieldsIndex = 1
  30.     fields[fieldsIndex] = {
  31.         name = ":tada: Today! :tada:",
  32.         value = table.concat(today, "\n")
  33.     }
  34. end
  35. if upcomingIndex > 0 then
  36.     fieldsIndex = fieldsIndex + 1
  37.     fields[fieldsIndex] = {
  38.         name = ":tada: Upcoming birthdays this month :tada:",
  39.         value = table.concat(upcoming, "\n")
  40.     }
  41. end
  42. if pastIndex > 0 then
  43.     fieldsIndex = fieldsIndex + 1
  44.     fields[fieldsIndex] = {
  45.         name = ":tada: Past birthdays this month :tada:",
  46.         value = table.concat(past, "\n")
  47.     }
  48. end
  49.  
  50. local color, title, description
  51. if fieldsIndex > 0 then
  52.     color = 0x65D665
  53. else
  54.     color = 0xD67265
  55.     title = ":( ..."
  56.     description = "There is no birthday this month :disappointed:"
  57. end
  58.  
  59. discord.reply({
  60.     embed = {
  61.         color = color,
  62.         fields = fields,
  63.         title = title,
  64.         description = description
  65.     }
  66. })
RAW Paste Data