2015-02-01 00:49:03 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import re
|
|
|
|
import widgetUtils
|
|
|
|
import output
|
2015-08-06 13:16:55 -05:00
|
|
|
from wxUI.dialogs import userActions
|
|
|
|
from pubsub import pub
|
2015-02-01 00:49:03 -06:00
|
|
|
from twython import TwythonError
|
2015-08-06 13:16:55 -05:00
|
|
|
from extra import autocompletionUsers
|
2015-02-01 00:49:03 -06:00
|
|
|
|
|
|
|
class userActionsController(object):
|
|
|
|
def __init__(self, buffer, users=[], default="follow"):
|
|
|
|
super(userActionsController, self).__init__()
|
|
|
|
self.buffer = buffer
|
|
|
|
self.session = buffer.session
|
|
|
|
self.dialog = userActions.UserActionsDialog(users, default)
|
2015-08-06 13:16:55 -05:00
|
|
|
widgetUtils.connect_event(self.dialog.autocompletion, widgetUtils.BUTTON_PRESSED, self.autocomplete_users)
|
2015-02-01 00:49:03 -06:00
|
|
|
if self.dialog.get_response() == widgetUtils.OK:
|
|
|
|
self.process_action()
|
|
|
|
|
2015-08-06 13:16:55 -05:00
|
|
|
def autocomplete_users(self, *args, **kwargs):
|
|
|
|
c = autocompletionUsers.completion.autocompletionUsers(self.dialog, self.session.session_id)
|
|
|
|
c.show_menu("dm")
|
|
|
|
|
2015-02-01 00:49:03 -06:00
|
|
|
def process_action(self):
|
|
|
|
action = self.dialog.get_action()
|
|
|
|
user = self.dialog.get_user()
|
|
|
|
if user == "": return
|
|
|
|
getattr(self, action)(user)
|
|
|
|
|
|
|
|
def follow(self, user):
|
|
|
|
try:
|
|
|
|
self.session.twitter.twitter.create_friendship(screen_name=user )
|
|
|
|
except TwythonError as err:
|
|
|
|
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
|
|
|
|
|
|
|
|
def unfollow(self, user):
|
|
|
|
try:
|
|
|
|
id = self.session.twitter.twitter.destroy_friendship(screen_name=user )
|
|
|
|
except TwythonError as err:
|
|
|
|
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
|
|
|
|
|
|
|
|
def mute(self, user):
|
|
|
|
try:
|
|
|
|
id = self.session.twitter.twitter.create_mute(screen_name=user )
|
|
|
|
except TwythonError as err:
|
|
|
|
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
|
|
|
|
|
|
|
|
def unmute(self, user):
|
|
|
|
try:
|
|
|
|
id = self.session.twitter.twitter.destroy_mute(screen_name=user )
|
|
|
|
except TwythonError as err:
|
|
|
|
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
|
|
|
|
|
|
|
|
def report(self, user):
|
|
|
|
try:
|
|
|
|
id = self.session.twitter.twitter.report_spam(screen_name=user )
|
|
|
|
except TwythonError as err:
|
|
|
|
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
|
|
|
|
|
|
|
|
def block(self, user):
|
|
|
|
try:
|
|
|
|
id = self.session.twitter.twitter.create_block(screen_name=user )
|
|
|
|
except TwythonError as err:
|
|
|
|
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
|
|
|
|
|
|
|
|
def unblock(self, user):
|
|
|
|
try:
|
|
|
|
id = self.session.twitter.twitter.destroy_block(screen_name=user )
|
|
|
|
except TwythonError as err:
|
|
|
|
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
|
|
|
|
|
|
|
|
def ignore_client(self, user):
|
|
|
|
tweet = self.buffer.get_right_tweet()
|
|
|
|
if tweet.has_key("sender"):
|
|
|
|
output.speak(_(u"You can't ignore direct messages"))
|
|
|
|
return
|
|
|
|
client = re.sub(r"(?s)<.*?>", "", tweet["source"])
|
|
|
|
if client not in self.session.settings["twitter"]["ignored_clients"]:
|
2017-01-14 06:11:41 -06:00
|
|
|
self.session.settings["twitter"]["ignored_clients"].append(client)
|
|
|
|
self.session.settings.write()
|