This is the car.
window.botQueue = window.botQueue || {
queue: [],
processing: false,
minInterval: 7500,
lastSendTime: 0,
add: function(message) {
if (message.length > 250) {
message = message.substring(0, 247) + '...';
}
this.queue.push(message);
if (!this.processing) {
this.process();
}
},
process: function() {
var self = this;
if (this.queue.length === 0) {
this.processing = false;
return;
}
this.processing = true;
var now = Date.now();
var timeSinceLast = now - this.lastSendTime;
var delay = Math.max(this.minInterval, this.minInterval - timeSinceLast);
setTimeout(function() {
if (self.queue.length > 0) {
var message = self.queue.shift();
chatController.sendMessage(message);
self.lastSendTime = Date.now();
}
self.process();
}, delay);
}
};
Then the gas.
var nathanBot = {
keywords: [
{
triggers: [list of trigger words'],
replies: [your replies
]
},
lastMessageTime: Date.now(),
inactivityTimer: null,
inactivityThreshold: 120000,
inactivityInterval: 90000,
getReply: function(messageText) {
messageText = messageText.toLowerCase();
for (var i = 0; i < this.keywords.length; i++) {
var group = this.keywords[i];
for (var j = 0; j < group.triggers.length; j++) {
if (messageText.includes(group.triggers[j])) {
return group.replies[Math.floor(Math.random() * group.replies.length)];
}
}
}
return this.defaultReplies[Math.floor(Math.random() * this.defaultReplies.length)];
},
resetInactivityTimer: function() {
var self = this;
clearTimeout(this.inactivityTimer);
this.inactivityTimer = setTimeout(function() {
self.fireInactivity();
}, self.inactivityThreshold);
},
fireInactivity: function() {
var self = this;
window.botQueue.add(self.inactivityReplies[Math.floor(Math.random() * self.inactivityReplies.length)]);
self.inactivityTimer = setTimeout(function() {
self.fireInactivity();
}, self.inactivityInterval);
},
start: function() {
var self = this;
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
mutation.addedNodes.forEach(function(node) {
var $node = $(node);
var posterId = $node.data('chat-poster-id');
if (posterId && posterId !== chatController.currentUserId) {
self.resetInactivityTimer();
var messageText = $node.find('.js-chat-message-content').text();
var reply = self.getReply(messageText);
if (reply) window.botQueue.add(reply);
}
});
});
});
observer.observe(document.getElementById('chatMessagesBox'), { childList: true, subtree: true });
self.resetInactivityTimer();
window.botQueue.add("This is where you put the into text");
console.log("Your stupid ass chat bot is online.");
}
};
nathanBot.start();