Skip to content

Commit

Permalink
Client: support setting a status message
Browse files Browse the repository at this point in the history
  • Loading branch information
sirDonovan committed Dec 15, 2024
1 parent 22a3e2b commit 192f297
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const STAFF_BLOCKING_PMS_MESSAGE = "is too busy to answer private messages right
const BLOCK_CHALLENGES_COMMAND = "/text You are now blocking all incoming challenge requests.";
const ALREADY_BLOCKING_CHALLENGES_COMMAND = "/error You are already blocking challenges!";
const AVATAR_COMMAND = "/text Avatar changed to:";
const STATUS_COMMAND = "/text Your status has been set to: ";
const ROLL_COMMAND_HELP = "/text /dice ";

const DATA_COMMANDS: string[] = [
Expand Down Expand Up @@ -496,6 +497,14 @@ export class Client {
measure: true,
});
}

if (Config.status) {
this.send({
message: '|/status ' + Config.status,
type: 'status',
measure: true,
});
}
}
break;
}
Expand Down Expand Up @@ -1063,6 +1072,13 @@ export class Client {
return;
}

if (messageArguments.message.startsWith(STATUS_COMMAND)) {
if (lastOutgoingMessage && lastOutgoingMessage.type === 'status') {
this.websocket.clearLastOutgoingMessage(now);
}
return;
}

const recipientId = Tools.toId(messageArguments.recipientUsername);
if (messageArguments.message.startsWith(USER_NOT_FOUND_MESSAGE) ||
messageArguments.message.startsWith(USER_BLOCKING_PMS_MESSAGE) ||
Expand Down Expand Up @@ -1351,6 +1367,11 @@ export class Client {
Tools.toId(lastOutgoingMessage.pageId) === Tools.toId(pageId)) {
this.websocket.clearLastOutgoingMessage(now);
}
} else if (messageArguments.message.startsWith("Your status has been set to: ")) {
if (lastOutgoingMessage && lastOutgoingMessage.type === 'status' &&
lastOutgoingMessage.roomid === room.id) {
this.websocket.clearLastOutgoingMessage(now);
}
} else if (messageArguments.message.startsWith(CHAT_ERROR_MESSAGE)) {
Tools.warningLog("Chat error message in " + room.title + ": " + messageArguments.message.substr(CHAT_ERROR_MESSAGE.length));
}
Expand Down
5 changes: 5 additions & 0 deletions src/config-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ export let bannedWords: string[] | null = null;
*/
export let avatar = '';

/**
* The status to set after logging in
*/
export let status = '';

/**
* The character used to denote commands in chat messages
*/
Expand Down
2 changes: 1 addition & 1 deletion src/types/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type IOutgoingMessageTypes = 'command' | 'chat' | 'chat-html' | 'chat-uht
'tournament-create' | 'tournament-start' | 'tournament-end' | 'tournament-name' | 'tournament-autostart' | 'tournament-autodq' |
'tournament-runautodq' | 'tournament-cap' | 'tournament-rules' | 'tournament-forcepublic' | 'tournament-forcetimer' |
'tournament-scouting' | 'tournament-modjoin' | 'tournament-disqualify' | 'notifyuser' | 'notifyoffuser' | 'query-userdetails' |
'query-rooms' | 'query-roominfo' | 'blockchallenges' | 'trn' | 'avatar' | 'allowpmlog' | 'create-groupchat';
'query-rooms' | 'query-roominfo' | 'blockchallenges' | 'trn' | 'avatar' | 'allowpmlog' | 'create-groupchat' | 'status';

export interface IOutgoingMessageAttributes {
/**Return `false` to prevent a message from being sent */
Expand Down

0 comments on commit 192f297

Please sign in to comment.