2015-02-01 00:49:03 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-06-06 11:52:23 -05:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
from builtins import object
|
2015-02-01 00:49:03 -06:00
|
|
|
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:
|
2018-08-18 23:09:08 -05:00
|
|
|
self.session.twitter.create_friendship(screen_name=user )
|
2015-02-01 00:49:03 -06:00
|
|
|
except TwythonError as err:
|
|
|
|
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
|
|
|
|
|
|
|
|
def unfollow(self, user):
|
|
|
|
try:
|
2018-08-18 23:09:08 -05:00
|
|
|
id = self.session.twitter.destroy_friendship(screen_name=user )
|
2015-02-01 00:49:03 -06:00
|
|
|
except TwythonError as err:
|
|
|
|
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
|
|
|
|
|
|
|
|
def mute(self, user):
|
|
|
|
try:
|
2018-08-18 23:09:08 -05:00
|
|
|
id = self.session.twitter.create_mute(screen_name=user )
|
2015-02-01 00:49:03 -06:00
|
|
|
except TwythonError as err:
|
|
|
|
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
|
|
|
|
|
|
|
|
def unmute(self, user):
|
|
|
|
try:
|
2018-08-18 23:09:08 -05:00
|
|
|
id = self.session.twitter.destroy_mute(screen_name=user )
|
2015-02-01 00:49:03 -06:00
|
|
|
except TwythonError as err:
|
|
|
|
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
|
|
|
|
|
|
|
|
def report(self, user):
|
|
|
|
try:
|
2018-08-18 23:09:08 -05:00
|
|
|
id = self.session.twitter.report_spam(screen_name=user )
|
2015-02-01 00:49:03 -06:00
|
|
|
except TwythonError as err:
|
|
|
|
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
|
|
|
|
|
|
|
|
def block(self, user):
|
|
|
|
try:
|
2018-08-18 23:09:08 -05:00
|
|
|
id = self.session.twitter.create_block(screen_name=user )
|
2015-02-01 00:49:03 -06:00
|
|
|
except TwythonError as err:
|
|
|
|
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
|
|
|
|
|
|
|
|
def unblock(self, user):
|
|
|
|
try:
|
2018-08-18 23:09:08 -05:00
|
|
|
id = self.session.twitter.destroy_block(screen_name=user )
|
2015-02-01 00:49:03 -06:00
|
|
|
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()
|
2018-11-22 13:35:19 -06:00
|
|
|
if "sender" in tweet:
|
2015-02-01 00:49:03 -06:00
|
|
|
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()
|