bot.rb 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. require 'bundler'
  2. require 'erb'
  3. require 'yaml'
  4. require 'json'
  5. require 'terminal-table'
  6. BOT_ENV = ENV.fetch('BOT_ENV') { 'development' }
  7. Bundler.require(:default, BOT_ENV)
  8. require 'active_record'
  9. # Constants: such as roles and channel ids
  10. ADMINS = 308250685554556930
  11. #ADMINS = 453262984769437696
  12. # ---
  13. Dotenv.load if BOT_ENV != 'production'
  14. db_yml = File.open('config/database.yml') do |erb|
  15. ERB.new(erb.read).result
  16. end
  17. db_config = YAML.safe_load(db_yml)[BOT_ENV]
  18. ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
  19. ActiveRecord::Base.establish_connection(
  20. adapter: 'postgresql',
  21. host: db_config.fetch('host') { 'localhost' },
  22. database: db_config['database'],
  23. user: db_config['user'],
  24. password: db_config['password']
  25. )
  26. Dir['app/**/*.rb'].each { |f| require File.join(File.expand_path(__dir__), f) }
  27. Dir['/lib/*.rb'].each { |f| require f }
  28. token = ENV['DISCORD_BOT_TOKEN']
  29. bot = Discordrb::Bot.new(token: token)
  30. # Methods: define basic methods here
  31. # ---
  32. # Commands: structure basic bot commands here
  33. commands = []
  34. pm_commands = []
  35. hello = Command.new(:hello, "Says hello!") do |event|
  36. user = event.author.nickname || event.author.name
  37. greetings = [
  38. "Hi there, #{user}",
  39. "Greetings #{user}, you lovable bum",
  40. "Alola, #{user}",
  41. "Hello, #{user}! The Guildmasters have been waiting",
  42. "#{user} would like to battle!"
  43. ]
  44. Embed.new(
  45. description: greetings.sample,
  46. color: event.author.color.combined,
  47. thumbnail: {
  48. url: Image::HAPPY
  49. }
  50. )
  51. end
  52. opts = {
  53. "" => "displays a list of all commands",
  54. "command" => "displays info and usage for specified command"
  55. }
  56. desc = "Displays help information for the commands"
  57. help = Command.new(:help, desc, opts) do |event, command|
  58. if command
  59. short = /pkmn-(\w+)/.match(command)
  60. command = short ? short[1] : command
  61. cmd = commands.detect { |c| c.name == command.to_sym }
  62. pm_cmd = pm_commands.detect { |pc| pc.name == command.to_sym }
  63. end
  64. if command && cmd
  65. command_embed(cmd)
  66. elsif command && pm_cmd
  67. command_embed(pm_cmd, "PM Command")
  68. elsif !command
  69. embed = command_list_embed(
  70. pm_commands,
  71. "Can only be used in a pm with the bot",
  72. "PM Commands"
  73. )
  74. event.send_embed("", embed)
  75. command_list_embed(commands)
  76. else
  77. command_error_embed("Command not found!", help)
  78. end
  79. end
  80. opts = { "type" => "" }
  81. desc = "Displays a chart of effectiveness for the given type"
  82. matchup = Command.new(:matchup, desc, opts) do |event, type|
  83. channel = event.channel.id
  84. file = "images/Type #{type.capitalize}.png"
  85. if File.exists?(file)
  86. bot.send_file(channel, File.open(file, 'r'))
  87. else
  88. bot.respond("I do not know this pokemon type! Please try again!")
  89. end
  90. end
  91. opts = {
  92. "" => "starts a new app",
  93. "name" => "edits an existing app",
  94. "name | (in)active" => "sets app to active or inactive"
  95. }
  96. desc = "Everything to do with character applications"
  97. app = Command.new(:app, desc, opts) do |event, name, status|
  98. user = event.author
  99. user_name = user.nickname || user.name
  100. color = user.color ? user.color.combined : Color::DEFAULT
  101. character = Character.where(user_id: user.id).find_by(name: name) if name
  102. active = status.match(/(in)?active/i) if status
  103. case
  104. when name && !character
  105. app_not_found_embed(user_name, name)
  106. when status && active && character
  107. character.update!(active: active[0].capitalize)
  108. character.reload
  109. success_embed("Successfully updated #{name} to be #{active[0].downcase}")
  110. when name && character && !status
  111. edit_url = Url::CHARACTER + character.edit_url
  112. embed = edit_app_dm(name, edit_url, color)
  113. bot.send_message(user.dm.id, "", false, embed)
  114. edit_app_embed(user_name, name, color)
  115. when !name && !status
  116. embed = new_app_dm(user_name, color, user.id)
  117. message = bot.send_message(user.dm.id, "", false, embed)
  118. message.react(Emoji::PHONE)
  119. new_app_embed(user_name, color)
  120. else
  121. command_error_embed("There was an error processing your application!", app)
  122. end
  123. end
  124. opts = { "question | option1, option2, etc" => ""}
  125. desc = "Creates a dynamic poll in any channel"
  126. poll = Command.new(:poll, desc, opts) do |event, question, options|
  127. if options
  128. options_array = options.split(/\s?,\s?/)
  129. new_poll_embed(event, question, options_array)
  130. else
  131. command_error_embed("There was an error creating your poll!", poll)
  132. end
  133. end
  134. opts = {
  135. "participants" =>
  136. "Accepts Everyone, Here, or a comma seperated list of names"
  137. }
  138. desc = "Creates a raffle and picks a winner"
  139. raffle = Command.new(:raffle, desc, opts) do |event, participant|
  140. participants =
  141. case participant
  142. when /^everyone$/i
  143. event.server.members
  144. when /^here$/i
  145. event.message.channel.users
  146. else
  147. participant.split(/\s?,\s?/)
  148. end
  149. winner = participants.sample
  150. winner_name =
  151. case winner
  152. when String
  153. winner
  154. else
  155. winner.nickname || winner.username
  156. end
  157. if winner_name
  158. message_embed("Raffle Results!", "Winner: #{winner_name}")
  159. else
  160. command_error_embed("There was an error creating your raffle!", raffle)
  161. end
  162. end
  163. opts = {
  164. "name | keyword | (n)sfw | url" => "add or update image",
  165. "name | keyword | delete" => "remove image",
  166. "name | keyword" => "display image",
  167. "name" => "list all images"
  168. }
  169. desc = "View, add and edit your characters' images"
  170. image = Command.new(:image, desc, opts) do |event, name, keyword, tag, url|
  171. user = event.author
  172. char = Character.where(user_id: user.id).find_by!(name: name) if name
  173. color = CharacterController.type_color(char) if char
  174. img = CharImage.where(char_id: char.id).find_by(keyword: keyword) if keyword
  175. case
  176. when /^Default$/i.match(keyword)
  177. error_embed(
  178. "Cannot update Default here!",
  179. "Use `pkmn-app character` to edit your default image in your form"
  180. )
  181. when char && keyword && url && tag && tag.match(/(n)?sfw/i)
  182. img_app = CharImage.to_form(
  183. char: char,
  184. keyword: keyword,
  185. category: tag,
  186. url: url,
  187. user_id: user.id
  188. )
  189. approval = bot.send_message(Channel::APPROVAL, "", false, img_app)
  190. approval.react(Emoji::Y)
  191. approval.react(Emoji::N)
  192. success_embed("Your image has been submitted for approval!")
  193. when char && img && tag && tag.match(/delete/i)
  194. CharImage.find(img.id).delete
  195. success_embed("Removed image: #{keyword}")
  196. when char && img && !tag
  197. char_image_embed(char, img, user, color)
  198. when char && !keyword
  199. imgs = CharImage.where(char_id: char.id)
  200. image_list_embed(char, imgs, user, color)
  201. when keyword && !img
  202. error_embed("Could not find your image!")
  203. else
  204. command_error_embed("Could not process your image request!", image)
  205. end
  206. rescue ActiveRecord::RecordNotFound
  207. error_embed(
  208. "Character not Found!",
  209. "I could not find your character named #{name}"
  210. )
  211. end
  212. opts = {
  213. "" => "List all guild members",
  214. "@user" => "List all characters belonging to the user",
  215. "name " => "Display the given character",
  216. "name | section" => "Display the given section for the character",
  217. "name | image | keword" => "Display the given image"
  218. }
  219. desc = "Display info about the guild members"
  220. member = Command.new(:member, desc, opts) do |event, name, section, keyword|
  221. sections = [:all, :default, :bio, :type, :status, :rumors, :image]
  222. case name
  223. when Regex::UID
  224. user_id = Regex::UID.match(name)
  225. when String
  226. chars = Character.where(name: name)
  227. char = chars.first if chars.length == 1
  228. if char
  229. img = CharImage.where(char_id: char.id).find_by(keyword: 'Default')
  230. user = event.server.member(char.user_id)
  231. color = CharacterController.type_color(char)
  232. end
  233. end
  234. case
  235. when !name
  236. chars = Character.all
  237. char_list_embed(chars)
  238. when name && user_id
  239. chars = Character.where(user_id: user_id[1])
  240. user = event.server.member(user_id[1])
  241. chars_id = []
  242. chars.each do |char|
  243. chars_id.push char.id if char.active == 'Active'
  244. end
  245. embed = user_char_embed(chars, user)
  246. msg = event.send_embed("", embed)
  247. Carousel.create(message_id: msg.id, options: chars_id)
  248. option_react(msg, chars_id)
  249. when name && chars.empty?
  250. error_embed(
  251. "Character not found!",
  252. "Could not find a character named #{name}"
  253. )
  254. when name && chars && !char
  255. embed = dup_char_embed(chars, name)
  256. chars_id = chars.map(&:id)
  257. msg = event.send_embed("", embed)
  258. Carousel.create(message_id: msg.id, options: chars_id)
  259. option_react(msg, chars_id)
  260. when name && char && !section
  261. embed = character_embed(
  262. char: char,
  263. img: img,
  264. section: :default,
  265. user: user,
  266. color: color
  267. )
  268. msg = event.send_embed("", embed)
  269. Carousel.create(message_id: msg.id, char_id: char.id)
  270. section_react(msg)
  271. when char && section && keyword
  272. embed = command_error_embed(
  273. "Invalid Arguments",
  274. member
  275. )unless /image/i.match(section)
  276. unless embed
  277. img = CharImage.where(char_id: char.id).find_by!(keyword: keyword)
  278. embed = error_embed(
  279. "Wrong Channel!",
  280. "The requested image is NSFW"
  281. )if img.category == 'NSFW' && !event.channel.nsfw?
  282. end
  283. unless embed
  284. embed = character_embed(
  285. char: char,
  286. img: img,
  287. section: :image,
  288. user: user,
  289. color: color
  290. )
  291. msg = event.send_embed("", embed)
  292. Carousel.create(message_id: msg.id, char_id: char.id, image_id: img.id)
  293. arrow_react(msg)
  294. end
  295. embed
  296. when name && char && section
  297. sect = section.downcase.to_sym
  298. nsfw = event.channel.nsfw?
  299. img = ImageController.img_scroll(
  300. char_id: char.id,
  301. nsfw: nsfw
  302. )if section == :image
  303. if sections.detect{ |s| s == sect }
  304. embed = character_embed(
  305. char: char,
  306. img: img,
  307. section: sect,
  308. user: user,
  309. color: color,
  310. )
  311. msg = event.send_embed("", embed)
  312. Carousel.create(message_id: msg.id, char_id: char.id, image_id: img.id)
  313. if sect == :image
  314. arrow_react(msg)
  315. else
  316. section_react(msg)
  317. end
  318. else
  319. error_embed("Invalid Section!")
  320. end
  321. end
  322. rescue ActiveRecord::RecordNotFound => e
  323. error_embed("Record Not Found!", e.message)
  324. end
  325. # ---
  326. commands = [
  327. hello,
  328. matchup,
  329. app,
  330. help,
  331. poll,
  332. raffle,
  333. member
  334. ]
  335. # This will trigger on every message sent in discord
  336. bot.message do |event|
  337. content = event.message.content
  338. author = event.author.id
  339. command = /^pkmn-(\w+)/.match(content)
  340. cmd = commands.detect { |c| c.name == command[1].to_sym } if command
  341. reply = cmd.call(content, event) if cmd
  342. case reply
  343. when Embed
  344. event.send_embed("", reply)
  345. when String
  346. event.respond(reply)
  347. end
  348. event.send_embed(
  349. "",
  350. error_embed("Command not found!")
  351. )if command && !cmd && event.server
  352. Character.check_user(event) if author == Bot::CHARACTER
  353. end
  354. pm_commands = [ image ]
  355. # This will trigger when a dm is sent to the bot from a user
  356. bot.pm do |event|
  357. content = event.message.content
  358. command = /^pkmn-(\w+)/.match(content)
  359. cmd = pm_commands.detect { |c| c.name == command[1].to_sym } if command
  360. reply = cmd.call(content, event) if cmd
  361. case reply
  362. when Embed
  363. event.send_embed("", reply)
  364. when String
  365. event.respond(reply)
  366. end
  367. end
  368. # This will trigger when any reaction is added in discord
  369. bot.reaction_add do |event|
  370. reactions = event.message.reactions
  371. app = event.message.embeds.first
  372. carousel = Carousel.find_by(message_id: event.message.id)
  373. maj = if event.server
  374. event.server.roles.find{ |r| r.id == ADMINS }.members.count / 2
  375. end
  376. maj = 1
  377. form =
  378. case app.author.name
  379. when 'New App' then :new_app
  380. when 'Character Application' then :character_application
  381. when 'Character Rejection' then :character_rejection
  382. when 'Image Application' then :image_application
  383. when 'Image Rejection' then :image_rejection
  384. else
  385. :carousel if carousel
  386. end
  387. vote =
  388. case
  389. when reactions[Emoji::Y]&.count.to_i > maj then :yes
  390. when reactions[Emoji::N]&.count.to_i > maj then :no
  391. when reactions[Emoji::CHECK]&.count.to_i > 1 then :check
  392. when reactions[Emoji::CROSS]&.count.to_i > 1 then :cross
  393. when reactions[Emoji::CRAYON]&.count.to_i > 1 then :crayon
  394. when reactions[Emoji::NOTEBOOK]&.count.to_i > 1 then :notebook
  395. when reactions[Emoji::QUESTION]&.count.to_i > 1 then :question
  396. when reactions[Emoji::PALLET]&.count.to_i > 1 then :pallet
  397. when reactions[Emoji::EAR]&.count.to_i > 1 then :ear
  398. when reactions[Emoji::PICTURE]&.count.to_i > 1 then :picture
  399. when reactions[Emoji::BAGS]&.count.to_i > 1 then :bags
  400. when reactions[Emoji::FAMILY]&.count.to_i > 1 then :family
  401. when reactions[Emoji::EYES]&.count.to_i > 1 then :eyes
  402. when reactions[Emoji::KEY]&.count.to_i > 1 then :key
  403. when reactions[Emoji::PHONE]&.count.to_i > 1 then :phone
  404. when reactions[Emoji::LEFT]&.count.to_i > 1 then :left
  405. when reactions[Emoji::RIGHT]&.count.to_i > 1 then :right
  406. when reactions[Emoji::UNDO]&.count.to_i > 1 then :back
  407. when reactions.any? { |k,v| Emoji::NUMBERS.include? k } then :number
  408. end
  409. case [form, vote]
  410. when [:character_application, :yes]
  411. app = event.message.embeds.first
  412. uid = Regex::UID.match(app.description)
  413. user = event.server.member(uid[1])
  414. char = CharacterController.edit_character(app)
  415. img = ImageController.default_image(app.thumbnail.url, char.id)
  416. color = CharacterController.type_color(char)
  417. embed = character_embed(
  418. char: char,
  419. img: img,
  420. user: user,
  421. color: color
  422. )if char
  423. if embed
  424. bot.send_message(
  425. Channel::CHARACTER,
  426. "Good news, <@#{uid}>! Your character was approved",
  427. false,
  428. embed
  429. )
  430. event.message.delete
  431. else
  432. event.respond(
  433. "",
  434. admin_error_embed("Something went wrong when saving application")
  435. )
  436. end
  437. when [:character_application, :no]
  438. embed = reject_char_embed(app)
  439. event.message.delete
  440. reject = event.send_embed("", embed)
  441. Emoji::CHAR_APP.each do |reaction|
  442. reject.react(reaction)
  443. end
  444. reject.react(Emoji::CHECK)
  445. reject.react(Emoji::CROSS)
  446. reject.react(Emoji::CRAYON)
  447. when [:character_rejection, :check]
  448. user = event.server.member(Regex::UID.match(app.description)[1])
  449. embed = user_char_app(event)
  450. event.message.delete
  451. bot.send_temporary_message(event.channel.id, "", 5, false, embed)
  452. bot.send_message(user.dm.id, "", false, embed)
  453. when [:character_rejection, :cross]
  454. event.message.delete
  455. when [:character_rejection, :crayon]
  456. event.message.delete
  457. bot.send_temporary_message(
  458. event.channel.id,
  459. "",
  460. 35,
  461. false,
  462. self_edit_embed(app)
  463. )
  464. when [:new_app, :phone]
  465. event.message.delete_own_reaction(Emoji::PHONE)
  466. user = event.message.reacted_with(Emoji::PHONE).first
  467. bot.send_message(user.dm.id, user.id, false, nil)
  468. when [:image_application, :yes]
  469. img = ImageController.edit_image(app)
  470. char = Character.find(img.char_id)
  471. user = event.server.member(char.user_id)
  472. color = CharacterController.type_color(char)
  473. embed = char_image_embed(char, img, user, color)
  474. event.message.delete if embed
  475. channel = if img.category == 'SFW'
  476. Channel::CHARACTER
  477. else
  478. Channel::CHARACTER_NSFW
  479. end
  480. bot.send_message(channel, "Image Approved!", false, embed)
  481. when [:image_application, :no]
  482. embed = reject_img_embed(app)
  483. event.message.delete
  484. reject = event.send_embed("", embed)
  485. Emoji::IMG_APP.each do |reaction|
  486. reject.react(reaction)
  487. end
  488. reject.react(Emoji::CHECK)
  489. reject.react(Emoji::CROSS)
  490. when [:image_rejection, :check]
  491. user = event.server.member(Regex::UID.match(app.description)[1])
  492. embed = user_img_app(event)
  493. event.message.delete
  494. bot.send_temporary_message(event.channel.id, "", 5, false, embed)
  495. bot.send_message(user.dm.id, "", false, embed)
  496. when [:image_rejection, :cross]
  497. event.message.delete
  498. when [:carousel, :notebook]
  499. emoji = Emoji::NOTEBOOK
  500. users = event.message.reacted_with(emoji)
  501. users.each do |user|
  502. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  503. end
  504. char = Character.find(carousel.char_id)
  505. embed = character_embed(
  506. char: char,
  507. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  508. user: event.server.member(char.user_id),
  509. color: CharacterController.type_color(char),
  510. section: :bio
  511. )
  512. event.message.edit("", embed)
  513. when [:carousel, :question]
  514. emoji = Emoji::QUESTION
  515. users = event.message.reacted_with(emoji)
  516. users.each do |user|
  517. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  518. end
  519. char = Character.find(carousel.char_id)
  520. embed = character_embed(
  521. char: char,
  522. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  523. user: event.server.member(char.user_id),
  524. color: CharacterController.type_color(char),
  525. section: :status
  526. )
  527. event.message.edit("", embed)
  528. when [:carousel, :pallet]
  529. emoji = Emoji::PALLET
  530. users = event.message.reacted_with(emoji)
  531. users.each do |user|
  532. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  533. end
  534. char = Character.find(carousel.char_id)
  535. embed = character_embed(
  536. char: char,
  537. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  538. user: event.server.member(char.user_id),
  539. color: CharacterController.type_color(char),
  540. section: :type
  541. )
  542. event.message.edit("", embed)
  543. when [:carousel, :ear]
  544. emoji = Emoji::EAR
  545. users = event.message.reacted_with(emoji)
  546. users.each do |user|
  547. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  548. end
  549. char = Character.find(carousel.char_id)
  550. embed = character_embed(
  551. char: char,
  552. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  553. user: event.server.member(char.user_id),
  554. color: CharacterController.type_color(char),
  555. section: :rumors
  556. )
  557. event.message.edit("", embed)
  558. when [:carousel, :picture]
  559. event.message.delete_all_reactions
  560. char = Character.find(carousel.char_id)
  561. img = ImageController.img_scroll(
  562. char_id: char.id,
  563. nsfw: event.channel.nsfw?,
  564. )
  565. carousel.update(id: carousel.id, image_id: img.id)
  566. embed = character_embed(
  567. char: char,
  568. img: img,
  569. user: event.server.member(char.user_id),
  570. color: CharacterController.type_color(char),
  571. section: :image
  572. )
  573. event.message.edit("", embed)
  574. arrow_react(event.message)
  575. when [:carousel, :bags]
  576. when [:carousel, :family]
  577. when [:carousel, :eyes]
  578. emoji = Emoji::EYES
  579. users = event.message.reacted_with(emoji)
  580. users.each do |user|
  581. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  582. end
  583. char = Character.find(carousel.char_id)
  584. embed = character_embed(
  585. char: char,
  586. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  587. user: event.server.member(char.user_id),
  588. color: CharacterController.type_color(char),
  589. section: :all
  590. )
  591. event.message.edit("", embed)
  592. when [:carousel, :key]
  593. emoji = Emoji::KEY
  594. users = event.message.reacted_with(emoji)
  595. users.each do |user|
  596. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  597. end
  598. char = Character.find(carousel.char_id)
  599. embed = character_embed(
  600. char: char,
  601. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  602. user: event.server.member(char.user_id),
  603. color: CharacterController.type_color(char),
  604. section: :default
  605. )
  606. event.message.edit("", embed)
  607. when [:carousel, :back]
  608. event.message.delete_all_reactions
  609. char = Character.find(carousel.char_id)
  610. embed = character_embed(
  611. char: char,
  612. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  613. user: event.server.member(char.user_id),
  614. color: CharacterController.type_color(char),
  615. section: :default
  616. )
  617. event.message.edit("", embed)
  618. section_react(event.message)
  619. when [:carousel, :left], [:carousel, :right]
  620. emoji = vote == :left ? Emoji::LEFT : Emoji::RIGHT
  621. users = event.message.reacted_with(emoji)
  622. users.each do |user|
  623. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  624. end
  625. char = Character.find(carousel.char_id)
  626. img = ImageController.img_scroll(
  627. char_id: char.id,
  628. nsfw: event.channel.nsfw?,
  629. img: carousel.image_id,
  630. dir: vote
  631. )
  632. carousel.update(id: carousel.id, image_id: img.id)
  633. embed = character_embed(
  634. char: char,
  635. img: img,
  636. user: event.server.member(char.user_id),
  637. color: CharacterController.type_color(char),
  638. section: :image
  639. )
  640. event.message.edit("", embed)
  641. when [:carousel, :number]
  642. char_index = nil
  643. Emoji::NUMBERS.each.with_index do |emoji, i|
  644. char_index = i if reactions[emoji]&.count.to_i > 1
  645. end
  646. if char_index
  647. event.message.delete_all_reactions
  648. char = Character.find(carousel.options[char_index])
  649. carousel.update(id: carousel.id, char_id: char.id)
  650. embed = character_embed(
  651. char: char,
  652. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  653. user: event.server.member(char.user_id),
  654. color: CharacterController.type_color(char),
  655. section: :default
  656. )
  657. event.message.edit("", embed)
  658. section_react(event.message)
  659. end
  660. when [:carousel, :cross]
  661. event.message.delete
  662. carousel.delete
  663. end
  664. end
  665. # This will trigger when any reaction is removed in discord
  666. bot.reaction_remove do |event|
  667. end
  668. # This will trigger when a member is updated
  669. bot.member_update do |event|
  670. end
  671. # This will trigger when anyone joins the server
  672. bot.member_join do |event|
  673. end
  674. # This will trigger when anyone leaves the server
  675. bot.member_leave do |event|
  676. end
  677. # This will trigger when anyone is banned from the server
  678. bot.user_ban do |event|
  679. end
  680. # This will trigger when anyone is un-banned from the server
  681. bot.user_unban do |event|
  682. end
  683. bot.run