def send_challenge_message(self, duel): url = 'http://playpilots.nl/c/%d/' % duel.id if self.get_twitter_name(): logging.info('trying to send challenge tweet') challenger_name = duel.challenger.get_twitter_name() or duel.challenger.get_display_name() modifiers = { 1: ' zwak', 2: ' matig', 3: '', 4: ' goed', 5: ' hard' } modifier = modifiers[duel.challenge_awesomeness] messageParts = [ u'@%(target)s' % {'target': self.get_twitter_name()} ] if duel.challenge_message: message = duel.challenge_message if len(message) > 25: message = duel.challenge_message[:25] + u'…' messageParts.append(u'“%(style)s” @%(challenger)s daagt je%(modifier)s uit en zegt: %(message)s' % {'style': duel.challenge_move.style.name, 'challenger': challenger_name, 'message': message, 'modifier': modifier}) else: messageParts.append(u'Je bent%(modifier)s uitgedaagd door “%(style)s” @%(challenger)s.' % {'style': duel.challenge_move.style.name, 'challenger': challenger_name, 'modifier': modifier}) # TODO definitely needs special message on challenge_open to let somebody challenged claim messageParts.append(u'Doe iets terug op: %(url)s' % {'url': url}) send_tweet(u' '.join(messageParts))
def game_interest(request, slug): action = request.POST.get("action", "add") game = get_object_or_404(Game, slug=slug) if request.user.is_authenticated(): try: player = request.user.get_profile() except django.contrib.auth.models.SiteProfileNotAvailable: pass if action == "add": game.interested.add(player) actstream.action.send(player, verb="doet mee met", target=game) # Text needs to be modified is the game has already passed if game.end < datetime.datetime.now(): action = "deed" else: action = "doet" if game.slug == "de-stereoscoop": hashtags = "#NFF" else: hashtags = "" if player.get_twitter_name(): send_tweet( "@%(player)s je %(action)s mee met %(game)s, kijk op: http://playpilots.nl%(url)s en vertel je vrienden! %(hashtags)s" % { "player": player.get_twitter_name(), "game": game.name, "url": game.get_absolute_url(), "action": action, "hashtags": hashtags, } ) elif action == "remove": game.interested.remove(player) actstream.action.send(player, verb="doet niet meer mee met", target=game) if player.get_twitter_name(): send_tweet( "@%(player)s doet helaas niet meer mee met %(game)s, maar wil je wel al je vrienden vertellen over: http://playpilots.nl%(url)s ?" % {"player": player.get_twitter_name(), "game": game.name, "url": game.get_absolute_url()} ) if "json" in request.META.get("HTTP_ACCEPT", ""): return HttpResponse(json.dumps({"success": 1})) else: return HttpResponseRedirect("/games/%s/" % game.slug) return HttpResponse(json.dumps({"success": 0}))
def send_challenge_message(self, duel): url = 'http://playpilots.nl/c/%d/' % duel.id if self.get_twitter_name(): logging.info('trying to send challenge tweet') challenger_name = duel.challenger.get_twitter_name( ) or duel.challenger.get_display_name() modifiers = { 1: ' zwak', 2: ' matig', 3: '', 4: ' goed', 5: ' hard' } modifier = modifiers[duel.challenge_awesomeness] messageParts = [ u'@%(target)s' % { 'target': self.get_twitter_name() } ] if duel.challenge_message: message = duel.challenge_message if len(message) > 25: message = duel.challenge_message[:25] + u'…' messageParts.append( u'“%(style)s” @%(challenger)s daagt je%(modifier)s uit en zegt: %(message)s' % { 'style': duel.challenge_move.style.name, 'challenger': challenger_name, 'message': message, 'modifier': modifier }) else: messageParts.append( u'Je bent%(modifier)s uitgedaagd door “%(style)s” @%(challenger)s.' % { 'style': duel.challenge_move.style.name, 'challenger': challenger_name, 'modifier': modifier }) # TODO definitely needs special message on challenge_open to let somebody challenged claim messageParts.append(u'Doe iets terug op: %(url)s' % {'url': url}) send_tweet(u' '.join(messageParts))
def send_win_message(self, duel): logging.info('sending win message to %s', self.get_display_name()) url = 'http://playpilots.nl/c/%d/' % duel.id if self.get_twitter_name(): logging.info('trying to send twitter win message to @%s', self.get_twitter_name()) loser_name = duel.get_loser().get_twitter_name() or duel.get_loser().get_display_name() # TODO add twitter '@' for the other message = u'@%(winner)s, je bent de baas! Je hebt als “%(style)s” gewonnen van @%(loser)s. Ga naar %(url)s om het resultaat te zien.' % { 'winner': self.get_twitter_name(), 'style': duel.get_winner_style().name, 'loser': loser_name, 'url': url } send_tweet(message)
def send_lose_message(self, duel): logging.info('sending lose message to %s', self.get_display_name()) url = 'http://playpilots.nl/c/%d/' % duel.id if self.get_twitter_name(): logging.info('trying to send twitter lose message to @%s', self.get_twitter_name()) winner_name = duel.get_winner().get_twitter_name() or duel.get_winner().get_display_name() message = u'@%(loser)s jammer! Je hebt verloren van “%(style)s” @%(winner)s. Ga naar %(url)s om het resultaat te zien.' % { 'loser': self.get_twitter_name(), 'style': duel.get_winner_style().name, 'winner': winner_name, 'url': url } send_tweet(message)
def send_win_message(self, duel): logging.info('sending win message to %s', self.get_display_name()) url = 'http://playpilots.nl/c/%d/' % duel.id if self.get_twitter_name(): logging.info('trying to send twitter win message to @%s', self.get_twitter_name()) loser_name = duel.get_loser().get_twitter_name() or duel.get_loser( ).get_display_name() # TODO add twitter '@' for the other message = u'@%(winner)s, je bent de baas! Je hebt als “%(style)s” gewonnen van @%(loser)s. Ga naar %(url)s om het resultaat te zien.' % { 'winner': self.get_twitter_name(), 'style': duel.get_winner_style().name, 'loser': loser_name, 'url': url } send_tweet(message)
def send_lose_message(self, duel): logging.info('sending lose message to %s', self.get_display_name()) url = 'http://playpilots.nl/c/%d/' % duel.id if self.get_twitter_name(): logging.info('trying to send twitter lose message to @%s', self.get_twitter_name()) winner_name = duel.get_winner().get_twitter_name( ) or duel.get_winner().get_display_name() message = u'@%(loser)s jammer! Je hebt verloren van “%(style)s” @%(winner)s. Ga naar %(url)s om het resultaat te zien.' % { 'loser': self.get_twitter_name(), 'style': duel.get_winner_style().name, 'winner': winner_name, 'url': url } send_tweet(message)
def stereoscoop_code(request): if request.user.is_authenticated() and request.method=="POST": player = request.user.get_profile() code = request.POST.get('codeinput', '') if not StereoscoopCode.objects.filter(code=code).exists(): # Check for unlock try: unlock = StereoscoopUnlock.objects.get(code=code) # Only create the code object if the unlock exists StereoscoopCode.objects.create(player=player, code=code) if player.get_twitter_name(): send_tweet('@%(player)s heeft %(badgetitle)s gevonden bij De Stereoscoop %(badgelink)s #NFF' % { 'player': player.get_twitter_name(), 'badgetitle': unlock.badge.title, 'badgelink': 'http://playpilots.nl/de-stereoscoop/badge/%s/' % unlock.badge.slug }) actstream.action.send(request.user.get_profile(), verb="scratchte op de Stereoscoop net de", target=unlock.badge) except StereoscoopUnlock.DoesNotExist: logging.error('we do not have an unlock for code: %s', code) return HttpResponse(json.dumps({ 'result': 0, 'error': 'Sorry, maar onze robots kunnen deze code niet ontcijferen. Weet je zeker dat je geen typefout hebt gemaakt?' })) return HttpResponse(json.dumps({'result': 1})) else: logging.error('code %s aready exists in the database', code) return HttpResponse(json.dumps({ 'result': 0, 'error': 'Iemand anders heeft deze code al geclaimed. Of was jij het?' }))