bot.rb 40 KB

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