Ver Fonte

levelup

tBKwtWS há 7 anos atrás
pai
commit
850f740827
2 ficheiros alterados com 110 adições e 47 exclusões
  1. 44 0
      commands/common.py
  2. 66 47
      commands/games.py

+ 44 - 0
commands/common.py

@@ -122,6 +122,50 @@ class GameHelpers():
         for iterations in range(amount):
             rolls.append(random.randint(1, type))
         return rolls
+    
+    def get_info(self, user):
+        user = user.lower()
+        all_joins = self.db.all("SELECT joins FROM joins WHERE LOWER(\"user\")=%s AND user_network='" + self.network + "'", (user, ))
+        all_kicks = self.db.all("SELECT given, received FROM kicks WHERE LOWER(\"user\")=%s AND user_network='" + self.network + "'", (user, ))
+        all_messages = self.db.all("SELECT messages, messages_words, messages_characters, actions, actions_words, actions_characters, notices, notices_words, notices_characters FROM messages WHERE LOWER(\"user\")=%s AND user_network='" + self.network + "'", (user, ))
+        joins =0
+        for record in all_joins:
+            joins += record
+        given = 0
+        received = 0
+        for record in all_kicks:
+            given += int(record[0])
+            received += int(record[1])
+        messages = 0
+        messages_words = 0
+        messages_characters = 0
+        actions = 0
+        actions_words = 0
+        actions_characters = 0
+        notices = 0
+        notices_words = 0
+        notices_characters = 0
+        for record in all_messages:
+            messages += int(record[0])
+            messages_words += int(record[1])
+            messages_characters += int(record[2])
+            actions += int(record[3])
+            actions_words += int(record[4])
+            actions_characters += int(record[5])
+            notices += int(record[6])
+            notices_words += int(record[7])
+            notices_characters += int(record[8])
+        userrecord = self.db.one("SELECT xp_spent, level FROM users WHERE LOWER(name)=%s AND network='" + self.network + "'", (user, ))
+        total_xp = (joins + (given * received) + messages + (messages_words / 4) + (messages_characters / 10) + ((actions + (actions_words / 4) + (actions_characters / 10)) * 2) + ((notices + (notices_words / 4) + (notices_characters / 10)) / 2)) / 20
+        xp = total_xp - userrecord[0]
+        total_messages = messages + actions + notices
+        total_words = messages_words + actions_words + notices_words
+        if joins < 1:
+            joins = 1
+        if total_messages < 1:
+            total_messages = 1
+        karma = ((((messages / 30) - joins) / 5) + ((total_words / 10) - total_messages) / 40) - (given * received)
+        return userrecord[1], xp, userrecord[0], karma
 
 class StatisticsHelpers():
     def add_message_stats(stats):

+ 66 - 47
commands/games.py

@@ -20,14 +20,14 @@ def do_command(self, connection, event):
     
     if command == "cmd" or command == "cmds" or command == "commands":
         if cmdtype == "cmd":
-            connection.privmsg(replyto, grey + "Games: " + CH.ccc(self, "8ball") + CH.ccc(self, "dice") + CH.ccc(self, "players")[:-2] + ".")
+            connection.privmsg(replyto, grey + "Games: " + CH.ccc(self, "8ball") + CH.ccc(self, "dice") + CH.ccc(self, "players") + CH.ccc(self, "levelup")[:-2] + ".")
     
     elif command.split()[0] == "8ball":
         if cmdtype == "help":    #Display help text.
             connection.privmsg(replyto, "Ask a question of the mighty and illusive 8-Ball.")
-            connection.privmsg(replyto, grey + "Usage: " + blue + "!8ball " + reset + italic + "question")
-            
+            connection.privmsg(replyto, grey + "Usage: " + blue + self.cmdchar + "8ball " + reset + italic + "question")
         elif cmdtype == "cmd":
+            
             if len(command.split()) < 2:    # Command contains only !8ball.
                 messages = [
                     "Don't forget to ask a question...", 
@@ -72,8 +72,8 @@ def do_command(self, connection, event):
             if len(command.split()) is not 1:
                 return
             connection.privmsg(replyto, "Rolls multiple dices of chosen type. Specifying type or amount is optional.")
-            connection.privmsg(replyto, grey + "Usage: " + blue + "!dice " + reset + italic + "amount type")
-            connection.privmsg(replyto, grey + "Example: " + blue + "!dice " + reset + italic + "2 d10")
+            connection.privmsg(replyto, grey + "Usage: " + blue + self.cmdchar + "dice " + reset + italic + "amount type")
+            connection.privmsg(replyto, grey + "Example: " + blue + self.cmdchar + "dice " + reset + italic + "2 d10")
             connection.privmsg(replyto, grey + "Note: " + reset + "The dice type is specified as a " + italic + "d " + reset + "followed by the amount of sides.")
         elif cmdtype == "cmd":
             
@@ -130,8 +130,8 @@ def do_command(self, connection, event):
     elif command.split()[0] == "players":
         if cmdtype == "help":    #Display help text.
             connection.privmsg(replyto, "Displays a users game info. User optional.")
-            
         elif cmdtype == "cmd":
+            
             if len(command.split()) == 1:
                 user = event.source.nick.lower()
                 message = "Your info. "
@@ -147,45 +147,64 @@ def do_command(self, connection, event):
                     message = "Your info. "
                 else:
                     message = "Info for " + red + trigger.split()[1] + reset + ". "
-            all_joins = self.db.all("SELECT joins FROM joins WHERE LOWER(\"user\")=%s AND user_network='" + self.network + "'", (user, ))
-            all_kicks = self.db.all("SELECT given, received FROM kicks WHERE LOWER(\"user\")=%s AND user_network='" + self.network + "'", (user, ))
-            all_messages = self.db.all("SELECT messages, messages_words, messages_characters, actions, actions_words, actions_characters, notices, notices_words, notices_characters FROM messages WHERE LOWER(\"user\")=%s AND user_network='" + self.network + "'", (user, ))
-            joins =0
-            for record in all_joins:
-                joins += record
-            given = 0
-            received = 0
-            for record in all_kicks:
-                given += int(record[0])
-                received += int(record[1])
-            messages = 0
-            messages_words = 0
-            messages_characters = 0
-            actions = 0
-            actions_words = 0
-            actions_characters = 0
-            notices = 0
-            notices_words = 0
-            notices_characters = 0
-            for record in all_messages:
-                messages += int(record[0])
-                messages_words += int(record[1])
-                messages_characters += int(record[2])
-                actions += int(record[3])
-                actions_words += int(record[4])
-                actions_characters += int(record[5])
-                notices += int(record[6])
-                notices_words += int(record[7])
-                notices_characters += int(record[8])
-            userrecord = self.db.one("SELECT xp_spent, level FROM users WHERE LOWER(name)=%s AND network='" + self.network + "'", (user, ))
-            total_xp = (joins + (given * received) + messages + (messages_words / 4) + (messages_characters / 10) + ((actions + (actions_words / 4) + (actions_characters / 10)) * 2) + ((notices + (notices_words / 4) + (notices_characters / 10)) / 2)) / 20
-            xp = total_xp - userrecord[0]
-            total_messages = messages + actions + notices
-            total_words = messages_words + actions_words + notices_words
-            if joins < 1:
-                joins = 1
-            if total_messages < 1:
-                total_messages = 1
-            karma = ((((messages / 10) - joins) / 5) + ((total_words / 5) - total_messages) / 40) - (given * received) 
+            else:
+                connection.privmsg(replyto, "Too many arguments, For help type " + blue + self.helpchar + "players " + reset + ".")
+                return
+             
+            level, xp, xpspent, karma = GameHelpers.get_info(self, user)
+            connection.privmsg(replyto, message + "Level: " + str(level) + ", XP: " + str(xp) + ", karma: " + str(karma))
+    
+    elif command.split()[0] == "levelup":
+        if cmdtype == "help":    #Display help text.
+            connection.privmsg(replyto, "Spend 10 XP per level gained. Gain multiple levels by specifying the amount.")
+        elif cmdtype == "cmd":
+            
+            user = event.source.nick.lower()
+            level, xp, xpspent, karma = GameHelpers.get_info(self, user)
+            if len(command.split()) == 1:
+                if xp < 10:
+                    connection.privmsg(replyto, "Insuficcient XP, you need at least 10.")
+                else:
+                    self.db.run("UPDATE users SET level=level+1, xp_spent=xp_spent+10 WHERE LOWER(name)='" + user + "' AND network='" + self.network + "'")
+            elif len(command.split()) == 2:
+                try:
+                    levels = int(command.split()[1])
+                except:
+                    connection.privmsg(replyto, "Invalid amount.")
+                    return
+                if levels < 1:
+                    connection.privmsg(replyto, "Invalid amount.")
+                elif xp < levels * 10:
+                    connection.privmsg(replyto, "Insuficcient XP, you need at least " + str(levels * 10) + ".")
+                else:
+                    print("UPDATE users SET level=level+" + str(levels) + ", xp_spent=xp_spent+" + str(levels * 10) + " WHERE LOWER(name)='" + user + "' AND network='" + self.network + "'")
+                    self.db.run("UPDATE users SET level=level+" + str(levels) + ", xp_spent=xp_spent+" + str(levels * 10) + " WHERE LOWER(name)='" + user + "' AND network='" + self.network + "'")
+            else:
+                connection.privmsg(replyto, "Too many arguments. For help type " + blue + self.helpchar + "levelup " + reset + ".")
     
-            connection.privmsg(replyto, message + "Level: " + str(userrecord[1]) + ", XP: " + str(xp) + ", karma: " + str(karma))
+#    elif command.split()[0] == "classup":
+#        if cmdtype == "help":    #Display help text.
+#            connection.privmsg(replyto, "Spend 10 XP to gain a class in your current level. List available classes with " + blue + self.helpchar + "classup available " + reset + ".")
+#            connection.privmsg(replyto, grey + "Usage: " + blue + self.cmdchar + "classup " + reset + italic + "class")
+#        elif cmdtype == "cmd":
+#            
+#            if len(command.split()) == 1:
+#                connection.privmsg(replyto, "Insufficient arguments. For help type " + blue + self.helpchar + "classup" + reset + ".")
+#            if len(command.split()) == 2:
+#                if command.split()[1] == "available":
+#                    level, xp, xpspent, karma = GameHelpers.get_info(self, event.source.nick)
+#                    if level == 0:
+#                        connection.privmsg(replyto, "There are no level 0 classes.")
+#                    if level == 1:
+#                        connection.privmsg(replyto, "Level 1 classes: Maggot, nubcake, ")
+#                    if level == 2:
+#                        connection.privmsg(replyto, "Level 2 classes: Retard, ")
+#                    if level == 3:
+#                        connection.privmsg(replyto, "Level 3 classes: ")
+#                    if level == 4:
+#                        connection.privmsg(replyto, "Level 3 classes: ")
+#                    if level == 5:
+#                        connection.privmsg(replyto, "Level 4 classes: ")
+#                else:
+#            else:
+#                connection.privmsg(replyto, "Too many arguments. For help type " + blue + self.helpchar + "classup" + reset + ".")