def slack_game_start(): # TODO : 요청이 들어온 채널의 redis status 체크해서 게임이 이미 시작했으면 게임 플레이를 안하도록 수정 필요 payload = request.get_data().decode() app.logger.info(payload) data = {} teamId = request.form.get('team_id') teamLang = util.get_team_lang(teamId) data['team_id'] = request.form.get('team_id') data['channel'] = request.form.get('channel_id') data['text'] = static.GAME_COMMAND_START data['user'] = request.form.get('user_id') data['mode'] = "normal" redis_manager.redis_client.set( 'game_mode_' + request.form.get('channel_id'), "normal") game_state = redis_manager.redis_client.get("status_" + data['channel']) app.logger.info(game_state) if game_state == None or game_state == static.GAME_STATE_IDLE: # 현재 채널 상태 설정 redis_manager.redis_client.set("status_" + data["channel"], static.GAME_STATE_LOADING) app.logger.info("rtm status : " + str(rtm_manager.is_socket_opened(teamId))) if rtm_manager.is_socket_opened(teamId) != static.SOCKET_STATUS_IDLE: redis_manager.redis_client.hset( 'rtm_status_' + teamId, 'expire_time', time.time() + static.SOCKET_EXPIRE_TIME) redis_manager.redis_client.set("status_" + data["channel"], static.GAME_STATE_LOADING), print('start') worker.delay(data) else: rtm_manager.open_new_socket(teamId, data) response = Response( json.dumps({ 'response_type': 'in_channel', 'text': '' })) response.headers['Content-type'] = 'application/json' return response else: response = Response( json.dumps({ 'response_type': 'in_channel', 'text': static.getText(static.CODE_TEXT_ALREADY_STARTED, teamLang), 'as_user': '******' })) response.headers['Content-type'] = 'application/json' return response
def slack_game_help(): payload = request.get_data().decode() print(payload) teamId = request.form.get('team_id') teamLang = util.get_team_lang(teamId) response = Response( json.dumps({ 'response_type': 'in_channel', 'text': static.getText(static.CODE_TEXT_HELP, teamLang) })) response.headers['Content-type'] = 'application/json' return response
def slack_send_review(): payload = request.get_data().decode() app.logger.info(payload) teamId = request.form.get('team_id') teamLang = util.get_team_lang(teamId) response = Response( json.dumps({ 'response_type': 'in_channel', 'channel': request.form.get('channel_id'), 'text': static.getText(static.CODE_TEXT_GAME_REVIEW, teamLang) })) response.headers['Content-type'] = 'application/json' return response
def slack_game_kok(): payload = request.get_data().decode() app.logger.info(payload) data = {} data['team_id'] = request.form.get('team_id') data['channel'] = request.form.get('channel_id') data['text'] = static.GAME_COMMAND_KOK data['user'] = request.form.get('user_id') teamId = request.form.get('team_id') teamLang = util.get_team_lang(teamId) if redis_manager.redis_client.get('kokstatus_' + data["channel"]) == "1": response = Response( json.dumps({ 'response_type': 'in_channel', 'text': static.getText(static.CODE_TEXT_ALREADY_STARTED, teamLang) })) response.headers['Content-type'] = 'application/json' else: if rtm_manager.is_socket_opened(teamId) != static.SOCKET_STATUS_IDLE: redis_manager.redis_client.hset( 'rtm_status_' + teamId, 'expire_time', time.time() + static.SOCKET_EXPIRE_TIME) redis_manager.redis_client.set("status_" + data["channel"], static.GAME_STATE_LOADING), redis_manager.redis_client.set('kokstatus_' + data["channel"], "1") print('start') worker.delay(data) else: rtm_manager.open_new_socket(teamId, data) response = Response( json.dumps({ 'response_type': 'in_channel', 'text': '' })) response.headers['Content-type'] = 'application/json' return response
def slack_game_lang(): payload = request.get_data().decode() print(payload) slackApi = util.init_slackapi(request.form.get('team_id')) teamLang = util.get_team_lang(request.form.get('team_id')) slackApi.chat.postMessage({ 'channel': request.form.get('channel_id'), 'text': static.getText(static.CODE_TEXT_BUTTON_LANG, teamLang), 'attachments': json.dumps([{ "text": "", "fallback": "fallbacktext", "callback_id": "wopr_game", "color": "#3AA3E3", "attachment_type": "default", "actions": [{ "name": "lang_en", "text": ":us: English", "type": "button", "value": "lang_en" }, { "name": "lang_kr", "text": ":kr: 한국어", "type": "button", "value": "lang_kr" }] }]) }) response = Response(json.dumps({ 'response_type': 'in_channel', 'text': '' })) response.headers['Content-type'] = 'application/json' return response
def slack_event_btn(): payload = json.loads(request.form.get('payload')) channelId = payload['channel']['id'] teamId = payload['team']['id'] teamLang = util.get_team_lang(teamId) slackApi = util.init_slackapi(teamId) app.logger.info("btn callback" + str(payload)) if payload['actions'][0]['name'] == 'invite_bot': if channelId[0] == "G": # private channel slackApi.groups.invite({ 'channel': channelId, 'user': util.get_bot_id(teamId) }) else: # public channel slackApi.channels.invite({ 'channel': channelId, 'user': util.get_bot_id(teamId) }) elif payload['actions'][0]['name'] == 'lang_en': db_manager.query( "UPDATE TEAM " "SET " "team_lang = %s " "WHERE " "team_id = %s ", ("en", teamId)) slackApi.chat.postMessage({ 'channel': channelId, 'text': static.getText(static.CODE_TEXT_LANG_CHANGED, "en"), 'as_user': '******' }) elif payload['actions'][0]['name'] == 'lang_kr': db_manager.query( "UPDATE TEAM " "SET " "team_lang = %s " "WHERE " "team_id = %s ", ("kr", teamId)) slackApi.chat.postMessage({ 'channel': channelId, 'text': static.getText(static.CODE_TEXT_LANG_CHANGED, "kr"), 'as_user': '******' }) elif payload['actions'][0]['name'] == 'kok_join': ts = redis_manager.redis_client.get('kokmsg_' + channelId) game_id = redis_manager.redis_client.get('kokgame_id_' + channelId) redis_manager.redis_client.hset('kokusers_' + game_id, payload['user']['id'], "1") users = redis_manager.redis_client.hgetall('kokusers_' + game_id) print(users) userString = "" for key, value in users.items(): if value == "1": userString += "<@" + key + "> " slackApi.chat.update({ 'channel': channelId, 'text': "", 'ts': ts, 'attachments': json.dumps([{ "text": static.getText(static.CODE_TEXT_KOK_ENTRY, teamLang) % (userString), "fallback": "fallbacktext", "callback_id": "wopr_game", "color": "#FF2222", "attachment_type": "default", "actions": [{ "name": "kok_join", "text": ":dagger_knife: Join", "type": "button", "value": "kok_join" }] }]) }) return ''