bot.rb 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454
  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.bot_account? && !event.author.webhook?
  705. usr = User.find_by(id: author.to_s)
  706. msg = URL.match(content) ? content.gsub(URL, "x" * 149) : content
  707. binding.pr
  708. img = usr.update_xp(msg, event.author)
  709. bot.send_file(event.message.channel, File.open(img, 'r')) if img
  710. end
  711. end
  712. pm_commands = [ image ]
  713. # This will trigger when a dm is sent to the bot from a user
  714. bot.pm do |event|
  715. content = event.message.content
  716. command = /^pkmn-(\w+)/.match(content)
  717. cmd = pm_commands.detect { |c| c.name == command[1].to_sym } if command
  718. reply = cmd.call(content, event) if cmd
  719. case reply
  720. when Embed
  721. event.send_embed("", reply)
  722. when String
  723. event.respond(reply)
  724. end
  725. end
  726. # This will trigger when any reaction is added in discord
  727. bot.reaction_add do |event|
  728. reactions = event.message.reactions
  729. app = event.message.embeds.first
  730. carousel = Carousel.find_by(message_id: event.message.id)
  731. app = event.message.embeds.first
  732. carousel = Carousel.find_by(message_id: event.message.id)
  733. carousel = Carousel.find_by(message_id: event.message.id)
  734. maj = 100
  735. form =
  736. case app.author&.name
  737. when 'New App' then :new_app
  738. when 'Character Application'
  739. m = event.server.roles.find{ |r| r.id == ENV['ADMINS'].to_i }.members
  740. maj = m.count > 2 ? m.count/2.0 : 2
  741. :character_application
  742. when 'Character Rejection' then :character_rejection
  743. when 'Image Application'
  744. m = event.server.roles.find{ |r| r.id == ENV['ADMINS'].to_i }.members
  745. maj = m.count > 2 ? m.count/2.0 : 2
  746. :image_application
  747. when 'Image Rejection' then :image_rejection
  748. when 'Item Application'
  749. m = event.server.roles.find{ |r| r.id == ENV['ADMINS'].to_i }.members
  750. maj = m.count > 2 ? m.count/2.0 : 2
  751. :item_application
  752. when 'Item Rejection' then :item_rejection
  753. when 'Team Application'
  754. m = event.server.roles.find{ |r| r.id == ENV['ADMINS'].to_i }.members
  755. maj = m.count > 2 ? m.count/2.0 : 2
  756. :team_application
  757. when 'Team Join Request'
  758. team_id = Team.find_by(channel: event.message.channel.id.to_s).role.to_i
  759. m = event.server.roles.find{ |r| r.id == team_id }.members
  760. maj = m.count > 2 ? m.count/2.0 : 2
  761. :team_request
  762. else
  763. :carousel if carousel
  764. end
  765. vote =
  766. case
  767. when reactions[Emoji::Y]&.count.to_i > maj then :yes
  768. when reactions[Emoji::N]&.count.to_i > maj then :no
  769. when reactions[Emoji::CHECK]&.count.to_i > 1 then :check
  770. when reactions[Emoji::CROSS]&.count.to_i > 1 then :cross
  771. when reactions[Emoji::CRAYON]&.count.to_i > 1 then :crayon
  772. when reactions[Emoji::NOTEBOOK]&.count.to_i > 1 then :notebook
  773. when reactions[Emoji::QUESTION]&.count.to_i > 1 then :question
  774. when reactions[Emoji::PALLET]&.count.to_i > 1 then :pallet
  775. when reactions[Emoji::EAR]&.count.to_i > 1 then :ear
  776. when reactions[Emoji::PICTURE]&.count.to_i > 1 then :picture
  777. when reactions[Emoji::BAGS]&.count.to_i > 1 then :bags
  778. #when reactions[Emoji::FAMILY]&.count.to_i > 1 then :family
  779. when reactions[Emoji::EYES]&.count.to_i > 1 then :eyes
  780. when reactions[Emoji::KEY]&.count.to_i > 1 then :key
  781. when reactions[Emoji::PHONE]&.count.to_i > 1 then :phone
  782. when reactions[Emoji::LEFT]&.count.to_i > 1 then :left
  783. when reactions[Emoji::RIGHT]&.count.to_i > 1 then :right
  784. when reactions[Emoji::UNDO]&.count.to_i > 1 then :back
  785. when reactions.any? { |k,v| Emoji::NUMBERS.include? k } then :number
  786. end
  787. case [form, vote]
  788. when [:character_application, :yes]
  789. uid = UID.match(app.description)
  790. user =
  791. app.description.match(/public/i) ? 'Public' : event.server.member(uid[1])
  792. img_url = case
  793. when !app.thumbnail&.url.nil? then app.thumbnail.url
  794. when !app.image&.url.nil? then app.image.url
  795. end
  796. char = CharacterController.edit_character(app)
  797. img = ImageController.default_image(
  798. img_url,
  799. char.id
  800. )if img_url
  801. color = CharacterController.type_color(char)
  802. embed = character_embed(
  803. char: char,
  804. img: img,
  805. user: user,
  806. color: color
  807. )if char
  808. if embed
  809. bot.send_message(
  810. ENV['CHAR_CH'].to_i,
  811. "Good news, #{uid}! Your character was approved",
  812. false,
  813. embed
  814. )
  815. event.message.delete
  816. else
  817. event.respond(
  818. "",
  819. admin_error_embed("Something went wrong when saving application")
  820. )
  821. end
  822. when [:character_application, :no]
  823. embed = reject_app_embed(app, :character)
  824. event.message.delete
  825. reject = event.send_embed("", embed)
  826. Emoji::CHAR_APP.each do |reaction|
  827. reject.react(reaction)
  828. end
  829. reject.react(Emoji::CHECK)
  830. reject.react(Emoji::CROSS)
  831. reject.react(Emoji::CRAYON)
  832. when [:character_application, :cross]
  833. event.message.delete
  834. when [:character_rejection, :check]
  835. user = event.server.member(UID.match(app.description)[1])
  836. embed = user_char_app(event)
  837. event.message.delete
  838. bot.send_temporary_message(event.channel.id, "", 5, false, embed)
  839. bot.send_message(user.dm.id, "", false, embed)
  840. when [:character_rejection, :cross]
  841. event.message.delete
  842. when [:character_rejection, :crayon]
  843. event.message.delete
  844. bot.send_temporary_message(
  845. event.channel.id,
  846. "",
  847. 35,
  848. false,
  849. self_edit_embed(app, Url::CHARACTER)
  850. )
  851. when [:new_app, :phone]
  852. event.message.delete_own_reaction(Emoji::PHONE)
  853. user = event.message.reacted_with(Emoji::PHONE).first
  854. bot.send_message(user.dm.id, user.id, false, nil)
  855. when [:image_application, :yes]
  856. img = ImageController.edit_image(app)
  857. char = Character.find(img.char_id)
  858. user = event.server.member(char.user_id)
  859. color = CharacterController.type_color(char)
  860. embed = char_image_embed(char, img, user, color)
  861. event.message.delete if embed
  862. channel = if img.category == 'SFW'
  863. ENV['CHAR_CH'].to_i
  864. else
  865. ENV['CHAR_CH_NSFW'].to_i
  866. end
  867. bot.send_message(channel, "Image Approved!", false, embed)
  868. when [:image_application, :no]
  869. embed = reject_app_embed(app, :image)
  870. event.message.delete
  871. reject = event.send_embed("", embed)
  872. Emoji::IMG_APP.each do |reaction|
  873. reject.react(reaction)
  874. end
  875. reject.react(Emoji::CHECK)
  876. reject.react(Emoji::CROSS)
  877. when [:image_rejection, :check]
  878. user = event.server.member(UID.match(app.description)[1])
  879. embed = user_img_app(event)
  880. event.message.delete
  881. bot.send_temporary_message(event.channel.id, "", 5, false, embed)
  882. bot.send_message(user.dm.id, "", false, embed)
  883. when [:image_rejection, :cross]
  884. event.message.delete
  885. when [:item_application, :yes]
  886. item = ItemController.edit_item(app)
  887. embed = item_embed(item)
  888. event.message.delete
  889. bot.send_message(ENV['CHAR_CH'], "New Item!", false, embed)
  890. when [:item_application, :no]
  891. embed = reject_app_embed(app)
  892. event.message.delete
  893. reject = event.send_embed("", embed)
  894. reject.react(Emoji::CRAYON)
  895. reject.react(Emoji::CROSS)
  896. when [:item_rejection, :crayon]
  897. embed = self_edit_embed(app, Url::ITEM)
  898. event.message.delete
  899. bot.send_temporary_message(event.channel.id, "", 25, false, embed)
  900. when [:item_rejection, :cross]
  901. event.message.delete
  902. when [:carousel, :notebook]
  903. emoji = Emoji::NOTEBOOK
  904. users = event.message.reacted_with(emoji)
  905. users.each do |user|
  906. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  907. end
  908. char = Character.find(carousel.char_id)
  909. user =
  910. case
  911. when char.user_id.match(/public/i)
  912. "Public"
  913. when member = event.server.member(char.user_id)
  914. member
  915. else
  916. nil
  917. end
  918. embed = character_embed(
  919. char: char,
  920. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  921. user: user,
  922. color: CharacterController.type_color(char),
  923. section: :bio
  924. )
  925. event.message.edit("", embed)
  926. when [:carousel, :question]
  927. emoji = Emoji::QUESTION
  928. users = event.message.reacted_with(emoji)
  929. users.each do |user|
  930. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  931. end
  932. char = Character.find(carousel.char_id)
  933. user =
  934. case
  935. when char.user_id.match(/public/i)
  936. "Public"
  937. when member = event.server.member(char.user_id)
  938. member
  939. else
  940. nil
  941. end
  942. embed = character_embed(
  943. char: char,
  944. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  945. user: user,
  946. color: CharacterController.type_color(char),
  947. section: :status
  948. )
  949. event.message.edit("", embed)
  950. when [:carousel, :pallet]
  951. emoji = Emoji::PALLET
  952. users = event.message.reacted_with(emoji)
  953. users.each do |user|
  954. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  955. end
  956. char = Character.find(carousel.char_id)
  957. user =
  958. case
  959. when char.user_id.match(/public/i)
  960. "Public"
  961. when member = event.server.member(char.user_id)
  962. member
  963. else
  964. nil
  965. end
  966. embed = character_embed(
  967. char: char,
  968. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  969. user: user,
  970. color: CharacterController.type_color(char),
  971. section: :type
  972. )
  973. event.message.edit("", embed)
  974. when [:carousel, :ear]
  975. emoji = Emoji::EAR
  976. users = event.message.reacted_with(emoji)
  977. users.each do |user|
  978. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  979. end
  980. char = Character.find(carousel.char_id)
  981. user =
  982. case
  983. when char.user_id.match(/public/i)
  984. "Public"
  985. when member = event.server.member(char.user_id)
  986. member
  987. else
  988. nil
  989. end
  990. embed = character_embed(
  991. char: char,
  992. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  993. user: user,
  994. color: CharacterController.type_color(char),
  995. section: :rumors
  996. )
  997. event.message.edit("", embed)
  998. when [:carousel, :picture]
  999. event.message.delete_all_reactions
  1000. char = Character.find(carousel.char_id)
  1001. img = ImageController.img_scroll(
  1002. char_id: char.id,
  1003. nsfw: event.channel.nsfw?,
  1004. )
  1005. carousel.update(id: carousel.id, image_id: img.id)
  1006. user =
  1007. case
  1008. when char.user_id.match(/public/i)
  1009. "Public"
  1010. when member = event.server.member(char.user_id)
  1011. member
  1012. else
  1013. nil
  1014. end
  1015. embed = character_embed(
  1016. char: char,
  1017. img: img,
  1018. user: user,
  1019. color: CharacterController.type_color(char),
  1020. section: :image
  1021. )
  1022. event.message.edit("", embed)
  1023. arrow_react(event.message)
  1024. when [:carousel, :bags]
  1025. emoji = Emoji::BAGS
  1026. users = event.message.reacted_with(emoji)
  1027. users.each do |user|
  1028. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  1029. end
  1030. char = Character.find(carousel.char_id)
  1031. user =
  1032. case
  1033. when char.user_id.match(/public/i)
  1034. "Public"
  1035. when member = event.server.member(char.user_id)
  1036. member
  1037. else
  1038. nil
  1039. end
  1040. embed = character_embed(
  1041. char: char,
  1042. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  1043. user: user,
  1044. color: CharacterController.type_color(char),
  1045. section: :bags
  1046. )
  1047. event.message.edit("", embed)
  1048. when [:carousel, :family]
  1049. when [:carousel, :eyes]
  1050. emoji = Emoji::EYES
  1051. users = event.message.reacted_with(emoji)
  1052. users.each do |user|
  1053. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  1054. end
  1055. char = Character.find(carousel.char_id)
  1056. user =
  1057. case
  1058. when char.user_id.match(/public/i)
  1059. "Public"
  1060. when member = event.server.member(char.user_id)
  1061. member
  1062. else
  1063. nil
  1064. end
  1065. embed = character_embed(
  1066. char: char,
  1067. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  1068. user: user,
  1069. color: CharacterController.type_color(char),
  1070. section: :all
  1071. )
  1072. event.message.edit("", embed)
  1073. when [:carousel, :key]
  1074. emoji = Emoji::KEY
  1075. users = event.message.reacted_with(emoji)
  1076. users.each do |user|
  1077. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  1078. end
  1079. char = Character.find(carousel.char_id)
  1080. user =
  1081. case
  1082. when char.user_id.match(/public/i)
  1083. "Public"
  1084. when member = event.server.member(char.user_id)
  1085. member
  1086. else
  1087. nil
  1088. end
  1089. embed = character_embed(
  1090. char: char,
  1091. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  1092. user: user,
  1093. color: CharacterController.type_color(char),
  1094. section: :default
  1095. )
  1096. event.message.edit("", embed)
  1097. when [:carousel, :back]
  1098. event.message.delete_all_reactions
  1099. char = Character.find(carousel.char_id)
  1100. user =
  1101. case
  1102. when char.user_id.match(/public/i)
  1103. "Public"
  1104. when member = event.server.member(char.user_id)
  1105. member
  1106. else
  1107. nil
  1108. end
  1109. embed = character_embed(
  1110. char: char,
  1111. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  1112. user: user,
  1113. color: CharacterController.type_color(char),
  1114. section: :default
  1115. )
  1116. event.message.edit("", embed)
  1117. section_react(event.message)
  1118. when [:carousel, :left], [:carousel, :right]
  1119. emoji = vote == :left ? Emoji::LEFT : Emoji::RIGHT
  1120. users = event.message.reacted_with(emoji)
  1121. users.each do |user|
  1122. event.message.delete_reaction(user.id, emoji) unless user.current_bot?
  1123. end
  1124. char = Character.find(carousel.char_id)
  1125. img = ImageController.img_scroll(
  1126. char_id: char.id,
  1127. nsfw: event.channel.nsfw?,
  1128. img: carousel.image_id,
  1129. dir: vote
  1130. )
  1131. carousel.update(id: carousel.id, image_id: img.id)
  1132. user =
  1133. case
  1134. when char.user_id.match(/public/i)
  1135. "Public"
  1136. when member = event.server.member(char.user_id)
  1137. member
  1138. else
  1139. nil
  1140. end
  1141. embed = character_embed(
  1142. char: char,
  1143. img: img,
  1144. user: user,
  1145. color: CharacterController.type_color(char),
  1146. section: :image
  1147. )
  1148. event.message.edit("", embed)
  1149. when [:carousel, :number]
  1150. char_index = nil
  1151. Emoji::NUMBERS.each.with_index do |emoji, i|
  1152. char_index = i if reactions[emoji]&.count.to_i > 1
  1153. end
  1154. if char_index
  1155. event.message.delete_all_reactions
  1156. char = Character.find(carousel.options[char_index])
  1157. carousel.update(id: carousel.id, char_id: char.id)
  1158. user =
  1159. case
  1160. when char.user_id.match(/public/i)
  1161. "Public"
  1162. when member = event.server.member(char.user_id)
  1163. member
  1164. else
  1165. nil
  1166. end
  1167. embed = character_embed(
  1168. char: char,
  1169. img: CharImage.where(char_id: char.id).find_by(keyword: 'Default'),
  1170. user: user,
  1171. color: CharacterController.type_color(char),
  1172. section: :default
  1173. )
  1174. event.message.edit("", embed)
  1175. section_react(event.message)
  1176. end
  1177. when [:carousel, :cross]
  1178. event.message.delete
  1179. carousel.delete
  1180. when [:team_application, :yes]
  1181. t = Team.create!(name: app.title, description: app.description)
  1182. # create role
  1183. role = event.server.create_role(
  1184. name: t.name,
  1185. colour: 3447003,
  1186. hoist: true,
  1187. mentionable: true,
  1188. reason: "New Team"
  1189. )
  1190. role.sort_above(ENV['TEAM_ROLE'])
  1191. # create channel
  1192. channel = event.server.create_channel(
  1193. t.name,
  1194. parent: 642055732321189928,
  1195. permission_overwrites: [
  1196. { id: event.server.everyone_role.id, deny: 1024 },
  1197. { id: role.id, allow: 1024 }
  1198. ]
  1199. )
  1200. t.update(role: role.id.to_s, channel: channel.id.to_s)
  1201. # embed
  1202. embed = message_embed(
  1203. "Team Approved: #{t.name}!",
  1204. "You can join with ```pkmn-team #{t.name} | apply | character_name```"
  1205. )
  1206. bot.send_message(ENV['TEAM_CH'], "", false, embed)
  1207. event.message.delete
  1208. when [:team_application, :no]
  1209. event.message.delete
  1210. when [:team_request, :yes]
  1211. char_id = /\s\|\s([0-9]+)$/.match(app.footer.text)
  1212. char = Character.find(char_id[1].to_i)
  1213. t = Team.find_by(channel: event.message.channel.id.to_s)
  1214. event.message.delete
  1215. if ct = CharTeam.where(team_id: t.id).find_by(char_id: char.id)
  1216. ct.update(active: true)
  1217. else
  1218. CharTeam.create(char_id: char.id, team_id: t.id)
  1219. end
  1220. user = event.server.member(char.user_id)
  1221. user.add_role(t.role.to_i) if user
  1222. embed = message_embed("New Member!", "Welcome #{char.name} to the team!")
  1223. event.send_embed("", embed)
  1224. when [:team_request, :no]
  1225. char_id = /\s\|\s([0-9]+)$/.match(app.footer.text)
  1226. char = Character.find(char_id[1])
  1227. t = Team.find_by(channel: event.message.channel.id.to_s)
  1228. bot.send_message(
  1229. ENV['TEAM_CH'],
  1230. "#{char.name} has been declined from team #{t.name}",
  1231. false,
  1232. nil
  1233. )
  1234. event.message.delete
  1235. end
  1236. end
  1237. # This will trigger when any reaction is removed in discord
  1238. bot.reaction_remove do |event|
  1239. end
  1240. # This will trigger when a member is updated
  1241. bot.member_update do |event|
  1242. end
  1243. # This will trigger when anyone joins the server
  1244. bot.member_join do |event|
  1245. unless User.find_by(id: event.author.id.to_s)
  1246. usr = User.create(id: event.author.id.to_s)
  1247. usr.make_stats
  1248. end
  1249. end
  1250. # This will trigger when anyone leaves the server
  1251. bot.member_leave do |event|
  1252. end
  1253. # This will trigger when anyone is banned from the server
  1254. bot.user_ban do |event|
  1255. end
  1256. # This will trigger when anyone is un-banned from the server
  1257. bot.user_unban do |event|
  1258. end
  1259. bot.run