team.rb 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. TEAM_BLUE = "#3498db"
  2. def new_team_embed(user, team_name, desc)
  3. footer_text = "#{user.name}##{user.tag}"
  4. footer_text += " | #{user.nickname}" if user.nickname
  5. Embed.new(
  6. title: team_name,
  7. description: desc,
  8. color: TEAM_BLUE,
  9. author: {
  10. name: 'Team Application'
  11. },
  12. footer: {
  13. text: footer_text,
  14. icon_url: user.avatar_url
  15. }
  16. )
  17. end
  18. def team_embed(team)
  19. fields = []
  20. active = []
  21. members = CharTeam.where(team_id: team.id)
  22. members.each do |member|
  23. if member.active
  24. active.push(Character.find(member.char_id).name)
  25. end
  26. end
  27. fields.push({
  28. name: 'Active Members',
  29. value: active.join(", ")
  30. })unless active.empty?
  31. embed = Embed.new(
  32. title: team.name,
  33. color: TEAM_BLUE,
  34. fields: fields
  35. )
  36. embed.description = team.description if team.description
  37. embed
  38. end
  39. def teams_embed
  40. fields = []
  41. active = []
  42. inactive = []
  43. teams = Team.all
  44. teams.each do |team|
  45. if team.active
  46. active.push(team.name)
  47. else
  48. inactive.push(team.name)
  49. end
  50. end
  51. fields.push({
  52. name: 'Active Teams',
  53. value: active.join(", ")
  54. })unless active.empty?
  55. fields.push({
  56. name: 'Inactive Teams',
  57. value: inactive.join(", ")
  58. })unless inactive.empty?
  59. Embed.new(
  60. title: 'Rescue Teams',
  61. description: 'Use `pkmn-team team_name` to learn more',
  62. color: TEAM_BLUE,
  63. fields: fields
  64. )
  65. end
  66. def team_app_embed(team, char, user)
  67. footer_text = user ? "#{user.name}##{user.tag}" : "Public NPC"
  68. footer_text += " | #{user.nickname}" if user && user.nickname
  69. footer_text += " | #{char.id}"
  70. img = CharImage.where(char_id: char.id).find_by(keyword: 'Default')
  71. embed = Embed.new(
  72. title: "#{char.name} would like to join your team!",
  73. description: "Please react to indicate if you'd like them to join!",
  74. author: { name: 'Team Join Request' }
  75. )
  76. embed.footer = user ?
  77. { text: footer_text, icon_url: user.avatar_url } : { text: footer_text }
  78. embed.thumbnail = { url: img.url } if img
  79. embed
  80. end