Add quote function
This commit is contained in:
parent
acfb985d87
commit
97958f2497
|
@ -36,10 +36,14 @@ def twoExceptions(e, message):
|
||||||
def callback(bot, update):
|
def callback(bot, update):
|
||||||
args = update.callback_query.data.split()
|
args = update.callback_query.data.split()
|
||||||
|
|
||||||
if args[0] == "/like":
|
try:
|
||||||
bottools.methods.like(bot, update, args[1:])
|
feature = commands[args[0][1:]]
|
||||||
elif args[0] == "/retweet":
|
try:
|
||||||
bottools.methods.retweet(bot, update, args[1:])
|
feature(bot, update, args[1:])
|
||||||
|
except:
|
||||||
|
feature(bot, update)
|
||||||
|
except:
|
||||||
|
update.callback_query.reply_text(bottools.strings.unknownCommand)
|
||||||
|
|
||||||
def mentionHelper(bot, update):
|
def mentionHelper(bot, update):
|
||||||
args = update.message.text.split()
|
args = update.message.text.split()
|
||||||
|
@ -49,9 +53,11 @@ def mentionHelper(bot, update):
|
||||||
try:
|
try:
|
||||||
feature(bot, update, args[2:])
|
feature(bot, update, args[2:])
|
||||||
except:
|
except:
|
||||||
|
print(e)
|
||||||
feature(bot, update)
|
feature(bot, update)
|
||||||
except:
|
except Exception as e:
|
||||||
update.message.reply_text(bottools.strings.unknown)
|
logging.exception(e)
|
||||||
|
update.message.reply_text(bottools.strings.unknownCommand)
|
||||||
|
|
||||||
# Actual methods:
|
# Actual methods:
|
||||||
# ---------------
|
# ---------------
|
||||||
|
@ -222,6 +228,20 @@ def reply(bot, update, args):
|
||||||
|
|
||||||
bottools.methods.explicitTweet(bot, update, pargs, reply)
|
bottools.methods.explicitTweet(bot, update, pargs, reply)
|
||||||
|
|
||||||
|
def quote(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
|
||||||
|
|
||||||
|
args += ["https://twitter.com/%s/status/%i" % (sender, int(reply))]
|
||||||
|
except:
|
||||||
|
update.message.reply_text(bottools.strings.cantfind % args[0])
|
||||||
|
raise
|
||||||
|
|
||||||
|
bottools.methods.explicitTweet(bot, update, args)
|
||||||
|
|
||||||
def retweet(bot, update, args):
|
def retweet(bot, update, args):
|
||||||
message = update.message or update.callback_query.message
|
message = update.message or update.callback_query.message
|
||||||
for tweet in args:
|
for tweet in args:
|
||||||
|
@ -253,27 +273,28 @@ def tweet(bot, update):
|
||||||
|
|
||||||
# Timelines
|
# Timelines
|
||||||
|
|
||||||
def tweetMessage(status, message):
|
def tweetMessage(status, cid, bot):
|
||||||
db = dbtools.dbHelper()
|
db = dbtools.dbHelper()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
db.executeQuery("SELECT MAX(nr) FROM timelines WHERE cid = %i;" % int(message.chat_id))
|
db.executeQuery("SELECT MAX(nr) FROM timelines WHERE cid = %i;" % int(cid))
|
||||||
i = int(db.getNext()[0]) + 1
|
i = int(db.getNext()[0]) + 1
|
||||||
except:
|
except:
|
||||||
i = 1
|
i = 1
|
||||||
|
|
||||||
db.executeQuery("INSERT INTO timelines VALUES(%i, %i, %i);" % (message.chat_id, i, status.id))
|
db.executeQuery("INSERT INTO timelines VALUES(%i, %i, %i);" % (cid, i, status.id))
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
buttons = [
|
buttons = [
|
||||||
telegram.InlineKeyboardButton("Like", callback_data = "/like %i" % i),
|
telegram.InlineKeyboardButton("Like", callback_data = "/like %i" % i),
|
||||||
telegram.InlineKeyboardButton("Retweet", callback_data = "/retweet %i" % i),
|
telegram.InlineKeyboardButton("Retweet", callback_data = "/retweet %i" % i),
|
||||||
telegram.InlineKeyboardButton("Reply", switch_inline_query_current_chat = "/reply %i " % i)
|
telegram.InlineKeyboardButton("Reply", switch_inline_query_current_chat = "/reply %i " % i),
|
||||||
|
telegram.InlineKeyboardButton("Quote",switch_inline_query_current_chat = "/quote %i " % i)
|
||||||
]
|
]
|
||||||
|
|
||||||
rmu = telegram.InlineKeyboardMarkup(makeMenu(buttons))
|
rmu = telegram.InlineKeyboardMarkup(makeMenu(buttons))
|
||||||
|
|
||||||
message.reply_text("Tweet %i:\n%s (@%s) at %s:\n%s" % (i, status.author.name, status.author.screen_name, status.created_at, html.unescape(status.text)), reply_markup=rmu)
|
bot.sendMessage(chat_id = cid, text = "Tweet %i:\n%s (@%s) at %s:\n%s" % (i, status.author.name, status.author.screen_name, status.created_at, html.unescape(status.text)), reply_markup=rmu)
|
||||||
|
|
||||||
|
|
||||||
def timeline(bot, update, args = [10]):
|
def timeline(bot, update, args = [10]):
|
||||||
|
@ -291,7 +312,7 @@ def timeline(bot, update, args = [10]):
|
||||||
two = bottools.methods.getTwo(update.message)
|
two = bottools.methods.getTwo(update.message)
|
||||||
|
|
||||||
for status in two.api.home_timeline(count=count):
|
for status in two.api.home_timeline(count=count):
|
||||||
tweetMessage(status, update.message)
|
tweetMessage(status, update.message.chat_id, bot)
|
||||||
|
|
||||||
except tweepy.error.TweepError as e:
|
except tweepy.error.TweepError as e:
|
||||||
bottools.methods.twoExceptions(e, update.message)
|
bottools.methods.twoExceptions(e, update.message)
|
||||||
|
@ -384,6 +405,7 @@ commands = {
|
||||||
"login": auth,
|
"login": auth,
|
||||||
"logout": unauth,
|
"logout": unauth,
|
||||||
"mentionstream": mentionstream,
|
"mentionstream": mentionstream,
|
||||||
|
"quote": quote,
|
||||||
"reply": reply,
|
"reply": reply,
|
||||||
"restart": restart,
|
"restart": restart,
|
||||||
"retweet": retweet,
|
"retweet": retweet,
|
||||||
|
@ -402,6 +424,7 @@ pargs = [
|
||||||
emergency,
|
emergency,
|
||||||
follow,
|
follow,
|
||||||
like,
|
like,
|
||||||
|
quote,
|
||||||
reply,
|
reply,
|
||||||
retweet,
|
retweet,
|
||||||
timeline,
|
timeline,
|
||||||
|
|
|
@ -33,7 +33,8 @@ Additionally, you will be able to use the following commands:
|
||||||
|
|
||||||
*Tweet functions*
|
*Tweet functions*
|
||||||
* /like TWEET - Like a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline.
|
* /like TWEET - Like a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline.
|
||||||
* /reply TWEET TEXT - Reply TEXT to a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline.
|
* /quote TWEET - Quote a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline.
|
||||||
|
* /reply TWEET TEXT - Reply TEXT to a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline. If you do not include any mentions, I will take care of this for you.
|
||||||
* /retweet TWEET - Retweet a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline.
|
* /retweet TWEET - Retweet a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline.
|
||||||
* /togglementions - Turn on/off notifications when you are mentioned in a tweet.
|
* /togglementions - Turn on/off notifications when you are mentioned in a tweet.
|
||||||
* /toggletweet - Turn automatic tweeting of messages on/off. Useful in groups.
|
* /toggletweet - Turn automatic tweeting of messages on/off. Useful in groups.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import dbtools, html, tweepy
|
import bottools.methods, dbtools, html, tweepy
|
||||||
|
|
||||||
class BotStreamListener(tweepy.StreamListener):
|
class BotStreamListener(tweepy.StreamListener):
|
||||||
def __init__(self, bot, cid, *args, **kwargs):
|
def __init__(self, bot, cid, *args, **kwargs):
|
||||||
|
@ -7,17 +7,7 @@ class BotStreamListener(tweepy.StreamListener):
|
||||||
self.cid = cid
|
self.cid = cid
|
||||||
|
|
||||||
def on_status(self, status):
|
def on_status(self, status):
|
||||||
db = dbtools.dbHelper()
|
bottools.methods.tweetMessage(status, self.cid, self.bot)
|
||||||
try:
|
|
||||||
db.executeQuery("SELECT MAX(nr) FROM timelines WHERE cid = %i;" % self.cid)
|
|
||||||
i = int(db.getNext()[0]) + 1
|
|
||||||
except:
|
|
||||||
i = 1
|
|
||||||
|
|
||||||
db.executeQuery("INSERT INTO timelines VALUES(%i, %i, %i);" % (self.cid, i, status.id))
|
|
||||||
db.commit()
|
|
||||||
|
|
||||||
self.bot.sendMessage(chat_id=self.cid, text="Tweet %i:\n%s (@%s) at %s:\n%s" % (i, status.author.name, status.author.screen_name, status.created_at, html.unescape(status.text)))
|
|
||||||
|
|
||||||
def on_error(self, status):
|
def on_error(self, status):
|
||||||
if status == 420:
|
if status == 420:
|
||||||
|
|
Loading…
Reference in a new issue