bot.rb 25 KB

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