Bots Home
|
Create an App
Polytest2
Author:
polymathcs
Description
Source Code
Launch Bot
Current Users
Created by:
Polymathcs
/** * Created by polymath614 on 05/06/2017. * * This is an app for polling your users that takes mulitple tips as a votes though it is built for just two options at this time. */ // var appName = 'Multi tip poll' var pollNotice = ''; var pollSubject = ''; var fPollVotes = 0; var fPollAmount = 0; var fPollSubject = ''; var sPollVotes = 0; var sPollAmount = 0; var sPollSubject = ''; var moderator = false; var pollBackground = ''; var pollForeground = ''; var noticeRotation = ''; var CBdate = new Date(); cb.settings_choices = [ {name: 'pollSubject_CB', label: 'What is the purpose of your Poll?', type: 'str'}, {name: 'pollNotice_CB', label: 'What is a longer explination for the poll?', type: 'str'}, {name: 'fPollSubject', label: 'First Poll Subject?', type: 'str'}, {name: 'fPollAmount', label: 'How Much for the first poll?', type: 'int'}, {name: 'fPollVotes', label: 'How Many votes have been casted for the first poll?', type: 'int'}, {name: 'sPollSubject', label: 'Second poll subject?', type: 'str'}, {name: 'sPollAmount', label: 'How much for the second poll?', type: 'int'}, {name: 'sPollVotes', label: 'How Many votes have been casted for the second poll?', type: 'int'}, {name: 'noticeRotation', label: 'How often would you like the token poll notice to be advertised?', type: 'int'}, {name: 'pollBackground', label: 'What color would you like the background of the poll notice? (must enter as a hex color code with the #)', type: 'str', defaultValue: '#ff93be'}, {name: 'pollForeground', label: 'What color would you like the text of the poll notice? (must enter as a hex color code with the #)', type: 'str', defaultValue: '#ff0000'}, {name: 'adminBackground', label: 'What color would you like the background of the admins to be? (must enter as a hex color code with the #)', type: 'str', defaultValue: '#bfffc2'} ] function showResults (user) { var responseHeader = '--- The poll is for ' + pollSubject + '---\n'; var responseBody = fPollSubject + ' has ' + fPollVotes + ' votes \n' + sPollSubject + ' has ' + sPollVotes + ' votes \n'; var responseFooter = 'to see the poll status please enter !poll to vote simply tip the token amount or mutiples of that amount. warning amounts that are multiples of both will not count but can be add by a mod or model.'; if (fPollVotes > sPollVotes) { var responseBody = 'In first place ' + fPollSubject + ' has ' + fPollVotes + ' votes \n in Second place ' + sPollSubject + ' has ' + sPollVotes + ' votes \n'; cb.sendNotice(responseHeader + responseBody + responseFooter, user['user'], '#8dbaf4', '#ffffff') } else { var responseBody = 'In first place ' + sPollSubject + ' has ' + sPollVotes + ' votes \n in Second place ' + fPollSubject + ' has ' + fPollVotes + ' votes \n'; cb.sendNotice(responseHeader + responseBody + responseFooter, user['user'], '#8dbaf4', '#ffffff') } } function howToVote (user) { var responseHeader = '--- The poll is for ' + pollSubject + '---\n'; var responseFooter = 'to see the poll status please enter !poll to vote simply tip the token amount or mutiples of that amount. warning amounts that are multiples of both will not count but can be add by a mod or model.'; var responseBody = 'to Vote for ' + fPollSubject + ' please tip ' + fPollAmount + ' or you can tip in multiples of that ammount. \n' + 'to Vote For ' + sPollSubject + ' Please tip ' + sPollAmount + ' or you can tip in multiples of that ammount.'; cb.sendNotice(responseHeader + responseBody + responseFooter, user['user'], '#048e00', '#000000'); } function instToOne (user) { var responseHeader = '--- The poll is for ' + pollSubject + '---\n'; var responseFooter = 'to see the poll status please enter !poll. To vote simply tip the token amount or mutiples of that amount. warning amounts that are multiples of both will not count but can be add by a mod or model.'; if (fPollVotes > sPollVotes) { var responseBody = 'In first place ' + fPollSubject + ' has ' + fPollVotes + ' votes tip ' + fPollAmount + ' to vote for ' + fPollSubject + '\n in Second place ' + sPollSubject + ' has ' + sPollVotes + ' votes tip ' + sPollAmount + ' to vote for ' + sPollSubject + '\n'; cb.sendNotice(responseHeader + responseBody + responseFooter, user, '#8dbaf4', '#ffffff') } else { var responseBody = 'In first place ' + sPollSubject + ' has ' + sPollVotes + ' votes tip ' + sPollAmount + ' to vote for ' + sPollSubject + '\n in Second place ' + fPollSubject + ' has ' + fPollVotes + ' votes tip ' + fPollAmount + ' to vote for ' + fPollSubject + '\n'; cb.sendNotice(responseHeader + responseBody + responseFooter, user, '#8dbaf4', '#ffffff') } } function instToAll () { var responseHeader = '--- The poll is for ' + pollSubject + '---\n'; var responseFooter = 'to see the poll status please enter !poll. To vote simply tip the token amount or mutiples of that amount. warning amounts that are multiples of both will not count but can be add by a mod or model.'; if (fPollVotes > sPollVotes) { var responseBody = 'In first place ' + fPollSubject + ' has ' + fPollVotes + ' votes tip ' + fPollAmount + ' to vote for ' + fPollSubject + '\n in Second place ' + sPollSubject + ' has ' + sPollVotes + ' votes tip ' + sPollAmount + ' to vote for ' + sPollSubject + '\n'; cb.sendNotice(responseHeader + responseBody + responseFooter, '', '#8dbaf4', '#ffffff') } else { var responseBody = 'In first place ' + sPollSubject + ' has ' + sPollVotes + ' votes tip ' + sPollAmount + ' to vote for ' + sPollSubject + '\n in Second place ' + fPollSubject + ' has ' + fPollVotes + ' votes tip ' + fPollAmount + ' to vote for ' + fPollSubject + '\n'; cb.sendNotice(responseHeader + responseBody + responseFooter, '', '#8dbaf4', '#ffffff') } cb.setTimeout(instToAll, (60000 * parseInt(noticeRotation))); } cb.onMessage(function (msg) { msgUser = msg['user']; msgMsg = msg['m']; msgMod = (cb.room_slug == m['user'] || m['is_mod']); if (msgMsg.startsWith('/')) { msg['X-Spam'] = true; var msgArray = msgMsg.split(' '); if (msgMod) { switch (msgArray[0]) { case '/poll': instToAll(); break; case '/addvote': var voteSelect = msgArray[2]; var numVotes = msgArray[1]; if (fPollSubject.includes(voteSelect)) { fPollVotes = fPollVotes + parseInt(numVotes); cb.sendNotice(msgUser + ' has add ' + numVotes + ' votes to ' + fPollSubject, '', pollBackground, pollForeground) } else if (sPollSubject.includes(voteSelect)) { sPollVotes = sPollVotes + parseInt(numVotes); cb.sendNotice(msgUser + ' has add ' + numVotes + ' votes to ' + sPollSubject, '', pollBackground, pollForeground) } else { cb.sendNotice('There is something wrong with this command --->' + msgMsg + ' did not work if please try again', msgUser, pollBackground, pollForeground, 'red') } } } else { // non mods what it displays when they run a command switch (msgArray[0]) { case '/poll': case '/Poll': instToOne(msgUser); break; default: cb.sendNotice('i am Sorry but ' + msgArray[0] + ' is not a supported command for you.', msgUser, pollBackground, pollForeground); } } } else if (msgMsg.startsWith('!')) { // these messages go only to user that asked if a mod wants to send to all they can enter '/poll' msg['X-Spam'] = true; var msgArray = msgMsg.split(' '); switch (msgArray[0]) { case '!poll': case '!Poll': instToOne(msgUser); break; case '!stats': showResults(msgUser); break } } if (msg['user'] === 'polymath614' || msg['user'] === 'polymathcs' || msg['user'] === 'csimaniac614') { msg['background'] = '#8dbaf4'; return msg; } }); cb.onTip(function (tip) { var tipAmount = tip['amount']; var tipUser = tip['from_user']; var totalVotes = 0; if ((parseInt(tipAmount) % parseInt(fPollAmount) === 0) && (parseInt(tipAmount) % parseInt(sPollAmount) === 0)){ cb.sendNotice('You tipped a multiple of both of the options please inform a mod or model what you wanted to vote for', tipUser, pollBackground, pollForeground); cb.sendNotice(tipUser + ' tipped a multiple of both of the options please ask what the user wanted to vote for', cb.room_slug, pollBackground, pollForeground, 'red'); } else if (parseInt(tipAmount) % parseInt(fPollAmount) === 0) { totalVotes = parseInt(tipAmount) / parseInt(fPollAmount); cb.sendNotice(tipUser + ' has voted ' + totalVotes + ' times for ' + fPollSubject, '', pollBackground, pollForeground); fPollVotes = fPollVotes + totalVotes; } else if (parseInt(tipAmount) % parseInt(sPollAmount) === 0) { totalVotes = parseInt(tipAmount) / parseInt(sPollAmount); cb.sendNotice(tipUser + ' has voted ' + totalVotes + ' times for ' + sPollSubject, '', pollBackground, pollForeground); sPollVotes = sPollVotes + totalVotes; } else { //do nothing as this is all the other tips i mean this would be a good spot for a thank you } }) cb.onEnter(function(user) { //need to check if the user is a mod or model and show them the codes to make changes to the bot while it is running if (user['user'] === cb.room_slug || user['is_mod']) { moderator = true; cb.sendNotice(appName + ' is running you have the ability to add and subtract votes and possibly end the vote. ') } else { cb.sendNotice('Welcome to the room there is currently a poll running and at some point i will show you the results here.', user['user'], '#ff0000', '#0000000'); } }); function init() { pollNotice = cb.settings['pollNotice_CB']; pollSubject = cb.settings['pollSubject_CB']; fPollSubject = cb.settings['fPollSubject']; fPollAmount = cb.settings['fPollAmount']; fPollVotes = cb.settings['fPollVotes']; fPollVotes = parseInt(fPollVotes); sPollSubject = cb.settings['sPollSubject']; sPollAmount = cb.settings['sPollAmount']; sPollVotes = cb.settings['sPollVotes']; sPollVotes = parseInt(sPollVotes); pollBackground = cb.settings['pollBackground']; pollForeground = cb.settings['pollForeground']; noticeRotation = cb.settings['noticeRotation']; } cb.setTimeout(instToAll, (60000 * parseInt(noticeRotation))); init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.