Created
December 11, 2018 16:49
-
-
Save prawnsalad/31ad29d029c7f44baf3a73c80621be86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (command === 'message') { | |
let isPrivateMessage = false; | |
let bufferName = event.from_server ? '*' : event.target; | |
// PMs should go to a buffer with the name of the other user | |
if (!event.from_server && event.target === client.user.nick) { | |
isPrivateMessage = true; | |
bufferName = event.nick; | |
} | |
// Chanserv sometimes PMs messages about a channel on join in the format of | |
// [#channel] welcome! | |
// Redirect these to #channel | |
if ( | |
event.nick.toLowerCase() === 'chanserv' && | |
isPrivateMessage && | |
event.message[0] === '[' | |
) { | |
bufferName = event.message.substr(1, event.message.indexOf(']') - 1); | |
} | |
// Notices from somewhere when we don't have an existing buffer for them should go into | |
// the server tab. ie. notices from servers | |
if (event.type === 'notice') { | |
let existingBuffer = state.getBufferByName(networkid, bufferName); | |
let noticeActiveBuffer = state.setting('noticeActiveBuffer'); | |
let activeBuffer = state.getActiveBuffer(); | |
let hasActiveBuffer = activeBuffer && activeBuffer.networkid === networkid; | |
// If we don't have a buffer for this notice sender, either show it in our active | |
// buffer or the server buffer | |
if (!existingBuffer) { | |
if (noticeActiveBuffer && hasActiveBuffer) { | |
bufferName = activeBuffer.name; | |
} else { | |
bufferName = '*'; | |
} | |
} | |
} | |
const PM_BLOCK_BLOCKED = false; | |
const PM_BLOCK_NOT_BLOCKED = true; | |
const PM_BLOCK_REQUIRES_CHECK = null; | |
let pmBlock = network.isNickExemptFromPmBlocks(event.nick); | |
let blockNewPms = state.setting('buffers.block_pms'); | |
let buffer = state.getBufferByName(networkid, bufferName); | |
let textFormatType = 'privmsg'; | |
if (event.type === 'action') { | |
textFormatType = 'action'; | |
} else if (event.type === 'notice') { | |
textFormatType = 'notice'; | |
} | |
let messageBody = TextFormatting.formatText(textFormatType, { | |
nick: event.nick, | |
username: event.ident, | |
host: event.hostname, | |
text: event.message, | |
}); | |
let message = { | |
time: event.time || Date.now(), | |
nick: event.nick, | |
message: messageBody, | |
type: event.type, | |
tags: event.tags || {}, | |
}; | |
// If this is a new PM and the sending user is not exempt from blocks, ignore it | |
if (blockNewPms && isPrivateMessage && !buffer && pmBlock === PM_BLOCK_BLOCKED) { | |
return; | |
} | |
if (blockNewPms && isPrivateMessage && !buffer && pmBlock === PM_BLOCK_REQUIRES_CHECK) { | |
network.pendingPms.push({ bufferName, message }); | |
network.ircClient.whois(event.nick, event.nick, (whoisData) => { | |
network.pendingPms.forEach((pm, idx, obj) => { | |
if (pm.message.nick === whoisData.nick) { | |
if (whoisData.operator) { | |
buffer = state.getOrAddBufferByName(network.id, pm.bufferName); | |
state.addMessage(buffer, pm.message); | |
} | |
obj.splice(idx, 1); | |
} | |
}); | |
}); | |
return; | |
} | |
// Make sure we have a buffer for our message | |
if (!buffer) { | |
buffer = state.getOrAddBufferByName(networkid, bufferName); | |
} | |
state.addMessage(buffer, message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment