bot.rb 39 KB

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