Ver Fonte

agression now reacts to taking channelrights. added coin to the game.

tBKwtWS há 7 anos atrás
pai
commit
3078c4a54f
4 ficheiros alterados com 83 adições e 20 exclusões
  1. 9 7
      irc/commands/common.py
  2. 38 7
      irc/commands/games.py
  3. 20 1
      irc/common/networkservices.py
  4. 16 5
      irc/events/on_mode.py

+ 9 - 7
irc/commands/common.py

@@ -155,10 +155,11 @@ class GameHelpers():
             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, ))
-        level = userrecord[1]
-        total_xp = (level + 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)) / 140
+        userrecord = self.db.one("SELECT xp_spent, level, coin FROM users WHERE LOWER(name)=%s AND network='" + self.network + "'", (user, ))
         xp_spent = userrecord[0]
+        level = userrecord[1]
+        coin = userrecord[2]
+        total_xp = ((level + 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)) / 140) - (level / 25)
         xp = total_xp - xp_spent
         total_messages = messages + actions + notices
         total_words = messages_words + actions_words + notices_words
@@ -179,11 +180,12 @@ class GameHelpers():
         print("Kick karma: (" + str(given) + " * " + str(received) + ") / "+ str(total_xp) + " = " + str(kickkarma))
         xpkarma = xp / 25
         print("XP Karma: " + str(xp) + " /  25 = " + str(xpkarma))
-        karma = joinkarma + chatkarma - kickkarma + xpkarma
-        print("karma: " + str(joinkarma) + " + "+ str(chatkarma) + " - " + str(kickkarma) + " + " + str(xpkarma) + " = " + str(karma))
-        #karma = ((((messages / 20) - joins) / 20) + ((((total_words / 6) - total_messages) + ((total_characters / 6) - total_words)) / 1337) - (given * received) / level) + (xp / 40)
+        coinkarma = (coin / (xp_spent + 1)) / 99
+        print("Coin karma: (" + str(coin) + " / (" + str(xp_spent + 1) + ")) / 99 = " + str(coinkarma))
+        karma = float(joinkarma) + float(chatkarma) - float(kickkarma) + float(xpkarma) - float(coinkarma)
+        print("karma: " + str(joinkarma) + " + "+ str(chatkarma) + " - " + str(kickkarma) + " + " + str(xpkarma) + " - " + str(coinkarma) + " = " + str(karma))
         
-        return level, xp, userrecord[0], karma
+        return level, xp, userrecord[0], karma, coin
 
 class StatisticsHelpers():
     def add_message_stats(stats):

+ 38 - 7
irc/commands/games.py

@@ -20,7 +20,7 @@ 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, "player") + CH.ccc(self, "levelup")[:-2] + ".")
+            connection.privmsg(replyto, grey + "Games: " + CH.ccc(self, "8ball") + CH.ccc(self, "dice") + CH.ccc(self, "player") + CH.ccc(self, "levelup") + CH.ccc(self, "givecoin")[:-2] + ".")
     
     elif command.split()[0] == "8ball":
         if cmdtype == "help":    #Display help text.
@@ -134,7 +134,7 @@ def do_command(self, connection, event):
             
             if len(command.split()) == 1:
                 user = event.source.nick.lower()
-                message = "Your info. "
+                message = grey + "Your info. " + reset
             elif len(command.split()) == 2:
                 user = command.split()[1]
                 if not self.db.one("SELECT id FROM users WHERE LOWER(name)=%s AND network='" + self.network + "'", (user, )):
@@ -144,15 +144,15 @@ def do_command(self, connection, event):
                     connection.privmsg(replyto, "The game does not play the master.")
                     return
                 if user == event.source.nick.lower():
-                    message = "Your info. "
+                    message = grey + "Your info. " + reset
                 else:
-                    message = "Info for " + red + trigger.split()[1] + reset + ". "
+                    message = grey + "Info for " + red + trigger.split()[1] + reset + ". "
             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))
+            level, xp, xpspent, karma, coin = GameHelpers.get_info(self, user)
+            connection.privmsg(replyto, message + "Level: " + str(level) + ", XP: " + str(xp) + ", coin: " + str(coin) + ", karma: " + str(karma))
     
     elif command.split()[0] == "levelup":
         if cmdtype == "help":    #Display help text.
@@ -160,12 +160,13 @@ def do_command(self, connection, event):
         elif cmdtype == "cmd":
             
             user = event.source.nick.lower()
-            level, xp, xpspent, karma = GameHelpers.get_info(self, user)
+            level, xp, xpspent, karma, coin = 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 + "'")
+                    self.sd.run("UPDATE users SET coin=coin+0.3 WHERE level>0")
             elif len(command.split()) == 2:
                 try:
                     levels = int(command.split()[1])
@@ -179,9 +180,39 @@ def do_command(self, connection, event):
                 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 + "'")
+                    self.sd.run("UPDATE users SET coin=coin+" + str(0.3 * levels) + " WHERE level>0")
             else:
                 connection.privmsg(replyto, "Too many arguments. For help type " + blue + self.helpchar + "levelup " + reset + ".")
     
+    elif command.split()[0] == "givecoin":
+        if cmdtype == "help":    #Display help text.
+            connection.privmsg(replyto, "Give coins to another player. Amount optional.")
+            connection.privmsg(replyto, grey + "Usage: " + blue + self.cmdchar + "givecoin " + reset + italic + "user amount")
+        elif cmdtype == "cmd":
+            
+            if len(command.split()) == 1:
+                connection.privmsg(replyto, "Insufficient arguments. For help type " + blue + self.helpchar + "givecoin" + reset + ".")
+                return
+            elif len(command.split()) > 3:
+                connection.privmsg(replyto, "Too many arguments. For help type " + blue + self.helpchar + "givecoin" + reset + ".")
+                return
+            level, xp, xpspent, karma, coin = GameHelpers.get_info(self, event.source.nick)
+            if coin < 1:
+                connection.privmsg(replyto, "You have no coin to give.")
+                return
+            elif not self.db.one("SELECT id FROM users WHERE LOWER(name)=%s AND network='" + self.network + "'", (command.split()[1], )):
+                connection.action(replyto, "does not know of any \"" + red + trigger.split()[1] + reset + "\".")
+                return
+            elif not self.db.one("SELECT id FROM users WHERE LOWER(name)=%s AND network='" + self.network + "' AND LEVEL>0", (command.split()[1], )):
+                connection.privmsg(replyto, red + trigger.split()[1] + reset + " is not playing the game.")
+                return
+            if len(command.split) == 2:
+                self.db.run("UPDATE users SET coin=coin-1 WHERE name=%s AND network='" + self.network + "'", (event.source.nick, ))
+                self.db.run("UPDATE users SET coin=coin+1 WHERE LOWER(name)=%s AND network='" + self.network + "'", (command.split()[1], ))
+            elif len(command.split) == 3:
+                self.db.run("UPDATE users SET coin=coin-%s WHERE name=%s AND network='" + self.network + "'", (command.split()[2], event.source.nick, ))
+                self.db.run("UPDATE users SET coin=coin+%s WHERE LOWER(name)=%s AND network='" + self.network + "'", (command.split()[2], command.split()[1], ))
+    
 #    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 + ".")

+ 20 - 1
irc/common/networkservices.py

@@ -29,4 +29,23 @@ class ChanServ():
     
     def kick(connection, channel, user, reason):
         connection.privmsg("ChanServ", "KICK " + channel + " " + user + " " + reason)
-
+    
+    def give_mode(connection, channel, user, mode):
+        if mode[1] == "q":
+            modename = "OWNER"
+        if mode[1] == "a":
+            modename = "PROTECT"
+        if mode[1] == "o":
+            modename = "OP"
+        if mode[1] == "h":
+            modename = "HALFOP"
+        if mode[1] == "v":
+            modename = "VOICE"
+        connection.privmsg("ChanServ", modename + " " + channel + " " + user)
+    
+    def take_all_modes(connection, channel, user):
+        connection.privmsg("ChanServ", "DEVOICE " + channel + " " + user)
+        connection.privmsg("ChanServ", "DEHALFOP " + channel + " " + user)
+        connection.privmsg("ChanServ", "DEOP " + channel + " " + user)
+        connection.privmsg("ChanServ", "DEPROTECT " + channel + " " + user)
+        connection.privmsg("ChanServ", "DEOWNER " + channel + " " + user)

+ 16 - 5
irc/events/on_mode.py

@@ -67,16 +67,16 @@ def process_event(self, connection, event):
                     return
                 elif behaviour == "defense_only":   # Defensive only behaviour.
                     if mode[1] == "b" and mode[0] == "+":  # Ban.
-                        #for protectee in self.protectees:
                         if fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]):  # Protectee.
                             do_everything_to.unban(connection, event.target, protectee, mode[2])
                     elif mode[1] == "e" and mode[0] == "-":  # Removed exception.
-                        #for protectee in self.protectees:
                         if fnmatch.fnmatch(self.protectees[protectee]['ident'], event.arguments[idx + 1]):  # Protectee.
                             connection.mode(event.target, "+e " + mode[2])
+                    elif mode[0] == "-" and mode[1] in ["q", "a", "o", "h", "v"]:   # Channel right taken.
+                        ChanServ.give_mode(connection, event.target, mode[2], mode[1])
+                        connection.mode(event.target, mode[0] + mode[1] + " " + mode[2])
                 elif behaviour == "equal_retalliation":   # Equal retaliatory behaviour.
                     if modes[1] == "b" and mode[0] == "+":  # Ban.
-                        #for protectee in self.protectees:
                         if fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]):  # Protectee.
                             do_everything_to.unban(connection, event.target, protectee, mode[2])
                             if protectee == connection.get_nickname():  # Bot banned.
@@ -85,12 +85,23 @@ def process_event(self, connection, event):
                                 ChanServ.ban(connection, event.target, event.source.nick, "Aggression channel function = equal_retalliation: " + protectee + " is an operator of " + connection.get_nickname() + ".")
                             connection.mode(event.target, "+b " + event.source)
                     elif mode[1] == "e" and mode[0] == "-":  # Removed exception.
-                        #for protectee in self.protectees:
                         if fnmatch.fnmatch(self.protectees[protectee]['ident'], event.arguments[idx + 1]):  # Protectee.
                             connection.mode(event.target, "+e " + event.arguments[idx + 1])
+                    elif mode[0] == "-" and mode[1] in ["q", "a", "o", "h", "v"]:   # Channel right taken.
+                        ChanServ.give_mode(connection, event.target, mode[2], mode[1])
+                        connection.mode(event.target, mode[0] + mode[1] + " " + mode[2])
+                        ChanServ.take_all_modes(connection, event.target, mode[2])
+                        connection.mode(event.target, "-vhoaq " + mode[2] + " " + mode[2]+ " " + mode[2]+ " " + mode[2]+ " " + mode[2])
                 elif behaviour == "battlebot":  # Battlebot behaviour.
+                    if mode[0] == "-" and mode[1] in ["q", "a", "o", "h", "v"]:   # Channel right taken.
+                        ChanServ.give_mode(connection, event.target, mode[2], mode[1])
+                        connection.mode(event.target, mode[0] + mode[1] + " " + mode[2])
+                        do_everything_to.unban(connection, event.target, protectee, mode[2])
+                        do_everything_to.ban(connection, event.target, event.source.nick, event.source, Aggressiveness.retalliation_reason(self, connection, protectee, behaviour))
+                        connection.mode(event.target, "+e " + mode[2])
+                        ChanServ.akick_add(connection, event.target, event.source.nick)
+                        do_everything_to.kick(connection, event.target, event.source.nick, Aggressiveness.retalliation_reason(self, connection, protectee, behaviour))
                     if mode[1] == "b" and mode[0] == "+":  # Ban.
-                        #for protectee in self.protectees:
                         if fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]):  # Protectee.
                             do_everything_to.unban(connection, event.target, protectee, mode[2])
                             do_everything_to.ban(connection, event.target, event.source.nick, event.source, Aggressiveness.retalliation_reason(self, connection, protectee, behaviour))