From 66ae28d58927c0dc0160996cb97eb9ccdb3b4a3a Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Thu, 23 Mar 2017 17:32:06 +0100 Subject: [PATCH] Add broadcast method --- bottools/methods.py | 7 +++++++ dbtools/__init__.py | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/bottools/methods.py b/bottools/methods.py index 19e61d9..9091a6a 100644 --- a/bottools/methods.py +++ b/bottools/methods.py @@ -219,6 +219,7 @@ def timeline(bot, update, args = [10]): db.commit() # Streaming + mentionstreams = {} def makeStream(bot, cid): @@ -264,3 +265,9 @@ def restart(bot, update): else: bottools.methods.unknown(bot, update) +def broadcast(bot, update, args): + if bottools.methods.isadmin(update.message): + for u in dbtools.dbHelper().allUsers(): + bot.sendMessage(chat_id = u, text = ' '.join(args)) + else: + bottools.methods.unknown(bot, update) diff --git a/dbtools/__init__.py b/dbtools/__init__.py index 8663904..bd14899 100644 --- a/dbtools/__init__.py +++ b/dbtools/__init__.py @@ -166,6 +166,11 @@ class dbObject: for u in self.getAll(): yield u[0] + def allUsers(self): + self.executeQuery("SELECT cid FROM tokens;") + for u in self.getAll(): + yield u[0] + def addFish(self, cid): self.executeQuery("UPDATE tokens SET fish = fish + 1 WHERE cid = %i;" % int(cid)) self.commit()