from modules.module_base import ModuleBase
from tools.nsfw import Nsfw
import random

class ModuleRandom(ModuleBase):
    RANDOM_MIN = 1
    RANDOM_MAX = 6
    def __init__(self, bot):
        ModuleBase.__init__(self, bot)
        self.name = "ModuleRandom"
        self.nsfw = Nsfw(self.logger);

    def notify_command(self, message_id, from_attr, date, chat, commandName, commandStr):
        commandStr = commandStr.lower()
        if commandName == "random":
            try:
                n = int(commandStr)
                if n > self.RANDOM_MAX or n < self.RANDOM_MIN:
                    self.error_msg(chat)
                else:
                    b = random.randint(self.RANDOM_MIN, self.RANDOM_MAX)
                    if b == n:
                        type = random.choice(list(self.nsfw.bonjours.keys()))
                        self.bot.sendMessage("You win, getting %d %s\nYou are such a coquin" % (b, type), chat["id"])
                        for i in range(n):
                            result = self.nsfw.image(type, "random", "out.jpg")
                            if result.ok():
                                self.bot.sendPhoto(chat["id"], "out.jpg", result.message())
                            else:
                                self.bot.sendMessage(result.message(), chat["id"])
                    else:
                        self.bot.sendMessage("You loose ! (%d)" % b, chat["id"])
            except ValueError:
                self.error_msg(chat)

    def error_msg(self, chat):
        self.bot.sendMessage("Value must be a int between %d and %d !" % (self.RANDOM_MIN, self.RANDOM_MAX), chat["id"])


    def get_commands(self):
        return [
            ("random", "Random [%d %d]" % (self.RANDOM_MIN, self.RANDOM_MAX)),
        ]
@@ -149,16 +149,62 @@
 MAX = 6%0A
+    CHALLENGE_MIN = 1%0A    CHALLENGE_MAX = 100%0A
     def 
@@ -339,9 +339,8 @@
 ger)
-;
 %0A%0A  
@@ -349,175 +349,116 @@
 def 
-notify_command(self, message_id, from_attr, date, chat, commandName, commandStr):%0A        commandStr = commandStr.lower()%0A        if commandName == %22random%22:%0A 
+random(self, a, b, commandStr, chat):%0A        print(%22Raddnom a:%25d b:%25d cs:%25s%22 %25 (a, b, commandStr))%0A
         
    t
@@ -457,20 +457,13 @@
     
-   
 try:%0A
-    
     
@@ -506,63 +506,27 @@
     
-    
 if n %3E 
-self.RANDOM_MAX or n %3C self.RANDOM_MIN:%0A    
+b or n %3C a:%0A
     
@@ -556,22 +556,24 @@
 msg(chat
-)%0A    
+, a, b)%0A
         
@@ -602,13 +602,9 @@
     
-    b
+c
  = r
@@ -621,46 +621,50 @@
 int(
-self.RANDOM_MIN, self.RANDOM_MAX)%0A    
+a, b)%0A                print(%22b = %25d%22 %25 c)%0A
     
@@ -678,17 +678,17 @@
      if 
-b
+c
  == n:%0A 
@@ -706,20 +706,22 @@
         
-    
+image_
 type = r
@@ -778,36 +778,32 @@
                 
-    
 self.bot.sendMes
@@ -858,19 +858,25 @@
 uin%22 %25 (
-b
+n
 , 
+image_
 type), c
@@ -878,36 +878,32 @@
 e), chat%5B%22id%22%5D)%0A
-    
                 
@@ -949,20 +949,16 @@
         
-    
 result =
@@ -974,16 +974,22 @@
 w.image(
+image_
 type, %22r
@@ -1031,20 +1031,16 @@
         
-    
 if resul
@@ -1067,36 +1067,32 @@
                 
-   
- 
 self.bot.sendPho
@@ -1151,36 +1151,32 @@
                 
-    
 else:%0A          
@@ -1185,36 +1185,32 @@
                 
- 
-   
 self.bot.sendMes
@@ -1256,38 +1256,30 @@
             
-  
-  
 else:%0A
-    
             
@@ -1328,17 +1328,17 @@
 (%25d)%22 %25 
-b
+c
 , chat%5B%22
@@ -1351,20 +1351,16 @@
         
-   
- 
 except V
@@ -1374,36 +1374,32 @@
 or:%0A            
-    
 self.error_msg(c
@@ -1393,24 +1393,363 @@
 f.error_msg(
+chat, a, b)%0A%0A    def notify_command(self, message_id, from_attr, date, chat, commandName, commandStr):%0A        if commandName == %22random%22:%0A            self.random(self.RANDOM_MIN, self.RANDOM_MAX, commandStr, chat)%0A        elif commandName == %22randomchallenger%22:%0A            self.random(self.CHALLENGE_MIN, self.CHALLENGE_MAX, commandStr, 
 chat)%0A%0A    d
@@ -1767,24 +1767,30 @@
 g(self, chat
+, a, b
 ):%0A        s
@@ -1858,40 +1858,12 @@
  %25 (
-self.RANDOM_MIN, self.RANDOM_MAX
+a, b
 ), c
@@ -1874,17 +1874,16 @@
 %22id%22%5D)%0A%0A
-%0A
     def 
@@ -2006,9 +2006,105 @@
         
-%5D
+    (%22randomchallenger%22, %22Random %5B%25d %25d%5D%22 %25 (self.CHALLENGE_MIN, self.CHALLENGE_MAX)),%0A        %5D%0A

add random challenger [1, 100]