team.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. inactive = []
  22. members = CharTeam.where(team_id: team.id)
  23. members.each do |member|
  24. if member.active
  25. active.push(Character.find(member.char_id).name)
  26. else
  27. inactive.push(Character.find(member.char_id).name)
  28. end
  29. end
  30. fields.push({
  31. name: 'Active Members',
  32. value: active.join(", ")
  33. })unless active.empty?
  34. fields.push({
  35. name: 'Former Members',
  36. value: inactive.join(", ")
  37. })unless inactive.empty?
  38. embed = Embed.new(
  39. title: team.name,
  40. color: TEAM_BLUE,
  41. fields: fields
  42. )
  43. embed.description = team.description if team.description
  44. embed
  45. end
  46. def teams_embed
  47. fields = []
  48. active = []
  49. inactive = []
  50. teams = Team.all
  51. teams.each do |team|
  52. if team.active
  53. active.push(team.name)
  54. else
  55. inactive.push(team.name)
  56. end
  57. end
  58. fields.push({
  59. name: 'Active Teams',
  60. value: active.join(", ")
  61. })unless active.empty?
  62. fields.push({
  63. name: 'Inactive Teams',
  64. value: inactive.join(", ")
  65. })unless inactive.empty?
  66. Embed.new(
  67. title: 'Rescue Teams',
  68. description: 'Use `pkmn-team team_name` to learn more',
  69. color: TEAM_BLUE,
  70. fields: fields
  71. )
  72. end
  73. def team_app_embed(team, char, user)
  74. footer_text = user ? "#{user.name}##{user.tag}" : "Public NPC"
  75. footer_text += " | #{user.nickname}" if user && user.nickname
  76. footer_text += " | #{char.id}"
  77. img = CharImage.where(char_id: char.id).find_by(keyword: 'Default')
  78. embed = Embed.new(
  79. title: "#{char.name} would like to join your team!",
  80. description: "Please react to indicate if you'd like them to join!",
  81. author: { name: 'Team Join Request' }
  82. )
  83. embed.footer = user ?
  84. { text: footer_text, icon_url: user.avatar_url } : { text: footer_text }
  85. embed.thumbnail = { url: img.url } if img
  86. embed
  87. end