Browse Source

Better custom function for showoffhourbot

Lertsenem 3 years ago
parent
commit
401552ef03
1 changed files with 26 additions and 10 deletions
  1. 26 10
      custom.py

+ 26 - 10
custom.py

@@ -26,28 +26,44 @@ def answer_next_showoffhour_delta(mastodon, context, toot):
26 26
                                         soh3_end.next(default_utc=True),
27 27
                                         soh4_end.next(default_utc=True) ) )
28 28
     
29
-    days                = next_soh_in_seconds // (3600*24)
30
-    next_soh_in_seconds = next_soh_in_seconds %  (3600*24)
31
-    hours               = next_soh_in_seconds // 3600
32
-    next_soh_in_seconds = next_soh_in_seconds %  3600
33
-    minutes             = next_soh_in_seconds // 60
34
-    next_soh_in_seconds = next_soh_in_seconds %  60
29
+    seconds = next_soh_in_seconds
30
+    days    = seconds // (3600*24)
31
+    seconds = seconds %  (3600*24)
32
+    hours   = seconds // 3600
33
+    seconds = seconds %  3600
34
+    minutes = seconds // 60
35
+    seconds = seconds %  60
36
+
37
+    now      = datetime.datetime.now()
38
+    tomorrow = datetime.datetime.combine (    datetime.date.today()      \
39
+                                            + datetime.timedelta(days=1),
40
+                                            datetime.datetime.min.time() )
41
+    seconds_to_tomorrow = (tomorrow - now).total_seconds()
35 42
 
36 43
     status  = "@{} ".format(context["author"])
37 44
     status += "The next #showoffhour is "
38 45
 
39 46
     if next_soh_end_in_seconds < 60:
40 47
         status += "right now! Show the world your hard work!"
48
+
41 49
     else:
42 50
         if   days == 1:
43
-            status += "tomorrow! Be sure to join in. :)"
51
+            if seconds_to_tomorrow > next_soh_end_in_seconds - (24*3600):
52
+                status += "tomorrow! Be sure to join in. :)"
53
+            else:
54
+                status += "the day after tomorrow! Come back later!"
44 55
         elif days == 2:
45
-            status += "the day after tomorrow! Come back later!"
56
+            if seconds_to_tomorrow > next_soh_end_in_seconds - (48*3600):
57
+                status += "the day after tomorrow! Come back later!"
58
+            else:
59
+                status += "in three days! You still have time to get ready"
46 60
         elif days != 0:
47
-            status += "in {} days! You still have time to get ready. :)" \
61
+            status += "in more than {} days! You still have time. :)" \
48 62
                         .format(days)
49 63
         else:
50
-            if   3 < hours:
64
+            if   seconds_to_tomorrow < (hours*3600) + (minutes*60):
65
+                status += "tomorrow! Be sure to join in. :)"
66
+            elif 3 < hours:
51 67
                 status += "in about {} hours. Time to prepare your gifs." \
52 68
                             .format(hours)
53 69
             elif 0 < hours < 3: