Skip to content

Commit 4ae47df

Browse files
committed
Showing current player count in bot nickname
1 parent 0a41b0e commit 4ae47df

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

lib/compretty.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,8 +1560,10 @@ export class CompRettyTeams {
15601560
return this.#rest.createInteractionResponse(interaction, getInteractionResponse(_message, _type));
15611561
}
15621562

1563-
_logEvents(channelID, events) {
1564-
if (channelID == true) return events;
1563+
_logEvents(guildID, channelID, events) {
1564+
if (guildID == true) return events;
1565+
if (this.playerCount == 0) this.#rest.modifyCurrentMember(guildID, '{"nick":"CompRetty"}');
1566+
else this.#rest.modifyCurrentMember(guildID, `{"nick":"CompRetty (${this.playerCount} players entered)"}`);
15651567
var _contentIndex = 0;
15661568
var _contents = [''];
15671569
for (let i = 0; i != events.length; i++) {
@@ -1576,26 +1578,26 @@ export class CompRettyTeams {
15761578
_contents.forEach((content) => this.#rest.createMessage(channelID, `{"content":"${content}","allowed_mentions":{"parse":[]}}`));
15771579
}
15781580

1579-
logEvent(channelID, event) {
1581+
logEvent(guildID, channelID, event) {
15801582
if (!this.#logEnabled) return;
15811583
var _events = [];
15821584
_events.push(event);
15831585
if (!burstStacksStarted) {
1584-
return this._logEvents(channelID, _events);
1586+
return this._logEvents(guildID, channelID, _events);
15851587
}
15861588
var _stackName = `log${channelID}`;
15871589
var _logEvents = burstStack10.get(_stackName);
15881590
if (_logEvents == null) {
1589-
burstStack10.set(_stackName, (_channelID = channelID) => {
1590-
return this._logEvents(_channelID, _events);
1591+
burstStack10.set(_stackName, (_guildID = guildID, _channelID = channelID) => {
1592+
return this._logEvents(_guildID, _channelID, _events);
15911593
});
15921594
return;
15931595
}
15941596
burstStack10.remove(_stackName);
15951597
_events = _logEvents(true);
15961598
_events.push(event);
1597-
burstStack10.set(_stackName, (_channelID = channelID) => {
1598-
return this._logEvents(_channelID, _events);
1599+
burstStack10.set(_stackName, (_guildID = guildID, _channelID = channelID) => {
1600+
return this._logEvents(_guildID, _channelID, _events);
15991601
});
16001602
}
16011603

@@ -1620,7 +1622,7 @@ export class CompRettyTeams {
16201622
var _teamName = _team.name;
16211623
_team.dmReadyPlayers(`{"content":"> ${this.#competitionName}: <@${_playerID}> (\`@${_username}\`) left ${_teamName == 'cr_queue' ? 'player queue' : `team ${_teamName}`}.\\n\\nYou are no longer marked ready, make sure that the team arrangement is still good at https://discord.com/channels/${interaction.guild_id}/${interaction.channel_id}"}`);
16221624
this.removePlayer(_playerID);
1623-
this.logEvent(interaction.channel_id, new CompRettyEvent(_playerID, _teamName, CompRettyEventType.Joined, `<@${_playerID}> (\`@${_username}\`) left ${_teamName == 'cr_queue' ? 'player queue' : `team ${_teamName}`} (${_team.playerCount}) / **${this.playerCount} player(s) entered**.`));
1625+
this.logEvent(interaction.guild_id, interaction.channel_id, new CompRettyEvent(_playerID, _teamName, CompRettyEventType.Joined, `<@${_playerID}> (\`@${_username}\`) left ${_teamName == 'cr_queue' ? 'player queue' : `team ${_teamName}`} (${_team.playerCount}) / **${this.playerCount} player(s) entered**.`));
16241626
await this._onSave();
16251627
return await this.#rest.createInteractionResponse(interaction, getEphemeralResponse(`You have left ${_teamName == 'cr_queue' ? 'player queue' : `team ${_teamName}`}. :levitate:`));
16261628
}
@@ -1640,7 +1642,7 @@ export class CompRettyTeams {
16401642
_team.dmReadyPlayers(`{"content":"> ${this.#competitionName}: <@${_playerID}> (\`@${_username}\`) joined team ${_teamName}.\\n\\nYou are no longer marked ready, make sure that the team arrangement is still good at https://discord.com/channels/${interaction.guild_id}/${interaction.channel_id}"}`);
16411643
this.setPlayerTeam(_playerID, _teamName);
16421644
await this._onSave();
1643-
this.logEvent(interaction.channel_id, new CompRettyEvent(_playerID, _teamName, CompRettyEventType.Joined, `<@${_playerID}> (\`@${_username}\`) joined team ${_teamName} (${_team.playerCount}) / **${this.playerCount} player(s) entered**.`));
1645+
this.logEvent(interaction.guild_id, interaction.channel_id, new CompRettyEvent(_playerID, _teamName, CompRettyEventType.Joined, `<@${_playerID}> (\`@${_username}\`) joined team ${_teamName} (${_team.playerCount}) / **${this.playerCount} player(s) entered**.`));
16441646
return await this.#rest.createInteractionResponse(interaction, getEphemeralResponse(`You have been randomly assigned to team ${_teamName}. :game_die:`));
16451647
}
16461648

@@ -1702,7 +1704,7 @@ export class CompRettyTeams {
17021704
_team.dmReadyPlayers(`{"content":"> ${this.#competitionName}: <@${_playerID}> (\`@${_username}\`) joined team ${teamName}.\\n\\nYou are no longer marked ready, make sure that the team arrangement is still good at https://discord.com/channels/${interaction.guild_id}/${interaction.channel_id}"}`);
17031705
this.setPlayerTeam(_playerID, teamName);
17041706
await this._onSave();
1705-
this.logEvent(interaction.channel_id, new CompRettyEvent(_playerID, teamName, CompRettyEventType.Joined, `<@${_playerID}> (\`@${_username}\`) joined team ${teamName} (${_team.playerCount}) / **${this.playerCount} player(s) entered**.`));
1707+
this.logEvent(interaction.guild_id, interaction.channel_id, new CompRettyEvent(_playerID, teamName, CompRettyEventType.Joined, `<@${_playerID}> (\`@${_username}\`) joined team ${teamName} (${_team.playerCount}) / **${this.playerCount} player(s) entered**.`));
17061708
}
17071709

17081710
async _onJoinQueue(interaction, isWizard = false) {
@@ -1726,7 +1728,7 @@ export class CompRettyTeams {
17261728
_team.getOrCreatePlayer(_playerID);
17271729
this.#playerTeams[_playerID] = _team;
17281730
await this._onSave();
1729-
this.logEvent(interaction.channel_id, new CompRettyEvent(_playerID, 'cr_queue', CompRettyEventType.Joined, `<@${_playerID}> (\`@${_username}\`) joined player queue (${_team.playerCount}) / **${this.playerCount} player(s) entered**.`));
1731+
this.logEvent(interaction.guild_id, interaction.channel_id, new CompRettyEvent(_playerID, 'cr_queue', CompRettyEventType.Joined, `<@${_playerID}> (\`@${_username}\`) joined player queue (${_team.playerCount}) / **${this.playerCount} player(s) entered**.`));
17301732
}
17311733

17321734
async _onKickPlayer(interaction, playerID) {
@@ -1737,7 +1739,7 @@ export class CompRettyTeams {
17371739
var _teamName = _playerTeam.name;
17381740
var _msg = `<@${interaction.member.user.id}> kicked <@${playerID}> from ${_teamName == 'cr_queue' ? 'player queue' : `team ${_teamName}`}. :wind_blowing_face:`;
17391741
this.#rest.createDMMessage(playerID, `{"content":"> ${this.#competitionName}: ${_msg}\\n\\nhttps://discord.com/channels/${interaction.guild_id}/${interaction.channel_id}"}`);
1740-
this.logEvent(interaction.channel_id, new CompRettyEvent(playerID, _teamName, CompRettyEventType.Left, _msg));
1742+
this.logEvent(interaction.guild_id, interaction.channel_id, new CompRettyEvent(playerID, _teamName, CompRettyEventType.Left, _msg));
17411743
return await this.#rest.createInteractionResponse(interaction, getEphemeralResponse(`Kicked player <@${playerID}> from team ${_playerTeam.name} :wind_blowing_face:`));
17421744
}
17431745

@@ -1888,7 +1890,7 @@ export class CompRettyTeams {
18881890
this.dmPlayers(`{"content":"> ${this.#competitionName}: ${_msg}\\n\\nhttps://discord.com/channels/${interaction.guild_id}/${interaction.channel_id}"}`);
18891891
this.clearPlayers();
18901892
await this._onSave();
1891-
this.logEvent(interaction.channel_id, new CompRettyEvent(null, null, CompRettyEventType.Left, _msg));
1893+
this.logEvent(interaction.guild_id, interaction.channel_id, new CompRettyEvent(null, null, CompRettyEventType.Left, _msg));
18921894
return await this.#rest.createInteractionResponse(interaction, getEphemeralResponse(`Kicked all players from all teams. :cloud_tornado:`));
18931895
case 'player':
18941896
var _playerID = _option.options[0].value;
@@ -2002,7 +2004,7 @@ export class CompRettyTeams {
20022004
_teamName = _team.name;
20032005
_team.dmReadyPlayers(`{"content":"> ${this.#competitionName}: <@${_playerID}> (\`@${_username}\`) left ${_teamName == 'cr_queue' ? 'player queue' : `team ${_teamName}`}.\\n\\nYou are no longer marked ready, make sure that the team arrangement is still good at https://discord.com/channels/${interaction.guild_id}/${interaction.channel_id}"}`);
20042006
this.removePlayer(_playerID);
2005-
this.logEvent(interaction.channel_id, new CompRettyEvent(_playerID, _teamName, CompRettyEventType.Joined, `<@${_playerID}> (\`@${_username}\`) left ${_teamName == 'cr_queue' ? 'player queue' : `team ${_teamName}`} (${_team.playerCount}) / **${this.playerCount} player(s) entered**.`));
2007+
this.logEvent(interaction.guild_id, interaction.channel_id, new CompRettyEvent(_playerID, _teamName, CompRettyEventType.Joined, `<@${_playerID}> (\`@${_username}\`) left ${_teamName == 'cr_queue' ? 'player queue' : `team ${_teamName}`} (${_team.playerCount}) / **${this.playerCount} player(s) entered**.`));
20062008
await this._onSave();
20072009
}
20082010
if (_arg3 == 'minimalist') {

lib/gleamcord.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ export class REST {
167167
removeGuildMemberRole(guildID, userID, roleID) {
168168
return this.delete(`${restGuildsURL}/${guildID}/members/${userID}/roles/${roleID}`);
169169
}
170+
171+
modifyCurrentMember(guildID, member) {
172+
return this.patch(`${restGuildsURL}/${guildID}/members/@me`, member);
173+
}
170174

171175
createGlobalApplicationCommand(applicationID, command) {
172176
return this.post(`${restApplicationsURL}/${applicationID}/commands`, command);

0 commit comments

Comments
 (0)