Skip to content

Commit

Permalink
remove twitter feed + slack post (#9424)
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc authored Sep 2, 2021
1 parent b4288b8 commit 6542cd0
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 413 deletions.
6 changes: 1 addition & 5 deletions app/dashboard/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
HackathonEvent, UserAction,
)
from dashboard.notifications import (
maybe_market_to_email, maybe_market_to_github, maybe_market_to_slack, maybe_market_to_user_slack,
maybe_market_to_email, maybe_market_to_github,
notify_of_lowball_bounty,
)
from dashboard.tokens import addr_to_token
Expand Down Expand Up @@ -960,8 +960,6 @@ def process_bounty_changes(old_bounty, new_bounty):
# marketing
if event_name != 'unknown_event':
print("============ posting ==============")
did_post_to_slack = maybe_market_to_slack(new_bounty, event_name)
did_post_to_user_slack = maybe_market_to_user_slack(new_bounty, event_name)
did_post_to_github = maybe_market_to_github(new_bounty, event_name, profile_pairs)
did_post_to_email = maybe_market_to_email(new_bounty, event_name)
print("============ done posting ==============")
Expand All @@ -971,8 +969,6 @@ def process_bounty_changes(old_bounty, new_bounty):
'did_bsr': did_bsr,
'did_post_to_email': did_post_to_email,
'did_post_to_github': did_post_to_github,
'did_post_to_slack': did_post_to_slack,
'did_post_to_user_slack': did_post_to_user_slack,
'did_post_to_twitter': False,
}

Expand Down
4 changes: 1 addition & 3 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
from unidecode import unidecode
from web3 import Web3

from .notifications import maybe_market_to_github, maybe_market_to_slack, maybe_market_to_user_slack
from .notifications import maybe_market_to_github
from .signals import m2m_changed_interested

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -2195,8 +2195,6 @@ def auto_user_approve(interest, bounty):
interest.acceptance_date = timezone.now()
start_work_approved(interest, bounty)
maybe_market_to_github(bounty, 'work_started', profile_pairs=bounty.profile_pairs)
maybe_market_to_slack(bounty, 'worker_approved')
maybe_market_to_user_slack(bounty, 'worker_approved')


@receiver(post_save, sender=Interest, dispatch_uid="psave_interest")
Expand Down
192 changes: 0 additions & 192 deletions app/dashboard/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,148 +83,6 @@ def github_org_to_twitter_tags(github_org):
return twitter_tags


def maybe_market_to_twitter(bounty, event_name):
"""Tweet the specified Bounty event.
Args:
bounty (dashboard.models.Bounty): The Bounty to be marketed.
event_name (str): The name of the event.
Returns:
bool: Whether or not the twitter notification was sent successfully.
"""
if not bounty.is_notification_eligible(var_to_check=settings.TWITTER_CONSUMER_KEY):
return False

api = twitter.Api(
consumer_key=settings.TWITTER_CONSUMER_KEY,
consumer_secret=settings.TWITTER_CONSUMER_SECRET,
access_token_key=settings.TWITTER_ACCESS_TOKEN,
access_token_secret=settings.TWITTER_ACCESS_SECRET,
)
tweet_txts = [
"Earn {} {} {} now by completing this task: \n\n{}",
"Oppy to earn {} {} {} for completing this task: \n\n{}",
"Is today the day you (a) boost your OSS rep (b) make some extra cash? 🤔 {} {} {} \n\n{}",
]
if event_name == 'remarket_bounty':
tweet_txts = tweet_txts + [
"Gitcoin open task of the day is worth {} {} {} ⚡️ \n\n{}",
"Task of the day 💰 {} {} {} ⚡️ \n\n{}",
]
elif event_name == 'new_bounty':
tweet_txts = tweet_txts + [
"Extra! Extra 🗞🗞 New Funded Issue, Read all about it 👇 {} {} {} \n\n{}",
"Hot off the blockchain! 🔥🔥🔥 There's a new task worth {} {} {} \n\n{}",
"💰 New Task Alert.. 💰 Earn {} {} {} for working on this 👇 \n\n{}",
]
elif event_name == 'increased_bounty':
tweet_txts = [
'Increased Payout on {} {} {}\n{}'
]
elif event_name == 'start_work':
tweet_txts = [
'Work started on {} {} {}\n{}'
]
elif event_name == 'stop_work':
tweet_txts = [
'Work stopped on {} {} {}\n{}'
]
elif event_name == 'work_done':
tweet_txts = [
'Work done on {} {} {}\n{}'
]
elif event_name == 'work_submitted':
tweet_txts = [
'Work submitted on {} {} {}\n{}'
]
elif event_name == 'killed_bounty':
tweet_txts = [
'Bounty killed on {} {} {}\n{}'
]
elif event_name == 'worker_rejected':
tweet_txts = [
'Worked rejected on {} {} {}\n{}'
]
elif event_name == 'worker_approved':
tweet_txts = [
'Worked approved on {} {} {}\n{}'
]

random.shuffle(tweet_txts)
tweet_txt = tweet_txts[0]
utm = ''
if bounty.metadata.get('hyper_tweet_counter', False):
utm = f'utm_source=hypercharge-auto&utm_medium=twitter&utm_campaign={bounty.title}'

url = f'{bounty.get_absolute_url()}?{utm}'
is_short = False
for shortener in ['Tinyurl', 'Adfly', 'Isgd', 'QrCx']:
try:
if not is_short:
shortener = Shortener(shortener)
response = shortener.short(url)
if response != 'Error' and 'http' in response:
url = response
is_short = True
except Exception:
pass

new_tweet = tweet_txt.format(
round(bounty.get_natural_value(), 4),
bounty.token_name,
f"({bounty.value_in_usdt_now} USD @ ${round(convert_token_to_usdt(bounty.token_name),2)}/{bounty.token_name})" if bounty.value_in_usdt_now else "",
url
)
new_tweet = new_tweet + " " + github_org_to_twitter_tags(bounty.org_name) # twitter tags
if bounty.keywords: # hashtags
for keyword in bounty.keywords.split(','):
_new_tweet = new_tweet + " #" + str(keyword).lower().strip()
if len(_new_tweet) < 140:
new_tweet = _new_tweet

try:
api.PostUpdate(new_tweet)
except Exception as e:
print(e)
return False
return True


def maybe_market_to_slack(bounty, event_name):
"""Send a Slack message for the specified Bounty.
Args:
bounty (dashboard.models.Bounty): The Bounty to be marketed.
event_name (str): The name of the event.
Returns:
bool: Whether or not the Slack notification was sent successfully.
"""
if not bounty.is_notification_eligible(var_to_check=settings.SLACK_TOKEN):
return False

msg = build_message_for_integration(bounty, event_name)
if not msg:
return False

try:
channel = 'notif-gitcoin'
sc = SlackClient(settings.SLACK_TOKEN)
sc.api_call(
"chat.postMessage",
channel=channel,
text=msg,
icon_url=settings.GITCOIN_SLACK_ICON_URL,
)
except Exception as e:
print(e)
return False
return True


def build_message_for_integration(bounty, event_name):
"""Build message to be posted to integrated service (e.g. slack).
Expand Down Expand Up @@ -257,56 +115,6 @@ def build_message_for_integration(bounty, event_name):
return msg


def maybe_market_to_user_slack(bounty, event_name):
from dashboard.tasks import maybe_market_to_user_slack
maybe_market_to_user_slack.delay(bounty.pk, event_name)


def maybe_market_to_user_slack_helper(bounty, event_name):
"""Send a Slack message to the user's slack channel for the specified Bounty.
Args:
bounty (dashboard.models.Bounty): The Bounty to be marketed.
event_name (str): The name of the event.
Returns:
bool: Whether or not the Slack notification was sent successfully.
"""
from dashboard.models import Profile
if bounty.get_natural_value() < 0.0001:
return False
if bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK:
return False

msg = build_message_for_integration(bounty, event_name)
if not msg:
return False

url = bounty.github_url
sent = False
try:
repo = org_name(url) + '/' + repo_name(url)
subscribers = Profile.objects.filter(slack_repos__contains=[repo])
subscribers = subscribers & Profile.objects.exclude(slack_token='', slack_channel='')
for subscriber in subscribers:
try:
sc = SlackClient(subscriber.slack_token)
sc.api_call(
"chat.postMessage",
channel=subscriber.slack_channel,
text=msg,
icon_url=settings.GITCOIN_SLACK_ICON_URL,
)
sent = True
except Exception as e:
print(e)
except Exception as e:
print(e)

return sent


def maybe_market_tip_to_email(tip, emails):
"""Send an email for the specified Tip.
Expand Down
14 changes: 0 additions & 14 deletions app/dashboard/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,6 @@ def update_trust_bonus(self, pk):
profile.save()


@app.shared_task(bind=True)
def maybe_market_to_user_slack(self, bounty_pk, event_name, retry: bool = True) -> None:
"""
:param self:
:param bounty_pk:
:param event_name:
:return:
"""
with redis.lock("maybe_market_to_user_slack:bounty", timeout=LOCK_TIMEOUT):
bounty = Bounty.objects.get(pk=bounty_pk)
from dashboard.notifications import maybe_market_to_user_slack_helper
maybe_market_to_user_slack_helper(bounty, event_name)


@app.shared_task(bind=True, soft_time_limit=600, time_limit=660, max_retries=3)
def grant_update_email_task(self, pk, retry: bool = True) -> None:
"""
Expand Down
3 changes: 0 additions & 3 deletions app/dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
from web3.middleware import geth_poa_middleware

from .abi import erc20_abi
from .notifications import maybe_market_to_slack

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1054,8 +1053,6 @@ def re_market_bounty(bounty, auto_save = True):
if auto_save:
bounty.save()

maybe_market_to_slack(bounty, 'issue_remarketed')

result_msg = 'The issue will appear at the top of the issue explorer. '
further_permitted_remarket_count = settings.RE_MARKET_LIMIT - bounty.remarketed_count
if further_permitted_remarket_count >= 1:
Expand Down
15 changes: 1 addition & 14 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@
MediaFile, Option, Poll, PortfolioItem, Profile, ProfileSerializer, ProfileVerification, ProfileView, Question,
SearchHistory, Sponsor, Tool, TribeMember, UserAction, UserVerificationModel,
)
from .notifications import (
maybe_market_to_email, maybe_market_to_github, maybe_market_to_slack, maybe_market_to_user_slack,
)
from .notifications import maybe_market_to_email, maybe_market_to_github
from .poh_utils import is_registered_on_poh
from .router import HackathonEventSerializer, TribesSerializer
from .utils import (
Expand Down Expand Up @@ -284,8 +282,6 @@ def create_new_interest_helper(bounty, user, issue_message):
record_bounty_activity(bounty, user, 'start_work' if not approval_required else 'worker_applied', interest=interest)
bounty.interested.add(interest)
record_user_action(user, 'start_work', interest)
maybe_market_to_slack(bounty, 'start_work' if not approval_required else 'worker_applied')
maybe_market_to_user_slack(bounty, 'start_work' if not approval_required else 'worker_applied')
return interest


Expand Down Expand Up @@ -614,8 +610,6 @@ def remove_interest(request, bounty_id):

bounty.interested.remove(interest)
interest.delete()
maybe_market_to_slack(bounty, 'stop_work')
maybe_market_to_user_slack(bounty, 'stop_work')
except Interest.DoesNotExist:
return JsonResponse({
'errors': [_('You haven\'t expressed interest on this bounty.')],
Expand Down Expand Up @@ -768,8 +762,6 @@ def uninterested(request, bounty_id, profile_id):
try:
interest = Interest.objects.get(profile_id=profile_id, bounty=bounty)
bounty.interested.remove(interest)
maybe_market_to_slack(bounty, 'stop_work')
maybe_market_to_user_slack(bounty, 'stop_work')
if is_staff or is_moderator:
event_name = "bounty_removed_slashed_by_staff" if slashed else "bounty_removed_by_staff"
else:
Expand Down Expand Up @@ -1846,19 +1838,14 @@ def helper_handle_approvals(request, bounty):
start_work_approved(interest, bounty)

maybe_market_to_github(bounty, 'work_started', profile_pairs=bounty.profile_pairs)
maybe_market_to_slack(bounty, 'worker_approved')
record_bounty_activity(bounty, request.user, 'worker_approved', interest)
maybe_market_to_user_slack(bounty, 'worker_approved')
else:
start_work_rejected(interest, bounty)

record_bounty_activity(bounty, request.user, 'worker_rejected', interest)
bounty.interested.remove(interest)
interest.delete()

maybe_market_to_slack(bounty, 'worker_rejected')
maybe_market_to_user_slack(bounty, 'worker_rejected')

messages.success(request, _(f'{worker} has been {mutate_worker_action_past_tense}'))
else:
messages.warning(request, _('Only the funder of this bounty may perform this action.'))
Expand Down
9 changes: 2 additions & 7 deletions app/marketing/management/commands/hypercharge_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from django.utils import timezone

from dashboard.models import Bounty, BountyEvent, Profile
from dashboard.notifications import maybe_market_to_twitter
from marketing.mails import bounty_hypercharged
from townsquare.models import Offer

Expand Down Expand Up @@ -75,19 +74,15 @@ def handle(self, *args, **options):
offer_title = f'Work on "{bounty.title}" and receive {floatformat(bounty.value_true)} {bounty.token_name}'
offer_desc = ''

event_name = ''
counter = bounty.metadata['hyper_tweet_counter']
# counter is 0 -> new_bounty
# counter is 1 -> remarket_bounty
if counter == 0:
event_name = 'new_bounty'
notify_previous_workers(bounty)
make_secret_offer(profile, offer_title, offer_desc, bounty)
elif counter == 1:
event_name = 'remarket_bounty'
elif counter % 2 == 0:
make_secret_offer(profile, offer_title, offer_desc, bounty)

bounty.metadata['hyper_tweet_counter'] += 1
bounty.hyper_next_publication = now + timedelta(hours=12)
bounty.save()

maybe_market_to_twitter(bounty, event_name)
Loading

0 comments on commit 6542cd0

Please sign in to comment.