Skip to content

Commit

Permalink
Substitution by message id
Browse files Browse the repository at this point in the history
  • Loading branch information
kendfrey committed Jan 16, 2015
1 parent 4073be4 commit 835ed87
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
25 changes: 18 additions & 7 deletions master.js
Expand Up @@ -5737,9 +5737,13 @@ bot.addCommand( statsCmd );
( #flag capturing group
g? #global (optional)
i? #case insensitive (optional)
) #FIN
)
(?:
\s+
(\d+) #message id
)? #FIN
*/
var sub = /^\s*s(\/|\|)((?:(?:\\\1)|[^\1])*?)\1((?:(?:\\\1)|[^\1])*?)\1(g?i?)/;
var sub = /^\s*s(\/|\|)((?:(?:\\\1)|[^\1])*?)\1((?:(?:\\\1)|[^\1])*?)\1(g?i?)(?:\s+(\d+))?/;
bot.listen( sub, substitute );

function substitute ( msg ) {
Expand All @@ -5750,7 +5754,17 @@ function substitute ( msg ) {
return 'Empty regex is empty';
}

getMatchingMessage( re, msg.get('message_id'), function ( err, message ) {
var messages;
if ( msg.matches[5] ) {
messages = Array.from(
document.querySelectorAll('#message-' + msg.matches[5] + ' .content') );
}
else {
messages = Array.from(
document.getElementsByClassName('content') ).reverse();
}

getMatchingMessage( re, messages, msg.get('message_id'), function ( err, message ) {
if ( err ) {
msg.reply( err );
return;
Expand Down Expand Up @@ -5783,10 +5797,7 @@ function substitute ( msg ) {
});
}

function getMatchingMessage ( re, onlyBefore, cb ) {
var messages = Array.from(
document.getElementsByClassName('content') ).reverse();

function getMatchingMessage ( re, messages, onlyBefore, cb ) {
var arg = {
maxId : onlyBefore,
pattern : re,
Expand Down

0 comments on commit 835ed87

Please sign in to comment.