smoothretro82

Txc#Bot 1.2

Jan 16th, 2026 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.06 KB | None | 0 0
  1. // ================== BOT METADATA ==================
  2. const START_TIME = Date.now();
  3. const BOT_VERSION = "1.2";
  4. const CREATOR_NAME = "Coinbot Developer";
  5. const COMMAND_PREFIX = "txc#";
  6. const ADMIN_NAME = "dominoguy_";
  7.  
  8. // ================== BOT STATE ==================
  9. let botAlive = true;
  10.  
  11. // ================== EVENT SETTINGS ==================
  12. const EVENT_INTERVAL = 600000; // 10 min
  13. const EVENT_DURATION = 300000; // 5 min
  14.  
  15. let eventActive = false;
  16. let eventAmount = 0;
  17. let eventTimeout = null;
  18. let eventIntervalId = null;
  19.  
  20. // ================== DATA STORAGE ==================
  21. const balances = {};
  22. const globalStats = {
  23. tcGiven: 0,
  24. tcTransferred: 0
  25. };
  26.  
  27. // ================== EVENT HANDLING ==================
  28. function endEventTimeout() {
  29. if (!botAlive || !eventActive) return;
  30.  
  31. eventActive = false;
  32. eventAmount = 0;
  33. eventTimeout = null;
  34.  
  35. w.chat.send("Nobody collected the fallen tc.");
  36. }
  37.  
  38. function triggerEvent() {
  39. if (!botAlive || eventActive) return;
  40.  
  41. eventActive = true;
  42. eventAmount = Math.floor(Math.random() * 301) + 100;
  43.  
  44. w.chat.send(
  45. `${eventAmount} tc fell from the sky — ${COMMAND_PREFIX}collect them before anybody else.`
  46. );
  47.  
  48. eventTimeout = setTimeout(endEventTimeout, EVENT_DURATION);
  49. }
  50.  
  51. eventIntervalId = setInterval(triggerEvent, EVENT_INTERVAL);
  52.  
  53. // ================== JOIN MESSAGE ==================
  54. w.on("join", () => {
  55. if (!botAlive) return;
  56. w.chat.send(`TxcBot v${BOT_VERSION} — Type ${COMMAND_PREFIX}help for commands`);
  57. });
  58.  
  59. // ================== LEADERBOARD RENDER ==================
  60. let lastDraw = [];
  61. let lastHeight = 0;
  62. let lastWidth = 0;
  63.  
  64. const leaderboardX = 5;
  65. const leaderboardY = 2;
  66.  
  67. function resetLeaderboardDrawState() {
  68. lastDraw = [];
  69. lastHeight = 0;
  70. lastWidth = 0;
  71. }
  72.  
  73. function writeDiff(lines, x0, y0) {
  74. if (!botAlive) return;
  75.  
  76. for (let y = 0; y < lines.length; y++) {
  77. const newLine = lines[y];
  78. const oldLine = lastDraw[y] || [];
  79. const maxLen = Math.max(newLine.length, oldLine.length);
  80.  
  81. for (let x = 0; x < maxLen; x++) {
  82. const n = newLine[x] || { char: " ", color: 0 };
  83. const o = oldLine[x] || { char: " ", color: 0 };
  84. if (n.char !== o.char || n.color !== o.color) {
  85. writeCharAt(n.char, n.color, x0 + x, y0 + y);
  86. }
  87. }
  88. }
  89.  
  90. lastDraw = lines.map(r => [...r]);
  91. lastHeight = lines.length;
  92. lastWidth = Math.max(...lines.map(r => r.length));
  93. }
  94.  
  95. const text = t => [...t].map(c => ({ char: c, color: 0 }));
  96. const colored = (t, c) => [...t].map(ch => ({ char: ch, color: c }));
  97.  
  98. function drawLeaderboard() {
  99. if (!botAlive) return;
  100.  
  101. const sorted = Object.entries(balances)
  102. .sort((a, b) => b[1] - a[1])
  103. .slice(0, 20);
  104.  
  105. const rows = [text("=== Leaderboard ===")];
  106.  
  107. sorted.forEach(([user, tc], i) => {
  108. let color = 0;
  109. if (i === 0) color = 14;
  110. else if (i === 1) color = 8;
  111. else if (i === 2) color = 12;
  112.  
  113. rows.push([
  114. ...text(`${i + 1}. `),
  115. ...colored(user, color),
  116. ...text(` - ${tc}tc`)
  117. ]);
  118. });
  119.  
  120. if (
  121. rows.length < lastHeight ||
  122. Math.max(...rows.map(r => r.length)) < lastWidth
  123. ) {
  124. writeDiff(
  125. Array.from({ length: lastHeight }, () =>
  126. Array.from({ length: lastWidth }, () => ({ char: " ", color: 0 }))
  127. ),
  128. leaderboardX,
  129. leaderboardY
  130. );
  131. }
  132.  
  133. writeDiff(rows, leaderboardX, leaderboardY);
  134. }
  135.  
  136. // ================== MESSAGE HANDLER ==================
  137. w.on("msg", data => {
  138. if (!botAlive) return;
  139.  
  140. const rawNick = data.nick;
  141. const nick = rawNick.toLowerCase();
  142. const msg = data.msg.trim().toLowerCase();
  143.  
  144. // -------- COLLECT EVENT --------
  145. if (msg === `${COMMAND_PREFIX}collect`) {
  146. if (!eventActive) {
  147. w.chat.send(`${rawNick}, there is no tc to collect.`);
  148. return;
  149. }
  150.  
  151. balances[nick] = (balances[nick] || 0) + eventAmount;
  152. globalStats.tcGiven += eventAmount;
  153.  
  154. clearTimeout(eventTimeout);
  155. eventActive = false;
  156. eventAmount = 0;
  157. eventTimeout = null;
  158.  
  159. w.chat.send(`${rawNick} collected the tc! (${balances[nick]}tc)`);
  160. drawLeaderboard();
  161. return;
  162. }
  163.  
  164. if (!msg.startsWith(COMMAND_PREFIX)) return;
  165.  
  166. const args = msg.slice(COMMAND_PREFIX.length).split(/\s+/);
  167. const command = args.shift();
  168.  
  169. // -------- HELP --------
  170. if (command === "help") {
  171. w.chat.send(
  172. "Commands: help, balance [nick], leaderboard, top <rank>, give <nick> <amount>, send <nick> <amount> (admin), collect, info, uptime, stats"
  173. );
  174. return;
  175. }
  176.  
  177. // -------- BALANCE --------
  178. if (command === "balance") {
  179. const target = (args[0] || nick).toLowerCase();
  180. w.chat.send(`${target} has ${balances[target] || 0}tc`);
  181. return;
  182. }
  183.  
  184. // -------- LEADERBOARD (FIXED) --------
  185. if (command === "leaderboard") {
  186. resetLeaderboardDrawState();
  187. drawLeaderboard();
  188. return;
  189. }
  190.  
  191. // -------- TOP --------
  192. if (command === "top") {
  193. const rank = parseInt(args[0], 10);
  194. if (!rank || rank < 1) return;
  195.  
  196. const sorted = Object.entries(balances).sort((a, b) => b[1] - a[1]);
  197. const entry = sorted[rank - 1];
  198. if (!entry) return;
  199.  
  200. w.chat.send(`#${rank}: ${entry[0]} — ${entry[1]}tc`);
  201. return;
  202. }
  203.  
  204. // -------- GIVE --------
  205. if (command === "give") {
  206. const target = args[0]?.toLowerCase();
  207. const amount = parseInt(args[1], 10);
  208. if (!target || !amount || amount <= 0) return;
  209.  
  210. balances[target] = (balances[target] || 0) + amount;
  211. globalStats.tcGiven += amount;
  212.  
  213. w.chat.send(`${rawNick} gave ${amount}tc to ${target}`);
  214. drawLeaderboard();
  215. return;
  216. }
  217.  
  218. // -------- SEND (ADMIN) --------
  219. if (command === "send") {
  220. if (nick !== ADMIN_NAME.toLowerCase()) {
  221. w.chat.send(`${rawNick}, you are not authorized.`);
  222. return;
  223. }
  224.  
  225. const target = args[0]?.toLowerCase();
  226. const amount = parseInt(args[1], 10);
  227. if (!target || !amount || amount <= 0) return;
  228.  
  229. balances[target] = (balances[target] || 0) + amount;
  230. globalStats.tcTransferred += amount;
  231.  
  232. w.chat.send(`Admin sent ${amount}tc to ${target}`);
  233. drawLeaderboard();
  234. return;
  235. }
  236.  
  237. // -------- INFO --------
  238. if (command === "info") {
  239. w.chat.send(
  240. `TxcBot v${BOT_VERSION} | Events every ${EVENT_INTERVAL / 60000}min`
  241. );
  242. return;
  243. }
  244.  
  245. // -------- UPTIME --------
  246. if (command === "uptime") {
  247. const min = Math.floor((Date.now() - START_TIME) / 60000);
  248. w.chat.send(`Uptime: ${min} minutes`);
  249. return;
  250. }
  251.  
  252. // -------- STATS --------
  253. if (command === "stats") {
  254. w.chat.send(
  255. `Stats: ${globalStats.tcGiven}tc given | ${globalStats.tcTransferred}tc transferred`
  256. );
  257. return;
  258. }
  259.  
  260. // -------- ADMIN EXIT --------
  261. if (command === "exit") {
  262. if (nick !== ADMIN_NAME.toLowerCase()) {
  263. w.chat.send(`${rawNick}, you are not authorized.`);
  264. return;
  265. }
  266.  
  267. w.chat.send("TxcBot is shutting down...");
  268. botAlive = false;
  269.  
  270. clearInterval(eventIntervalId);
  271. clearTimeout(eventTimeout);
  272.  
  273. if (typeof w.close === "function") w.close();
  274. }
  275. });
  276.  
Advertisement
Add Comment
Please, Sign In to add comment