Message hosting offer to "Find a Host" chat
This commit is contained in:
		@@ -22,7 +22,7 @@ from django.core.cache import cache
 | 
			
		||||
from django.utils.timezone import now, pytz
 | 
			
		||||
 | 
			
		||||
from . import models, serializers, utils_ldap, utils_stats, utils_auth, utils, utils_email
 | 
			
		||||
from .. import settings
 | 
			
		||||
from .. import settings, secrets
 | 
			
		||||
 | 
			
		||||
STATIC_FOLDER = 'data/static/'
 | 
			
		||||
 | 
			
		||||
@@ -42,6 +42,23 @@ def alert_tanner(message):
 | 
			
		||||
    except BaseException as e:
 | 
			
		||||
        logger.error('Problem alerting Tanner: ' + str(e))
 | 
			
		||||
 | 
			
		||||
def spaceporter_host(message):
 | 
			
		||||
    logger.info('Spaceporter bot sending to host chat: ' + message)
 | 
			
		||||
 | 
			
		||||
    if secrets.SPACEPORTER_HOST_TOKEN:
 | 
			
		||||
        url = 'https://forum.protospace.ca/chat/hooks/{}.json'.format(
 | 
			
		||||
            secrets.SPACEPORTER_HOST_TOKEN,
 | 
			
		||||
        )
 | 
			
		||||
    else:
 | 
			
		||||
        logger.info('Aborting Spaceporter bot message, no token.')
 | 
			
		||||
        return
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        data = dict(text=message)
 | 
			
		||||
        requests.post(url, json=data, timeout=4)
 | 
			
		||||
    except BaseException as e:
 | 
			
		||||
        logger.error('Problem with bot: ' + str(e))
 | 
			
		||||
 | 
			
		||||
def num_months_spanned(d1, d2):
 | 
			
		||||
    '''
 | 
			
		||||
    Return number of month thresholds two dates span.
 | 
			
		||||
 
 | 
			
		||||
@@ -1794,6 +1794,20 @@ class HostingViewSet(Base):
 | 
			
		||||
 | 
			
		||||
            logging.info('No current hosting for that user, new hosting #%s created.', h.id)
 | 
			
		||||
 | 
			
		||||
            try:  # TODO: remove try / except
 | 
			
		||||
                # send a message to Spacebar
 | 
			
		||||
                message = 'A member just offered to host for {} hours from now until {}!'.format(
 | 
			
		||||
                    hours,
 | 
			
		||||
                    h.finished_at.astimezone(utils.TIMEZONE_CALGARY).strftime('%-I:%M %p'),
 | 
			
		||||
                )
 | 
			
		||||
                if hosting_user.member.discourse_username:
 | 
			
		||||
                    message += ' Tag @{} here to get their attention.'.format(
 | 
			
		||||
                        hosting_user.member.discourse_username,
 | 
			
		||||
                    )
 | 
			
		||||
                utils.spaceporter_host(message)
 | 
			
		||||
            except:
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
        # update "open until" time
 | 
			
		||||
        hosting = models.Hosting.objects.order_by('-finished_at').first()
 | 
			
		||||
        closing = dict(
 | 
			
		||||
 
 | 
			
		||||
@@ -80,6 +80,12 @@ PINBALL_API_TOKEN = ''
 | 
			
		||||
# head /dev/urandom | base32 | head -c 40
 | 
			
		||||
ALARM_API_TOKEN = ''
 | 
			
		||||
 | 
			
		||||
# Spaceporter bot webhook URL token
 | 
			
		||||
# Posts to the "find a host" chat
 | 
			
		||||
# Found in /admin/plugins/chat URL section
 | 
			
		||||
# should look like '37f5e8d9c64064c86109b7ea'
 | 
			
		||||
SPACEPORTER_HOST_TOKEN = ''
 | 
			
		||||
 | 
			
		||||
# Protospace general info
 | 
			
		||||
DOOR_CODE = ''
 | 
			
		||||
WIFI_PASS = ''
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user