Skip to content

Commit

Permalink
Merge pull request #13 from SchwaIndustries/dev
Browse files Browse the repository at this point in the history
Version 1.3.0
  • Loading branch information
Kalissaac authored Aug 24, 2020
2 parents 4b76580 + 24a2392 commit e537dfc
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ dist
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
.vscode/launch.json
.vscode/settings.json

# yarn v2
.yarn/cache
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scrimbot",
"version": "1.2.2",
"version": "1.3.0",
"description": "A Discord bot for organizing Valorant custom games.",
"main": "src/index.js",
"scripts": {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ module.exports = exports = {

const create = async (message, GLOBALS) => {
if (!message.guild) return message.reply('This command can only be run in a server!')
const playerInformation = await GLOBALS.db.collection('users').doc(message.author.id).get()
if (!playerInformation.exists) {
if (await GLOBALS.userIsRegistered(message.author.id) === false) {
message.reply('You are not registered with ScrimBot. Please type `v!register` before creating a match!')
return
}
Expand Down
9 changes: 9 additions & 0 deletions src/commands/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = exports = {
name: 'settings', // command name
usage: '<way too many to list>', // arguments for the command
enabled: true, // whether the command should be loaded
process: async (message, GLOBALS) => {
// function called when command is invoked
}
}

8 changes: 4 additions & 4 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ module.exports = exports = {
ascent: 'https://images.contentstack.io/v3/assets/bltb6530b271fddd0b1/blt47bef6aa9e43d8ec/5ecd64df96a8996de38bbf8f/ascent-minimap-2.jpg'
},

GAME_MODES: ['standard', 'spike rush', 'team deathmatch'],
GAME_MODES: ['standard', 'spike rush', 'deathmatch'],

AFFIRMATIVE_WORDS: ['yes', 'yeah', 'sure', 'true', '1', 'si', 'yea', 'ok', 'mhm', 'k', 'yah', 'on'],
AFFIRMATIVE_WORDS: ['yes', 'yeah', 'sure', 'true', '1', 'one', 'si', 'yea', 'ok', 'okay', 'mhm', 'k', 'yah', 'on', 'why not', 'alright', 'aight', 'affirmative'],

userRegistrationSteps: [
['1. Valorant Username', 'What is your FULL Valorant username? (including tag, e.g. `Username#NA1`)'],
['2. Valorant Rank', 'What rank are you in Valorant? If you don\'t have a rank, go with "Iron 1"'],
['3. Notifications', 'Do you want to be notified when LFG starts? Respond "yes" if you would like to opt-in.']
['3. Notifications', 'Do you want to be notified when matches are created? Respond "yes" if you would like to opt-in.']
],

matchCreationSteps: [
Expand All @@ -86,7 +86,7 @@ module.exports = exports = {
['4. Player Count', 'How many players should be on each team? Max 5.'],
['5. Spectators', 'Are spectators allowed?'],
['6. Map', 'Which map would you like to play on? Respond 1 for Split, 2 for Bind, 3 for Haven, 4 for Ascent. If any, type "any"'],
['7. Game Mode', 'What game mode would you like? Options are "standard", "spike rush", and "team deathmatch".']
['7. Game Mode', 'What game mode would you like? Options are "standard", "spike rush", and "deathmatch".']
],

capitalizeFirstLetter: string => {
Expand Down
42 changes: 40 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ class ScrimBotEmbed extends Discord.MessageEmbed {
}

class MatchEmbed extends ScrimBotEmbed {
constructor (matchData, specialColor) {
super(specialColor)
async setMatchData (matchData) {
this.setTitle('Match Information')
this.setDescription('React with 🇦 to join the A team, react with 🇧 to join the B team and, if enabled, react with 🇸 to be a spectator.')
this.setThumbnail(CONSTANTS.MAPS_THUMBNAILS[matchData.map])
Expand All @@ -87,6 +86,36 @@ class MatchEmbed extends ScrimBotEmbed {
this.addField('Team A', 'None', true)
this.addField('Team B', 'None', true)
this.addField('Spectators', matchData.spectators instanceof Array ? 'None' : 'Not allowed', true)

if (matchData.players.a.length > 0) {
this.fields[6].value = ''
for (const playerRef of matchData.players.a) {
let playerDoc = await playerRef.get()
playerDoc = playerDoc.data()
this.fields[6].value += `\n• ${playerDoc.valorantUsername}`
}
}
if (matchData.players.b.length > 0) {
this.fields[7].value = ''
for (const playerRef of matchData.players.b) {
let playerDoc = await playerRef.get()
playerDoc = playerDoc.data()
this.fields[7].value += `\n• ${playerDoc.valorantUsername}`
}
}
if (matchData.spectators instanceof Array && matchData.spectators.length > 0) {
this.fields[8].value = ''
for (const playerRef of matchData.spectators) {
let playerDoc = await playerRef.get()
playerDoc = playerDoc.data()
this.fields[8].value += `\n• ${playerDoc.valorantUsername}`
}
}
}

constructor (matchData, specialColor) {
super(specialColor)
this.setMatchData(matchData)
}
}

Expand All @@ -106,6 +135,15 @@ const GLOBALS = {
const userData = await db.collection('users').doc(userId).get()
if (!userData.exists) return false
return userData.get('admin') === true
},
/**
* Checks whether a specified user is registered with the bot
* @param {String} userId User ID to check
*/
userIsRegistered: async userId => {
const userData = await db.collection('users').doc(userId).get()
if (!userData.exists) return false
else return userData
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/services/matchCreation.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const handleMatchCreation = async (matchRecord, userMessage, GLOBALS) => {
switch (matchRecord.step) {
case 0: {
const date = chrono.parseDate(`${userMessage.content} ${moment.tz.zone(process.env.TIME_ZONE).abbr(Date.now())}`)
if (isNaN(date)) return userMessage.reply('please give a valid date!').then(msg => msg.delete({ timeout: 5000 }))
if (!date) return userMessage.reply('please give a valid date!').then(msg => msg.delete({ timeout: 5000 }))
matchRecord.creationInformation.date = date
break
}
Expand Down Expand Up @@ -116,9 +116,9 @@ const handleMatchCreation = async (matchRecord, userMessage, GLOBALS) => {

const matchEmbed = new GLOBALS.Embed()
.setTitle('Match Information')
.setDescription('React with 🇦 to join the A team, react with 🇧 to join the B team and, if enabled, react with 🇸 to be a spectator.')
.setDescription('React with 🇦 to join the A team, react with 🇧 to join the B team' + (matchRecord.creationInformation.spectators instanceof Array ? ', and react with 🇸 to be a spectator.' : '.'))
.setThumbnail(CONSTANTS.MAPS_THUMBNAILS[matchRecord.creationInformation.map])
.setTimestamp(new Date(matchRecord.creationInformation.date))
.setTimestamp(matchRecord.creationInformation.date)
.setAuthor(userMessage.author.tag, userMessage.author.avatarURL())
.addField('Status', CONSTANTS.capitalizeFirstLetter(matchRecord.creationInformation.status), true)
.addField('Game Mode', CONSTANTS.capitalizeFirstLetter(matchRecord.creationInformation.mode), true)
Expand All @@ -129,13 +129,12 @@ const handleMatchCreation = async (matchRecord, userMessage, GLOBALS) => {
.addField('Team A', 'None', true)
.addField('Team B', 'None', true)
.addField('Spectators', matchRecord.creationInformation.spectators instanceof Array ? 'None' : 'Not allowed', true)
matchRecord.botMessage.channel.send(`<@&${guildInformation.notificationRole}> a match has been created!`, matchEmbed)
matchRecord.botMessage.channel.send(`A match has been created for ${moment().to(matchRecord.creationInformation.date)}! <@&${guildInformation.notificationRole}>`, matchEmbed)
.then(async message => {
message.react('🇦')
message.react('🇧')
if (matchRecord.creationInformation.spectators) message.react('🇸')
matchEmbed.setFooter('match id: ' + message.id)
console.log('match id: ' + message.id)
message.edit(matchEmbed)
matchRecord.userMessage.delete()
matchRecord.creationInformation.message = {
Expand Down

0 comments on commit e537dfc

Please sign in to comment.