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):
|
def getTwo(message):
|
||||||
try:
|
try:
|
||||||
|
@ -161,10 +161,39 @@ def explicitTweet(bot, update, args, reply = None):
|
||||||
def reply(bot, update, args):
|
def reply(bot, update, args):
|
||||||
try:
|
try:
|
||||||
reply = bottools.methods.getTweetID(args[0], update.message.chat_id)
|
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:
|
except:
|
||||||
update.message.reply_text(bottools.strings.cantfind % args[0])
|
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):
|
def retweet(bot, update, args):
|
||||||
for tweet in args:
|
for tweet in args:
|
||||||
|
@ -276,13 +305,19 @@ def restart(bot, update):
|
||||||
def broadcast(bot, update, args):
|
def broadcast(bot, update, args):
|
||||||
if bottools.methods.isadmin(update.message):
|
if bottools.methods.isadmin(update.message):
|
||||||
for u in dbtools.dbHelper().broadcastUsers():
|
for u in dbtools.dbHelper().broadcastUsers():
|
||||||
bot.sendMessage(chat_id = u, text = ' '.join(args))
|
try:
|
||||||
|
bot.sendMessage(chat_id = u, text = ' '.join(args))
|
||||||
|
except:
|
||||||
|
logging.exception("Could not send broadcast.")
|
||||||
else:
|
else:
|
||||||
bottools.methods.unknown(bot, update)
|
bottools.methods.unknown(bot, update)
|
||||||
|
|
||||||
def emergency(bot, update, args):
|
def emergency(bot, update, args):
|
||||||
if bottools.methods.isadmin(update.message):
|
if bottools.methods.isadmin(update.message):
|
||||||
for u in dbtools.dbHelper().allUsers():
|
for u in dbtools.dbHelper().allUsers():
|
||||||
bot.sendMessage(chat_id = u, text = ' '.join(args))
|
try:
|
||||||
|
bot.sendMessage(chat_id = u, text = ' '.join(args))
|
||||||
|
except:
|
||||||
|
logging.exception("Could not send emergency broadcast.")
|
||||||
else:
|
else:
|
||||||
bottools.methods.unknown(bot, update)
|
bottools.methods.unknown(bot, update)
|
||||||
|
|
|
@ -177,6 +177,11 @@ class dbObject:
|
||||||
for u in self.getAll():
|
for u in self.getAll():
|
||||||
yield u[0]
|
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):
|
def allUsers(self):
|
||||||
self.executeQuery("SELECT cid FROM tokens;")
|
self.executeQuery("SELECT cid FROM tokens;")
|
||||||
for u in self.getAll():
|
for u in self.getAll():
|
||||||
|
|
|
@ -56,10 +56,13 @@ def getNameByID(uid, section = setuptools.TWITTER):
|
||||||
return twoHelper(section).api.get_user(uid).screen_name
|
return twoHelper(section).api.get_user(uid).screen_name
|
||||||
|
|
||||||
def getNamesByIDs(fids=getFollowerIDs(), section = setuptools.TWITTER):
|
def getNamesByIDs(fids=getFollowerIDs(), section = setuptools.TWITTER):
|
||||||
for page in setuptools.paginate(fids, 100):
|
for page in setuptools.paginate(fids, 100):
|
||||||
followers = twoHelper(section).api.lookup_users(user_ids=page)
|
followers = twoHelper(section).api.lookup_users(user_ids=page)
|
||||||
for follower in followers:
|
for follower in followers:
|
||||||
yield {"id": follower.id, "name": follower.screen_name}
|
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):
|
def twoHelper(section = setuptools.TWITTER):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue