Browse Source

fix xp for pasted images

Kylie Jo Swistak 6 years ago
parent
commit
90cdf7c187
2 changed files with 5 additions and 3 deletions
  1. 2 2
      app/models/users.rb
  2. 3 1
      bot.rb

+ 2 - 2
app/models/users.rb

@@ -35,11 +35,11 @@ class User < ActiveRecord::Base
   def update_xp(msg, user=nil)
     xp =
       case msg.length
-      when 0..40 then 0
+      when 0..39 then 0
       when 40..149 then 1
       when 150..299 then 2
       when 300..599 then 3
-      when 600..1000 then 4
+      when 600..999 then 4
       else 5
       end
 

+ 3 - 1
bot.rb

@@ -820,7 +820,9 @@ bot.message do |event|
     User.import_user(File.open('users.txt', 'r'))
   elsif !event.author.bot_account? && !event.author.webhook?
     usr = User.find_by(id: author.to_s)
-    msg = URL.match(content) ? content.gsub(URL, "x" * 149) : content
+    msg = URL.match(content) ? content.gsub(URL, "x" * 150) : content
+    file = event.message.attachments.map(&:filename).count
+    msg = file > 0 ? msg + ("x" * 40) : msg
 
     img = usr.update_xp(msg, event.author)
     bot.send_file(event.message.channel, File.open(img, 'r')) if img