Skip to content

Commit

Permalink
feat: add death messages
Browse files Browse the repository at this point in the history
  • Loading branch information
vyneer committed Dec 11, 2023
1 parent c88d79d commit 96dd580
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 3 deletions.
9 changes: 8 additions & 1 deletion assets/chat/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,12 @@ hr {
}
}

.msg-death {
.text {
font-style: italic;
}
}

/* Highlight */
.msg-highlight {
color: $color-chat-text1;
Expand Down Expand Up @@ -845,7 +851,8 @@ hr {

.watching-focus {
.msg-emote,
.msg-user {
.msg-user,
.msg-death {
opacity: 0.3;

&.watching-same,
Expand Down
26 changes: 24 additions & 2 deletions assets/chat/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class Chat {
this.source.on('MASSGIFT', (data) => this.onMASSGIFT(data));
this.source.on('DONATION', (data) => this.onDONATION(data));
this.source.on('UPDATEUSER', (data) => this.onUPDATEUSER(data));
this.source.on('DEATH', (data) => this.onDEATH(data));

this.control.on('SEND', (data) => this.cmdSEND(data));
this.control.on('HINT', (data) => this.cmdHINT(data));
Expand Down Expand Up @@ -206,6 +207,9 @@ class Chat {
this.control.on('UNMOTD', () => this.cmdUNPIN());
this.control.on('HOST', (data) => this.cmdHOST(data));
this.control.on('UNHOST', () => this.cmdUNHOST());
this.control.on('DIE', () => this.cmdDIE());
this.control.on('SUICIDE', () => this.cmdDIE());
this.control.on('BITLY', () => this.cmdDIE());
}

setUser(user) {
Expand Down Expand Up @@ -736,11 +740,13 @@ class Chat {
MessageTypes.GIFTSUB,
MessageTypes.MASSGIFT,
MessageTypes.DONATION,
MessageTypes.DEATH,
].includes(message.type)
) {
// check if message is `/me `
// check if message is `/me ` or a death message
message.slashme =
message.message.substring(0, 4).toLowerCase() === '/me ';
message.message.substring(0, 4).toLowerCase() === '/me ' ||
message.type === MessageTypes.DEATH;
// check if this is the current users message
message.isown = message.user.username === this.user.username;
// get mentions from message
Expand Down Expand Up @@ -1435,6 +1441,18 @@ class Chat {
}
}

onDEATH(data) {
const user = this.users.get(data.nick) ?? new ChatUser(data.nick);
if (this.user.username === data.nick.toLowerCase()) {
if (isMuteActive(data)) {
this.mutedtimer.setTimer(data.duration);
this.mutedtimer.startTimer();
}
}
this.censor(data.nick);
MessageBuilder.death(data.data, user, data.timestamp).into(this);
}

cmdSHOWPOLL() {
if (this.chatpoll.poll) {
this.chatpoll.show();
Expand Down Expand Up @@ -2226,6 +2244,10 @@ class Chat {
this.source.send('PIN', { data: '' });
}

cmdDIE() {
this.source.send('DIE', { data: '' });
}

openConversation(nick) {
const normalized = nick.toLowerCase();
const conv = this.whispers.get(normalized);
Expand Down
5 changes: 5 additions & 0 deletions assets/chat/js/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const CHAT_COMMANDS = [
name: 'baninfo',
description: 'Check your ban status.',
},
{
name: 'die',
description: 'Mute yourself for 10 minutes.',
alias: ['suicide', 'bitly'],
},
{
name: 'embed',
description: 'Embed a video to bigscreen.',
Expand Down
1 change: 1 addition & 0 deletions assets/chat/js/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const errorstrings = new Map(
alreadyvoted: 'You have already voted!',
nochatting:
"You aren't allowed to chat. Either you haven't picked a username, or a mod disabled your privileges.",
cantbanprotected: "Protected users can't die.",
}),
);

Expand Down
2 changes: 2 additions & 0 deletions assets/chat/js/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ChatUserFocus {
rule = `.msg-user.${value}{opacity:1 !important;}`;
} else if (this.chat.settings.get('focusmentioned')) {
rule = `
.msg-death[data-username="${value}"], .msg-death[data-mentioned~="${value}"],
.msg-subscription[data-username="${value}"], .msg-subscription[data-mentioned~="${value}"],
.msg-giftsub[data-username="${value}"], .msg-giftsub[data-mentioned~="${value}"], .msg-giftsub[data-giftee="${value}"],
.msg-massgift[data-username="${value}"], .msg-massgift[data-mentioned~="${value}"],
Expand All @@ -58,6 +59,7 @@ class ChatUserFocus {
`;
} else {
rule = `
.msg-death[data-username="${value}"],
.msg-subscription[data-username="${value}"],
.msg-giftsub[data-username="${value}"], .msg-giftsub[data-giftee="${value}"],
.msg-massgift[data-username="${value}"],
Expand Down
13 changes: 13 additions & 0 deletions assets/chat/js/messages/ChatDeathMessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ChatUserMessage from './ChatUserMessage';
import MessageTypes from './MessageTypes';

export default class ChatDeathMessage extends ChatUserMessage {
constructor(message, user, timestamp = null) {
super(message, user, timestamp);
this.type = MessageTypes.DEATH;
}

html(chat = null) {
return super.html(chat);
}
}
5 changes: 5 additions & 0 deletions assets/chat/js/messages/MessageBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ChatDonationMessage from './ChatDonationMessage';
import ChatRegularSubscriptionMessage from './subscriptions/ChatRegularSubscriptionMessage';
import ChatGiftedSubscriptionMessage from './subscriptions/ChatGiftedSubscriptionMessage';
import ChatMassSubscriptionMessage from './subscriptions/ChatMassSubscriptionMessage';
import ChatDeathMessage from './ChatDeathMessage';

export default class MessageBuilder {
static element(message, classes = []) {
Expand Down Expand Up @@ -105,4 +106,8 @@ export default class MessageBuilder {
data.uuid,
);
}

static death(message, user, timestamp = null) {
return new ChatDeathMessage(message, user, timestamp);
}
}
1 change: 1 addition & 0 deletions assets/chat/js/messages/MessageTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export default {
GIFTSUB: 'GIFTSUB',
MASSGIFT: 'MASSGIFT',
DONATION: 'DONATION',
DEATH: 'DEATH',
};
1 change: 1 addition & 0 deletions assets/chat/js/messages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export {
default as PinnedMessage,
checkIfPinWasDismissed,
} from './PinnedMessage';
export { default as ChatDeathMessage } from './ChatDeathMessage';

0 comments on commit 96dd580

Please sign in to comment.