Bots Home
|
Create an App
Goals Imp
Author:
12345610a
Description
Source Code
Launch Bot
Current Users
Created by:
12345610a
cb.log(cb,cb.app_id) Reflect.ownKeys(cb).forEach(key => cb.log(key + " = " + cb[key])) var iteratee = (arr)=>{ var len = arr.length var n = 0 return { next: next } function next(inx=n) { if (inx < len && inx) n = inx var ret = arr[n] n += 1 return ret } } var tids = [] var delay = (f,ms,...args)=>{ var id = cb.setTimeout(f, ms, ...args) tids.push(id) return id } var cdelay = (...ids)=>{ ids.forEach(id=>{ cb.clearTimeout(id) } ) } var ugoals = [] for (const k in cb.settings) { if (cb.settings[k].length == 0) continue if (k.indexOf('goal_') == 0) { var [p,t,n] = cb.settings[k].split(',', 3) var sign = Math.sign(p) t = parseInt(t.split('m', 1)) p = Math.abs(p) ugoals.push({ change: sign * Math.floor(p / t), price: p, remaining: p, time: t, id: n }) } } var tips_log = [] var users_log = {} var tip_amounts = {} var tips_total = 0 var high_tip var king_tippers var giter = iteratee(ugoals) var next_goal = giter.next() var crons = { updatesubject: 0, processgoal: 0, processtips: 0, updategoal: 0, mlasttip: 0, mtoptippers: 0, mlasttip: 0 } crons.updatesubject = (r=true)=>{ if (next_goal == undefined) { giter = iteratee(ugoals) next_goal = giter.next() } cb.changeRoomSubject(next_goal.id + ' (' + next_goal.remaining + ') ' + cb.settings.tags) if (r) delay(crons.updatesubject, 180000) } crons.processgoal = (r=true)=>{ if (next_goal.remaining <= 0) { next_goal = giter.next() crons.updatesubject(false) } if (next_goal == undefined) { giter = iteratee(ugoals) next_goal = giter.next() crons.updatesubject(false) } if (r) delay(crons.processgoal, 15000) } crons.updategoal = (r=true)=>{ next_goal.remaining += next_goal.change if (next_goal.remaining > next_goal.price) next_goal.remaining = next_goal.price if (r) delay(crons.updategoal, 60000) } crons.mtoptippers = (r=true)=>{ var top_tippers = [] for (k in users_log) { var user = users_log[k] top_tippers.push([user.user, user.tips_total, user.last_amount, user.last_time]) } top_tippers.sort((a,b)=>{ return (b.tips_total - a.tips_total) } ) king_tippers = top_tippers.splice(0, 5) var msg = '' var places = ['\u00B9', '\u00B2', '\u00B3', '\u2074', '\u2075'] king_tippers.forEach(n=>{ msg += ' - ' + places.shift() + ' ' + n[0] + ' (' + n[1] + ' tokens)' + '\n' } ) cb.sendNotice(' - \uD83D\uDC51 King Tippers ', '', '#FF6347', '#FFFFFF', 'bolder') if (msg.length != 0) cb.sendNotice(msg.trim(), '', '#fdf6f5', '#FF6347', 'bold') else cb.sendNotice('No Kings Yet!', '', '#FFE4E1', '#FF6347', 'bold') if (r) delay(crons.mtoptippers, 180000) } crons.processtips = (r=true)=>{ if (typeof tips_log == 'undefined') return tips_log = [] var log = tips_log.splice(0, tips_log.length) log.forEach(last_tip=>{ var [amt,user,time] = [...last_tip] if (!users_log.hasOwnProperty(user)) { var udata = {} udata.user = user udata.last_time = time udata.last_amount = amt udata.high_tip = last_tip udata.tips_total = 0 udata.tips_log = [] users_log[user] = udata } users_log[user].tips_log.push(last_tip) users_log[user].tips_total += amt if (amt > users_log[user].high_tip[0]) { users_log[user].high_tip = last_tip } if (typeof high_tip == 'undefined') high_tip = last_tip if (amt > high_tip[0]) { high_tip = last_tip } next_goal.remaining -= last_tip[0] tips_total += last_tip[0] } ) cb.drawPanel() if (r) delay(crons.processtips, 15000) } crons.mlasttip = (r=true)=>{ var last_tip = tips_log[tips_log.length - 1] if (typeof last_tip == 'undefined') return var agos = Math.round(Date.now() / 1000) - last_tip[2] var agom = (agos / 60) var agoms if (agom <= 1) agoms = 'less than 1 min ago' else agoms = agom.toPrecision(2) + ' mins ago' var msg = last_tip[1] + ' tipped ' + last_tip[0] + ' tokens ' + agoms cb.sendNotice(msg, '', '#FFFFFF', '#FA5858', 'bold') if (r) delay(crons.mlasttip, 180000) } cb.onTip(tip=>{ var amt = parseInt(tip.amount) tips_log.push([amt, tip.from_user, Math.round(Date.now() / 1000)]) if (!tip_amounts.hasOwnProperty(tip.amount)) tip_amounts[tip.amount] = 0 tip_amounts[tip.amount] += 1 if (amt > 20) cb.drawPanel() } ) cb.setTimeout(x=>cb.drawPanel(),3000) cb.onDrawPanel(function(u){ return { template: '3_rows_of_labels', row1_label: 'Goal ID', row1_value: '1', row2_label: 'ROW 2', row2_value: '0', row3_label: 'ROW 3', row3_value: '0' } }) /* cb.onDrawPanel(function(u){ var r3 = '' if (users_log.hasOwnProperty(u.user)) r3 += 'Lover ' + u.user + ' ' + users_log[u.user].tips_total return { template: '3_rows_of_labels', row1_label: next_goal.id + ': ', row1_value: next_goal.remaining, row2_label: (()=>{ var done = Math.floor(10 * (next_goal.price / next_goal.remaining)) var str = '' while (done--) str += '\u2665' return str.padEnd(10, '\u26ac') } )(), row2_value: '0', row3_label: r3, row3_value: '0' } }) */ var goalopt = (n)=>{ return { name: 'goal_' + n, type: 'str', minLength: 0, maxLength: 255, required: false, label: 'Goal #' + n } } var goals = [] var goal1 = goalopt(1) goal1.default = '250,20m,Flash Boobs' goals.push(goal1) for (var i = 2; i <= 10; i++) { goals.push(goalopt(i)) } var tags = { name: 'tags', type: 'str', minLength: 0, maxLength: 255, required: false, label: 'Room tags', default: '#love #five' } cb.settings_choices = [tags, ...goals]
© Copyright Chaturbate 2011- 2024. All Rights Reserved.