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