From 49cdb48bbaf936eb5c3cdc3572e5686a8f55fbdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Wed, 28 Aug 2019 11:31:52 +0200 Subject: [PATCH] limit /orphan and /stats cmds to protected chats to curb trolling --- delojza.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/delojza.py b/delojza.py index 1a86dbb..5acbe8d 100755 --- a/delojza.py +++ b/delojza.py @@ -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!")