-
-
Save relative2/d4b1083a4e879f0e0810fa8f6f13b4c9 to your computer and use it in GitHub Desktop.
A chat bot for the reddit 1. April chat (it just sends the time that is left until the room ends and can send you your color and the current votes)
This file contains 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
document.querySelector( '#robinChatMessageList' ).addEventListener( 'DOMSubtreeModified', function ( event ) { | |
var messages = event.target.querySelectorAll( '.robin-message' ); | |
var lastMessage = messages[ messages.length - 1 ]; | |
if ( lastMessage ) { | |
var author = lastMessage.querySelector( '.robin--username' ); | |
var message = lastMessage.querySelector( '.robin-message--message' ); | |
if ( message && message.innerHTML ) { | |
message_text = message.innerHTML.toLowerCase(); | |
if ( message_text.match( "!time" ) ) { | |
sendTimeLeft() | |
} else if ( message_text.match( "!code" ) ) { | |
sendMessage( "You can find the code here: https://gist.github.com/Lergin/30121e75e783562eaa20c854f4cbeea2" ) | |
} else if ( message_text.match( "!help" ) ) { | |
sendMessage( "time -> time till the room ends code -> links to the sourcecode color -> shows your color" ) | |
} else if ( message_text.match( /!colou*r/ ) || message_text.match("what[s]* [is ]*my colo") || message_text.match("what colo")) { | |
color = "yellow" | |
if ( lastMessage.classList.contains( 'robin--flair-class--flair-4' ) ) { | |
color = "blue" | |
} else if ( lastMessage.classList.contains( 'robin--flair-class--flair-5' ) ) { | |
color = "purple" | |
} else if ( lastMessage.classList.contains( 'robin--flair-class--flair-1' ) ) { | |
color = "orange" | |
} else if ( lastMessage.classList.contains( 'robin--flair-class--flair-2' ) ) { | |
color = "yellow" | |
} else if ( lastMessage.classList.contains( 'robin--flair-class--flair-3' ) ) { | |
color = "green" | |
} else if ( lastMessage.classList.contains( 'robin--flair-class--flair-0' ) ) { | |
color = "red" | |
} | |
sendMessage( "Your color is: " + color ) | |
} else if ( message_text.match( "!vote" ) ) { | |
var stay=0; | |
var grow=0; | |
var abond=0; | |
var noVote=0; | |
var user = r.config.robin_user_list; | |
for(member in user){ | |
if(user[member].vote == "CONTINUE"){ | |
stay++; | |
}else if(user[member].vote == "NOVOTE"){ | |
noVote++; | |
}else if(user[member].vote == "INCREASE"){ | |
grow++; | |
}else if(user[member].vote == "ABANDON"){ | |
abond++; | |
} | |
} | |
} | |
} | |
} | |
} ); | |
function sendTimeLeft() { | |
var timeRemaining = new Date( parseInt( r.config.robin_room_reap_time ) ) - Date.now(); | |
sendMessage( | |
"[TimeLeft] " + | |
Math.round( timeRemaining / 1000 / 60 ) + " minutes " + | |
"(" + new Date( parseInt( r.config.robin_room_reap_time ) ).toString().split( " " ).splice( 4, 2 ).join( " " ) + ") all functions: help" | |
) | |
} | |
function sendMessage( text ) { | |
new r.robin.models.RobinRoom( { | |
room_id: r.config.robin_room_id | |
} ).postMessage( text ); | |
} | |
setInterval( sendTimeLeft, 3 * 60 * 1000 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment