tBKwtWS 6 лет назад
Родитель
Сommit
fe83743a9a

+ 1 - 1
rotbot/commands/chat.py

@@ -25,7 +25,7 @@ def do_command(self, connection, event, user, channel):
 
     if command == 'cmd' or command == 'cmds' or command == 'commands':
         if cmdtype == 'cmd':
-            connection.privmsg(replyto, '%sChat: %s %s' % (font.grey, CH.ccc(self, "curse")[:-2]))
+            connection.privmsg(replyto, '%sChat: %s' % (font.grey, CH.ccc(self, "curse")[:-2]))
 
     elif one == 'curse':
         curse = queries.random_curse(self)

+ 29 - 40
rotbot/commands/common.py

@@ -138,65 +138,54 @@ class GameHelpers():
 
         # Experience & action points.
         chat_xp = total_messages + (total_actions * 3) + (total_notices / 3)
-        print('chat_xp: ' + str(chat_xp) + ' = total_messages: ' + str(total_messages) + ' + (' + str(total_actions) + ' *3) + (' + str(total_notices) + ' / 3)')
-        curse_add_xp = (total_cursewords_added + total_curseadjectives_added) * 10
-        print('curse_add_xp: ' + str(curse_add_xp) + ' = (total_cursewords_added:' + str(total_cursewords_added) + ' + total_curseadjectives_added:' + str(total_curseadjectives_added) + ') * 10')
-        coin_xp = (coin_given * 5) + coin_spent
-        print('coin_xp: ' + str(coin_xp) + ' = (coin_given:' + str(coin_given) + ' * 5) + coin_spent:' + str(coin_spent))
-        total_xp = chat_xp + curse_add_xp + coin_xp + total_joins + total_kicks + total_kicked + ap_spent
-        print('total_xp: ' + str(total_xp) + ' = chat_xp: ' + str(chat_xp) + ' + curse_add_xp: ' + str(curse_add_xp) + ' + coin_xp: ' + str(coin_xp) + ' + total_joins: ' + str(total_joins) + ' + total_kicks: ' + str(total_kicks) + ' + total_kicked: ' + str(total_kicked) + ' + ap_spent : ' + str(ap_spent))
-        xp = (total_xp - xp_spent - (level * 2))
-        print('xp :' + str(xp) + ' = (total_xp: ' + str(total_xp) + ' - xp_spent: ' + str(xp_spent) + ' - (level: ' + str(level) + ' * 100))')
-        ap = (total_xp / 100) - ap_spent
-        print('ap: + ' + str(ap) + ' = (total_xp: ' + str(total_xp) + ' / 100) - ap_spent: ' + str(ap_spent))
+        print('chat_xp:' + str(chat_xp) + ' = total_messages:' + str(total_messages) + ' + ( total_actions:' + str(total_actions) + ' *3) + ( + total_notices:' + str(total_notices) + ' / 3)')
+        curse_add_xp = (total_cursewords_added + total_curseadjectives_added) * 10.1
+        print('curse_add_xp:' + str(curse_add_xp) + ' = (total_cursewords_added:' + str(total_cursewords_added) + ' + total_curseadjectives_added:' + str(total_curseadjectives_added) + ') * 10.1')
+        coin_xp = (coin_given * 5.1) + coin_spent
+        print('coin_xp:' + str(coin_xp) + ' = (coin_given:' + str(coin_given) + ' * 5) + coin_spent:' + str(coin_spent))
+        total_xp = (chat_xp + curse_add_xp + coin_xp + total_joins + total_kicks + total_kicked + ap_spent) / 10.1
+        print('total_xp:' + str(total_xp) + ' = chat_xp:' + str(chat_xp) + ' + curse_add_xp: ' + str(curse_add_xp) + ' + coin_xp:' + str(coin_xp) + ' + total_joins:' + str(total_joins) + ' + total_kicks:' + str(total_kicks) + ' + total_kicked:' + str(total_kicked) + ' + ap_spent :' + str(ap_spent) + ' / 10.1')
+        xp = (total_xp - xp_spent) - (level * 2.1)
+        print('xp:' + str(xp) + ' = (total_xp:' + str(total_xp) + ' - xp_spent:' + str(xp_spent) + ') - (level:' + str(level) + ' * 2.1))')
+        ap = (total_xp / 3.1) - ap_spent
+        print('ap:' + str(ap) + ' = (total_xp:' + str(total_xp) + ' / 3.1) - ap_spent:' + str(ap_spent))
 
         # Karma.
         if total_xp == 0:
             total_xp = 0.01
         join_karma = total_joins / total_xp   # High value should have negative impact.
-        print('join_karma: ' + str(join_karma) + ' = joins: ' + str(total_joins) + ' / total_xp: ' + str(total_xp))
+        print('join_karma:' + str(join_karma) + ' = joins:' + str(total_joins) + ' / total_xp:' + str(total_xp))
         kick_karma = (total_kicks + total_kicked) / total_xp  # High value should have negative impact.
-        print('kick_karma: ' + str(kick_karma) + ' = (given: ' + str(total_kicks) + ' + received: ' + str(total_kicked) + ') / total_xp:' + str(total_xp))
+        print('kick_karma:' + str(kick_karma) + ' = (given:' + str(total_kicks) + ' + received:' + str(total_kicked) + ') / total_xp:' + str(total_xp))
         shout_karma =  total_notices / total_xp # High value should have negative impact.
-        print('shout_karma: ' + str(shout_karma) + ' =  total_notices: ' + str(total_notices) + ' + / total_xp: ' + str(total_xp))
+        print('shout_karma:' + str(shout_karma) + ' =  total_notices:' + str(total_notices) + ' + / total_xp:' + str(total_xp))
         curse_add_karma = ((total_cursewords_added + total_curseadjectives_added) * 10 ) / total_xp  # High value should have positive impact.
-        print('curse_add_karma: ' + str(curse_add_karma) + ' = ((total_cursewords_added: ' + str(total_cursewords_added) + ' + total_curseadjectives_added: ' + str(total_curseadjectives_added) + ') * 10 ) / total_xp: '+ str(total_xp))
-        wealth_karma = (coin * 50) / total_xp
-        print('wealth_karma: ' + str(wealth_karma) + ' = (coin: ' + str(coin) + ' * 50) / total_xp: ' + str(total_xp))
-        charity_karma = (coin_given * 10) / total_xp
-        print('charity_karma: ' + str(charity_karma) + ' = (coin_given: ' + str(coin_given) + ' * 10) / total_xp: ' + str(total_xp))
+        print('curse_add_karma:' + str(curse_add_karma) + ' = ((total_cursewords_added:' + str(total_cursewords_added) + ' + total_curseadjectives_added:' + str(total_curseadjectives_added) + ') * 10 ) / total_xp:'+ str(total_xp))
+        wealth_karma = (coin * 50.1) / total_xp
+        print('wealth_karma:' + str(wealth_karma) + ' = (coin:' + str(coin) + ' * 50) / total_xp:' + str(total_xp))
+        charity_karma = (coin_given * 10.1) / total_xp
+        print('charity_karma:' + str(charity_karma) + ' = (coin_given:' + str(coin_given) + ' * 10) / total_xp:' + str(total_xp))
         karma =  float(karma_correction) + float(curse_add_karma) + float(charity_karma) - float(join_karma) - float(kick_karma) - float(shout_karma) - float(wealth_karma)
-        print('karma: ' + str(karma) + ' =  float(karma_correction: ' + str(karma_correction) + ') + float(curse_karma: ' + str(curse_add_karma) + ') + float(charity_karma: ' + str(charity_karma) + ') - float(join_karma: ' + str(join_karma) + ') - float(kick_karma: ' + str(kick_karma) + ') - float(shout_karma: ' + str(shout_karma) + ') - float(wealth_karma: ' + str(wealth_karma) + ')')
+        print('karma: ' + str(karma) + ' =  float(karma_correction:' + str(karma_correction) + ') + float(curse_karma:' + str(curse_add_karma) + ') + float(charity_karma:' + str(charity_karma) + ') - float(join_karma:' + str(join_karma) + ') - float(kick_karma:' + str(kick_karma) + ') - float(shout_karma:' + str(shout_karma) + ') - float(wealth_karma:' + str(wealth_karma) + ')')
 
         return level, xp, xp_spent, total_xp, karma, coin, coin_spent, coin_given, ap, ap_spent
 
     def player_info(self, user):
         level, xp, xp_spent, total_xp, karma, coin, coin_spent, coin_given, ap, ap_spent = GameHelpers.get_info(self, user)
-        return 'Level: ' + str(level) + font.grey + ", " + font.reset + "XP: " + str(int(xp)) + "/" + font.grey + str(round(total_xp, 4)) + ", " + font.reset + "AP: " + str(int(ap)) + font.grey + ", " + font.reset + "coin: " + str(coin) + font.grey + "[S " + str(coin_spent) + ", G " + str(coin_given) + "], " + font.reset + "karma: " + str(round(karma, 4))
+        #return 'Level: ' + str(level) + font.grey + ", " + font.reset + "XP: " + str(int(xp)) + "/" + font.grey + str(round(total_xp, 4)) + ", " + font.reset + "AP: " + str(int(ap)) + font.grey + ", " + font.reset + "coin: " + str(coin) + font.grey + "[S " + str(coin_spent) + ", G " + str(coin_given) + "], " + font.reset + "karma: " + str(round(karma, 4))
+        return 'Level: ' + str(level) + font.grey + ", " + font.reset + "XP: " + str(int(xp)) + "/" + font.grey + str(int(total_xp)) + ", " + font.reset + "AP: " + str(int(ap)) + font.grey + ", " + font.reset + "coin: " + str(coin) + font.grey + "[S " + str(coin_spent) + ", G " + str(coin_given) + "], " + font.reset + "karma: " + str(round(karma, 4))
 
     def list_top_players(self, sort):
         result = queries.get_top_users(self, sort)
         if sort == "level":
-            column = 1
-            threshold = 0
-        if sort == "xp_spent":
             column = 2
-            threshold = 0
-        if sort == "coin":
+        if sort == "xp_spent":
             column = 3
-            threshold = 10
+        if sort == "coin":
+            column = 4
         message = ""
         for record in result:
-
-            #if not record[column] <= threshold:
-
-            level, xp, xp_spent, total_xp, karma, coin, coin_spent, coin_given, ap, ap_spent = GameHelpers.get_info(self, record)
-            if ap < 0:
-                ap = 0
-            if sort == "level":
-                message += font.red + str(record[0]) + font.reset + " [" + font.blue + "L " + font.green + str(level) + font.reset + ", X " + font.grey + str(xp_spent) + "/" + font.green + str(int(xp)) + font.reset + ", A " + str(int(ap)) + ", C " + font.green + str(coin) + font.reset + ", K " + font.green + str(round(karma, 2)) + font.reset + "], "
-            if sort == "xp_spent":
-                message += font.red + str(record[0]) + font.reset + " [L " + font.green + str(level) + font.reset + ", " + font.blue + "X " + font.grey + str(xp_spent) + "/" + font.green + str(int(xp)) + font.reset + ", A " + str(int(ap)) + ", C " + font.green + str(coin) + font.reset + ", K " + font.green + str(round(karma, 2)) + font.reset + "], "
-            if sort == "coin":
-                message += font.red + str(record[0]) + font.reset + " [L " + font.green + str(level) + font.reset + ", X " + font.grey + str(xp_spent) + "/" + font.green + str(int(xp)) + font.reset + ", " + font.reset + "A " + str(int(ap)) + ", " + font.blue + "C " + font.green + str(coin) + font.reset + ", K " + font.green + str(round(karma, 2)) + font.reset + "], "
-        return message[:-2]
+            if not int(record[column]) < 1:
+                level, xp, xp_spent, total_xp, karma, coin, coin_spent, coin_given, ap, ap_spent = GameHelpers.get_info(self, record)
+                message += font.red + str(record[1]) + font.grey + " L " + font.green + str(level) + font.grey + ", XP " + font.green + str(int(xp)) + font.grey + "/" + str(int(total_xp)) + ", A " + font.green + str(int(ap)) + font.grey + ", C " + font.green + str(coin) + font.grey + ", K " + font.green + str(round(karma, 2)) + font.grey + ", "
+            return message[:-2]

+ 42 - 34
rotbot/commands/games.py

@@ -22,12 +22,12 @@ def do_command(self, connection, event, user, channel):
 
     # Do noting if the games channel function is off and it's a channel message.
     if event.target != connection.get_nickname():   # Command issued to channel.
-        if not queries.get_channel_setting_game_commands:   # Games are turned off in channel settigns.
+        if not queries.get_channel_setting_game_commands(self, channel.id):   # Games are turned off in channel settigns.
             return  # Do nothing.
 
     if command == 'cmd' or command == 'cmds' or command == 'commands':
         if cmdtype == 'cmd':
-            connection.privmsg(replyto, '%sGames: %s %s %s %s %s %s' % (font.grey, CH.ccc(self, "player"), CH.ccc(self, "players"), CH.ccc(self, "levelup") ,CH.ccc(self, "givecoin"), CH.ccc(self, "8ball"), CH.ccc(self, "dice")[:-2]))
+            connection.privmsg(replyto, '%sGames: %s%s%s%s%s%s' % (font.grey, CH.ccc(self, "player"), CH.ccc(self, "players"), CH.ccc(self, "levelup") ,CH.ccc(self, "givecoin"), CH.ccc(self, "8ball"), CH.ccc(self, "dice")[:-2]))
             connection.privmsg(replyto, font.grey + "Game help: " + font.blue + self.network.help_character + "level" + font.grey + ", " + font.blue + self.network.help_character + "xp" + font.grey + ", " + font.blue + self.network.help_character + "ap" + font.grey + ", " + font.blue + self.network.help_character + "coin" + font.grey + ", " + font.blue + self.network.help_character + "karma" + font.grey + ".")
 
 
@@ -37,7 +37,7 @@ def do_command(self, connection, event, user, channel):
                 connection.privmsg(replyto, 'Displays a users game statistics. User optional.')
                 connection.privmsg(replyto, 'Usage: %s%s%s%s %snickname' % (font.blue, self.network.command_character, one, font.reset, font.italic))
                 return
-            message = '%s Your player stats: ' % font.grey
+            message = '%sYour player stats: ' % font.grey
             player_name = event.source.nick
             player = queries.get_user(self, player_name)
         elif len(command.split()) == 2:
@@ -70,7 +70,7 @@ def do_command(self, connection, event, user, channel):
             if xp < int(level * 2.7):
                 connection.privmsg(replyto, "Insufficient XP, you need at least " + str(int(level * 2.7)) + ".")
                 return
-            elif ap <= 0:
+            elif ap < 1:
                 connection.privmsg(replyto, "Insufficient AP, you need at least 1.")
                 return
             elif len(command.split()) == 2:   # Command with one argument.
@@ -96,12 +96,11 @@ def do_command(self, connection, event, user, channel):
             info = GameHelpers.player_info(self, user)
             connection.privmsg(replyto, "Your new statistics: " + info)
 
-    elif command.split()[0] == "givecoin":
-        if cmdtype == "help":    #Display help text.
+    elif one == 'givecoin':
+        if cmdtype == 'help':    #Display help text.
             connection.privmsg(replyto, "Give coins to another player. Amount optional.")
             connection.privmsg(replyto, font.grey + "Usage: " + font.blue + self.network.command_character + "givecoin " + font.reset + font.italic + "user amount")
         elif cmdtype == "cmd":
-
             if len(command.split()) == 1:
                 connection.privmsg(replyto, "Insufficient arguments. For help type " + font.blue + self.network.help_character + "givecoin" + font.reset + ".")
                 return
@@ -111,67 +110,76 @@ def do_command(self, connection, event, user, channel):
             elif command.split()[1] == event.source.nick.lower():
                 connection.privmsg(replyto, "You already have your own coin. For help type " + font.blue + self.network.help_character + "givecoin" + font.reset + ".")
                 return
+            elif command.split()[1] == connection.get_nickname() or command.split()[1] == self.network.nickname:
+                connection.privmsg(replyto, "I don't need that. If I wanted I could take all your coin and there would be nothing for you to do to stop me....")
+                return
             elif len(command.split()) == 3:
-                stop = False
                 try:
                     if float(command.split()[2]) < 0:
                         connection.privmsg(replyto, "You clever abuser! The " + font.red + self.network.command_character + font.bold + "give" + font.bold + "coin" + font.reset + " command is not designed for robbing. There will be consequences...")
-                        self.db.run("UPDATE users SET coin=coin-3, karma_correction=karma_correction-0.5 WHERE name=%s AND network=%s", (event.source.nick, self.network))
-                        stop = True
+                        queries.punish_user(self, user, -3, -1)
+                        return
                 except TypeError:
                     connection.privmsg(replyto, "Invalid amount. For help type " + font.blue + self.network.help_character + "givecoin" + font.reset + ".")
                     return
-                if stop:
+            elif event.target == connection.get_nickname(): # Private message
+                for channel in self.channels:
+                    user_present = False
+                    if command.split()[1] in self.channels[channel].users():    # User is on a channel the bot inhabits.
+                        user_present = True
+                if not user_present:
+                    connection.privmsg(replyto, font.red + trigger.split()[1] + font.reset + " is not present on any channel I inhabit.")
                     return
-            elif not event.target == connection.get_nickname():
+            else:   # Channel message
                 if not command.split()[1] in self.channels[event.target].users():
-                    connection.privmsg(replyto, font.red + trigger.split()[1] + font.reset + " is not present.")
+                    connection.privmsg(replyto, font.red + trigger.split()[1] + font.reset + " is not present on this channel.")
                     return
 
-            level, xp, xpspent, totalxp, karma, coin, coinspent, coingiven, ap, apspent = GameHelpers.get_info(self, event.source.nick)
-            receivingrecord = self.db.one("SELECT level, away FROM users WHERE LOWER(name)=%s AND network=%s", (command.split()[1], self.network, ))
+            level, xp, xpspent, totalxp, karma, coin, coinspent, coingiven, ap, apspent = GameHelpers.get_info(self, user)
+            receiver = queries.get_user(self, command.split()[1])
             if level < 1:
                 connection.privmsg(replyto, "You need to " + font.blue + self.network.command_character + "levelup " + font.reset + "to be able to give coin.")
                 return
             elif coin < 1:
                 connection.privmsg(replyto, "You have no coin to give.")
                 return
-            elif not receivingrecord:
+            elif not receiver:
                 connection.action(replyto, "does not know of any \"" + font.red + trigger.split()[1] + font.reset + "\".")
                 return
-            elif receivingrecord[0] == 0:
+            elif receiver.level <= 0:
                 connection.privmsg(replyto, font.red + trigger.split()[1] + font.reset + " is not playing the game.")
                 return
-            elif receivingrecord[1] == True:
-                connection.privmsg(replyto, font.red + trigger.split()[1] + font.reset + "is not here right now.")
-                return
+            #elif receiver.away == True:
+            #    connection.privmsg(replyto, font.red + trigger.split()[1] + font.reset + "is not here right now.")
+            #    return
             elif ap < 1:
-                connection.privmsg(replyto, "You have no action points, go use IRC some more...")
+                connection.privmsg(replyto, "You have no action points.")
                 return
             if len(command.split()) == 2:
-                self.db.run("UPDATE users SET coin=coin-1, coin_spent=coin_spent+1, coin_given=coin_given+1, ap_spent=ap_spent+1 WHERE name=%s AND network=%s", (event.source.nick, self.network, ))
-                self.db.run("UPDATE users SET coin=coin+1 WHERE LOWER(name)=%s AND network=%s", (command.split()[1], self.network, ))
+                queires.cointransfer(self, event.source.nick, command.split()[1])
             elif len(command.split()) == 3:
-                self.db.run("UPDATE users SET coin=coin-%s, coin_spent=coin_spent+%s, coin_given=coin_given+%s, ap_spent=ap_spent+1 WHERE name=%s AND network=%s", (command.split()[2], command.split()[2], command.split()[2], event.source.nick, self.network, ))
-                self.db.run("UPDATE users SET coin=coin+%s WHERE LOWER(name)=%s AND network=%s", (command.split()[2], command.split()[1], self.network))
+                if coin < command.split()[2]:
+                    connection.privmsg(replyto, "You do not have enough coin.")
+                    return
+                queires.cointransfer(self, event.source.nick, command.split()[2])
             info = GameHelpers.player_info(self, event.source.nick)
             connection.notice(event.source.nick, "Your new statistics: " + info)
 
-    elif command.split()[0] == "players":
-        if cmdtype == "help":    #Display help text.
-            connection.privmsg(replyto, "Display top player rankings.")
+    elif one == 'players':
+        if cmdtype == 'help':    #Display help text.
+            connection.privmsg(replyto, 'Display top player rankings.')
         elif cmdtype == "cmd":
-
             toplevel = GameHelpers.list_top_players(self, "level")
+            topxp = GameHelpers.list_top_players(self, "xp_spent")
+            topcoin = GameHelpers.list_top_players(self, "coin")
             if toplevel:
                 connection.notice(event.source.nick, "Ranking level: " + toplevel)
-            topxp = GameHelpers.list_top_players(self, "xp_spent")
-            if topxp:
+            elif topxp:
                 connection.notice(event.source.nick, "Ranking experience: " + topxp)
-            topcoin = GameHelpers.list_top_players(self, "coin")
-            if topcoin:
+
+            elif topcoin:
                 connection.notice(event.source.nick, "Ranking wealth: " + topcoin)
-            if not toplevel and not topxp and not topcoin:
+            else:
                 connection.privmsg(replyto, "Nobody is playing the game.")
 
 

+ 1 - 1
rotbot/commands/public.py

@@ -35,7 +35,7 @@ def do_command(self, connection, event, user, channel):
                 connection.privmsg(replyto, 'Displays a list of commands, usage: %s%s%s' % (font.blue, self.network.command_character, command))
                 return
             elif cmdtype == 'cmd':
-                connection.privmsg(replyto, '%sPublic: %s %s' % (font.grey, CH.ccc(self, "cmd"), CH.ccc(self, "help")[:-2]))# + CH.ccc(self, "away") + CH.ccc(self, "stopgreet")[:-2] + ".")
+                connection.privmsg(replyto, '%sPublic: %s%s' % (font.grey, CH.ccc(self, "cmd"), CH.ccc(self, "help")[:-2]))# + CH.ccc(self, "away") + CH.ccc(self, "stopgreet")[:-2] + ".")
 
     if command == 'help':
         if cmdtype == 'help':    #Display help text.

+ 2 - 2
rotbot/commands/statistics.py

@@ -22,12 +22,12 @@ def do_command(self, connection, event, user, channel):
 
     # Do noting if the statistics channel function is off and it's a channel message.
     if not event.target == connection.get_nickname():
-        if not queries.get_channel_setting_statistic_commands(self, event.target):
+        if not queries.get_channel_setting_statistic_commands(self, channel.id):
             return
 
     if command == 'cmd' or command == 'cmds' or command == 'commands':
         if cmdtype == 'cmd':
-            connection.privmsg(replyto, '%sStatistics: %s' % (font.grey, CH.ccc(self, "stat")[:-2] + ".")) #CH.ccc(self, "seen") + CH.ccc(self, "joins") + CH.ccc(self, "kicks") + CH.ccc(self, "messages") + CH.ccc(self, "actions") + CH.ccc(self, "notices")[:-2] + "."))
+            connection.privmsg(replyto, '%sStatistics: %s' % (font.grey, CH.ccc(self, "stat")[:-2])) #CH.ccc(self, "seen") + CH.ccc(self, "joins") + CH.ccc(self, "kicks") + CH.ccc(self, "messages") + CH.ccc(self, "actions") + CH.ccc(self, "notices")[:-2] + "."))
 
 
     elif one == 'stat' or one == 'stats' or one == 'statistic' or one == 'statistics':

+ 40 - 13
rotbot/common/queries.py

@@ -1,4 +1,4 @@
-import random, secrets, datetime, uuid
+import random, secrets, datetime, uuid, random
 from slugify import slugify
 from common import log
 
@@ -119,17 +119,19 @@ def create_or_get_and_update_last_event(self, table, event_type, channel_name=No
 def get_owners(self):
     return self.db.all('SELECT * FROM rotbot_owner')
 
+
+# Channel
 def get_channel_id(self, channel_name):
     return self.db.one('SELECT id FROM rotbot_channel WHERE network_id=%(network_id)s AND LOWER(name)=LOWER(%(channel_name)s)', network_id=self.network.id, channel_name=channel_name)
 
 def get_channel_slug(self, channel_name):
     return self.db.one('SELECT slug FROM rotbot_channel WHERE network_id=%(network_id)s AND LOWER(name)=LOWER(%(channel_name)s)', network_id=self.network.id, channel_name=channel_name)
 
-def get_channel_setting_statistic_commands(self, channel_name):
-    return self.db.one('SELECT statistic_commands FROM rotbot_channel WHERE LOWER(name)=LOWER(%(channel_name)s) AND network_id=%(network_id)s', channel_name=channel_name, network_id=self.network.id)
+def get_channel_setting_statistic_commands(self, channel_id):
+    return self.db.one('SELECT statistic_commands FROM rotbot_channel WHERE id=%(channel_id)s', channel_id=channel_id)
 
-def get_channel_setting_game_commands(self, channel_name):
-    return self.db.one('SELECT games FROM rotbot_channel WHERE name=LWOER(%(channel_name)s) AND network_id=%(network_id)', channel_name=channel_name, network_id=self.network.id)
+def get_channel_setting_game_commands(self, channel_id):
+    return self.db.one('SELECT games FROM rotbot_channel WHERE id=%(channel_id)s', channel_id=channel_id)
 
 def get_autojoin_channels(self):
     return self.db.all('SELECT name FROM rotbot_channel WHERE network_id=%(network_id)s AND autojoin=True', network_id=self.network.id)
@@ -142,6 +144,8 @@ def create_tempchannelkey(self, channel_id):
     self.db.run('INSERT INTO rotbot_tempchannelkey (key, network_id, channel_id, created) VALUES (%(key)s, %(network_id)s, %(channel_id)s, %(created)s)', key=temp_key, network_id=self.network.id, channel_id=channel_id, created=datetime.datetime.now())
     return temp_key
 
+
+# Statistics
 def update_message_statistics(self, type, channel, user):
     if not self.db.one('SELECT id FROM rotbot_' + type + ' WHERE network_id=%(network_id)s AND channel_id=%(channel_id)s AND user_id=%(user_id)s', network_id=self.network.id, channel_id=channel.id ,user_id=user.id):  # Not on record.
         self.db.run('INSERT INTO rotbot_' + type + ' (network_id, channel_id, user_id, amount) VALUES (%(network_id)s, %(channel_id)s, %(user_id)s, 1)', network_id=self.network.id, channel_id=channel.id ,user_id=user.id)   # Create record.
@@ -154,16 +158,14 @@ def increment_join(self, channel, user):
     else:
         self.db.run('UPDATE rotbot_join SET amount = amount + 1 WHERE network_id=%(network_id)s AND channel_id=%(channel_id)s AND user_id=%(user_id)s', network_id=self.network.id, channel_id=channel.id, user_id=user.id)   # Update existing record.
 
-def get_top_users(self, sort):
-    return self.db.all('SELECT id, name, level, xp_spent, coin FROM rotbot_user WHERE network_id=%(network_id)s ORDER BY ' + sort + ' DESC LIMIT 3 ', network_id=self.network.id)
-
-def levelup_user(self, user, xp):
-    self.db.run('UPDATE rotbot_user SET level=level+1, xp_spent=xp_spent+%(xp)s, ap_spent=ap_spent+1 WHERE id=%(user_id)s', xp=xp, user_id=user.id)
-    self.db.run('UPDATE rotbot_user SET coin=coin+0.3 WHERE level>0 AND user_id=%(user_id)s', (self.user.id))
+def increment_kick(self, channel, user):
+    if not self.db.one('SELECT id FROM rotbot_kick WHERE channel_id=%(channel_id)s AND kicker_id=%(kicker_id)s AND kicked_id=%(kicked_id)s', network_id=self.network.id, channel_id=channel.id, kicker_id=kicker.id, kicked_id=kicked.id): # No records for kicker channel combination.
+        self.db.run('INSERT INTO rotbot_kick (channel_id, kicker_id, kicked_id, amount) VALUES (%(channel_id)s, %(kicker_id)s, %(kicked_id)s), 1', channel_id=channel.id, kicker_id=kicker.id, kicked_id=kicked.id)  # Create record.
+    else:
+        self.db.run('UPDATE rotbot_kick SET amount = amount + 1 WHERE channel_id=%(channel_id)s AND kicker_id=%(kicker_id)s AND kicked_id=%(kicked_id)s', channel_id=channel.id, kicker_id=kicker.id, kicked_id=kicked.id) # Update record.
 
-def get_user_gamestats(self, user):
-    return self.db.one('SELECT xp_spent, level, coin, coin_given, coin_spent, ap_spent, karma_correction FROM rotbot_user WHERE id=%(id)s', id=user.id)
 
+# User
 def get_user(self, user_name):
     return self.db.one('SELECT * FROM rotbot_user WHERE network_id=%(network_id)s AND LOWER(name)=LOWER(%(user_name)s)', network_id=self.network.id, user_name=user_name)
 
@@ -221,6 +223,31 @@ def add_curseword(self, word, user_id):
     return self.db.run('INSERT INTO rotbot_curseword (word, created, irc_user_id, banned) VALUES (LOWER(%(word)s), %(created)s, %(irc_user_id)s, %(banned)s)', word=word, created=datetime.datetime.now, irc_user_id=user_id, banned=False)
 
 
+# Game
+def get_top_users(self, sort):
+    return self.db.all('SELECT id, name, level, xp_spent, coin FROM rotbot_user WHERE network_id=%(network_id)s ORDER BY ' + sort + ' DESC LIMIT 3 ', network_id=self.network.id)
+
+def get_user_gamestats(self, user):
+    return self.db.one('SELECT xp_spent, level, coin, coin_given, coin_spent, ap_spent, karma_correction FROM rotbot_user WHERE id=%(id)s', id=user.id)
+
+def levelup_user(self, user, xp):
+    self.db.run('UPDATE rotbot_user SET level=level+1, xp_spent=xp_spent+%(xp)s, ap_spent=ap_spent+1 WHERE id=%(user_id)s', xp=xp, user_id=user.id)
+    coin = random.uniform(0.1, 0.5)
+    payday(self, coin)
+    return
+
+def punish_user(self, user, coin, karma):
+    self.db.run('UPDATE website_users SET coin=coin-$(coin)s, karma_correction=karma_correction-%(karma)s WHERE id=%(user_id)s', coin=coin, karma=karma, user_id=user.id)
+    return
+
+def payday(self, coin):
+    self.db.run('UPDATE rotbot_user SET coin=coin+%(coin)s WHERE level>0', user_id=user.id)
+    return
+
+def cointransfer(self, sender, receiver, coin):
+    self.db.run('UPDATE rotbot_user SET coin=coin-%(coin)s, coin_spent=coin_spent+%(coin)s, coin_given=coin_given+%(coin)s, ap_spent=ap_spent+1 WHERE id=%(sender_id)s', coin=coin, sender_id=sender.id)
+    self.db.run("UPDATE rotbot_user SET coin=coin+%(coin)s WHERE id=%(user_id)s", coin=coin, id=receiver.id)
+
 # Common.
 
 def total_amount_in_recordset(recordset):

+ 1 - 1
website/rotbot/forms.py

@@ -65,7 +65,7 @@ class ChannelForm(ModelForm):
         labels={
             'autojoin': '<i class="power icon"></i>Auto join',
             'statistic_commands': '<i class="chart pie icon"></i>Statistic commands',
-            'chat': '<i class="gamepad icon"></i>Games',
+            'chat': '<i class="comment dots icon"></i>Chat',
             'games': '<i class="gamepad icon"></i>Games',
         }
         widgets={