-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from x-team/main
Merging main
- Loading branch information
Showing
39 changed files
with
1,268 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# API | ||
HOST=0.0.0.0 | ||
PORT=3010 | ||
|
||
# DATABASE | ||
DB_USERNAME=postgres | ||
DB_PASSWORD=*games-2021 | ||
DB_NAME=gameshq_api | ||
DB_HOSTNAME=127.0.0.1 | ||
DB_PORT=5434 | ||
|
||
# THE ARENA APP | ||
SLACK_ARENA_TOKEN= | ||
SLACK_ARENA_SIGNING_SECRET= | ||
# Private Channel | ||
SLACK_ARENA_XHQ_CHANNEL= | ||
|
||
# CAMPAIGN APP | ||
SLACK_CAMPAIGN_SIGNING_SECRET= | ||
SLACK_CAMPAIGN_TOKEN= | ||
SLACK_NEUTRAL_ZONE_CHANNEL= | ||
|
||
# THE TOWER APP | ||
SLACK_TOWER_SIGNING_SECRET= | ||
SLACK_TOWER_TOKEN= | ||
SLACK_THE_TOWER_CHANNEL= | ||
|
||
# FRONT-END-APP | ||
FRONT_END_SIGNING_SECRET= | ||
FRONT_END_APP_BOT_TOKEN= | ||
|
||
# FIREBASE | ||
GOOGLE_APPLICATION_CREDENTIALS="/path/to/yours/service/account/file/service-account-file.json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v16.10.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { getGameResponse } from '../../utils'; | ||
import { GAMES_SLACK_COMMANDS } from '../consts'; | ||
|
||
import { register } from './register'; | ||
|
||
interface GamesHQSwitchCommandOptions { | ||
command: string; | ||
commandText: string; | ||
slackId: string; | ||
channelId: string; | ||
triggerId: string; | ||
} | ||
|
||
export function gamesSwitchCommand({ command, slackId }: GamesHQSwitchCommandOptions) { | ||
switch (command) { | ||
// ADMIN | ||
case GAMES_SLACK_COMMANDS.REGISTER: | ||
return register(slackId); | ||
|
||
default: | ||
return getGameResponse('Invalid command.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Boom from '@hapi/boom'; | ||
|
||
import { USER_ROLE_LEVEL } from '../../../consts/model'; | ||
import { findOrganizationByName } from '../../../models/Organization'; | ||
import { createUser, userExists } from '../../../models/User'; | ||
import { getGameResponse, getSlackUserInfo } from '../../utils'; | ||
|
||
export const register = async (slackUserId: string) => { | ||
const exists = await userExists(slackUserId); | ||
if (exists) { | ||
return getGameResponse(`Your user is already registered.`); | ||
} | ||
|
||
const xteamOrganization = await findOrganizationByName('x-team'); | ||
const { user } = await getSlackUserInfo(slackUserId); | ||
|
||
if (!user || !user.profile || !xteamOrganization) { | ||
throw Boom.badRequest(`Failed to create new user on GamesHQ.`); | ||
} | ||
const { profile } = user; | ||
const { email, image_512 } = profile; | ||
|
||
await createUser({ | ||
email: email, | ||
displayName: user.real_name, | ||
firebaseUserUid: null, | ||
profilePictureUrl: image_512, | ||
slackId: user.id, | ||
_teamId: null, | ||
_roleId: USER_ROLE_LEVEL.USER, | ||
_organizationId: xteamOrganization?.id, | ||
}); | ||
|
||
return getGameResponse( | ||
`Your e-mail _${email}_ is now registered to all our games :partyparrot: ` | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum GAMES_SLACK_COMMANDS { | ||
// USER COMMANDS | ||
REGISTER = '/games-register', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createOrUpdateArenaZone, deleteZoneById } from '../../../../models/ArenaZone'; | ||
import { ARENA_ZONE_RING } from '../../../arena/consts'; | ||
import { withZoneTransaction } from '../../../arena/utils'; | ||
|
||
export interface IZoneEditorData { | ||
id?: number; | ||
name: string; | ||
emoji: string; | ||
ring: string; | ||
isArchived: boolean; | ||
} | ||
|
||
export const upsertZone = async (data: IZoneEditorData) => { | ||
return withZoneTransaction(async () => { | ||
const values = { | ||
...(data.id && { id: data.id }), | ||
name: data.name, | ||
emoji: data.emoji, | ||
isArchived: data.isArchived, | ||
ring: data.ring as ARENA_ZONE_RING, | ||
isActive: data.isArchived, | ||
}; | ||
return createOrUpdateArenaZone(values); | ||
}); | ||
}; | ||
|
||
export const deleteZone = async (zoneId: number) => { | ||
return withZoneTransaction(async (transaction) => { | ||
return deleteZoneById(zoneId, transaction); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { createOrUpdateEnemy, deleteEnemyById } from '../../../../models/Enemy'; | ||
import { createEnemyPattern, existsEnemyPattern } from '../../../../models/EnemyPattern'; | ||
import { withEnemyTransaction } from '../../../arena/utils'; | ||
import { AbilityProperty } from '../../../classes/GameAbilities'; | ||
|
||
export interface IEnemyEditorData { | ||
id?: number; | ||
name: string; | ||
gifUrl: string; | ||
emoji: string; | ||
abilitiesJSON: AbilityProperty; | ||
health: number; | ||
isBoss: boolean; | ||
majorDamageRate: number; | ||
minorDamageRate: number; | ||
actionPattern: string; | ||
} | ||
|
||
export const upsertEnemy = async (data: IEnemyEditorData) => { | ||
return withEnemyTransaction(async (transaction) => { | ||
const enemyPatternExists = await existsEnemyPattern(data.actionPattern, transaction); | ||
let enemyPatternId = data.actionPattern; | ||
if (!enemyPatternExists) { | ||
const newPattern = await createEnemyPattern(data.actionPattern); | ||
enemyPatternId = newPattern.id; | ||
} | ||
|
||
return createOrUpdateEnemy( | ||
{ | ||
...(data.id && { id: data.id }), | ||
abilitiesJSON: data.abilitiesJSON, | ||
emoji: data.emoji, | ||
gifUrl: data.gifUrl, | ||
name: data.name, | ||
health: data.health, | ||
isBoss: data.isBoss, | ||
majorDamageRate: data.majorDamageRate, | ||
minorDamageRate: data.minorDamageRate, | ||
_enemyPatternId: enemyPatternId, | ||
}, | ||
transaction | ||
); | ||
}); | ||
}; | ||
|
||
export const deleteEnemy = async (enemyId: number) => { | ||
return withEnemyTransaction(async (transaction) => { | ||
return deleteEnemyById(enemyId, transaction); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { findAdmin } from '../../../../models/User'; | ||
|
||
import { addEnemiesToFloor } from './actions/admin/tower-floors-operations'; | ||
|
||
export const addEnemies = async (floorNumber: number, enemyIds: number[]) => { | ||
const adminUser = await findAdmin(); | ||
if (!adminUser) { | ||
return; | ||
} | ||
|
||
await addEnemiesToFloor(adminUser, floorNumber, enemyIds); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { startTowerGame } from '../../../../models/TowerGame'; | ||
import { findAdmin } from '../../../../models/User'; | ||
import { withTowerTransaction } from '../../utils'; | ||
import { endGame, openOrCloseTowerGates } from './actions/admin/create-or-finish-game'; | ||
|
||
export interface ICreateTowerGameData { | ||
name: string; | ||
height: number; | ||
} | ||
|
||
export const createTowerGame = async (data: ICreateTowerGameData) => { | ||
return withTowerTransaction(async (transaction) => { | ||
await startTowerGame( | ||
{ | ||
name: data.name, | ||
height: data.height, | ||
isOpen: false, | ||
lunaPrize: 0, | ||
coinPrize: 0, | ||
_createdById: 1, | ||
}, | ||
transaction | ||
); | ||
}); | ||
}; | ||
|
||
export const endCurrentTowerGame = async () => { | ||
const adminUser = await findAdmin(); | ||
if (!adminUser) { | ||
return; | ||
} | ||
return endGame(adminUser); | ||
}; | ||
|
||
export const openOrCloseTower = async (open: boolean) => { | ||
const adminUser = await findAdmin(); | ||
if (!adminUser) { | ||
return; | ||
} | ||
return openOrCloseTowerGates(adminUser, open); | ||
}; |
Oops, something went wrong.