Skip to content
This repository has been archived by the owner on May 23, 2022. It is now read-only.

Commit

Permalink
Added CTCP TIME support, fixed the CTCP VERSION command from not work…
Browse files Browse the repository at this point in the history
…ing properly (I'm a dummy). Made PMs show in the sources list. Made it work quite a lot better too
  • Loading branch information
Madison Tries committed Feb 28, 2016
1 parent 3f41176 commit e788984
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 8 deletions.
37 changes: 36 additions & 1 deletion src/client/js/modules/Incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class Incoming {
ping: () => {},

privmsg: () => {
// Check if the message is from the server
if (_data.prefix === _data.server) {
_data.args[0] = 'server';
}

// Detect if the message is a CTCP
if (_data.args[1].startsWith('\x01') && _data.args[1].endsWith('\x01')) {
// If its an ACTION message (/me)
Expand All @@ -58,7 +63,7 @@ class Incoming {
this.addMessage({
type: 'privmsg',
channel: _data.nick,
icon: ['fa-angle-double-right', 'Action'],
icon: ['fa-angle-double-right', 'Version'],
message: `Recieved a CTCP VERSION from ${_data.nick}`,
isHighlightable: true,
});
Expand All @@ -69,6 +74,22 @@ class Incoming {
_data.nick,
`VERSION Maid-IRC ${Maid.version}`,
]);
} else if (_data.args[1].startsWith('\x01TIME')) {
// Display the CTCP VERSION request
this.addMessage({
type: 'privmsg',
channel: _data.nick,
icon: ['fa-clock-o', 'Time'],
message: `Recieved a CTCP TIME from ${_data.nick}`,
isHighlightable: true,
});

// Respond
connections.send('send-raw', [
'NOTICE',
_data.nick,
`TIME ${new Date}`,
]);
}
} else {
// Normal message
Expand All @@ -83,6 +104,20 @@ class Incoming {
},

notice: () => {
// Check if the message is from the server
if (
_data.prefix === _data.server
|| ['chanserv', 'nickserv'].indexOf(_data.nick.toLowerCase()) >= 0
// TODO: Check what services the network supports
) {
_data.args[0] = 'server';
}

// Check if it's a PM
if (_data.args[0] === network.nick) {
_data.args[0] = _data.nick;
}

this.addMessage({
type: 'notice',
channel: _data.args[0],
Expand Down
5 changes: 5 additions & 0 deletions src/client/js/modules/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class Message {
output.removeChild(select('article.filler'));
}

// Make sure the source is displayed in the list
if (!Maid.sessions[this.connectionId].sources[this.channel]) {
sources.addToList(this.connectionId, this.channel);
}

// Insert message into the console
output.insertAdjacentHTML('beforeend', Maid.Templates['src/client/views/message.hbs']({
connectionId: this.connectionId,
Expand Down
37 changes: 35 additions & 2 deletions src/client/js/modules/Outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class Outgoing {
},

version: () => {
// Verify that the user specified a target
if (!_args.split(' ')[0]) {
return;
}

const message = {
type: 'privmsg',
icon: ['fa-angle-double-right', 'VERSION'],
Expand All @@ -35,7 +40,30 @@ class Outgoing {
NewMessage.display();

// Send message data to the server
connections.send('send-raw', ['PRIVMSG', Maid.focusedSource, _args]);
connections.send('send-raw', ['PRIVMSG', _args.split(' ')[0], '\x01VERSION\x01']);
},

time: () => {
// Verify that the user specified a target
if (!_args.split(' ')[0]) {
return;
}

const message = {
type: 'privmsg',
icon: ['fa-angle-double-right', 'TIME'],
head: `To ${_args.split(' ')[0]}`,
channel: Maid.focusedSource,
message: 'CTCP TIME',
};

// Display the message
const NewMessage = new Message(message, Maid.focusedServer);
NewMessage.filter();
NewMessage.display();

// Send message data to the server
connections.send('send-raw', ['PRIVMSG', _args.split(' ')[0], '\x01TIME\x01']);
},
};

Expand All @@ -49,7 +77,12 @@ class Outgoing {
}

// List of supported commands
const commands = ['me', 'join', 'part', 'whois', 'notice', 'away', 'topic'];
const commands = [
// CTCP
'me', 'version', 'time',
// Core
'join', 'part', 'whois', 'notice', 'away', 'topic',
];
const message = data.substring(data.split(' ')[0].length + 1, data.length);
const command = data.split(' ')[0].toLowerCase();

Expand Down
20 changes: 15 additions & 5 deletions src/client/js/modules/Sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@ class Sources {
this.addServer(networkId);
}

// Don't display duplicates
if (select(`${networkSelector} li[data-source="${source}"]`) || source === 'server') {
return;
}

// Determin what the type of source provided
let type = 'channel';

if (['#', '&', '!', '+'].indexOf(source.charAt(0)) === -1) {
// TODO: Figure out how to determin if the message is from the server or a person (PM)
type = 'server';
if (source === 'server') {
type = 'server';
} else {
type = 'other';
}
}

const chosenNetwork = Maid.sessions[networkId];
Expand Down Expand Up @@ -135,18 +144,19 @@ class Sources {
select('#users').style.display = 'none';
break;
}
default: {
case 'other': {
// Update displayed focused source in the networks panel
select(`${networkSelector} header`).classList.add('focusedSource');
select(`${networkSelector} ul li[data-source="${source}"]`).classList.add('focusedSource');

// Change header input value to "unknown"
select('#channel-console header input').value = 'Unknown';
// Change header input value to the name of the server
select('#channel-console header input').value = source;

// Disable the user from being able to edit the topic (there is no point to)
select('#channel-console header input').disabled = true;

// Hide the users list
select('#users').style.display = 'none';
break;
}
}

Expand Down

0 comments on commit e788984

Please sign in to comment.