from random import choice
from moneybot.command import Command
from moneybot.exc import InvalidCommand
from moneybot.ledger import transfer_balance


class Fling(Command):
    prefix = "fling"
    
    description = "Sends the money to a randomly chosen person"
    
    examples = [
        "$fling 100 @user1 @user2 @user3",
        "$fling 100 @user1"
    ]
    

    def default(self):
        server_id = int(self.message.server.id)
        source_user_id = int(self.message.author.id)
        amount = self.parse_int(self.tokens[1])
        user_ids = []
        
        if len(self.tokens) < 3:
            raise InvalidCommand("Who are the lucky ones?")

        if amount is None:
            raise InvalidCommand("Amount must be an number!")

        for user in self.parse_user_string(self.tokens(2:]):
            destination_user_id = self.parse_user_string(user)

            if not destination_user_id:
                raise InvalidCommand("No such user!".format(user))
            
            user_ids.append(destination_user_id)
        
        lucky_user_id = choice(user_ids)

        transfer_balance(server_id, source_user_id, lucky_user_id, amount)

        word = choice(["caught", "got lucky with", "found", "won", "stumbled upon"])

        return "<@{}> {} ${}".format(lucky_user_id, word, amount)





@@ -186,20 +186,16 @@
 %22fling%22%0A
-    
 %0A    des
@@ -251,20 +251,16 @@
 person%22%0A
-    
 %0A    exa
@@ -350,17 +350,18 @@
   %5D%0A
+%0A
     
-%0A%0A   
+async
  def
@@ -547,24 +547,16 @@
 ds = %5B%5D%0A
-        
 %0A       
@@ -752,39 +752,16 @@
 user in 
-self.parse_user_string(
 self.tok
@@ -767,13 +767,12 @@
 kens
-(
+%5B
 2:%5D
-)
 :%0A  
@@ -940,28 +940,16 @@
 (user))%0A
-            
 %0A       
@@ -990,24 +990,16 @@
 ser_id)%0A
-        
 %0A       
@@ -1041,16 +1041,22 @@
         
+await 
 transfer
@@ -1267,12 +1267,8 @@
 amount)%0A
-%0A%0A%0A%0A

Fix fling