limit /orphan and /stats cmds to protected chats to curb trolling

This commit is contained in:
Tomáš Mládek 2019-08-28 11:31:52 +02:00
parent a5c1b724ab
commit 49cdb48bba

View file

@ -489,6 +489,10 @@ class DelojzaBot:
os.listdir(self.out_dir))))
def tg_stats(self, _, update):
self.db.initialize()
if update.message.chat.id not in self.db.get_protected_chats():
update.message.reply_text((self.markov.make_sentence() + "!") if self.markov and random() > .7 else "nope.")
return
tag_dirs = self._get_tag_dirs()
reply = "Total number of tags: {}\n\n".format(len(tag_dirs))
counts = [(directory, os.listdir(os.path.join(self.out_dir, directory))) for directory in tag_dirs]
@ -527,6 +531,10 @@ class DelojzaBot:
return sorted(result, key=itemgetter(0))
def tg_orphan(self, _, update):
self.db.initialize()
if update.message.chat.id not in self.db.get_protected_chats():
update.message.reply_text((self.markov.make_sentence() + "!") if self.markov and random() > .7 else "nope.")
return
orphans = self._get_orphan_tags()
if len(orphans) == 0:
update.message.reply_text("Good job, no orphan tags!")
@ -535,6 +543,10 @@ class DelojzaBot:
", ".join(map(itemgetter(0), orphans)))
def tg_orphan_full(self, _, update):
self.db.initialize()
if update.message.chat.id not in self.db.get_protected_chats():
update.message.reply_text((self.markov.make_sentence() + "!") if self.markov and random() > .7 else "nope.")
return
orphans = self._get_orphan_tags()
if len(orphans) == 0:
update.message.reply_text("Good job, no orphan tags!")