mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-29 22:23:12 -06:00
Implemented tweet, reply and direct message in base buffer
This commit is contained in:
parent
2b6efef831
commit
cfc25eb89a
@ -85,41 +85,15 @@ class BaseBuffer(base.Buffer):
|
|||||||
|
|
||||||
def post_status(self, *args, **kwargs):
|
def post_status(self, *args, **kwargs):
|
||||||
item = None
|
item = None
|
||||||
title = _(u"Tweet")
|
title = _("Tweet")
|
||||||
caption = _(u"Write the tweet here")
|
caption = _("Write the tweet here")
|
||||||
tweet = messages.tweet(self.session, title, caption, "")
|
tweet = messages.tweet(self.session, title, caption, "")
|
||||||
if tweet.message.get_response() == widgetUtils.OK:
|
response = tweet.message.ShowModal()
|
||||||
if config.app["app-settings"]["remember_mention_and_longtweet"]:
|
if response == wx.ID_OK:
|
||||||
config.app["app-settings"]["longtweet"] = tweet.message.long_tweet.GetValue()
|
tweet_data = tweet.get_tweet_data()
|
||||||
config.app.write()
|
call_threaded(self.session.send_tweet, *tweet_data)
|
||||||
text = tweet.message.get_text()
|
if hasattr(tweet.message, "destroy"):
|
||||||
if len(text) > 280 and tweet.message.get("long_tweet") == True:
|
tweet.message.destroy()
|
||||||
if not hasattr(tweet, "attachments"):
|
|
||||||
text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text)
|
|
||||||
else:
|
|
||||||
text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text, 1)
|
|
||||||
if not hasattr(tweet, "attachments") or len(tweet.attachments) == 0:
|
|
||||||
item = self.session.api_call(call_name="update_status", status=text, _sound="tweet_send.ogg", tweet_mode="extended")
|
|
||||||
else:
|
|
||||||
call_threaded(self.post_with_media, text=text, attachments=tweet.attachments)
|
|
||||||
# We will no longer will reuse the sent item from here as Streaming API should give us the new and correct item.
|
|
||||||
# but in case we'd need it, just uncomment the following couple of lines and make sure we reduce the item correctly.
|
|
||||||
# if item != None:
|
|
||||||
# pub.sendMessage("sent-tweet", data=item, user=self.session.db["user_name"])
|
|
||||||
if hasattr(tweet.message, "destroy"): tweet.message.destroy()
|
|
||||||
self.session.settings.write()
|
|
||||||
|
|
||||||
def post_with_media(self, text, attachments):
|
|
||||||
media_ids = []
|
|
||||||
for i in attachments:
|
|
||||||
img = self.session.twitter.media_upload(i["file"])
|
|
||||||
self.session.twitter.create_media_metadata(media_id=img.media_id, alt_text=i["description"])
|
|
||||||
media_ids.append(img.media_id)
|
|
||||||
item = self.session.twitter.update_status(status=text, media_ids=media_ids)
|
|
||||||
# We will no longer will reuse the sent item from here as Streaming API should give us the new and correct item.
|
|
||||||
# but in case we'd need it, just uncomment the following couple of lines and make sure we reduce the item correctly.
|
|
||||||
# if item != None:
|
|
||||||
# pub.sendMessage("sent-tweet", data=item, user=self.session.db["user_name"])
|
|
||||||
|
|
||||||
def get_formatted_message(self):
|
def get_formatted_message(self):
|
||||||
if self.type == "dm" or self.name == "direct_messages":
|
if self.type == "dm" or self.name == "direct_messages":
|
||||||
@ -422,7 +396,6 @@ class BaseBuffer(base.Buffer):
|
|||||||
user = self.session.get_user(tweet.user)
|
user = self.session.get_user(tweet.user)
|
||||||
screen_name = user.screen_name
|
screen_name = user.screen_name
|
||||||
id = tweet.id
|
id = tweet.id
|
||||||
twishort_enabled = hasattr(tweet, "twishort")
|
|
||||||
users = utils.get_all_mentioned(tweet, self.session.db, field="screen_name")
|
users = utils.get_all_mentioned(tweet, self.session.db, field="screen_name")
|
||||||
ids = utils.get_all_mentioned(tweet, self.session.db, field="id")
|
ids = utils.get_all_mentioned(tweet, self.session.db, field="id")
|
||||||
# Build the window title
|
# Build the window title
|
||||||
@ -430,38 +403,14 @@ class BaseBuffer(base.Buffer):
|
|||||||
title=_("Reply to {arg0}").format(arg0=screen_name)
|
title=_("Reply to {arg0}").format(arg0=screen_name)
|
||||||
else:
|
else:
|
||||||
title=_("Reply")
|
title=_("Reply")
|
||||||
message = messages.reply(self.session, title, _(u"Reply to %s") % (screen_name,), "", users=users, ids=ids)
|
message = messages.reply(self.session, title, _("Reply to %s") % (screen_name,), "", users=users, ids=ids)
|
||||||
if message.message.get_response() == widgetUtils.OK:
|
if message.message.ShowModal() == widgetUtils.OK:
|
||||||
if config.app["app-settings"]["remember_mention_and_longtweet"]:
|
if config.app["app-settings"]["remember_mention_and_longtweet"]:
|
||||||
config.app["app-settings"]["longtweet"] = message.message.long_tweet.GetValue()
|
|
||||||
if len(users) > 0:
|
if len(users) > 0:
|
||||||
config.app["app-settings"]["mention_all"] = message.message.mentionAll.GetValue()
|
config.app["app-settings"]["mention_all"] = message.message.mention_all.GetValue()
|
||||||
config.app.write()
|
config.app.write()
|
||||||
params = {"_sound": "reply_send.ogg", "in_reply_to_status_id": id, "tweet_mode": "extended"}
|
tweet_data = dict(text=message.message.text.GetValue(), attachments=message.attachments)
|
||||||
text = message.message.get_text()
|
call_threaded(self.session.reply, in_reply_to_status_id=id, text=message.message.text.GetValue(), attachments=message.attachments, exclude_reply_user_ids=message.get_ids(), auto_populate_reply_metadata=True)
|
||||||
if twishort_enabled == False:
|
|
||||||
excluded_ids = message.get_ids()
|
|
||||||
params["exclude_reply_user_ids"] =excluded_ids
|
|
||||||
params["auto_populate_reply_metadata"] =True
|
|
||||||
else:
|
|
||||||
mentioned_people = message.get_people()
|
|
||||||
text = "@"+screen_name+" "+mentioned_people+u" "+text
|
|
||||||
if len(text) > 280 and message.message.get("long_tweet") == True:
|
|
||||||
if message.image == None:
|
|
||||||
text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text)
|
|
||||||
else:
|
|
||||||
text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text, 1)
|
|
||||||
params["status"] = text
|
|
||||||
if message.image == None:
|
|
||||||
params["call_name"] = "update_status"
|
|
||||||
else:
|
|
||||||
params["call_name"] = "update_status_with_media"
|
|
||||||
params["media"] = message.file
|
|
||||||
item = self.session.api_call(**params)
|
|
||||||
# We will no longer will reuse the sent item from here as Streaming API should give us the new and correct item.
|
|
||||||
# but in case we'd need it, just uncomment the following couple of lines and make sure we reduce the item correctly.
|
|
||||||
# if item != None:
|
|
||||||
# pub.sendMessage("sent-tweet", data=item, user=self.session.db["user_name"])
|
|
||||||
if hasattr(message.message, "destroy"): message.message.destroy()
|
if hasattr(message.message, "destroy"): message.message.destroy()
|
||||||
self.session.settings.write()
|
self.session.settings.write()
|
||||||
|
|
||||||
@ -478,11 +427,11 @@ class BaseBuffer(base.Buffer):
|
|||||||
screen_name = self.session.get_user(tweet.user).screen_name
|
screen_name = self.session.get_user(tweet.user).screen_name
|
||||||
users = utils.get_all_users(tweet, self.session)
|
users = utils.get_all_users(tweet, self.session)
|
||||||
dm = messages.dm(self.session, _(u"Direct message to %s") % (screen_name,), _(u"New direct message"), users)
|
dm = messages.dm(self.session, _(u"Direct message to %s") % (screen_name,), _(u"New direct message"), users)
|
||||||
if dm.message.get_response() == widgetUtils.OK:
|
if dm.message.ShowModal() == widgetUtils.OK:
|
||||||
screen_name = dm.message.get("cb")
|
screen_name = dm.message.cb.GetValue()
|
||||||
user = self.session.get_user_by_screen_name(screen_name)
|
user = self.session.get_user_by_screen_name(screen_name)
|
||||||
recipient_id = user
|
recipient_id = user
|
||||||
text = dm.message.get_text()
|
text = dm.message.text.GetValue()
|
||||||
val = self.session.api_call(call_name="send_direct_message", recipient_id=recipient_id, text=text)
|
val = self.session.api_call(call_name="send_direct_message", recipient_id=recipient_id, text=text)
|
||||||
if val != None:
|
if val != None:
|
||||||
sent_dms = self.session.db["sent_direct_messages"]
|
sent_dms = self.session.db["sent_direct_messages"]
|
||||||
|
Loading…
Reference in New Issue
Block a user