Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.

Commit 4fd2420

Browse files
author
Zirak
committed
Merge branch 'master' of git://github.com/kendfrey/SO-ChatBot into kendfrey-master
2 parents d017f0a + 835ed87 commit 4fd2420

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

master.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5737,9 +5737,13 @@ bot.addCommand( statsCmd );
57375737
( #flag capturing group
57385738
g? #global (optional)
57395739
i? #case insensitive (optional)
5740-
) #FIN
5740+
)
5741+
(?:
5742+
\s+
5743+
(\d+) #message id
5744+
)? #FIN
57415745
*/
5742-
var sub = /^\s*s(\/|\|)((?:(?:\\\1)|[^\1])*?)\1((?:(?:\\\1)|[^\1])*?)\1(g?i?)/;
5746+
var sub = /^\s*s(\/|\|)((?:(?:\\\1)|[^\1])*?)\1((?:(?:\\\1)|[^\1])*?)\1(g?i?)(?:\s+(\d+))?/;
57435747
bot.listen( sub, substitute );
57445748

57455749
function substitute ( msg ) {
@@ -5750,7 +5754,17 @@ function substitute ( msg ) {
57505754
return 'Empty regex is empty';
57515755
}
57525756

5753-
getMatchingMessage( re, msg.get('message_id'), function ( err, message ) {
5757+
var messages;
5758+
if ( msg.matches[5] ) {
5759+
messages = Array.from(
5760+
document.querySelectorAll('#message-' + msg.matches[5] + ' .content') );
5761+
}
5762+
else {
5763+
messages = Array.from(
5764+
document.getElementsByClassName('content') ).reverse();
5765+
}
5766+
5767+
getMatchingMessage( re, messages, msg.get('message_id'), function ( err, message ) {
57545768
if ( err ) {
57555769
msg.reply( err );
57565770
return;
@@ -5783,10 +5797,7 @@ function substitute ( msg ) {
57835797
});
57845798
}
57855799

5786-
function getMatchingMessage ( re, onlyBefore, cb ) {
5787-
var messages = Array.from(
5788-
document.getElementsByClassName('content') ).reverse();
5789-
5800+
function getMatchingMessage ( re, messages, onlyBefore, cb ) {
57905801
var arg = {
57915802
maxId : onlyBefore,
57925803
pattern : re,

0 commit comments

Comments
 (0)