main.rb 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. require 'yaml'
  2. require 'discordrb'
  3. require 'icunicode'
  4. require 'open-uri'
  5. require 'fileutils'
  6. require 'securerandom'
  7. require 'net/http'
  8. require 'json'
  9. settings = YAML.load(File.read "config.yaml")['settings']
  10. bot = Discordrb::Commands::CommandBot.new token: settings['token'], prefix: settings['prefix']
  11. bot.command(:translit) do |_event, script, *text|
  12. _event.message.mentions.each do |user|
  13. member = user.on(_event.channel.server)
  14. original_name = member.nick
  15. original_name ||= member.username
  16. transliterated = original_name.transliterate(script).force_encoding("UTF-8")
  17. member.nick = transliterated
  18. _event.send_message("Congratulations on your new nickname, #{member.mention}")
  19. end
  20. _event.send_message("Translitterated: #{text.join(' ').transliterate(script).force_encoding("UTF-8")}")
  21. "Finished translitting"
  22. end
  23. bot.command(:reset) do |_event|
  24. _event.message.mentions.each do |user|
  25. user.on(_event.channel.server).nickname = nil
  26. end
  27. "Finished resetting"
  28. end
  29. bot.command(:loli) do |_event|
  30. "https://tankernn.eu/~frans/files/loli_police_#{rand(1..3)}.png"
  31. end
  32. bot.command(:reap) do |_event, stop_id|
  33. next "No stop_id supplied" if stop_id == nil
  34. FileUtils::mkdir_p("/tmp/tankbot_images/")
  35. stop = false
  36. earliest_message_id = nil
  37. control_message = _event.send_message("Reaping images sent by #{_event.author.mention}. React to this message to stop.")
  38. until stop
  39. messages = _event.channel.history(100, earliest_message_id)
  40. messages.select{ |message| message.author === _event.author }.each do |message|
  41. puts "#{message.id}, #{stop_id}"
  42. if control_message.reactions? or message.id == stop_id
  43. stop = true
  44. break
  45. end
  46. message.attachments.select{ |attachment| attachment.image? }.each do |attachment|
  47. control_message.edit(control_message.content + "\nDownloading **#{attachment.filename}**... (#{message.timestamp.strftime("%F")})")
  48. open("/tmp/tankbot_images/#{attachment.id}-#{attachment.filename}", 'wb') do |file|
  49. file << open(attachment.url).read
  50. end
  51. end
  52. end
  53. stop = messages.length < 100
  54. earliest_message_id = messages.last.id
  55. end
  56. filename = "#{SecureRandom.uuid}.tar.gz"
  57. `tar -czf /var/www/scr/#{filename} /tmp/tankbot_images`
  58. FileUtils::rm_rf("/tmp/tankbot_images")
  59. control_message.edit("https://scr.tankernn.eu/#{filename}")
  60. end
  61. bot.command(:neko) do |_event, keyword|
  62. url = "https://nekos.life/api/v2/img/"
  63. options = ["cum", "les", "meow", "tickle", "lewd", "feed", "bj",
  64. "nsfw_neko_gif", "poke", "anal", "slap", "avatar", "pussy",
  65. "lizard", "classic", "kuni", "pat", "kiss", "neko", "cuddle",
  66. "fox_girl", "boobs", "random_hentai_gif", "hug"]
  67. if options.include? keyword then
  68. response = JSON.parse(Net::HTTP.get(URI("#{url}#{keyword}")))
  69. "Here's your lewds! °˖✧◝(⁰▿⁰)◜✧˖°\n#{response['url']}"
  70. else
  71. "No such tag. Please specify one of `#{options.join(", ")}`"
  72. end
  73. end
  74. bot.command(:lmgtfy) do |_event, *args|
  75. "http://lmgtfy.com/?s=d&q=#{args.join('+')}"
  76. end
  77. bot.command(:copypasta) do |_event, keyword|
  78. pastafile = "copypastas.json"
  79. file = File.read pastafile
  80. pastas = JSON.parse file
  81. if pastas.include? keyword then
  82. pastas[keyword]
  83. else
  84. "No such pasta. Available pastas include `#{pastas.keys.join(", ")}`"
  85. end
  86. end
  87. bot.run