| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147 |
- require 'bundler'
- require 'erb'
- require 'yaml'
- require 'json'
- require 'terminal-table'
- require 'rmagick'
- BOT_ENV = ENV.fetch('BOT_ENV') { 'development' }
- Bundler.require(:default, BOT_ENV)
- require 'active_record'
- # Constants: such as roles and colors and regexes
- DISCORD = "#36393f"
- ERROR = "#a41e1f"
- UID = /<@\!?([0-9]+)>/
- # ---
- Dotenv.load if BOT_ENV != 'production'
- db_yml = File.open('config/database.yml') do |erb|
- ERB.new(erb.read).result
- end
- db_config = YAML.safe_load(db_yml)[BOT_ENV]
- ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
- ActiveRecord::Base.establish_connection(
- adapter: 'postgresql',
- host: db_config.fetch('host') { 'localhost' },
- database: db_config['database'],
- user: db_config['user'],
- password: db_config['password']
- )
- Dir['app/**/*.rb'].each { |f| require File.join(File.expand_path(__dir__), f) }
- Dir['./lib/*.rb'].each { |f| require f }
- token = ENV['DISCORD_BOT_TOKEN']
- bot = Discordrb::Bot.new(token: token)
- # Commands: structure basic bot commands here
- commands = []
- pm_commands = []
- hello = Command.new(:hello, "Says hello!") do |event|
- user = event.author.nickname || event.author.name
- img = ImageUrl.find_by(name: 'happy')
- greetings = [
- "Hi there, #{user}",
- "Greetings #{user}, you lovable bum",
- "Alola, #{user}",
- "Hello, #{user}! The Guildmasters have been waiting",
- "#{user} would like to battle!"
- ]
- Embed.new(
- description: greetings.sample,
- color: event.author.color.combined,
- thumbnail: {
- url: img.url
- }
- )
- end
- opts = {
- "" => "displays a list of all commands",
- "command" => "displays info and usage for specified command"
- }
- desc = "Displays help information for the commands"
- help = Command.new(:help, desc, opts) do |event, command|
- if command
- short = /pkmn-(\w+)/.match(command)
- command = short ? short[1] : command
- cmd = commands.detect { |c| c.name == command.to_sym }
- pm_cmd = pm_commands.detect { |pc| pc.name == command.to_sym }
- end
- if command && cmd
- command_embed(cmd)
- elsif command && pm_cmd
- command_embed(pm_cmd, "PM Command")
- elsif !command
- embed = command_list_embed(
- pm_commands,
- "Can only be used in a pm with the bot",
- "PM Commands"
- )
- event.send_embed("", embed)
- command_list_embed(commands)
- else
- command_error_embed("Command not found!", help)
- end
- end
- opts = {
- "primary" => "Single Display",
- "primary | secondary" => "Double Display"
- }
- desc = "Displays a chart of effectiveness for the given type"
- matchup = Command.new(:matchup, desc, opts) do |event, primary, secondary|
- channel = event.channel.id
- image_out = 'images/Type Double.png'
- file_p = "images/Type #{primary.capitalize}.png" if primary
- file_s = "images/Type #{secondary.capitalize}.png" if secondary
- case
- when !file_p
- command_error_embed("There was an error processing your request!", matchup)
- when !file_s && File.exists?(file_p)
- bot.send_file(channel, File.open(file_p, 'r'))
- when File.exists?(file_p) && File.exists?(file_s)
- append_image(file_p, file_s, image_out)
- bot.send_file(channel, File.open(image_out, 'r'))
- else
- error_embed("Type(s) not found!")
- end
- end
- opts = {
- "" => "starts a new app",
- "name" => "edits an existing app",
- "name | (in)active" => "sets app to active or inactive"
- }
- desc = "Everything to do with character applications"
- app = Command.new(:app, desc, opts) do |event, name, status|
- user = event.author
- user_name = user.nickname || user.name
- color = user.color.combined if user.color
- chars = []
- character =
- if user.roles.map(&:name).include?('Guild Masters')
- chars = Character.where(name: name)
- chars.first if chars.length == 1
- else
- Character.where(user_id: user.id).find_by(name: name) if name
- end
- active = status.match(/(in)?active/i) if status
- case
- when !chars.empty? && !character
- chars.each do |char|
- edit_url = Url::CHARACTER + char.edit_url
- embed = edit_app_dm(name, edit_url, color)
- bot.send_message(
- user.dm.id,
- "<@#{char.user_id}>'s character:",
- false,
- embed
- )
- end
- when name && !character
- app_not_found_embed(user_name, name)
- when status && active && character
- character.update!(active: active[0].capitalize)
- character.reload
- success_embed("Successfully updated #{name} to be #{active[0].downcase}")
- when name && character && !status
- edit_url = Url::CHARACTER + character.edit_url
- embed = edit_app_dm(name, edit_url, color)
- bot.send_message(user.dm.id, "", false, embed)
- edit_app_embed(user_name, name, color)
- when !name && !status
- embed = new_app_dm(user_name, user.id, color)
- message = bot.send_message(user.dm.id, "", false, embed)
- message.react(Emoji::PHONE)
- new_app_embed(user_name, color)
- else
- command_error_embed("There was an error processing your application!", app)
- end
- end
- opts = { "question | option1, option2, etc" => ""}
- desc = "Creates a dynamic poll in any channel"
- poll = Command.new(:poll, desc, opts) do |event, question, options|
- if options
- options_array = options.split(/\s?,\s?/)
- new_poll_embed(event, question, options_array)
- else
- command_error_embed("There was an error creating your poll!", poll)
- end
- end
- opts = {
- "participants" =>
- "Accepts Everyone, Here, or a comma seperated list of names"
- }
- desc = "Creates a raffle and picks a winner"
- raffle = Command.new(:raffle, desc, opts) do |event, participant|
- participants =
- case participant
- when /^everyone$/i
- event.server.members
- when /^here$/i
- event.message.channel.users
- else
- participant.split(/\s?,\s?/)
- end
- winner = participants.sample
- winner_name =
- case winner
- when String
- winner
- else
- winner.nickname || winner.username
- end
- if winner_name
- message_embed("Raffle Results!", "Winner: #{winner_name}")
- else
- command_error_embed("There was an error creating your raffle!", raffle)
- end
- end
- opts = {
- "name | keyword | (n)sfw | url" => "add or update image",
- "name | keyword | delete" => "remove image",
- "name | keyword" => "display image",
- "name" => "list all images"
- }
- desc = "View, add and edit your characters' images"
- image = Command.new(:image, desc, opts) do |event, name, keyword, tag, url|
- user = event.author
- chars = []
- char =
- if user.roles.map(&:name).include?('Guild Masters')
- chars = Character.where(name: name)
- chars.first if chars.length == 1
- else
- Character.where(user_id: user.id).find_by!(name: name) if name
- end
- color = CharacterController.type_color(char) if char
- img = CharImage.where(char_id: char.id).find_by(keyword: keyword) if keyword
- case
- when /^Default$/i.match(keyword)
- error_embed(
- "Cannot update Default here!",
- "Use `pkmn-app character` to edit your default image in your form"
- )
- when char && keyword && url && tag && tag.match(/(n)?sfw/i)
- img_app = CharImage.to_form(
- char: char,
- keyword: keyword,
- category: tag,
- url: url,
- user_id: user.id
- )
- approval = bot.send_message(ENV['APP_CH'].to_i, "", false, img_app)
- approval.react(Emoji::Y)
- approval.react(Emoji::N)
- success_embed("Your image has been submitted for approval!")
- when char && img && tag && tag.match(/delete/i)
- CharImage.find(img.id).delete
- success_embed("Removed image: #{keyword}")
- when char && img && !tag
- char_image_embed(char, img, user, color)
- when char && !keyword
- imgs = CharImage.where(char_id: char.id)
- image_list_embed(char, imgs, user, color)
- when keyword && !img
- error_embed("Could not find your image!")
- else
- command_error_embed("Could not process your image request!", image)
- end
- rescue ActiveRecord::RecordNotFound
- error_embed(
- "Character not Found!",
- "I could not find your character named #{name}"
- )
- end
- opts = {
- "" => "List all guild members",
- "@user" => "List all characters belonging to the user",
- "name " => "Display the given character",
- "name | section" => "Display the given section for the character",
- "name | image | keword" => "Display the given image"
- }
- desc = "Display info about the guild members"
- member = Command.new(:member, desc, opts) do |event, name, section, keyword|
- sections = [:all, :default, :bio, :type, :status, :rumors, :image, :bags]
- case name
- when UID
- user_id = UID.match(name)
- when String
- chars = Character.where(name: name)
- char = chars.first if chars.length == 1
- if char
- img = CharImage.where(char_id: char.id).find_by(keyword: 'Default')
- user = char.user_id.match(/public/i) ?
- char.user_id : event.server.member(char.user_id)
- color = CharacterController.type_color(char)
- end
- end
- case
- when !name
- chars = Character.all
- char_list_embed(chars)
- when name && user_id
- chars = Character.where(user_id: user_id[1])
- user = event.server.member(user_id[1])
- chars_id = []
- chars.each do |char|
- chars_id.push char.id if char.active == 'Active'
- end
- embed = user_char_embed(chars, user)
- msg = event.send_embed("", embed)
- Carousel.create(message_id: msg.id, options: chars_id)
- option_react(msg, chars_id)
- when name && chars.empty?
- error_embed(
- "Character not found!",
- "Could not find a character named #{name}"
- )
- when name && chars && !char
- embed = dup_char_embed(chars, name)
- chars_id = chars.map(&:id)
- msg = event.send_embed("", embed)
- Carousel.create(message_id: msg.id, options: chars_id)
- option_react(msg, chars_id)
- when name && char && !section
- embed = character_embed(
- char: char,
- img: img,
- section: :default,
- user: user,
- color: color
- )
- msg = event.send_embed("", embed)
- Carousel.create(message_id: msg.id, char_id: char.id)
- section_react(msg)
- when char && section && keyword
- embed = command_error_embed(
- "Invalid Arguments",
- member
- )unless /image/i.match(section)
- unless embed
- img = CharImage.where(char_id: char.id).find_by!(keyword: keyword)
- embed = error_embed(
- "Wrong Channel!",
- "The requested image is NSFW"
- )if img.category == 'NSFW' && !event.channel.nsfw?
- end
- unless embed
- embed = character_embed(
- char: char,
- img: img,
- section: :image,
- user: user,
- color: color
- )
- msg = event.send_embed("", embed)
- Carousel.create(message_id: msg.id, char_id: char.id, image_id: img.id)
- arrow_react(msg)
- end
- embed
- when name && char && section
- sect = section.downcase.to_sym
- nsfw = event.channel.nsfw?
- img = ImageController.img_scroll(
- char_id: char.id,
- nsfw: nsfw
- )if section == :image
- if sections.detect{ |s| s == sect }
- embed = character_embed(
- char: char,
- img: img,
- section: sect,
- user: user,
- color: color,
- )
- msg = event.send_embed("", embed)
- Carousel.create(
- message_id: msg.id,
- char_id: char.id,
- image_id: img ? img.id : nil
- )
- if sect == :image
- arrow_react(msg)
- else
- section_react(msg)
- end
- else
- error_embed("Invalid Section!")
- end
- end
- rescue ActiveRecord::RecordNotFound => e
- error_embed("Record Not Found!", e.message)
- end
- item = Command.new(:item, desc, opts) do |event, name|
- i = name ? Item.find_by!(name: name.capitalize) : Item.all
- case
- when name && i
- item_embed(i)
- when !name && i
- item_list_embed(i)
- else
- command_error_embed("Error proccessing your request!", item)
- end
- rescue ActiveRecord::RecordNotFound
- error_embed("Item Not Found!")
- end
- desc = "Add and remove items from characters' inventories"
- opts = { "item | (-/+) amount | character" => "" }
- inv = Command.new(:inv, desc, opts) do |event, item, amount, name|
- char = Character.find_by!(name: name) if name
- itm = Item.find_by!(name: item) if item
- amt = amount.to_i
- case
- when char && itm && amt
- i = Inventory.update_inv(itm, amt, char)
- user = event.server.member(char.user_id.to_i)
- color = CharacterController.type_color(char)
- case i
- when Inventory, true
- character_embed(char: char, user: user, color: color, section: :bags)
- when Embed
- i
- else
- error_embed("Something went wrong!", "Could not update inventory")
- end
- else
- command_error_embed("Could not proccess your request", inv)
- end
- rescue ActiveRecord::RecordNotFound => e
- error_embed(e.message)
- end
- desc = "Update or edit statuses"
- opts = { "name | effect" => "" }
- status = Command.new(:status, desc, opts) do |event, name, effect|
- if name && effect
- s = StatusController.edit_status(name, effect)
- case s
- when Status
- success_embed("Created Status: #{name}")
- when Embed
- s
- end
- else
- command_error_embed("Could not create status!", status)
- end
- end
- opts = { "character | ailment | %afflicted" => "" }
- afflict = Command.new(:afflict, desc, opts) do |event, name, status, amount|
- char = Character.find_by!(name: name) if name
- st = Status.find_by!(name: status) if status
- user = char.user_id.match(/public/i) ?
- 'Public' : event.server.member(char.user_id)
- if st && amount && char
- user = char.user_id.match(/public/i) ?
- 'Public' : event.server.member(char.user_id)
- color = CharacterController.type_color(char)
- s = StatusController.edit_char_status(st, amount, char)
- case s
- when CharStatus
- character_embed(char: char, user: user, color: color, section: :status)
- when Embed
- s
- end
- else
- command_error_embed("Error afflicting #{char}", afflict)
- end
- rescue ActiveRecord::RecordNotFound => e
- error_embed(e.message)
- end
- opts = {
- "character | all" => "completely cures all ailments",
- "character | ailment" => "completely cures the ailment",
- "character | ailment | %cured" => "cures a percentage of ailment"
- }
- cure = Command.new(:cure, desc, opts) do |event, name, status, amount|
- char = Character.find_by!(name: name) if name
- st = Status.find_by!(name: status) if status && !status.match(/all/i)
- case
- when char && st && amount
- user = char.user_id.match(/public/i) ?
- 'Public' : event.server.member(char.user_id)
- color = CharacterController.type_color(char)
- s = StatusController.edit_char_status(st, "-#{amount}", char)
- case s
- when CharStatus
- character_embed(char: char, user: user, color: color, section: :status)
- when Embed
- s
- end
- when char && st && !amount
- CharStatus.where(char_id: char.id).find_by!(status_id: st.id).delete
- success_embed("Removed #{status} from #{name}")
- when char && status && status.match(/all/i)
- csts = CharStatus.where(char_id: char.id)
- csts.each do |cst|
- cst.delete
- end
- success_embed("Removed all ailments from #{name}")
- else
- end
- rescue ActiveRecord::RecordNotFound => e
- error_embed(e.message)
- end
- # ---
- commands = [
- hello,
- matchup,
- app,
- help,
- poll,
- raffle,
- member,
- item,
- inv,
- status,
- afflict,
- cure
- ]
- locked_commands = [inv]
- # This will trigger on every message sent in discord
- bot.message do |event|
- content = event.message.content
- author = event.author.id
- command = /^pkmn-(\w+)/.match(content)
- cmd = commands.detect { |c| c.name == command[1].to_sym } if command
- reply = cmd.call(content, event) if cmd
- case reply
- when Embed
- event.send_embed("", reply)
- when String
- event.respond(reply)
- end
- event.send_embed(
- "",
- error_embed("Command not found!")
- )if command && !cmd && event.server
- if author == ENV['WEBHOOK'].to_i
- app = event.message.embeds.first
- if app.author.name == 'Character Application'
- Character.check_user(event)
- else
- approval_react(event)
- end
- end
- end
- pm_commands = [ image ]
- # This will trigger when a dm is sent to the bot from a user
- bot.pm do |event|
- content = event.message.content
- command = /^pkmn-(\w+)/.match(content)
- cmd = pm_commands.detect { |c| c.name == command[1].to_sym } if command
- reply = cmd.call(content, event) if cmd
- case reply
- when Embed
- event.send_embed("", reply)
- when String
- event.respond(reply)
- end
- end
- # This will trigger when any reaction is added in discord
- bot.reaction_add do |event|
- reactions = event.message.reactions
- app = event.message.embeds.first
- carousel = Carousel.find_by(message_id: event.message.id)
- app = event.message.embeds.first
- carousel = Carousel.find_by(message_id: event.message.id)
- carousel = Carousel.find_by(message_id: event.message.id)
- maj =
- if event.server
- m = event.server.roles.find{ |r| r.id == ENV['ADMINS'].to_i }.members
- m.count / 2
- end
- maj = 1
- form =
- case app.author&.name
- when 'New App' then :new_app
- when 'Character Application' then :character_application
- when 'Character Rejection' then :character_rejection
- when 'Image Application' then :image_application
- when 'Image Rejection' then :image_rejection
- when 'Item Application' then :item_application
- when 'Item Rejection' then :item_rejection
- else
- :carousel if carousel
- end
- vote =
- case
- when reactions[Emoji::Y]&.count.to_i > maj then :yes
- when reactions[Emoji::N]&.count.to_i > maj then :no
- when reactions[Emoji::CHECK]&.count.to_i > 1 then :check
- when reactions[Emoji::CROSS]&.count.to_i > 1 then :cross
- when reactions[Emoji::CRAYON]&.count.to_i > 1 then :crayon
- when reactions[Emoji::NOTEBOOK]&.count.to_i > 1 then :notebook
- when reactions[Emoji::QUESTION]&.count.to_i > 1 then :question
- when reactions[Emoji::PALLET]&.count.to_i > 1 then :pallet
- when reactions[Emoji::EAR]&.count.to_i > 1 then :ear
- when reactions[Emoji::PICTURE]&.count.to_i > 1 then :picture
- when reactions[Emoji::BAGS]&.count.to_i > 1 then :bags
- when reactions[Emoji::FAMILY]&.count.to_i > 1 then :family
- when reactions[Emoji::EYES]&.count.to_i > 1 then :eyes
- when reactions[Emoji::KEY]&.count.to_i > 1 then :key
- when reactions[Emoji::PHONE]&.count.to_i > 1 then :phone
- when reactions[Emoji::LEFT]&.count.to_i > 1 then :left
- when reactions[Emoji::RIGHT]&.count.to_i > 1 then :right
- when reactions[Emoji::UNDO]&.count.to_i > 1 then :back
- when reactions.any? { |k,v| Emoji::NUMBERS.include? k } then :number
- end
- case [form, vote]
- when [:character_application, :yes]
- uid = UID.match(app.description)
- user =
- app.description.match(/public/i) ? 'Public' : event.server.member(uid[1])
- char = CharacterController.edit_character(app)
- img = ImageController.default_image(
- app.thumbnail.url,
- char.id
- )if app.thumbnail
- color = CharacterController.type_color(char)
- embed = character_embed(
- char: char,
- img: img,
- user: user,
- color: color
- )if char
- if embed
- bot.send_message(
- ENV['CHAR_CH'].to_i,
- "Good news, #{uid}! Your character was approved",
- false,
- embed
- )
- event.message.delete
- else
- event.respond(
- "",
- admin_error_embed("Something went wrong when saving application")
- )
- end
- when [:character_application, :no]
- embed = reject_app_embed(app, :character)
- event.message.delete
- reject = event.send_embed("", embed)
- Emoji::CHAR_APP.each do |reaction|
- reject.react(reaction)
- end
- reject.react(Emoji::CHECK)
- reject.react(Emoji::CROSS)
- reject.react(Emoji::CRAYON)
- when [:character_rejection, :check]
- user = event.server.member(UID.match(app.description)[1])
- embed = user_char_app(event)
- event.message.delete
- bot.send_temporary_message(event.channel.id, "", 5, false, embed)
- bot.send_message(user.dm.id, "", false, embed)
- when [:character_rejection, :cross]
- event.message.delete
- when [:character_rejection, :crayon]
- event.message.delete
- bot.send_temporary_message(
- event.channel.id,
- "",
- 35,
- false,
- self_edit_embed(app, URL::CHARACTER)
- )
- when [:new_app, :phone]
- event.message.delete_own_reaction(Emoji::PHONE)
- user = event.message.reacted_with(Emoji::PHONE).first
- bot.send_message(user.dm.id, user.id, false, nil)
- when [:image_application, :yes]
- img = ImageController.edit_image(app)
- char = Character.find(img.char_id)
- user = event.server.member(char.user_id)
- color = CharacterController.type_color(char)
- embed = char_image_embed(char, img, user, color)
- event.message.delete if embed
- channel = if img.category == 'SFW'
- ENV['CHAR_CH'].to_i
- else
- ENV['CHAR_CH_NSFW'].to_i
- end
- bot.send_message(channel, "Image Approved!", false, embed)
- when [:image_application, :no]
- embed = reject_app_embed(app, :image)
- event.message.delete
- reject = event.send_embed("", embed)
- Emoji::IMG_APP.each do |reaction|
- reject.react(reaction)
- end
- reject.react(Emoji::CHECK)
- reject.react(Emoji::CROSS)
- when [:image_rejection, :check]
- user = event.server.member(UID.match(app.description)[1])
- embed = user_img_app(event)
- event.message.delete
- bot.send_temporary_message(event.channel.id, "", 5, false, embed)
- bot.send_message(user.dm.id, "", false, embed)
- when [:image_rejection, :cross]
- event.message.delete
- when [:item_application, :yes]
- item = ItemController.edit_item(app)
- embed = item_embed(item)
- event.message.delete
- bot.send_message(ENV['CHAR_CH'], "New Item!", false, embed)
- when [:item_application, :no]
- embed = reject_app_embed(app)
- event.message.delete
- reject = event.send_embed("", embed)
- reject.react(Emoji::CRAYON)
- reject.react(Emoji::CROSS)
- when [:item_rejection, :crayon]
- embed = self_edit_embed(app, Url::ITEM)
- event.message.delete
- bot.send_temporary_message(event.channel.id, "", 25, false, embed)
- when [:item_rejection, :cross]
- event.message.delete
- when [:carousel, :notebook]
- emoji = Emoji::NOTEBOOK
- users = event.message.reacted_with(emoji)
- users.each do |user|
- event.message.delete_reaction(user.id, emoji) unless user.current_bot?
- end
- char = Character.find(carousel.char_id)
- user =
- case
- when char.user_id.match(/public/i)
- "Public"
- when member = event.server.member(char.user_id)
- member
- else
- nil
- end
- embed = character_embed(
- char: char,
- img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
- user: user,
- color: CharacterController.type_color(char),
- section: :bio
- )
- event.message.edit("", embed)
- when [:carousel, :question]
- emoji = Emoji::QUESTION
- users = event.message.reacted_with(emoji)
- users.each do |user|
- event.message.delete_reaction(user.id, emoji) unless user.current_bot?
- end
- char = Character.find(carousel.char_id)
- user =
- case
- when char.user_id.match(/public/i)
- "Public"
- when member = event.server.member(char.user_id)
- member
- else
- nil
- end
- embed = character_embed(
- char: char,
- img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
- user: user,
- color: CharacterController.type_color(char),
- section: :status
- )
- event.message.edit("", embed)
- when [:carousel, :pallet]
- emoji = Emoji::PALLET
- users = event.message.reacted_with(emoji)
- users.each do |user|
- event.message.delete_reaction(user.id, emoji) unless user.current_bot?
- end
- char = Character.find(carousel.char_id)
- user =
- case
- when char.user_id.match(/public/i)
- "Public"
- when member = event.server.member(char.user_id)
- member
- else
- nil
- end
- embed = character_embed(
- char: char,
- img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
- user: user,
- color: CharacterController.type_color(char),
- section: :type
- )
- event.message.edit("", embed)
- when [:carousel, :ear]
- emoji = Emoji::EAR
- users = event.message.reacted_with(emoji)
- users.each do |user|
- event.message.delete_reaction(user.id, emoji) unless user.current_bot?
- end
- char = Character.find(carousel.char_id)
- user =
- case
- when char.user_id.match(/public/i)
- "Public"
- when member = event.server.member(char.user_id)
- member
- else
- nil
- end
- embed = character_embed(
- char: char,
- img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
- user: user,
- color: CharacterController.type_color(char),
- section: :rumors
- )
- event.message.edit("", embed)
- when [:carousel, :picture]
- event.message.delete_all_reactions
- char = Character.find(carousel.char_id)
- img = ImageController.img_scroll(
- char_id: char.id,
- nsfw: event.channel.nsfw?,
- )
- carousel.update(id: carousel.id, image_id: img.id)
- user =
- case
- when char.user_id.match(/public/i)
- "Public"
- when member = event.server.member(char.user_id)
- member
- else
- nil
- end
- embed = character_embed(
- char: char,
- img: img,
- user: user,
- color: CharacterController.type_color(char),
- section: :image
- )
- event.message.edit("", embed)
- arrow_react(event.message)
- when [:carousel, :bags]
- emoji = Emoji::BAGS
- users = event.message.reacted_with(emoji)
- users.each do |user|
- event.message.delete_reaction(user.id, emoji) unless user.current_bot?
- end
- char = Character.find(carousel.char_id)
- user =
- case
- when char.user_id.match(/public/i)
- "Public"
- when member = event.server.member(char.user_id)
- member
- else
- nil
- end
- embed = character_embed(
- char: char,
- img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
- user: user,
- color: CharacterController.type_color(char),
- section: :bags
- )
- event.message.edit("", embed)
- when [:carousel, :family]
- when [:carousel, :eyes]
- emoji = Emoji::EYES
- users = event.message.reacted_with(emoji)
- users.each do |user|
- event.message.delete_reaction(user.id, emoji) unless user.current_bot?
- end
- char = Character.find(carousel.char_id)
- user =
- case
- when char.user_id.match(/public/i)
- "Public"
- when member = event.server.member(char.user_id)
- member
- else
- nil
- end
- embed = character_embed(
- char: char,
- img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
- user: user,
- color: CharacterController.type_color(char),
- section: :all
- )
- event.message.edit("", embed)
- when [:carousel, :key]
- emoji = Emoji::KEY
- users = event.message.reacted_with(emoji)
- users.each do |user|
- event.message.delete_reaction(user.id, emoji) unless user.current_bot?
- end
- char = Character.find(carousel.char_id)
- user =
- case
- when char.user_id.match(/public/i)
- "Public"
- when member = event.server.member(char.user_id)
- member
- else
- nil
- end
- embed = character_embed(
- char: char,
- img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
- user: user,
- color: CharacterController.type_color(char),
- section: :default
- )
- event.message.edit("", embed)
- when [:carousel, :back]
- event.message.delete_all_reactions
- char = Character.find(carousel.char_id)
- user =
- case
- when char.user_id.match(/public/i)
- "Public"
- when member = event.server.member(char.user_id)
- member
- else
- nil
- end
- embed = character_embed(
- char: char,
- img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
- user: user,
- color: CharacterController.type_color(char),
- section: :default
- )
- event.message.edit("", embed)
- section_react(event.message)
- when [:carousel, :left], [:carousel, :right]
- emoji = vote == :left ? Emoji::LEFT : Emoji::RIGHT
- users = event.message.reacted_with(emoji)
- users.each do |user|
- event.message.delete_reaction(user.id, emoji) unless user.current_bot?
- end
- char = Character.find(carousel.char_id)
- img = ImageController.img_scroll(
- char_id: char.id,
- nsfw: event.channel.nsfw?,
- img: carousel.image_id,
- dir: vote
- )
- carousel.update(id: carousel.id, image_id: img.id)
- user =
- case
- when char.user_id.match(/public/i)
- "Public"
- when member = event.server.member(char.user_id)
- member
- else
- nil
- end
- embed = character_embed(
- char: char,
- img: img,
- user: user,
- color: CharacterController.type_color(char),
- section: :image
- )
- event.message.edit("", embed)
- when [:carousel, :number]
- char_index = nil
- Emoji::NUMBERS.each.with_index do |emoji, i|
- char_index = i if reactions[emoji]&.count.to_i > 1
- end
- if char_index
- event.message.delete_all_reactions
- char = Character.find(carousel.options[char_index])
- carousel.update(id: carousel.id, char_id: char.id)
- user =
- case
- when char.user_id.match(/public/i)
- "Public"
- when member = event.server.member(char.user_id)
- member
- else
- nil
- end
- embed = character_embed(
- char: char,
- img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
- user: user,
- color: CharacterController.type_color(char),
- section: :default
- )
- event.message.edit("", embed)
- section_react(event.message)
- end
- when [:carousel, :cross]
- event.message.delete
- carousel.delete
- end
- end
- # This will trigger when any reaction is removed in discord
- bot.reaction_remove do |event|
- end
- # This will trigger when a member is updated
- bot.member_update do |event|
- end
- # This will trigger when anyone joins the server
- bot.member_join do |event|
- end
- # This will trigger when anyone leaves the server
- bot.member_leave do |event|
- end
- # This will trigger when anyone is banned from the server
- bot.user_ban do |event|
- end
- # This will trigger when anyone is un-banned from the server
- bot.user_unban do |event|
- end
- bot.run
|