tBKwtWS 6 anos atrás
pai
commit
212c1413c3
3 arquivos alterados com 29 adições e 33 exclusões
  1. 1 1
      rotbot/commands/games.py
  2. 27 28
      rotbot/common/queries.py
  3. 1 4
      rotbot/events/on_kick.py

+ 1 - 1
rotbot/commands/games.py

@@ -185,7 +185,7 @@ def do_command(self, connection, event, user, channel):
 
     elif command.split()[0] == "level":
         if cmdtype == "help":    #Display help text.
-            connection.privmsg(replyto, "For 10 XP you can use !levelup to gain a level. As your level increases, things become more difficult, while more capabilities and options are unlocked.")
+            connection.privmsg(replyto, "For increasing amounts of XP you can use !levelup to gain a level. As your level increases, things become more difficult, while more capabilities and options are attained.")
     elif command.split()[0] == "xp":
         if cmdtype == "help":    #Display help text.
             connection.privmsg(replyto, "XP is earned by using IRC and playing the game, in channels with " + font.red + connection.get_nickname() + font.reset + ". Ask any operator in " + font.red + self.network.home_channel + font.reset + " to add a channel. XP is used to level up, advance classes, as a limit and as a multiplier. Once XP is expended it keeps counting towards your total.")

+ 27 - 28
rotbot/common/queries.py

@@ -37,17 +37,17 @@ def create_or_get_and_update_last_event(self, table, event_type, channel_name=No
 
     else:   # Not on record.
         new_slug = slugify('%s-%s' % (name, self.network.name), max_length=50) # Create a slug from the name.
-        slug_exists = self.db.one('SELECT id FROM rotbot_' + table + ' WHERE slug=%(slug)s AND network_id=%(network_id)s', slug=new_slug, network_id=self.network.id)   # Try to lookup a record with the proposed slug.
+        slug_exists = self.db.one('SELECT id FROM rotbot_' + table + ' WHERE slug=%(slug)s', slug=new_slug)   # Try to lookup a record with the proposed slug.
 
         # Keep adding random letters from the name to the slug until it is unique.
         while slug_exists and slug_exists <= 50:
             new_slug = new_slug + random.choice(name)
-            slug_exists = self.db.one('SELECT id FROM rotbot_' + table + ' WHERE slug=%(slug)s AND network_id=%(network_id)s', slug=new_slug, network_id=self.network.id)
+            slug_exists = self.db.one('SELECT id FROM rotbot_' + table + ' WHERE slug=%(slug)s', slug=new_slug)
             log.notice('Requested slug already taken on table %s with network %s: %s' % (table, self.network.name, new_slug))
         while slug_exists:
             new_slug = name + str(uuid.uuid4())
-            slug_exists = self.db.one('SELECT id FROM rotbot_' + table + ' WHERE slug=%(slug)s AND network_id=%(network_id)s', slug=new_slug, network_id=self.network.id)
-            log.warn('Please clean database. Newly generated uuid4 already taken on table %s with network %s: %s' % (table, self.network.name, new_slug))
+            slug_exists = self.db.one('SELECT id FROM rotbot_' + table + ' WHERE slug=%(slug)s', slug=new_slug)
+            log.warning('Please clean database. Newly generated uuid4 already taken on table %s with network %s: %s' % (table, self.network.name, new_slug))
 
         fields = 'name, network_id, slug, last_event_type, last_event_datetime'
         values = '%(name)s, %(network_id)s, %(slug)s, %(last_event_type)s, %(last_event_datetime)s'
@@ -145,26 +145,6 @@ def create_tempchannelkey(self, channel_id):
     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.
-    else:   # On record.
-        self.db.run('UPDATE rotbot_' + type + ' 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)  # Increment record.
-
-def increment_join(self, channel, user):
-    if not self.db.one('SELECT id FROM rotbot_join 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):   # No record yet
-        self.db.run('INSERT INTO rotbot_join (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.
-    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 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.
-
-
 # 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)
@@ -223,6 +203,26 @@ 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)
 
 
+# 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.
+    else:   # On record.
+        self.db.run('UPDATE rotbot_' + type + ' 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)  # Increment record.
+
+def increment_join(self, channel_id, user_id):
+    if not self.db.one('SELECT id FROM rotbot_join 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):   # No record yet
+        self.db.run('INSERT INTO rotbot_join (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.
+    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 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.
+
+
 # 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)
@@ -234,19 +234,18 @@ 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
+    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)
 
 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)
+    coin = random.uniform(0.1, 0.5)
+    payday(self, coin)
 
 # Common.
 

+ 1 - 4
rotbot/events/on_kick.py

@@ -12,10 +12,7 @@ def process_event(self, connection, event):
     kicked = queries.create_or_get_and_update_last_event(self, 'user','ck', channel_name=event.target, user_name=event.arguments[0], event_content=reason, event_subject_name=event.source.nick)
 
     # Record kick event in database.
-    if not self.db.one('SELECT id FROM rotbot_kick WHERE network_id=$(network_id)s AND 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 (network_id, channel_id, kicker_id, kicked_id, amount) VALUES (%(network_id)s, %(channel_id)s, %(kicker_id)s, %(kicked_id)s), 1', network_id=self.network.id, 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 network_id=$(network_id)s AND 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) # Update record.
+    queries.increment_join(self, channel.id, user.id)
 
     # # Update protectees if needed.
     # if channel == self.homechannel: # Kicked from home channel