bot.rb 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463
  1. require 'bundler'
  2. require 'erb'
  3. require 'yaml'
  4. require 'json'
  5. require 'terminal-table'
  6. require 'rmagick'
  7. require 'down'
  8. BOT_ENV = ENV.fetch('BOT_ENV') { 'development' }
  9. Bundler.require(:default, BOT_ENV)
  10. require 'active_record'
  11. # Constants: such as roles and colors and regexes
  12. DISCORD = "#36393f"
  13. ERROR = "#a41e1f"
  14. UID = /<@\!?([0-9]+)>/
  15. URL = /https?:\/\/[\S]+/
  16. # ---
  17. Dotenv.load if BOT_ENV != 'production'
  18. db_yml = File.open('config/database.yml') do |erb|
  19. ERB.new(erb.read).result
  20. end
  21. db_config = YAML.safe_load(db_yml)[BOT_ENV]
  22. ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
  23. ActiveRecord::Base.establish_connection(
  24. adapter: 'postgresql',
  25. host: db_config.fetch('host') { 'localhost' },
  26. database: db_config['database'],
  27. user: db_config['user'],
  28. password: db_config['password']
  29. )
  30. Dir['app/**/*.rb'].each { |f| require File.join(File.expand_path(__dir__), f) }
  31. Dir['./lib/*.rb'].each { |f| require f }
  32. token = ENV['DISCORD_BOT_TOKEN']
  33. bot = Discordrb::Bot.new(token: token)
  34. # Methods
  35. def stat_image(user, member, stats=nil)
  36. size_width = 570;
  37. size_height = 376;
  38. stats_frame = "images/LevelUp.png"
  39. level_up = "images/LevelUpFont.png"
  40. user_url_img = "images/Image_Builder/user_url_img.png"
  41. output_file = "images/Image_Builder/LevelUp"
  42. Down.download(member.avatar_url, destination: user_url_img)
  43. #Gif Destroyer
  44. i = Magick::ImageList.new(user_url_img)
  45. i[0].write(user_url_img) if i.count > 1
  46. if stats
  47. merge_image(
  48. [stats_frame, level_up, user_url_img],
  49. output_file,
  50. size_width,
  51. size_height,
  52. [nil, nil, 19],
  53. [nil, nil, 92],
  54. [size_width, size_width, 165],
  55. [size_height, size_height, 165]
  56. )
  57. this_level = user.next_level - ((user.level + 5) ** 3 / 10.0)
  58. else
  59. merge_image(
  60. [stats_frame, user_url_img],
  61. output_file,
  62. size_width,
  63. size_height,
  64. [nil, 19],
  65. [nil, 92],
  66. [size_width, 165],
  67. [size_height, 165]
  68. )
  69. this_level = user.next_level - ((user.level + 4) ** 3 / 10.0)
  70. end
  71. ratio = (user.next_level - user.boosted_xp).to_f / this_level
  72. user_name = member.nickname || member.name
  73. short_name = user_name.length > 15 ? "#{user_name[0..14]}..." : user_name
  74. rank = User.order(unboosted_xp: :desc)
  75. user_rank = rank.index{ |r| r.id == user.id } + 1
  76. gc = Draw.new
  77. gc.font('OpenSans-SemiBold.ttf')
  78. gc.stroke('#39c4ff').fill('#39c4ff')
  79. gc.rectangle(42, 48, 42 + (95 * ratio), 48 + 3)
  80. gc.stroke('none').fill('black')
  81. gc.pointsize('15')
  82. gc.text(15,25, short_name)
  83. gc.text(40, 45, "Lv.#{user.level}")
  84. gc.text(15, 290, "Rank: #{user_rank}")
  85. gc.text(40, 65, "Exp: #{user.boosted_xp}")
  86. gc.stroke('white').fill('white')
  87. gc.pointsize('30')
  88. gc.text(40,330, user_name)
  89. gc.text(40,360, "reached level #{user.level}!") if stats
  90. gc.text(40,360, "is level #{user.level}!") if !stats
  91. if stats
  92. gc.stroke('none').fill('black')
  93. gc.pointsize('18')
  94. gc.text(450, 97, stats['hp'].to_s)
  95. gc.text(450, 127, stats['attack'].to_s)
  96. gc.text(450, 159, stats['defense'].to_s)
  97. gc.text(450, 191, stats['sp_attack'].to_s)
  98. gc.text(450, 222, stats['sp_defense'].to_s)
  99. gc.text(450, 255, stats['speed'].to_s)
  100. gc.stroke('none').fill('maroon')
  101. gc.text(505, 97, "+ #{stats['hp'] - user.hp}")
  102. gc.text(505, 127, "+ #{stats['attack']- user.attack}")
  103. gc.text(505, 159, "+ #{stats['defense'] - user.defense}")
  104. gc.text(505, 191, "+ #{stats['sp_attack'] - user.sp_attack}")
  105. gc.text(505, 222, "+ #{stats['sp_defense']- user.sp_defense}")
  106. gc.text(505, 255, "+ #{stats['speed'] - user.speed}")
  107. else
  108. gc.stroke('none').fill('black')
  109. gc.pointsize('18')
  110. gc.text(450, 97, user.hp.to_s)
  111. gc.text(450, 127, user.attack.to_s)
  112. gc.text(450, 159, user.defense.to_s)
  113. gc.text(450, 191, user.sp_attack.to_s)
  114. gc.text(450, 222, user.sp_defense.to_s)
  115. gc.text(450, 255, user.speed.to_s)
  116. end
  117. u = Magick::ImageList.new("#{output_file}.png")
  118. gc.draw(u[0])
  119. u.write("#{output_file}.png")
  120. "#{output_file}.png"
  121. end
  122. #--
  123. # Commands: structure basic bot commands here
  124. commands = []
  125. pm_commands = []
  126. hello = Command.new(:hello, "Says hello!") do |event|
  127. user = event.author.nickname || event.author.name
  128. img = ImageUrl.find_by(name: 'happy')
  129. greetings = [
  130. "Hi there, #{user}",
  131. "Greetings #{user}, you lovable bum",
  132. "Alola, #{user}",
  133. "Hello, #{user}! The Guildmasters have been waiting",
  134. "#{user} would like to battle!"
  135. ]
  136. Embed.new(
  137. description: greetings.sample,
  138. color: event.author.color.combined,
  139. thumbnail: {
  140. url: img.url
  141. }
  142. )
  143. end
  144. opts = {
  145. "" => "displays a list of all commands",
  146. "command" => "displays info and usage for specified command"
  147. }
  148. desc = "Displays help information for the commands"
  149. help = Command.new(:help, desc, opts) do |event, command|
  150. if command
  151. short = /pkmn-(\w+)/.match(command)
  152. command = short ? short[1] : command
  153. cmd = commands.detect { |c| c.name == command.to_sym }
  154. pm_cmd = pm_commands.detect { |pc| pc.name == command.to_sym }
  155. end
  156. if command && cmd
  157. command_embed(cmd)
  158. elsif command && pm_cmd
  159. command_embed(pm_cmd, "PM Command")
  160. elsif !command
  161. embed = command_list_embed(
  162. pm_commands,
  163. "Can only be used in a pm with the bot",
  164. "PM Commands"
  165. )
  166. event.send_embed("", embed)
  167. command_list_embed(commands)
  168. else
  169. command_error_embed("Command not found!", help)
  170. end
  171. end
  172. opts = {
  173. "primary" => "Single Display",
  174. "primary | secondary" => "Double Display"
  175. }
  176. desc = "Displays a chart of effectiveness for the given type"
  177. matchup = Command.new(:matchup, desc, opts) do |event, primary, secondary|
  178. channel = event.channel.id
  179. image_out = 'images/Type Double.png'
  180. file_p = "images/Type #{primary.capitalize}.png" if primary
  181. file_s = "images/Type #{secondary.capitalize}.png" if secondary
  182. case
  183. when !file_p
  184. command_error_embed("There was an error processing your request!", matchup)
  185. when !file_s && File.exists?(file_p)
  186. bot.send_file(channel, File.open(file_p, 'r'))
  187. when File.exists?(file_p) && File.exists?(file_s)
  188. append_image(file_p, file_s, image_out)
  189. bot.send_file(channel, File.open(image_out, 'r'))
  190. else
  191. error_embed("Type(s) not found!")
  192. end
  193. end
  194. opts = {
  195. "@user" => "List all user stats",
  196. }
  197. desc = "Shows ones stats, level, rank, and experience"
  198. stats = Command.new(:stats, desc, opts) do |event, name, all|
  199. case name
  200. when UID
  201. user_id = UID.match(name)
  202. user = event.server.member(user_id[1])
  203. when String
  204. #See if you can find the name some other way?
  205. end
  206. usr = User.find_by!(id: user&.id)
  207. case all
  208. when /all/i
  209. show_stats(usr, user)
  210. when /reroll/i
  211. usr.make_stats
  212. usr.reload
  213. show_stats(usr, user)
  214. else
  215. output_file = stat_image(usr, user)
  216. bot.send_file(event.channel.id, File.open(output_file, 'r'))
  217. end
  218. rescue ActiveRecord::RecordNotFound => e
  219. error_embed(e.message)
  220. end
  221. opts = {
  222. "" => "starts a new app",
  223. "name" => "edits an existing app",
  224. "name | (in)active" => "sets app to active or inactive"
  225. }
  226. desc = "Everything to do with character applications"
  227. app = Command.new(:app, desc, opts) do |event, name, status|
  228. user = event.author
  229. user_name = user.nickname || user.name
  230. color = user.color.combined if user.color
  231. chars = []
  232. character =
  233. if user.roles.map(&:name).include?('Guild Masters')
  234. chars = Character.where(name: name)
  235. chars.first if chars.length == 1
  236. else
  237. Character.where(user_id: user.id).find_by(name: name) if name
  238. end
  239. active = status.match(/(in)?active/i) if status
  240. case
  241. when !chars.empty? && !character
  242. chars.each do |char|
  243. edit_url = Url::CHARACTER + char.edit_url
  244. embed = edit_app_dm(name, edit_url, color)
  245. bot.send_message(
  246. user.dm.id,
  247. "<@#{char.user_id}>'s character:",
  248. false,
  249. embed
  250. )
  251. end
  252. when name && !character
  253. app_not_found_embed(user_name, name)
  254. when status && active && character
  255. character.update!(active: active[0].capitalize)
  256. character.reload
  257. success_embed("Successfully updated #{name} to be #{active[0].downcase}")
  258. when name && character && !status
  259. edit_url = Url::CHARACTER + character.edit_url
  260. embed = edit_app_dm(name, edit_url, color)
  261. bot.send_message(user.dm.id, "", false, embed)
  262. edit_app_embed(user_name, name, color)
  263. when !name && !status
  264. embed = new_app_dm(user_name, user.id, color)
  265. message = bot.send_message(user.dm.id, "", false, embed)
  266. message.react(Emoji::PHONE)
  267. new_app_embed(user_name, color)
  268. else
  269. command_error_embed("There was an error processing your application!", app)
  270. end
  271. end
  272. opts = { "question | option1, option2, etc" => ""}
  273. desc = "Creates a dynamic poll in any channel"
  274. poll = Command.new(:poll, desc, opts) do |event, question, options|
  275. if options
  276. options_array = options.split(/\s?,\s?/)
  277. new_poll_embed(event, question, options_array)
  278. else
  279. command_error_embed("There was an error creating your poll!", poll)
  280. end
  281. end
  282. opts = {
  283. "participants" =>
  284. "Accepts Everyone, Here, or a comma seperated list of names"
  285. }
  286. desc = "Creates a raffle and picks a winner"
  287. raffle = Command.new(:raffle, desc, opts) do |event, participant|
  288. participants =
  289. case participant
  290. when /^everyone$/i
  291. event.server.members
  292. when /^here$/i
  293. event.message.channel.users
  294. else
  295. participant.split(/\s?,\s?/)
  296. end
  297. winner = participants.sample
  298. winner_name =
  299. case winner
  300. when String
  301. winner
  302. else
  303. winner.nickname || winner.username
  304. end
  305. if winner_name
  306. message_embed("Raffle Results!", "Winner: #{winner_name}")
  307. else
  308. command_error_embed("There was an error creating your raffle!", raffle)
  309. end
  310. end
  311. opts = {
  312. "name | keyword | (n)sfw | url" => "add or update image",
  313. "name | keyword | delete" => "remove image",
  314. "name | keyword" => "display image",
  315. "name" => "list all images"
  316. }
  317. desc = "View, add and edit your characters' images"
  318. image = Command.new(:image, desc, opts) do |event, name, keyword, tag, url, id|
  319. user = event.author
  320. char =
  321. if id
  322. Character.where(user_id: id).find_by!(name: name) if name
  323. else
  324. Character.where(user_id: user.id).find_by!(name: name) if name
  325. end
  326. color = CharacterController.type_color(char) if char
  327. img = CharImage.where(char_id: char.id).find_by(keyword: keyword) if keyword
  328. case
  329. when /^Default$/i.match(keyword)
  330. error_embed(
  331. "Cannot update Default here!",
  332. "Use `pkmn-app character` to edit your default image in your form"
  333. )
  334. when char && keyword && url && tag && tag.match(/(n)?sfw/i)
  335. img_app = CharImage.to_form(
  336. char: char,
  337. keyword: keyword,
  338. category: tag,
  339. url: url,
  340. user_id: user.id
  341. )
  342. approval = bot.send_message(ENV['APP_CH'].to_i, "", false, img_app)
  343. approval.react(Emoji::Y)
  344. approval.react(Emoji::N)
  345. success_embed("Your image has been submitted for approval!")
  346. when char && img && tag && tag.match(/delete/i)
  347. CharImage.find(img.id).delete
  348. success_embed("Removed image: #{keyword}")
  349. when char && img && !tag
  350. char_image_embed(char, img, user, color)
  351. when char && !keyword
  352. imgs = CharImage.where(char_id: char.id)
  353. image_list_embed(char, imgs, user, color)
  354. when keyword && !img
  355. error_embed("Could not find your image!")
  356. else
  357. command_error_embed("Could not process your image request!", image)
  358. end
  359. rescue ActiveRecord::RecordNotFound
  360. error_embed(
  361. "Character not Found!",
  362. "I could not find your character named #{name}"
  363. )
  364. end
  365. opts = {
  366. "" => "List all guild members",
  367. "@user" => "List all characters belonging to the user",
  368. "name " => "Display the given character",
  369. "name | section" => "Display the given section for the character",
  370. "name | image | keword" => "Display the given image"
  371. }
  372. desc = "Display info about the guild members"
  373. member = Command.new(:member, desc, opts) do |event, name, section, keyword|
  374. sections = [:all, :default, :bio, :type, :status, :rumors, :image, :bags]
  375. case name
  376. when UID
  377. user_id = UID.match(name)
  378. when String
  379. chars = Character.where(name: name)
  380. char = chars.first if chars.length == 1
  381. if char
  382. img = CharImage.where(char_id: char.id).find_by(keyword: 'Default')
  383. user = char.user_id.match(/public/i) ?
  384. char.user_id : event.server.member(char.user_id)
  385. color = CharacterController.type_color(char)
  386. end
  387. end
  388. case
  389. when !name
  390. chars = Character.all
  391. char_list_embed(chars)
  392. when name && user_id
  393. chars = Character.where(user_id: user_id[1])
  394. user = event.server.member(user_id[1])
  395. chars_id = []
  396. chars.each do |char|
  397. chars_id.push char.id if char.active == 'Active'
  398. end
  399. embed = user_char_embed(chars, user)
  400. msg = event.send_embed("", embed)
  401. Carousel.create(message_id: msg.id, options: chars_id)
  402. option_react(msg, chars_id)
  403. when name && chars.empty?
  404. error_embed(
  405. "Character not found!",
  406. "Could not find a character named #{name}"
  407. )
  408. when name && chars && !char
  409. embed = dup_char_embed(chars, name)
  410. chars_id = chars.map(&:id)
  411. msg = event.send_embed("", embed)
  412. Carousel.create(message_id: msg.id, options: chars_id)
  413. option_react(msg, chars_id)
  414. when name && char && !section
  415. embed = character_embed(
  416. char: char,
  417. img: img,
  418. section: :default,
  419. user: user,
  420. color: color
  421. )
  422. msg = event.send_embed("", embed)
  423. Carousel.create(message_id: msg.id, char_id: char.id)
  424. section_react(msg)
  425. when char && section && keyword
  426. embed = command_error_embed(
  427. "Invalid Arguments",
  428. member
  429. )unless /image/i.match(section)
  430. unless embed
  431. img = CharImage.where(char_id: char.id).find_by!(keyword: keyword)
  432. embed = error_embed(
  433. "Wrong Channel!",
  434. "The requested image is NSFW"
  435. )if img.category == 'NSFW' && !event.channel.nsfw?
  436. end
  437. unless embed
  438. embed = character_embed(
  439. char: char,
  440. img: img,
  441. section: :image,
  442. user: user,
  443. color: color
  444. )
  445. msg = event.send_embed("", embed)
  446. Carousel.create(message_id: msg.id, char_id: char.id, image_id: img.id)
  447. arrow_react(msg)
  448. end
  449. embed
  450. when name && char && section
  451. sect = section.downcase.to_sym
  452. nsfw = event.channel.nsfw?
  453. img = ImageController.img_scroll(
  454. char_id: char.id,
  455. nsfw: nsfw
  456. )if section == :image
  457. if sections.detect{ |s| s == sect }
  458. embed = character_embed(
  459. char: char,
  460. img: img,
  461. section: sect,
  462. user: user,
  463. color: color,
  464. )
  465. msg = event.send_embed("", embed)
  466. Carousel.create(
  467. message_id: msg.id,
  468. char_id: char.id,
  469. image_id: img ? img.id : nil
  470. )
  471. if sect == :image
  472. arrow_react(msg)
  473. else
  474. section_react(msg)
  475. end
  476. else
  477. error_embed("Invalid Section!")
  478. end
  479. end
  480. rescue ActiveRecord::RecordNotFound => e
  481. error_embed("Record Not Found!", e.message)
  482. end
  483. desc = "Learn about Items"
  484. opts = { "" => "list all items", "item_name" => "show known info for the item" }
  485. item = Command.new(:item, desc, opts) do |event, name|
  486. #i = name ? Item.find_by!(name: name.capitalize) : Item.all
  487. #case
  488. #when name && i
  489. #item_embed(i)
  490. #when !name && i
  491. #item_list_embed(i)
  492. #else
  493. #command_error_embed("Error proccessing your request!", item)
  494. #end
  495. #rescue ActiveRecord::RecordNotFound
  496. #error_embed("Item Not Found!")
  497. end
  498. desc = "Add and remove items from characters' inventories"
  499. opts = { "item | (-/+) amount | character" => "negative numbers remove items" }
  500. inv = Command.new(:inv, desc, opts) do |event, item, amount, name|
  501. char = Character.find_by!(name: name) if name
  502. itm = Item.find_by!(name: item) if item
  503. amt = amount.to_i
  504. case
  505. when char && itm && amt
  506. i = Inventory.update_inv(itm, amt, char)
  507. user = event.server.member(char.user_id.to_i)
  508. color = CharacterController.type_color(char)
  509. case i
  510. when Inventory, true
  511. character_embed(char: char, user: user, color: color, section: :bags)
  512. when Embed
  513. i
  514. else
  515. error_embed("Something went wrong!", "Could not update inventory")
  516. end
  517. else
  518. command_error_embed("Could not proccess your request", inv)
  519. end
  520. rescue ActiveRecord::RecordNotFound => e
  521. error_embed(e.message)
  522. end
  523. desc = "Update or edit statuses"
  524. opts = { "name | effect" => "effect displays on user when afflicted" }
  525. status = Command.new(:status, desc, opts) do |event, name, effect, flag|
  526. admin = event.user.roles.map(&:name).include?('Guild Masters')
  527. if name && effect && admin
  528. s = StatusController.edit_status(name, effect, flag)
  529. case s
  530. when Status
  531. status_details(s)
  532. when Embed
  533. s
  534. end
  535. elsif name && !effect
  536. status_details(Status.find_by!(name: name))
  537. elsif !name && !effect
  538. status_list
  539. elsif !admin
  540. error_embed("You do not have permission to do that!")
  541. else
  542. command_error_embed("Could not create status!", status)
  543. end
  544. rescue ActiveRecord::RecordNotFound => e
  545. error_embed(e.message)
  546. end
  547. opts = { "character | ailment | %afflicted" => "afflictions apply in percentages" }
  548. afflict = Command.new(:afflict, desc, opts) do |event, name, status, amount|
  549. char = Character.find_by!(name: name) if name
  550. st = Status.find_by!(name: status) if status
  551. user = char.user_id.match(/public/i) ?
  552. 'Public' : event.server.member(char.user_id)
  553. if st && char
  554. user = char.user_id.match(/public/i) ?
  555. 'Public' : event.server.member(char.user_id)
  556. color = CharacterController.type_color(char)
  557. s = StatusController.edit_char_status(char, st, amount)
  558. case s
  559. when CharStatus
  560. character_embed(char: char, user: user, color: color, section: :status)
  561. when Embed
  562. s
  563. end
  564. else
  565. command_error_embed("Error afflicting #{char.name}", afflict)
  566. end
  567. rescue ActiveRecord::RecordNotFound => e
  568. error_embed(e.message)
  569. end
  570. opts = {
  571. "character | all" => "completely cures all ailments",
  572. "character | ailment" => "completely cures the ailment",
  573. "character | ailment | %cured" => "cures a percentage of ailment"
  574. }
  575. cure = Command.new(:cure, desc, opts) do |event, name, status, amount|
  576. char = Character.find_by!(name: name) if name
  577. st = Status.find_by!(name: status) if status && !status.match(/all/i)
  578. case
  579. when char && st && amount
  580. user = char.user_id.match(/public/i) ?
  581. 'Public' : event.server.member(char.user_id)
  582. color = CharacterController.type_color(char)
  583. s = StatusController.edit_char_status(st, "-#{amount}", char)
  584. case s
  585. when CharStatus
  586. character_embed(char: char, user: user, color: color, section: :status)
  587. when Embed
  588. s
  589. end
  590. when char && st && !amount
  591. CharStatus.where(char_id: char.id).find_by!(status_id: st.id).delete
  592. success_embed("Removed #{status} from #{name}")
  593. when char && status && status.match(/all/i)
  594. csts = CharStatus.where(char_id: char.id)
  595. csts.each do |cst|
  596. cst.delete
  597. end
  598. success_embed("Removed all ailments from #{name}")
  599. else
  600. end
  601. rescue ActiveRecord::RecordNotFound => e
  602. error_embed(e.message)
  603. end
  604. desc = "Everything to do with rescue teams"
  605. opts = {
  606. "" => "list of teams",
  607. "team_name" => "display team info",
  608. "team_name | (leave/apply) | character" => "leave or apply for team",
  609. "team_name | create | description" => "admin only command"
  610. }
  611. team = Command.new(:team, desc, opts) do |event, team_name, action, desc|
  612. unless action&.match(/create/i)
  613. t = Team.find_by!(name: team_name) if team_name
  614. char = if event.author.roles.map(&:name).include?('Guild Masters')
  615. Character.find_by!(name: desc) if desc
  616. else
  617. c = Character.where(user_id: event.author.id).find_by!(name: desc)
  618. ct = CharTeam.where(char_id: c.id).find_by(active: true)
  619. action = "second_team" if ct && action.match(/apply/i)
  620. c
  621. end
  622. end
  623. case action
  624. when /leave/i
  625. ct = CharTeam.where(team_id: t.id).find_by(char_id: char.id)
  626. if ct
  627. ct.update(active: false)
  628. user = event.server.member(char.user_id.to_i)
  629. user.remove_role(t.role.to_i) if user
  630. end
  631. bot.send_message(
  632. t.channel.to_i,
  633. "#{char.name} has left the team",
  634. false,
  635. nil
  636. )
  637. when /apply/i
  638. members = CharTeam.where(team_id: t.id)
  639. if members.count < 6
  640. embed = team_app_embed(t, char, event.server.member(char.user_id))
  641. msg = bot.send_message(t.channel.to_i, "", false, embed)
  642. msg.react(Emoji::Y)
  643. msg.react(Emoji::N)
  644. success_embed("Your request has been posted to #{t.name}!")
  645. else
  646. error_embed("#{t.name} is full!")
  647. end
  648. when /create/i
  649. team_name = team_name || ""
  650. desc = desc || ""
  651. embed = new_team_embed(event.message.author, team_name, desc)
  652. msg = bot.send_message(ENV['APP_CH'], "", false, embed)
  653. msg.react(Emoji::Y)
  654. msg.react(Emoji::N)
  655. success_embed("Your Team Application has been submitted!")
  656. when nil
  657. t ? team_embed(t) : teams_embed()
  658. when /second_team/i
  659. error_embed("#{char.name} is already in a team!")
  660. else
  661. command_error_embed("Could not process team request!", team)
  662. end
  663. rescue ActiveRecord::RecordNotFound => e
  664. error_embed(e.message)
  665. end
  666. # ---
  667. commands = [
  668. hello,
  669. matchup,
  670. app,
  671. help,
  672. poll,
  673. raffle,
  674. member,
  675. item,
  676. #inv,
  677. status,
  678. afflict,
  679. cure,
  680. team,
  681. stats
  682. ]
  683. #locked_commands = [inv]
  684. # This will trigger on every message sent in discord
  685. bot.message do |event|
  686. content = event.message.content
  687. author = event.author.id
  688. command = /^pkmn-(\w+)/.match(content)
  689. cmd = commands.detect { |c| c.name == command[1].to_sym } if command
  690. if cmd
  691. reply = cmd.call(content, event)
  692. case reply
  693. when Embed
  694. event.send_embed("", reply)
  695. when String
  696. event.respond(reply)
  697. end
  698. elsif command && !cmd && event.server
  699. event.send_embed(
  700. "",
  701. error_embed("Command not found!")
  702. )
  703. elsif author == ENV['WEBHOOK'].to_i
  704. app = event.message.embeds.first
  705. if app.author.name == 'Character Application'
  706. Character.check_user(event)
  707. else
  708. approval_react(event)
  709. end
  710. elsif content == 'import users' && author == 215240568245190656
  711. User.import_user(File.open('users.txt', 'r'))
  712. elsif !event.author.bot_account? && !event.author.webhook?
  713. usr = User.find_by(id: author.to_s)
  714. msg = URL.match(content) ? content.gsub(URL, "x" * 150) : content
  715. file = event.message.attachments.map(&:filename).count
  716. msg = file > 0 ? msg + ("x" * 40) : msg
  717. img = usr.update_xp(msg, event.author)
  718. bot.send_file(event.message.channel, File.open(img, 'r')) if img
  719. end
  720. end
  721. pm_commands = [ image ]
  722. # This will trigger when a dm is sent to the bot from a user
  723. bot.pm do |event|
  724. content = event.message.content
  725. command = /^pkmn-(\w+)/.match(content)
  726. cmd = pm_commands.detect { |c| c.name == command[1].to_sym } if command
  727. reply = cmd.call(content, event) if cmd
  728. case reply
  729. when Embed
  730. event.send_embed("", reply)
  731. when String
  732. event.respond(reply)
  733. end
  734. end
  735. # This will trigger when any reaction is added in discord
  736. bot.reaction_add do |event|
  737. reactions = event.message.reactions
  738. app = event.message.embeds.first
  739. carousel = Carousel.find_by(message_id: event.message.id)
  740. app = event.message.embeds.first
  741. carousel = Carousel.find_by(message_id: event.message.id)
  742. carousel = Carousel.find_by(message_id: event.message.id)
  743. maj = 100
  744. form =
  745. case app&.author&.name
  746. when 'New App' then :new_app
  747. when 'Character Application'
  748. m = event.server.roles.find{ |r| r.id == ENV['ADMINS'].to_i }.members
  749. maj = m.count > 2 ? m.count/2.0 : 2
  750. :character_application
  751. when 'Character Rejection' then :character_rejection
  752. when 'Image Application'
  753. m = event.server.roles.find{ |r| r.id == ENV['ADMINS'].to_i }.members
  754. maj = m.count > 2 ? m.count/2.0 : 2
  755. :image_application
  756. when 'Image Rejection' then :image_rejection
  757. when 'Item Application'
  758. m = event.server.roles.find{ |r| r.id == ENV['ADMINS'].to_i }.members
  759. maj = m.count > 2 ? m.count/2.0 : 2
  760. :item_application
  761. when 'Item Rejection' then :item_rejection
  762. when 'Team Application'
  763. m = event.server.roles.find{ |r| r.id == ENV['ADMINS'].to_i }.members
  764. maj = m.count > 2 ? m.count/2.0 : 2
  765. :team_application
  766. when 'Team Join Request'
  767. team_id = Team.find_by(channel: event.message.channel.id.to_s).role.to_i
  768. m = event.server.roles.find{ |r| r.id == team_id }.members
  769. maj = m.count > 2 ? m.count/2.0 : 2
  770. :team_request
  771. else
  772. :carousel if carousel
  773. end
  774. vote =
  775. case
  776. when reactions[Emoji::Y]&.count.to_i > maj then :yes
  777. when reactions[Emoji::N]&.count.to_i > maj then :no
  778. when reactions[Emoji::CHECK]&.count.to_i > 1 then :check
  779. when reactions[Emoji::CROSS]&.count.to_i > 1 then :cross
  780. when reactions[Emoji::CRAYON]&.count.to_i > 1 then :crayon
  781. when reactions[Emoji::NOTEBOOK]&.count.to_i > 1 then :notebook
  782. when reactions[Emoji::QUESTION]&.count.to_i > 1 then :question
  783. when reactions[Emoji::PALLET]&.count.to_i > 1 then :pallet
  784. when reactions[Emoji::EAR]&.count.to_i > 1 then :ear
  785. when reactions[Emoji::PICTURE]&.count.to_i > 1 then :picture
  786. when reactions[Emoji::BAGS]&.count.to_i > 1 then :bags
  787. #when reactions[Emoji::FAMILY]&.count.to_i > 1 then :family
  788. when reactions[Emoji::EYES]&.count.to_i > 1 then :eyes
  789. when reactions[Emoji::KEY]&.count.to_i > 1 then :key
  790. when reactions[Emoji::PHONE]&.count.to_i > 1 then :phone
  791. when reactions[Emoji::LEFT]&.count.to_i > 1 then :left
  792. when reactions[Emoji::RIGHT]&.count.to_i > 1 then :right
  793. when reactions[Emoji::UNDO]&.count.to_i > 1 then :back
  794. when reactions.any? { |k,v| Emoji::NUMBERS.include? k } then :number
  795. end
  796. case [form, vote]
  797. when [:character_application, :yes]
  798. uid = UID.match(app.description)
  799. user =
  800. app.description.match(/public/i) ? 'Public' : event.server.member(uid[1])
  801. img_url = case
  802. when !app.thumbnail&.url.nil? then app.thumbnail.url
  803. when !app.image&.url.nil? then app.image.url
  804. end
  805. char = CharacterController.edit_character(app)
  806. img = ImageController.default_image(
  807. img_url,
  808. char.id
  809. )if img_url
  810. color = CharacterController.type_color(char)
  811. embed = character_embed(
  812. char: char,
  813. img: img,
  814. user: user,
  815. color: color
  816. )if char
  817. if embed
  818. bot.send_message(
  819. ENV['CHAR_CH'].to_i,
  820. "Good news, #{uid}! Your character was approved",
  821. false,
  822. embed
  823. )
  824. event.message.delete
  825. else
  826. event.respond(
  827. "",
  828. admin_error_embed("Something went wrong when saving application")
  829. )
  830. end
  831. when [:character_application, :no]
  832. embed = reject_app_embed(app, :character)
  833. event.message.delete
  834. reject = event.send_embed("", embed)
  835. Emoji::CHAR_APP.each do |reaction|
  836. reject.react(reaction)
  837. end
  838. reject.react(Emoji::CHECK)
  839. reject.react(Emoji::CROSS)
  840. reject.react(Emoji::CRAYON)
  841. when [:character_application, :cross]
  842. event.message.delete
  843. when [:character_rejection, :check]
  844. user = event.server.member(UID.match(app.description)[1])
  845. embed = user_char_app(event)
  846. event.message.delete
  847. bot.send_temporary_message(event.channel.id, "", 5, false, embed)
  848. bot.send_message(user.dm.id, "", false, embed)
  849. when [:character_rejection, :cross]
  850. event.message.delete
  851. when [:character_rejection, :crayon]
  852. event.message.delete
  853. bot.send_temporary_message(
  854. event.channel.id,
  855. "",
  856. 35,
  857. false,
  858. self_edit_embed(app, Url::CHARACTER)
  859. )
  860. when [:new_app, :phone]
  861. event.message.delete_own_reaction(Emoji::PHONE)
  862. user = event.message.reacted_with(Emoji::PHONE).first
  863. bot.send_message(user.dm.id, user.id, false, nil)
  864. when [:image_application, :yes]
  865. img = ImageController.edit_image(app)
  866. char = Character.find(img.char_id)
  867. user = event.server.member(char.user_id)
  868. color = CharacterController.type_color(char)
  869. embed = char_image_embed(char, img, user, color)
  870. event.message.delete if embed
  871. channel = if img.category == 'SFW'
  872. ENV['CHAR_CH'].to_i
  873. else
  874. ENV['CHAR_CH_NSFW'].to_i
  875. end
  876. bot.send_message(channel, "Image Approved!", false, embed)
  877. when [:image_application, :no]
  878. embed = reject_app_embed(app, :image)
  879. event.message.delete
  880. reject = event.send_embed("", embed)
  881. Emoji::IMG_APP.each do |reaction|
  882. reject.react(reaction)
  883. end
  884. reject.react(Emoji::CHECK)
  885. reject.react(Emoji::CROSS)
  886. when [:image_rejection, :check]
  887. user = event.server.member(UID.match(app.description)[1])
  888. embed = user_img_app(event)
  889. event.message.delete
  890. bot.send_temporary_message(event.channel.id, "", 5, false, embed)
  891. bot.send_message(user.dm.id, "", false, embed)
  892. when [:image_rejection, :cross]
  893. event.message.delete
  894. when [:item_application, :yes]
  895. item = ItemController.edit_item(app)
  896. embed = item_embed(item)
  897. event.message.delete
  898. bot.send_message(ENV['CHAR_CH'], "New Item!", false, embed)
  899. when [:item_application, :no]
  900. embed = reject_app_embed(app)
  901. event.message.delete
  902. reject = event.send_embed("", embed)
  903. reject.react(Emoji::CRAYON)
  904. reject.react(Emoji::CROSS)
  905. when [:item_rejection, :crayon]
  906. embed = self_edit_embed(app, Url::ITEM)
  907. event.message.delete
  908. bot.send_temporary_message(event.channel.id, "", 25, false, embed)
  909. when [:item_rejection, :cross]
  910. event.message.delete
  911. when [:carousel, :notebook]
  912. emoji = Emoji::NOTEBOOK
  913. users = event.message.reacted_with(emoji)
  914. users.each do |user|
  915. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  916. end
  917. char = Character.find(carousel.char_id)
  918. user =
  919. case
  920. when char.user_id.match(/public/i)
  921. "Public"
  922. when member = event.server.member(char.user_id)
  923. member
  924. else
  925. nil
  926. end
  927. embed = character_embed(
  928. char: char,
  929. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  930. user: user,
  931. color: CharacterController.type_color(char),
  932. section: :bio
  933. )
  934. event.message.edit("", embed)
  935. when [:carousel, :question]
  936. emoji = Emoji::QUESTION
  937. users = event.message.reacted_with(emoji)
  938. users.each do |user|
  939. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  940. end
  941. char = Character.find(carousel.char_id)
  942. user =
  943. case
  944. when char.user_id.match(/public/i)
  945. "Public"
  946. when member = event.server.member(char.user_id)
  947. member
  948. else
  949. nil
  950. end
  951. embed = character_embed(
  952. char: char,
  953. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  954. user: user,
  955. color: CharacterController.type_color(char),
  956. section: :status
  957. )
  958. event.message.edit("", embed)
  959. when [:carousel, :pallet]
  960. emoji = Emoji::PALLET
  961. users = event.message.reacted_with(emoji)
  962. users.each do |user|
  963. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  964. end
  965. char = Character.find(carousel.char_id)
  966. user =
  967. case
  968. when char.user_id.match(/public/i)
  969. "Public"
  970. when member = event.server.member(char.user_id)
  971. member
  972. else
  973. nil
  974. end
  975. embed = character_embed(
  976. char: char,
  977. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  978. user: user,
  979. color: CharacterController.type_color(char),
  980. section: :type
  981. )
  982. event.message.edit("", embed)
  983. when [:carousel, :ear]
  984. emoji = Emoji::EAR
  985. users = event.message.reacted_with(emoji)
  986. users.each do |user|
  987. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  988. end
  989. char = Character.find(carousel.char_id)
  990. user =
  991. case
  992. when char.user_id.match(/public/i)
  993. "Public"
  994. when member = event.server.member(char.user_id)
  995. member
  996. else
  997. nil
  998. end
  999. embed = character_embed(
  1000. char: char,
  1001. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  1002. user: user,
  1003. color: CharacterController.type_color(char),
  1004. section: :rumors
  1005. )
  1006. event.message.edit("", embed)
  1007. when [:carousel, :picture]
  1008. event.message.delete_all_reactions
  1009. char = Character.find(carousel.char_id)
  1010. img = ImageController.img_scroll(
  1011. char_id: char.id,
  1012. nsfw: event.channel.nsfw?,
  1013. )
  1014. carousel.update(id: carousel.id, image_id: img&.id)
  1015. user =
  1016. case
  1017. when char.user_id.match(/public/i)
  1018. "Public"
  1019. when member = event.server.member(char.user_id)
  1020. member
  1021. else
  1022. nil
  1023. end
  1024. embed = character_embed(
  1025. char: char,
  1026. img: img,
  1027. user: user,
  1028. color: CharacterController.type_color(char),
  1029. section: :image
  1030. )
  1031. event.message.edit("", embed)
  1032. arrow_react(event.message)
  1033. when [:carousel, :bags]
  1034. emoji = Emoji::BAGS
  1035. users = event.message.reacted_with(emoji)
  1036. users.each do |user|
  1037. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  1038. end
  1039. char = Character.find(carousel.char_id)
  1040. user =
  1041. case
  1042. when char.user_id.match(/public/i)
  1043. "Public"
  1044. when member = event.server.member(char.user_id)
  1045. member
  1046. else
  1047. nil
  1048. end
  1049. embed = character_embed(
  1050. char: char,
  1051. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  1052. user: user,
  1053. color: CharacterController.type_color(char),
  1054. section: :bags
  1055. )
  1056. event.message.edit("", embed)
  1057. when [:carousel, :family]
  1058. when [:carousel, :eyes]
  1059. emoji = Emoji::EYES
  1060. users = event.message.reacted_with(emoji)
  1061. users.each do |user|
  1062. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  1063. end
  1064. char = Character.find(carousel.char_id)
  1065. user =
  1066. case
  1067. when char.user_id.match(/public/i)
  1068. "Public"
  1069. when member = event.server.member(char.user_id)
  1070. member
  1071. else
  1072. nil
  1073. end
  1074. embed = character_embed(
  1075. char: char,
  1076. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  1077. user: user,
  1078. color: CharacterController.type_color(char),
  1079. section: :all
  1080. )
  1081. event.message.edit("", embed)
  1082. when [:carousel, :key]
  1083. emoji = Emoji::KEY
  1084. users = event.message.reacted_with(emoji)
  1085. users.each do |user|
  1086. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  1087. end
  1088. char = Character.find(carousel.char_id)
  1089. user =
  1090. case
  1091. when char.user_id.match(/public/i)
  1092. "Public"
  1093. when member = event.server.member(char.user_id)
  1094. member
  1095. else
  1096. nil
  1097. end
  1098. embed = character_embed(
  1099. char: char,
  1100. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  1101. user: user,
  1102. color: CharacterController.type_color(char),
  1103. section: :default
  1104. )
  1105. event.message.edit("", embed)
  1106. when [:carousel, :back]
  1107. event.message.delete_all_reactions
  1108. char = Character.find(carousel.char_id)
  1109. user =
  1110. case
  1111. when char.user_id.match(/public/i)
  1112. "Public"
  1113. when member = event.server.member(char.user_id)
  1114. member
  1115. else
  1116. nil
  1117. end
  1118. embed = character_embed(
  1119. char: char,
  1120. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  1121. user: user,
  1122. color: CharacterController.type_color(char),
  1123. section: :default
  1124. )
  1125. event.message.edit("", embed)
  1126. section_react(event.message)
  1127. when [:carousel, :left], [:carousel, :right]
  1128. emoji = vote == :left ? Emoji::LEFT : Emoji::RIGHT
  1129. users = event.message.reacted_with(emoji)
  1130. users.each do |user|
  1131. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  1132. end
  1133. char = Character.find(carousel.char_id)
  1134. img = ImageController.img_scroll(
  1135. char_id: char.id,
  1136. nsfw: event.channel.nsfw?,
  1137. img: carousel.image_id,
  1138. dir: vote
  1139. )
  1140. carousel.update(id: carousel.id, image_id: img.id)
  1141. user =
  1142. case
  1143. when char.user_id.match(/public/i)
  1144. "Public"
  1145. when member = event.server.member(char.user_id)
  1146. member
  1147. else
  1148. nil
  1149. end
  1150. embed = character_embed(
  1151. char: char,
  1152. img: img,
  1153. user: user,
  1154. color: CharacterController.type_color(char),
  1155. section: :image
  1156. )
  1157. event.message.edit("", embed)
  1158. when [:carousel, :number]
  1159. char_index = nil
  1160. Emoji::NUMBERS.each.with_index do |emoji, i|
  1161. char_index = i if reactions[emoji]&.count.to_i > 1
  1162. end
  1163. if char_index
  1164. event.message.delete_all_reactions
  1165. char = Character.find(carousel.options[char_index])
  1166. carousel.update(id: carousel.id, char_id: char.id)
  1167. user =
  1168. case
  1169. when char.user_id.match(/public/i)
  1170. "Public"
  1171. when member = event.server.member(char.user_id)
  1172. member
  1173. else
  1174. nil
  1175. end
  1176. embed = character_embed(
  1177. char: char,
  1178. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  1179. user: user,
  1180. color: CharacterController.type_color(char),
  1181. section: :default
  1182. )
  1183. event.message.edit("", embed)
  1184. section_react(event.message)
  1185. end
  1186. when [:carousel, :cross]
  1187. event.message.delete
  1188. carousel.delete
  1189. when [:team_application, :yes]
  1190. t = Team.create!(name: app.title, description: app.description)
  1191. # create role
  1192. role = event.server.create_role(
  1193. name: t.name,
  1194. colour: 3447003,
  1195. hoist: true,
  1196. mentionable: true,
  1197. reason: "New Team"
  1198. )
  1199. role.sort_above(ENV['TEAM_ROLE'])
  1200. # create channel
  1201. channel = event.server.create_channel(
  1202. t.name,
  1203. parent: 642055732321189928,
  1204. permission_overwrites: [
  1205. { id: event.server.everyone_role.id, deny: 1024 },
  1206. { id: role.id, allow: 1024 }
  1207. ]
  1208. )
  1209. t.update(role: role.id.to_s, channel: channel.id.to_s)
  1210. # embed
  1211. embed = message_embed(
  1212. "Team Approved: #{t.name}!",
  1213. "You can join with ```pkmn-team #{t.name} | apply | character_name```"
  1214. )
  1215. bot.send_message(ENV['TEAM_CH'], "", false, embed)
  1216. event.message.delete
  1217. when [:team_application, :no]
  1218. event.message.delete
  1219. when [:team_request, :yes]
  1220. char_id = /\s\|\s([0-9]+)$/.match(app.footer.text)
  1221. char = Character.find(char_id[1].to_i)
  1222. t = Team.find_by(channel: event.message.channel.id.to_s)
  1223. event.message.delete
  1224. if ct = CharTeam.where(team_id: t.id).find_by(char_id: char.id)
  1225. ct.update(active: true)
  1226. else
  1227. CharTeam.create(char_id: char.id, team_id: t.id)
  1228. end
  1229. user = event.server.member(char.user_id)
  1230. user.add_role(t.role.to_i) if user
  1231. embed = message_embed("New Member!", "Welcome #{char.name} to the team!")
  1232. event.send_embed("", embed)
  1233. when [:team_request, :no]
  1234. char_id = /\s\|\s([0-9]+)$/.match(app.footer.text)
  1235. char = Character.find(char_id[1])
  1236. t = Team.find_by(channel: event.message.channel.id.to_s)
  1237. bot.send_message(
  1238. ENV['TEAM_CH'],
  1239. "#{char.name} has been declined from team #{t.name}",
  1240. false,
  1241. nil
  1242. )
  1243. event.message.delete
  1244. end
  1245. end
  1246. # This will trigger when any reaction is removed in discord
  1247. bot.reaction_remove do |event|
  1248. end
  1249. # This will trigger when a member is updated
  1250. bot.member_update do |event|
  1251. end
  1252. # This will trigger when anyone joins the server
  1253. bot.member_join do |event|
  1254. unless User.find_by(id: event.user.id)
  1255. usr = User.create(id: event.user.id)
  1256. usr.make_stats
  1257. end
  1258. end
  1259. # This will trigger when anyone leaves the server
  1260. bot.member_leave do |event|
  1261. end
  1262. # This will trigger when anyone is banned from the server
  1263. bot.user_ban do |event|
  1264. end
  1265. # This will trigger when anyone is un-banned from the server
  1266. bot.user_unban do |event|
  1267. end
  1268. bot.run