diff options
Diffstat (limited to 'cat.py')
| -rw-r--r-- | cat.py | 52 |
1 files changed, 40 insertions, 12 deletions
@@ -71,7 +71,7 @@ class VnilCat: exit() self.intimacy = {} print("[booting] init intimacy") - self.update_intimacy() + self.sync_db_intimacy() # try to fetch the lastest status from the timeline # so that we can skip the ones before we start. @@ -88,8 +88,9 @@ class VnilCat: print(f"[booting] Cat booted, all systems green, my name is {self.config.UNAME}, prepare to die, human") print("-------------") - def update_intimacy(self): - res = self.db.count_interaction() + def sync_db_intimacy(self): + # res = self.db.count_interaction() + res = self.db.get_intimacy() if res != None: self.intimacy = res @@ -104,7 +105,7 @@ class VnilCat: content=random.choice(cat_sounds) + " " + emojis.random_meowcode() self.session.status_reply( to_status=ori_status, status=content) - self.db.insert_event(_type="meow",remarks="",correspond=ori_status["account"]["acct"]) + # self.db.insert_event(_type="meow",remarks="",correspond=ori_status["account"]["acct"]) def post_hn_news(self, amount=3): print("posting news") @@ -125,13 +126,17 @@ class VnilCat: self.session.toot(status) + def meowaction(self, status): + self.session.post_emoji_react_by_id(status['id'], emojis.random_meowcode()) + def catch_birds(self, status, content): if re_contains_bird.search(content) is not None and len(content) < self.config.CATCH_BIRD_MAX_LENGTH: print("i see a bird", status["id"], " from ", status["account"]["acct"]) try: s = self.session.status_reply( to_status=status, status=random.choice(bird_sounds)) - self.db.insert_event(_type="bird",remarks="",correspond=status["account"]["acct"]) + # self.db.insert_event(_type="bird",remarks="",correspond=status["account"]["acct"]) + self.db.update_intimacy(ori_status["account"]["acct"]) return True except: print("fail to post") @@ -141,7 +146,10 @@ class VnilCat: if re_contains_meow.search(content) is not None and len(content) < self.config.CATCH_CAT_MAX_LENGTH: print("i see a cat", status["id"], " from ", status["account"]["acct"]) try: - self.reply_meow(status) + if bool(random.getrandbits(1)): + self.reply_meow(status) + else: + self.meowaction(status) return True except: print("fail to post") @@ -168,13 +176,27 @@ class VnilCat: if self.is_mine(status): print("this one is from myself, skipping") return - acc = status["account"] content = cleanhtml(status["content"]) # only one action is taken. if one succeed then return if self.catch_birds(status,content): return elif self.catch_cats(status,content): return + self.like_a_cat(status) + # do we have enough intimacy? + + def like_a_cat(self,status): + acct = status["account"]["acct"] + if acct not in self.intimacy.keys(): + return + if self.intimacy[acct] > 42 and self.decision(0.2): + try: + self.meowaction(status) + except: + return + + def decision(self, probability): + return random.random() < probability def scantimeline(self): # print("scanning timeline, lastseen=",self.tl_lastseen_sid) @@ -219,7 +241,8 @@ class VnilCat: nid = notification["id"] acct = notification['account']['acct'] print(f"{acct} is petting me! purrr") - self.db.insert_event(_type="fav", remarks="",correspond=acct) + # self.db.insert_event(_type="fav", remarks="",correspond=acct) + self.db.update_intimacy(acct) self.session.notifications_dismiss(nid) def handle_notification(self): @@ -238,11 +261,16 @@ class VnilCat: while True: try: self.handle_notification() - self.scantimeline() - if self.epoch % 360 == 1 : - # happens roughtly every 2 hours + if self.epoch % 2 == 1: + # 2x EPOCH = 40s + self.scantimeline() + if self.epoch % 360 == 1: + # 360x EPOCH = 7200s/2hr + self.sync_db_intimacy() + if self.epoch % 720 == 1 : + # 4hr self.post_hn_news(3) - self.update_intimacy() + except Exception as e: print("something wrong...") print(e) |
