Bots Home
|
Create an App
Blyster
Author:
blyster111
Description
Source Code
Launch Bot
Current Users
Created by:
Blyster111
class Person { constructor(nick, points) { this.nick = nick; this.points = points; this.count = 1; this.level = 0; } } var People = []; var ActualMode = 1; var Progress_Mode_Points = 0; var Progress_Mode_Decrease = 0; var Progress_Mode_ActualLevel = 0; var Started = false; var Last_Donator_Nick = "---"; var Last_Donator_Level = 0; var Last_Donator_Amount = 0; //=================================== function GetPercentFromPoints(points) { for(i = 100;i>= 20;i-= 20) { var pointsForLevel = parseInt(cb.settings["Progress_Mode_" + i + "%"]); if(points >= pointsForLevel) { return i; } } return 0; } //=================================== function Donated(nick, points) { if(Started) { Last_Donator_Nick = nick; Last_Donator_Amount = points; var person_found = false; var his_count = 1; var his_total = points; var donator; for(i = 0;i< People.length;i++) { if(People[i].nick == nick) { donator = People[i]; person_found = true; People[i].points += points; People[i].count ++; his_total = People[i].points; his_count = People[i].count; } } if(!person_found) { donator = new Person(nick, points); People.push(donator); } Last_Donator_Level = donator.level; if(ActualMode == 1) { var max_level = parseInt(cb.settings["Max_Level"]); if(donator.level < max_level) { var old_level = donator.level; var new_level = donator.level; for(i = max_level;i>= 1;i--) { if(donator.points >= parseInt(cb.settings["Level_" + i + "_From"])) { new_level = i; break; } } if(old_level != new_level) { donator.level = new_level; if(cb.settings["Send_LevelUp_Messages"] == "Yes") { Notice(nick, cb.settings["Level_" + new_level + "_LevelUp_Message"], cb.settings["Level_" + new_level + "_Text_Background"], cb.settings["Level_" + new_level + "_Text_Color"], "bolder"); } if(cb.settings["Send_RankUp_Global_Messages"] == "Yes") { var Result2 = cb.settings["RankUp_Global_Message"]; Result2 = Result2.replace("%nick%", nick); Result2 = Result2.replace("%levelname%", cb.settings["Level_" + new_level + "_Name"]); Notice("", Result2, cb.settings["Level_" + new_level + "_Text_Background"], cb.settings["Level_" + new_level + "_Text_Color"], "bolder"); } } else { if(cb.settings["Send_Thx_Messages"] == "Yes") { var Response = cb.settings["Level_" + new_level + "_Thx_Message"]; Response = Response.replace("%1", donator.points); Response = Response.replace("%2", cb.settings["Level_" + new_level + "_To"]); Notice(nick, Response, cb.settings["Level_" + new_level + "_Text_Background"], cb.settings["Level_" + new_level + "_Text_Color"], "bolder"); } } } else { if(cb.settings["Send_Thx_Messages"] == "Yes") { var Response = cb.settings["Level_" + max_level + "_Thx_Message"]; Response = Response.replace("%1", donator.points); Response = Response.replace("%2", cb.settings["Level_" + max_level + "_To"]); Notice(nick, Response, cb.settings["Level_" + max_level + "_Text_Background"], cb.settings["Level_" + max_level + "_Text_Color"], "bolder"); } } } else if(ActualMode == 2) { Progress_Mode_Points += points; var newLevel = GetPercentFromPoints(Progress_Mode_Points); if(Progress_Mode_ActualLevel < newLevel) { Progress_Mode_ActualLevel = newLevel; var Response2 = cb.settings["Progress_Mode_RankUp_To_" + newLevel + "_Message"]; Response2 = Response2.replace("%nick%", nick); Notice("", Response2, "#ffffff", "#750177", "bolder"); }else{ var Response = cb.settings["Progress_Mode_Global_Donate_Message"]; Response = Response.replace("%nick%", nick); Response = Response.replace("%points%", points); Response = Response.replace("%speed%", Progress_Mode_ActualLevel); Response = Response.replace("%progress%", Mode2_GetActualProgress()); Notice("", Response, "#ffffff", "#750177", "bolder"); } } DonateResponse(nick, points, his_total, his_count, donator.level); } } function Mode2_GetActualProgress() { var progress_from = Progress_Mode_Points; var progress_to = 0; if(Progress_Mode_ActualLevel < 100) { progress_to = parseInt(cb.settings["Progress_Mode_" + (Progress_Mode_ActualLevel + 20) + "%"]); } else { progress_to = parseInt(cb.settings["Progress_Mode_100%"]); } return progress_from + " / " + progress_to; } //=============================== function Level_MinValue(levelid) { var max_level = parseInt(cb.settings["Max_Level"]); if(levelid <= max_level) { return parseInt(cb.settings["Level_" + levelid + "_From"]); } else { return 10000; } } //=============================== function Level_MaxValue(levelid) { var max_level = parseInt(cb.settings["Max_Level"]); if(levelid <= max_level) { return parseInt(cb.settings["Level_" + levelid + "_To"]); } else { return 10000; } } //=============================== function DonateResponse(nick, points, totalpoints, donatecount, hislevel) { ToArduino("DonateInformation;" + nick + ";" + points + ";" + totalpoints + ";" + donatecount + ";" + hislevel + ";"); } //=============================== var MessageID = 0; function ToArduino(message) { MessageID++; var random = new Number(new Date().valueOf()) + new Number(MessageID); cb.sendNotice(random + ";" + message, cb.room_slug, "#ffffff", "#fffffc", "normal", null); } function Notice(touser, message, bgcolor, color, style) { cb.sendNotice(message, touser, bgcolor, color, style, null); } //=============================== cb.onMessage(function (message) { if (message['m'] == '/connect' && message['user'] == cb.room_slug) { message['X-Spam'] = true; ToArduino("ConnectedInformation"); } else if (message['m'] == '/toystart' && message['user'] == cb.room_slug) { Started = true; message['X-Spam'] = true; ToArduino("ToyStarted;1"); } else if (message['m'] == '/toystop' && message['user'] == cb.room_slug) { Started = false; message['X-Spam'] = true; ToArduino("ToyStopped;1"); } else if (message['m'] == '/levelmode' && message['user'] == cb.room_slug) { Started = false; ActualMode = 1; message['X-Spam'] = true; ToArduino("LevelMode;1"); } else if (message['m'] == '/progressmode' && message['user'] == cb.room_slug) { Started = false; Progress_Mode_Points = 0; ActualMode = 2; Progress_Mode_Decrease = parseInt(cb.settings["Progress_Mode_Decrease_Pre_Second"]); message['X-Spam'] = true; ToArduino("ProgressMode;" + cb.settings["Progress_Mode_20%"] + ";" + cb.settings["Progress_Mode_40%"] + ";" + cb.settings["Progress_Mode_60%"] + ";" + cb.settings["Progress_Mode_80%"] + ";" + cb.settings["Progress_Mode_100%"] + ";" + cb.settings["Progress_Mode_Decrease_Pre_Second"] + ";"); } else if (message['m'] == '/pcconnected' && message['user'] == cb.room_slug) { var statsstring = ""; if(Started) statsstring += "1;"; else statsstring += "0;"; statsstring += ActualMode + ";" + cb.settings["Progress_Mode_20%"] + ";" + cb.settings["Progress_Mode_40%"] + ";" + cb.settings["Progress_Mode_60%"] + ";" + cb.settings["Progress_Mode_80%"] + ";" + cb.settings["Progress_Mode_100%"] + ";" + cb.settings["Progress_Mode_Decrease_Pre_Second"] + ";" + Progress_Mode_Points + ";" + Last_Donator_Nick + ";" + Last_Donator_Amount + ";" + Last_Donator_Level + ";"; for(i = 0;i< People.length;i++) { statsstring += People[i].nick + "|" + People[i].points + "|" + People[i].level + "|;"; } ToArduino("Stats;" + statsstring); } else if (message['m'] == '/resetdonations' && message['user'] == cb.room_slug) { People.length = 0; ToArduino("DonationsResetOk;"); } else { Donated(message.user, 10); } }); cb.onTip(function (tip) { var amount = parseInt(tip['amount']); var from_user = tip['from_user']; Donated(from_user, amount); }); cb.settings_choices = [ {name:'Send_LevelUp_Messages', type:'choice', choice1:'Yes', choice2:'No', defaultValue: 'Yes'}, {name:'Send_Thx_Messages', type:'choice', choice1:'Yes', choice2:'No', defaultValue: 'Yes'}, {name: 'Max_Level', type: 'int', minValue: 1, maxValue: 6, defaultValue:6}, {name: 'Level_1_Name', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Level 1 [ 1-14 ]'}, {name: 'Level_1_LevelUp_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Now you are Level 1 !'}, {name: 'Level_1_Thx_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Thx ! Progress: %1 / %2'}, {name: 'Level_1_From', type: 'int', minValue: 1, maxValue: 99999, defaultValue:1}, {name: 'Level_1_To', type: 'int', minValue: 1, maxValue: 99999, defaultValue:14}, {name: 'Level_1_Text_Background', type: 'str', minLength: 1, maxLength: 255, defaultValue:'#6d025d'}, {name: 'Level_1_Text_Color', type: 'str', minLength: 1, maxLength: 255, defaultValue:'#ffffff'}, {name: 'Level_2_Name', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Level 2 [ 15-29 ]'}, {name: 'Level_2_LevelUp_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Now you are Level 2 !'}, {name: 'Level_2_Thx_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Thx much ! Progress: %1 / %2'}, {name: 'Level_2_From', type: 'int', minValue: 1, maxValue: 99999, defaultValue:15}, {name: 'Level_2_To', type: 'int', minValue: 1, maxValue: 99999, defaultValue:29}, {name: 'Level_2_Text_Background', type: 'str', minLength: 1, maxLength: 255, defaultValue:'#6d025d'}, {name: 'Level_2_Text_Color', type: 'str', minLength: 1, maxLength: 255, defaultValue:'#ffffff'}, {name: 'Level_3_Name', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Level 3 [ 30-49 ]'}, {name: 'Level_3_LevelUp_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Now you are Level 3 !'}, {name: 'Level_3_Thx_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Thx very much ! Progress: %1 / %2'}, {name: 'Level_3_From', type: 'int', minValue: 1, maxValue: 99999, defaultValue:30}, {name: 'Level_3_To', type: 'int', minValue: 1, maxValue: 99999, defaultValue:49}, {name: 'Level_3_Text_Background', type: 'str', minLength: 1, maxLength: 255, defaultValue:'#6d025d'}, {name: 'Level_3_Text_Color', type: 'str', minLength: 1, maxLength: 255, defaultValue:'#ffffff'}, {name: 'Level_4_Name', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Level 4 [ 50-99 ]'}, {name: 'Level_4_LevelUp_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Now you are Level 4 !'}, {name: 'Level_4_Thx_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Thx very very much ! Progress: %1 / %2'}, {name: 'Level_4_From', type: 'int', minValue: 1, maxValue: 99999, defaultValue:50}, {name: 'Level_4_To', type: 'int', minValue: 1, maxValue: 99999, defaultValue:99}, {name: 'Level_4_Text_Background', type: 'str', minLength: 1, maxLength: 255, defaultValue:'#6d025d'}, {name: 'Level_4_Text_Color', type: 'str', minLength: 1, maxLength: 255, defaultValue:'#ffffff'}, {name: 'Level_5_Name', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Level 5 [ 100-199 ]'}, {name: 'Level_5_LevelUp_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Now you are Level 5 !'}, {name: 'Level_5_Thx_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Thx very very very much ! Progress: %1 / %2'}, {name: 'Level_5_From', type: 'int', minValue: 1, maxValue: 99999, defaultValue:100}, {name: 'Level_5_To', type: 'int', minValue: 1, maxValue: 99999, defaultValue:199}, {name: 'Level_5_Text_Background', type: 'str', minLength: 1, maxLength: 255, defaultValue:'#6d025d'}, {name: 'Level_5_Text_Color', type: 'str', minLength: 1, maxLength: 255, defaultValue:'#ffffff'}, {name: 'Level_6_Name', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Level 6 [ 200-9999 ]'}, {name: 'Level_6_LevelUp_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Now you are Level 6'}, {name: 'Level_6_Thx_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'Thx very very very very much ! Progress: %1 / %2'}, {name: 'Level_6_From', type: 'int', minValue: 1, maxValue: 99999, defaultValue:200}, {name: 'Level_6_To', type: 'int', minValue: 1, maxValue: 99999, defaultValue:9999}, {name: 'Level_6_Text_Background', type: 'str', minLength: 1, maxLength: 255, defaultValue:'#6d025d'}, {name: 'Level_6_Text_Color', type: 'str', minLength: 1, maxLength: 255, defaultValue:'#ffffff'}, {name: 'RankUp_Global_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'%nick% ranked up to %levelname% !'}, {name: 'Send_RankUp_Global_Messages', type:'choice', choice1:'Yes', choice2:'No', defaultValue: 'Yes'}, {name: 'Progress_Mode_20%', type: 'int', minValue: 1, maxValue: 99999, defaultValue:100}, {name: 'Progress_Mode_40%', type: 'int', minValue: 1, maxValue: 99999, defaultValue:200}, {name: 'Progress_Mode_60%', type: 'int', minValue: 1, maxValue: 99999, defaultValue:300}, {name: 'Progress_Mode_80%', type: 'int', minValue: 1, maxValue: 99999, defaultValue:400}, {name: 'Progress_Mode_100%', type: 'int', minValue: 1, maxValue: 99999, defaultValue:500}, {name: 'Progress_Mode_RankUp_To_20_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'The toy speed is set to 20% now ! Thanks to %nick% ...'}, {name: 'Progress_Mode_RankUp_To_40_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'The toy speed is set to 40% now ! Thanks to %nick% ...'}, {name: 'Progress_Mode_RankUp_To_60_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'The toy speed is set to 60% now ! Thanks to %nick% ...'}, {name: 'Progress_Mode_RankUp_To_80_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'The toy speed is set to 80% now ! Thanks to %nick% ...'}, {name: 'Progress_Mode_RankUp_To_100_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'The toy speed is set to 100% now ! Thanks to %nick% ...'}, {name: 'Progress_Mode_RankDown_To_0_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'The toy is off now !'}, {name: 'Progress_Mode_RankDown_To_20_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'The toy speed went back to 20% !'}, {name: 'Progress_Mode_RankDown_To_40_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'The toy speed went back to 40% !'}, {name: 'Progress_Mode_RankDown_To_60_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'The toy speed went back to 60% !'}, {name: 'Progress_Mode_RankDown_To_80_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'The toy speed went back to 80% !'}, {name: 'Progress_Mode_Global_Donate_Message', type: 'str', minLength: 1, maxLength: 255, defaultValue:'%nick% donated %points% points! [ Speed: %speed% %, %progress% ]'}, {name: 'Progress_Mode_Text_Background', type: 'str', minLength: 1, maxLength: 255, defaultValue:'#6d025d'}, {name: 'Progress_Mode_Text_Color', type: 'str', minLength: 1, maxLength: 255, defaultValue:'#ffffff'}, {name: 'Progress_Mode_Decrease_Pre_Second', type: 'int', minValue: 0, maxValue: 99999, defaultValue:1}, ]; function cb_getvalue(choicename) { for(i = 0;i< cb.settings_choices.length;i++) { if(cb.settings_choices[i].name == choicename) return cb.settings_choices[i].value; } } function SecTimer() { if(Started && ActualMode == 2) { if(Progress_Mode_Points > 0) { Progress_Mode_Points -= Progress_Mode_Decrease; var updatedProgress = GetPercentFromPoints(Progress_Mode_Points); if(updatedProgress < Progress_Mode_ActualLevel) { Progress_Mode_ActualLevel = updatedProgress; Notice("", cb.settings["Progress_Mode_RankDown_To_" + Progress_Mode_ActualLevel + "_Message"], "#ffffff", "#750177", "bolder"); } } } cb.setTimeout(SecTimer, 1000); } Progress_Mode_Decrease = parseInt(cb.settings["Progress_Mode_Decrease_Pre_Second"]); cb.setTimeout(SecTimer, 1000);
© Copyright Chaturbate 2011- 2024. All Rights Reserved.