Bots Home
|
Create an App
solsexyhot
Author:
solsexyhot
Description
Source Code
Launch Bot
Current Users
Created by:
Solsexyhot
// LovelyAnne's Event Countdown chat enhancement bot // // Author: mark54321 // Version: 1.0 // // The main function of this bot is to periodically promote LovelyAnne's birthday party. // // LovelyAnne can set: // // * The date of the event // * The time of the event // * The time interval between message displays // * Up to 5 messages the bot will rotate through, displaying one at each time interval // var laEventCountdownBot = function () { 'use strict'; var appName = "LovelyAnne's Birthday Party Countdown bot", self, millisecondsPerDay = 60*1000*60*24, millisecondsPerHour = 60*1000*60, timerSet = false, interval = 60000, intervalCounter = 0, intervalMinutes, currentMsgIndex = 0, msgs = [], eventDateTime = null, eventDate = null, eventTime = null, eventTZ = null, replacements = { "%date%": "", "%time%": "", "%tz%": "", "%event%": "" }, // Fore- and background colors for different chot notices msgColors = { info:{background: "#ffffff", color: "#000090", weight:"normal"}, notice:{background: "#ffffff", color: "#aa0303", weight:"bold"}, warn:{background: "#cc6600", color: "#ffffff", weight:"normal"}, important:{background: "#aa0303", color: "#ffffff", weight:"bold"}, entered: {background: "#03aa03", color: "#ffffff", weight:"normal"} }; return { // Initializes the app // This should be called after the broadcaster settting have been made init: function () { cb.log("init"); self = this; self.initDateTime(); self.initMessages(); self.initTimer(cb.settings.interval); }, // Initializes the message interval from teh settings initDateTime: function () { cb.log("initDateTime"); eventDate = cb.settings ? cb.settings.date : null; eventTime = cb.settings ? cb.settings.time : null; eventTZ = cb.settings ? cb.settings.timeZone : null; if (eventDate) { var standardTime = eventTime.replace('.', ':'), dtString = eventDate + "T" + standardTime; if (self.isDaylight(eventDate)) { dtString += "+0300"; } else { dtString += "+0200"; } cb.log("initDateTime: " + dtString); eventDateTime = new Date(dtString); } }, // Returns true if the date string falls within daylight savings timeZone isDaylight: function (yearMonthDay) { //Set the time to noon and add TZ. Helps solve issue where it is the changeover day // but the server date/time is (way) behind the tested date making the date "yesterday" instead. var dt = new Date(yearMonthDay + "T12:00:00+0200"), month = dt.getMonth() + 1, // Month returned is zero-based date = dt.getDate(), dayOfWeek = dt.getDay(), // 0-based starting on Sunday daysLeftInMonth, daysToNextSunday; // Must be between end of march and end of october (last sunday of each) if (month > 3 && month < 11) { cb.log("isDaylight: true"); return true; } if (month == 3 || month == 10) { // To have a chance the date must be between the 26th and the 31st if (date > 25) { // Basically just need to check if the date is on or after the last // sunday of the month. daysLeftInMonth = 31 - date + 1; // Plus 1 to include the current day daysToNextSunday = 7 - dayOfWeek; if (daysLeftInMonth < daysToNextSunday) { cb.log("isDaylight: true"); return true; } } } cb.log("isDaylight: false"); return false; }, // Initializes the messages to display, doing variable replacement as needed initMessages: function () { self.initReplacementVariables(); var msgName, i; for(i = 1; i <= 5; i += 1) { msgName = "msg" + i; if (cb.settings[msgName] && cb.settings[msgName].length) { msgs.push(self.replaceVariables(cb.settings[msgName])); } } }, // Initislizes the replacement variables initReplacementVariables: function () { replacements["%date%"] = cb.settings ? cb.settings.date : null; replacements["%time%"] = cb.settings ? cb.settings.time : null; replacements["%tz%"] = cb.settings ? cb.settings.timeZone : null; replacements["%event%"] = cb.settings ? cb.settings.eventName : null; }, // Performs any variable replacement and returns the update string replaceVariables: function (msg) { var newMsg = msg, replacement; for (replacement in replacements) { newMsg = newMsg.replace(replacement, replacements[replacement]); } return newMsg; }, // Sets up and returns the broadcaster bot settings template getSettingChoices: function () { self = this; return [ { name: 'date', label: 'Enter the date of the event in the form YYYY-MM-DD, i.e. 2015-07-29', type: 'str', minLength: 10, maxLength: 10, required: true, defaultValue: "2015-07-29" }, { name: "time", label: "Enter the time of the event (24-hour clock) in the form HH.MM, i.e. 21.30", type: 'str', minLength: 5, maxLength: 5, required: true, defaultValue: "20.00" }, { name: "timeZone", label: "Enter the timezone of the event", type: 'str', minLength: 3, maxLength: 5, required: true, defaultValue: "EET" }, { name: "interval", label: "Select the time, in minutes, between display of messages", type: "choice", choice1: "5", choice2: "10", choice3: "15", choice4: "30", choice5: "45", choice6: "60", choice7: "1", defaultValue: "15" }, { name: "eventName", label: "Enter the name of the event", type: "str", maxLength: 256, required: true, defaultValue: "LovelyAnne's Birthday SuperParty" }, { name: "msg1", label: "Enter the first message to be displayed", type: "str", maxLength: 256, required: true, defaultValue: "Come party with LovelyAnne to celebrate her birthday :woohoo" }, { name: "msg2", label: "Enter the second message to be displayed (Optional)", type: "str", maxLength: 256, required: false, defaultValue: "Don't miss %event% on %date%, %time% (%tz%)" }, { name: "msg3", label: "Enter the third message to be displayed (Optional)", type: "str", maxLength: 256, required: false, defaultValue: "%event% on %date%, %time% (%tz%). Save the date! :mok" }, { name: "msg4", label: "Enter the fourth message to be displayed (Optional)", type: "str", maxLength: 256, required: false, defaultValue: ":noo you would have said if you missed %event% on %date%, %time% (%tz%)" }, { name: "msg5", label: "Enter the fifth message to be displayed (Optional)", type: "str", maxLength: 256, required: false, defaultValue: "Plenty of thrills, and spills :haha at %event%" } ]; }, // Helper function to initialize the timer initTimer: function () { cb.log("initTimer"); intervalMinutes = cb.settings.interval; // Set up the timer if (typeof intervalMinutes === 'undefined') { cb.log("initTimer: No interval set. Using default (15 minutes)."); intervalMinutes = 15; } else { cb.log("initTimer: Have interval: " + intervalMinutes); } if (!timerSet) { cb.log("initTimer: Setting timeout: " + interval); cb.setTimeout(self.onTimer, interval); timerSet = true; } }, // Our "on timer" callback onTimer: function () { cb.log("onTimer"); if (self.shouldDisplayMessage()) { cb.log("onTimer: Sending messages."); var index = currentMsgIndex % msgs.length; currentMsgIndex += 1; self.sendNotice(msgs[index]); // Send the countdown string self.sendCountdownNotice(); } intervalCounter += 1; cb.log("onTimer: Setting timeout: " + interval); cb.setTimeout(self.onTimer, interval); cb.log("onTimer: Timeout set: " + interval); }, // Returns true if we should display the message shouldDisplayMessage: function () { cb.log("shouldDisplayMessage: intervalCounter: " + intervalCounter); cb.log("shouldDisplayMessage: intervalMinutes: " + intervalMinutes); cb.log("shouldDisplayMessage: " + ((intervalCounter % intervalMinutes) == 0 ? "true" : "false")); return !self.isEventPassed() && (intervalCounter % intervalMinutes) == 0; }, // Sends the countdown message as a chat notice sendCountdownNotice: function () { cb.log("sendCountdownNotice"); // Get current date/time as unix timestamp var currentDate = new Date().getTime(), partyDate = eventDateTime.getTime(), daysToEvent, hoursToEvent, minutesToEvent, msg; daysToEvent = (partyDate - currentDate) / millisecondsPerDay; hoursToEvent = (partyDate - currentDate) / millisecondsPerHour; cb.log("sendCountdownNotice: Days to: " + daysToEvent); cb.log("sendCountdownNotice: Hours to: " + hoursToEvent); cb.log("sendCountdownNotice: Now: " + new Date().toISOString()); cb.log("sendCountdownNotice: PartyDate: " + eventDateTime.toISOString()); if (hoursToEvent < 1) { minutesToEvent = (partyDate - currentDate) / 60000; msg = "Mere minutes until " + replacements["%event%"]; } else if (daysToEvent < 1) { msg = "Only " + (Math.floor(hoursToEvent) + 1) + " hours until " + replacements["%event%"]; } else if (daysToEvent < 7) { msg = "Only " + (Math.floor(daysToEvent) + 1) + " days until " + replacements["%event%"]; } else { msg = Math.floor(daysToEvent) + 1 + " days until " + replacements["%event%"]; } self.sendNotice(msg); }, // Returns true if the event date/time has passed isEventPassed: function () { cb.log("isEventPassed"); var now = new Date().getTime(), partyDate = eventDateTime.getTime(); cb.log("isEventPassed now: " + now); cb.log("isEventPassed partyDate: " + partyDate); return now > partyDate; }, // Helper function to send a chat notice with specific colors sendNotice: function (text, username) { cb.sendNotice(text, username, msgColors.notice.background, msgColors.notice.color, msgColors.notice.weight); }, }; }; // Create the app var theApp = new laEventCountdownBot(); // Setup the broadcaster settings cb.settings_choices = theApp.getSettingChoices(); // Initialize the app theApp.init();
© Copyright Freesexcam 2011- 2024. All Rights Reserved.