Add function to actually fetch users subscribed to broadcasts, IMPROVE REPLIES!!!
This commit is contained in:
parent
6aba2e4396
commit
dbd7e794d2
|
@ -1,4 +1,4 @@
|
|||
import ast, dbtools, html, io, logging, moviepy.editor, os, PIL.Image, random, setuptools, string, bottools.strings, sys, telegram.ext, telegram, time, twitools, twitools.streaming, urllib.request, tweepy
|
||||
import ast, dbtools, html, io, logging, moviepy.editor, os, PIL.Image, random, re, setuptools, string, bottools.strings, sys, telegram.ext, telegram, time, twitools, twitools.streaming, urllib.request, tweepy
|
||||
|
||||
def getTwo(message):
|
||||
try:
|
||||
|
@ -161,10 +161,39 @@ def explicitTweet(bot, update, args, reply = None):
|
|||
def reply(bot, update, args):
|
||||
try:
|
||||
reply = bottools.methods.getTweetID(args[0], update.message.chat_id)
|
||||
two = bottools.methods.getTwo(update.message)
|
||||
otweet = twitools.getTweet(reply)
|
||||
sender = otweet.user.screen_name
|
||||
|
||||
if not ("@%s" % sender.strip("@")) in [("@%s" % a.strip("@")) for a in args]:
|
||||
mentions = []
|
||||
|
||||
for m in re.split('[^\w@]+', otweet.text):
|
||||
try:
|
||||
if m[0] == "@":
|
||||
mentions += [m]
|
||||
except:
|
||||
pass
|
||||
|
||||
for m in mentions:
|
||||
if m in args + [("@%s" % two.whoami().strip("@"))] + [("@%s" % sender.strip("@"))]:
|
||||
mentions.remove(m)
|
||||
|
||||
else:
|
||||
mentions = []
|
||||
|
||||
if "@%s" % sender.strip("@") != "@%s" % two.whoami().strip("@"):
|
||||
first = ["@%s" % sender.strip("@")]
|
||||
else:
|
||||
first = [""]
|
||||
|
||||
pargs = first + args[1:] + mentions
|
||||
|
||||
except:
|
||||
update.message.reply_text(bottools.strings.cantfind % args[0])
|
||||
raise
|
||||
|
||||
bottools.methods.explicitTweet(bot, update, args[1:], reply)
|
||||
bottools.methods.explicitTweet(bot, update, pargs, reply)
|
||||
|
||||
def retweet(bot, update, args):
|
||||
for tweet in args:
|
||||
|
@ -276,13 +305,19 @@ def restart(bot, update):
|
|||
def broadcast(bot, update, args):
|
||||
if bottools.methods.isadmin(update.message):
|
||||
for u in dbtools.dbHelper().broadcastUsers():
|
||||
try:
|
||||
bot.sendMessage(chat_id = u, text = ' '.join(args))
|
||||
except:
|
||||
logging.exception("Could not send broadcast.")
|
||||
else:
|
||||
bottools.methods.unknown(bot, update)
|
||||
|
||||
def emergency(bot, update, args):
|
||||
if bottools.methods.isadmin(update.message):
|
||||
for u in dbtools.dbHelper().allUsers():
|
||||
try:
|
||||
bot.sendMessage(chat_id = u, text = ' '.join(args))
|
||||
except:
|
||||
logging.exception("Could not send emergency broadcast.")
|
||||
else:
|
||||
bottools.methods.unknown(bot, update)
|
||||
|
|
|
@ -177,6 +177,11 @@ class dbObject:
|
|||
for u in self.getAll():
|
||||
yield u[0]
|
||||
|
||||
def broadcastUsers(self):
|
||||
self.executeQuery("SELECT cid FROM tokens WHERE broadcast;")
|
||||
for u in self.getAll():
|
||||
yield u[0]
|
||||
|
||||
def allUsers(self):
|
||||
self.executeQuery("SELECT cid FROM tokens;")
|
||||
for u in self.getAll():
|
||||
|
|
|
@ -61,6 +61,9 @@ def getNamesByIDs(fids=getFollowerIDs(), section = setuptools.TWITTER):
|
|||
for follower in followers:
|
||||
yield {"id": follower.id, "name": follower.screen_name}
|
||||
|
||||
def getTweet(tid, section = setuptools.TWITTER):
|
||||
return twoHelper(section).api.get_status(tid)
|
||||
|
||||
def twoHelper(section = setuptools.TWITTER):
|
||||
try:
|
||||
return twObject(ato = setuptools.ato(section), ase = setuptools.ase(section))
|
||||
|
|
Loading…
Reference in a new issue