bot.rb 39 KB

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