Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ================== BOT METADATA ==================
- const START_TIME = Date.now();
- const BOT_VERSION = "1.2";
- const CREATOR_NAME = "Coinbot Developer";
- const COMMAND_PREFIX = "txc#";
- const ADMIN_NAME = "dominoguy_";
- // ================== BOT STATE ==================
- let botAlive = true;
- // ================== EVENT SETTINGS ==================
- const EVENT_INTERVAL = 600000; // 10 min
- const EVENT_DURATION = 300000; // 5 min
- let eventActive = false;
- let eventAmount = 0;
- let eventTimeout = null;
- let eventIntervalId = null;
- // ================== DATA STORAGE ==================
- const balances = {};
- const globalStats = {
- tcGiven: 0,
- tcTransferred: 0
- };
- // ================== EVENT HANDLING ==================
- function endEventTimeout() {
- if (!botAlive || !eventActive) return;
- eventActive = false;
- eventAmount = 0;
- eventTimeout = null;
- w.chat.send("Nobody collected the fallen tc.");
- }
- function triggerEvent() {
- if (!botAlive || eventActive) return;
- eventActive = true;
- eventAmount = Math.floor(Math.random() * 301) + 100;
- w.chat.send(
- `${eventAmount} tc fell from the sky — ${COMMAND_PREFIX}collect them before anybody else.`
- );
- eventTimeout = setTimeout(endEventTimeout, EVENT_DURATION);
- }
- eventIntervalId = setInterval(triggerEvent, EVENT_INTERVAL);
- // ================== JOIN MESSAGE ==================
- w.on("join", () => {
- if (!botAlive) return;
- w.chat.send(`TxcBot v${BOT_VERSION} — Type ${COMMAND_PREFIX}help for commands`);
- });
- // ================== LEADERBOARD RENDER ==================
- let lastDraw = [];
- let lastHeight = 0;
- let lastWidth = 0;
- const leaderboardX = 5;
- const leaderboardY = 2;
- function resetLeaderboardDrawState() {
- lastDraw = [];
- lastHeight = 0;
- lastWidth = 0;
- }
- function writeDiff(lines, x0, y0) {
- if (!botAlive) return;
- for (let y = 0; y < lines.length; y++) {
- const newLine = lines[y];
- const oldLine = lastDraw[y] || [];
- const maxLen = Math.max(newLine.length, oldLine.length);
- for (let x = 0; x < maxLen; x++) {
- const n = newLine[x] || { char: " ", color: 0 };
- const o = oldLine[x] || { char: " ", color: 0 };
- if (n.char !== o.char || n.color !== o.color) {
- writeCharAt(n.char, n.color, x0 + x, y0 + y);
- }
- }
- }
- lastDraw = lines.map(r => [...r]);
- lastHeight = lines.length;
- lastWidth = Math.max(...lines.map(r => r.length));
- }
- const text = t => [...t].map(c => ({ char: c, color: 0 }));
- const colored = (t, c) => [...t].map(ch => ({ char: ch, color: c }));
- function drawLeaderboard() {
- if (!botAlive) return;
- const sorted = Object.entries(balances)
- .sort((a, b) => b[1] - a[1])
- .slice(0, 20);
- const rows = [text("=== Leaderboard ===")];
- sorted.forEach(([user, tc], i) => {
- let color = 0;
- if (i === 0) color = 14;
- else if (i === 1) color = 8;
- else if (i === 2) color = 12;
- rows.push([
- ...text(`${i + 1}. `),
- ...colored(user, color),
- ...text(` - ${tc}tc`)
- ]);
- });
- if (
- rows.length < lastHeight ||
- Math.max(...rows.map(r => r.length)) < lastWidth
- ) {
- writeDiff(
- Array.from({ length: lastHeight }, () =>
- Array.from({ length: lastWidth }, () => ({ char: " ", color: 0 }))
- ),
- leaderboardX,
- leaderboardY
- );
- }
- writeDiff(rows, leaderboardX, leaderboardY);
- }
- // ================== MESSAGE HANDLER ==================
- w.on("msg", data => {
- if (!botAlive) return;
- const rawNick = data.nick;
- const nick = rawNick.toLowerCase();
- const msg = data.msg.trim().toLowerCase();
- // -------- COLLECT EVENT --------
- if (msg === `${COMMAND_PREFIX}collect`) {
- if (!eventActive) {
- w.chat.send(`${rawNick}, there is no tc to collect.`);
- return;
- }
- balances[nick] = (balances[nick] || 0) + eventAmount;
- globalStats.tcGiven += eventAmount;
- clearTimeout(eventTimeout);
- eventActive = false;
- eventAmount = 0;
- eventTimeout = null;
- w.chat.send(`${rawNick} collected the tc! (${balances[nick]}tc)`);
- drawLeaderboard();
- return;
- }
- if (!msg.startsWith(COMMAND_PREFIX)) return;
- const args = msg.slice(COMMAND_PREFIX.length).split(/\s+/);
- const command = args.shift();
- // -------- HELP --------
- if (command === "help") {
- w.chat.send(
- "Commands: help, balance [nick], leaderboard, top <rank>, give <nick> <amount>, send <nick> <amount> (admin), collect, info, uptime, stats"
- );
- return;
- }
- // -------- BALANCE --------
- if (command === "balance") {
- const target = (args[0] || nick).toLowerCase();
- w.chat.send(`${target} has ${balances[target] || 0}tc`);
- return;
- }
- // -------- LEADERBOARD (FIXED) --------
- if (command === "leaderboard") {
- resetLeaderboardDrawState();
- drawLeaderboard();
- return;
- }
- // -------- TOP --------
- if (command === "top") {
- const rank = parseInt(args[0], 10);
- if (!rank || rank < 1) return;
- const sorted = Object.entries(balances).sort((a, b) => b[1] - a[1]);
- const entry = sorted[rank - 1];
- if (!entry) return;
- w.chat.send(`#${rank}: ${entry[0]} — ${entry[1]}tc`);
- return;
- }
- // -------- GIVE --------
- if (command === "give") {
- const target = args[0]?.toLowerCase();
- const amount = parseInt(args[1], 10);
- if (!target || !amount || amount <= 0) return;
- balances[target] = (balances[target] || 0) + amount;
- globalStats.tcGiven += amount;
- w.chat.send(`${rawNick} gave ${amount}tc to ${target}`);
- drawLeaderboard();
- return;
- }
- // -------- SEND (ADMIN) --------
- if (command === "send") {
- if (nick !== ADMIN_NAME.toLowerCase()) {
- w.chat.send(`${rawNick}, you are not authorized.`);
- return;
- }
- const target = args[0]?.toLowerCase();
- const amount = parseInt(args[1], 10);
- if (!target || !amount || amount <= 0) return;
- balances[target] = (balances[target] || 0) + amount;
- globalStats.tcTransferred += amount;
- w.chat.send(`Admin sent ${amount}tc to ${target}`);
- drawLeaderboard();
- return;
- }
- // -------- INFO --------
- if (command === "info") {
- w.chat.send(
- `TxcBot v${BOT_VERSION} | Events every ${EVENT_INTERVAL / 60000}min`
- );
- return;
- }
- // -------- UPTIME --------
- if (command === "uptime") {
- const min = Math.floor((Date.now() - START_TIME) / 60000);
- w.chat.send(`Uptime: ${min} minutes`);
- return;
- }
- // -------- STATS --------
- if (command === "stats") {
- w.chat.send(
- `Stats: ${globalStats.tcGiven}tc given | ${globalStats.tcTransferred}tc transferred`
- );
- return;
- }
- // -------- ADMIN EXIT --------
- if (command === "exit") {
- if (nick !== ADMIN_NAME.toLowerCase()) {
- w.chat.send(`${rawNick}, you are not authorized.`);
- return;
- }
- w.chat.send("TxcBot is shutting down...");
- botAlive = false;
- clearInterval(eventIntervalId);
- clearTimeout(eventTimeout);
- if (typeof w.close === "function") w.close();
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment