tBKwtWS 6 vuotta sitten
vanhempi
sitoutus
e0c896bc36
3 muutettua tiedostoa jossa 14 lisäystä ja 11 poistoa
  1. 2 0
      rotbot/common/queries.py
  2. 9 10
      rotbot/events/on_join.py
  3. 3 1
      rotbot/events/on_pubmsg.py

+ 2 - 0
rotbot/common/queries.py

@@ -259,8 +259,10 @@ def random_curse(self):
     # Try to hint the user of my capabilities.
     if not adjective:
         log.notice('No adjectives in the database, please add some for more colourfull language.')
+        return
     if not curse:
         log.notice('No curses in the database, please add some for more colourfull language.')
+        return
 
     return '%s %s' % (adjective, curse)
 

+ 9 - 10
rotbot/events/on_join.py

@@ -1,4 +1,4 @@
-import datetime
+import datetime, pytz
 from common import log, queries, font, userstatus
 
 def process_event(self, connection, event):
@@ -10,7 +10,6 @@ def process_event(self, connection, event):
     queries.increment_join(self, channel.id, user.id)
 
     if event.source.nick == connection.get_nickname():  # The bot joined a channel.
-        log.info('Joined %s' % event.target)
         if self.channels[event.target].has_key():   # Passworded channel.
             if event.target in self.channelkeys:    # New key used to join channel.
                 log.info('Saving channel key for %s.' %s)
@@ -24,15 +23,19 @@ def process_event(self, connection, event):
     user_lastgreet = queries.get_user_last_greet(self, user.id)
     greet = False
     amount_greet = False
+    cet = pytz.timezone('Europe/Amsterdam')
+
     if not chan_lastgreet:
-        chan_lastgreet = datetime.datetime.now() - datetime.timedelta(minutes=timeout+1)
+        chan_lastgreet = cet.localize(datetime.datetime.now()) - datetime.timedelta(minutes=timeout+1)
     if not user_lastgreet:
-        user_lastgreet = datetime.datetime.now() - datetime.timedelta(minutes=timeout+1)
-    if chan_lastgreet < datetime.datetime.now() - datetime.timedelta(minutes=timeout) and user_lastgreet < datetime.datetime.now() - datetime.timedelta(minutes=timeout):    # User or channel have not had greet message in the last timeout minutes, there is a curse available
+        user_lastgreet = cet.localize(datetime.datetime.now()) - datetime.timedelta(minutes=timeout+1)
+    if chan_lastgreet < cet.localize(datetime.datetime.now()) - datetime.timedelta(minutes=timeout) and user_lastgreet < cet.localize(datetime.datetime.now()) - datetime.timedelta(minutes=timeout):    # User or channel have not had greet message in the last timeout minutes, there is a curse available
         if joins % 200 == 0:    # Has joined 200, or a multiple of 200 times. (Also 0 but the join has already been saved.)
             amount_greet = True
         elif userstatus.atleast_voiced(self, event.source.nick, self.network.home_channel):  # User has atleast voice in home channel.
-            greet = True
+            curse = queries.random_curse(self)
+            if curse:
+                greet = True
 
     # Promotion conditions.
     promote = False
@@ -48,10 +51,6 @@ def process_event(self, connection, event):
         connection.mode(event.target, "+aohv %s %s %s %s" % (event.source.nick, event.source.nick, event.source.nick, event.source.nick))
 
     # Greet.
-    if greet or amount_greet:
-        curse = queries.random_curse(self)
-        if not curse:
-            return
     if amount_greet:
         log.info('Greeting %s in %s' % (event.source.nick, event.target))
         adjective = queries.random_adjective(self)

+ 3 - 1
rotbot/events/on_pubmsg.py

@@ -1,3 +1,4 @@
+import datetime, pytz
 import commands.public, commands.admin, commands.games, commands.statistics
 from common import log, queries
 
@@ -31,7 +32,8 @@ def process_event(self, connection, event):
         timeout = 10    # Timeout in minutes.
         chan_lastlame = queries.get_channel_last_lame(self, channel.id)
         user_lastlame = queries.get_user_last_lame(self, user.id)
-        if chan_lastlame and chan_lastlame > datetime.datetime.now() - datetime.timedelta(minutes=timeout) or user_lastlame and user_lastlame > datetime.datetime.now() - datetime.timedelta(minutes=timeout):  # Lamed channel or user recently.
+        cet = pytz.timezone('Europe/Amsterdam')
+        if chan_lastlame and chan_lastlame > cet.localize(datetime.datetime.now()) - datetime.timedelta(minutes=timeout) or user_lastlame and user_lastlame > cet.localize(datetime.datetime.now()) - datetime.timedelta(minutes=timeout):  # Lamed channel or user recently.
             return
 
         # Do not say KKK.