[text] hmm

Viewer

  1. const tmi = require('tmi.js');
  2. const axios = require('axios');
  3.  
  4. const { channel, username, password } = require('./settings.json');
  5.  
  6. const options = {
  7.   options: { debug: true },
  8.   connection: {
  9.     reconnect: true,
  10.     secure: true,
  11.   },
  12.   identity: {
  13.     username,
  14.     password,
  15.   },
  16.   channels: [channel],
  17. };
  18.  
  19.  
  20. let odds = 1
  21. //for showing odds at the begging of bot initlaization has no effect on actual odds
  22. let base_odds = 10
  23. daily_odds = (odds*100)
  24. if (odds === 1){
  25.     daily_odds = 0
  26. }
  27.  
  28.  
  29. const client = new tmi.Client(options);
  30.  
  31. // Define a function to fetch emotes from the 7TV API
  32. async function fetchEmotes() {
  33.   try {
  34.     const response = await axios.get('https://api.7tv.app/v2/users/wantep/emotes');
  35.     return response.data.map((emote) => ({
  36.       name: emote.name,
  37.       rarity: assignRarity()
  38.     }));
  39.   } catch (error) {
  40.     console.error(`Failed to fetch emotes: ${error.message}`);
  41.     return [];
  42.   }
  43. }
  44.  
  45.  
  46.  
  47. // Function to assign rarity to emotes
  48. function assignRarity() {
  49.   const rand = Math.random();
  50.  
  51.   if (rand < 0.6) {
  52.     return 'common';
  53.   } else if (rand < 0.85) {
  54.     return 'rare';
  55.   } else if (rand < 0.98) {
  56.     return 'epic';
  57.   } else {
  58.     return 'legendary';
  59.   }
  60. }
  61.  
  62.  
  63.  
  64. let emotes = [];
  65.  
  66. // Fetch emotes from the API and store them in the emotes array
  67. fetchEmotes()
  68.   .then((fetchedEmotes) => {
  69.     emotes = fetchedEmotes;
  70.     console.log(`Fetched ${emotes.length} emotes from the API`);
  71.   })
  72.   .catch((error) => {
  73.     console.error(`Failed to fetch emotes: ${error.message}`);
  74.   });
  75.  
  76. const userTimestamps = {};
  77. const emoteleaderboard = {};
  78.  
  79. setInterval(() => {
  80.   const threshold = 60 * 60 * 1000;
  81.   const now = Date.now();
  82.  
  83.   for (const user in userTimestamps) {
  84.     if (userTimestamps.hasOwnProperty(user)) {
  85.       const timestamp = userTimestamps[user];
  86.  
  87.       if (now - timestamp > threshold) {
  88.         delete userTimestamps[user];
  89.       }
  90.     }
  91.   }
  92. }, 60 * 60 * 1000);
  93.  
  94.  
  95. function updateLeaderboard(username, rarity) {
  96.     if (!emoteleaderboard[username]) {
  97.       emoteleaderboard[username] = 0;
  98.     }
  99.   
  100.     switch (rarity) {
  101.       case 'common':
  102.         emoteleaderboard[username] += 1;
  103.         break;
  104.       case 'rare':
  105.         emoteleaderboard[username] += 5;
  106.         break;
  107.       case 'epic':
  108.         emoteleaderboard[username] += 10;
  109.         break;
  110.       case 'legendary':
  111.         emoteleaderboard[username] += 20;
  112.         break;
  113.     }
  114.   }
  115.  
  116.   // Add a new object to store user points and rods
  117. const userPointsAndRods = {};
  118.  
  119. // Update this function to also update user points based on the emote rarity
  120. function updateLeaderboard(username, rarity) {
  121.     if (!emoteleaderboard[username]) {
  122.       emoteleaderboard[username] = 0;
  123.     }
  124.    
  125.     if (!userPointsAndRods[username]) {
  126.       userPointsAndRods[username] = { points: 0, rod: 1 };
  127.     }
  128.    
  129.     let pointsToAdd;
  130.     switch (rarity) {
  131.       case 'common':
  132.         pointsToAdd = 1;
  133.         break;
  134.       case 'rare':
  135.         pointsToAdd = 5;
  136.         break;
  137.       case 'epic':
  138.         pointsToAdd = 10;
  139.         break;
  140.       case 'legendary':
  141.         pointsToAdd = 20;
  142.         break;
  143.     }
  144.     emoteleaderboard[username] += pointsToAdd;
  145.     userPointsAndRods[username].points += pointsToAdd;
  146.   }
  147.  
  148.   
  149.   function upgradeRod(username) {
  150.     const userData = userPointsAndRods[username];
  151.     if (!userData) {
  152.       userPointsAndRods[username] = { points: 1, rod: 1 };
  153.       return;
  154.     }
  155.    
  156.     const rodCost = userData.rod * 5
  157.     
  158.     
  159.     ;
  160.    
  161.     if (userData.points >= rodCost) {
  162.       userData.points -= rodCost;
  163.       userData.rod += 1;
  164.       return `Upgraded your rod to level ${userData.rod}! Your new balance is ${userData.points} points.`;
  165.     } else {
  166.       return `You need ${rodCost} points to upgrade your rod. You currently have ${userData.points} points.`;
  167.     }
  168.   }
  169.    
  170.  
  171.  
  172.   function catchEmote(emote, username) {
  173.     const rodLevel = userPointsAndRods[username]?.rod || 1;
  174.     const catchRateMultiplier = 1 + (rodLevel - 1) * 0.1;
  175.     const rand = Math.random();
  176.     console.log("catchRateMultiplier",catchRateMultiplier)
  177.     
  178.    
  179.     switch (emote.rarity) {
  180.       case 'common':
  181.         return rand < 0.06 * odds * catchRateMultiplier;
  182.       case 'rare':
  183.         return rand < 0.025 * odds * catchRateMultiplier;
  184.       case 'epic':
  185.         return rand < 0.013 * odds * catchRateMultiplier;
  186.       case 'legendary':
  187.         return rand < 0.002 * odds * catchRateMultiplier;
  188.       default:
  189.         return false;
  190.     }
  191.   }
  192.  
  193.   function isBroadcasterOrMod(user) {
  194.     return user.badges?.broadcaster === '1' || user.mod;
  195.   }
  196.    
  197.   function setNewOdds(odds2) {
  198.     if (odds2 >= 0 && odds2 <= 10) {
  199.       return true;
  200.     } else {
  201.       return false;
  202.     }
  203.   }
  204.  
  205. function displayLeaderboard(channel) {
  206.   const sortedLeaderboard = Object.entries(emoteleaderboard)
  207.     .sort((a, b) => b[1] - a[1])
  208.     .slice(0, 10);
  209.  
  210.   let leaderboardMessage = '🎣 Fishing Leaderboard 🎣\n';
  211.  
  212.   sortedLeaderboard.forEach(([username, score], index) => {
  213.     leaderboardMessage += `${index + 1}. ${username} - ${score} points\n`;
  214.   });
  215.  
  216.   client.say(channel, leaderboardMessage);
  217. }
  218.  
  219. client.connect().catch(console.error);
  220. client.on('connected', () => {
  221.  
  222.   client.say(channel, `Fishing has BEGUN! The chances today are increased by ${daily_odds}% chance, now its ${odds*base_odds}% to catch a fish 'type fishing to fish :o`);
  223. });
  224.  
  225.  
  226.  
  227.   
  228.  
  229. client.on('message', (channel, user, message, self) => {
  230.  
  231.   if (self) return;
  232.   const lowerCaseMessage = message.toLowerCase();
  233.   if (message.toLowerCase().startsWith('fishing')) {
  234.     const currentTime = Date.now();
  235.     const lastTimestamp = userTimestamps[user.username];
  236.  
  237.     if (!lastTimestamp || currentTime - lastTimestamp > 100) {
  238.       userTimestamps[user.username] = currentTime;
  239.         
  240.       const randFakeChance = Math.floor(Math.random()*10)+ 1;
  241.       const emoterange = Math.floor(Math.random() * emotes.length);
  242.       const selectedEmote = emotes[emoterange];
  243.  
  244.  
  245.       if (catchEmote(selectedEmote)) {
  246.         updateLeaderboard(user.username, selectedEmote.rarity);
  247.         client.say(channel, `@${user.username}, WOHOOOO YOU CAUGHT A ${selectedEmote.rarity.toUpperCase()} EMOTE! HERE IT IS --> ${selectedEmote.name}`);
  248.       } else {
  249.         client.say(channel, `@${user.username}, No luck... (${randFakeChance} cm. away)`);
  250.       }
  251.     } else {
  252.       client.say(channel, `@${user.username}, please wait a bit longer before triggering the command again.`);
  253.     }
  254.   } else if (message.toLowerCase().startsWith('!emoteleaderboard')) {
  255.     displayLeaderboard(channel);
  256.   } else if (message.toLowerCase().startsWith('!upgraderod')) {
  257.     const upgradeResult = upgradeRod(user.username);
  258.     client.say(channel, `@${user.username}, ${upgradeResult}`);
  259.   } else if (lowerCaseMessage.startsWith('!setodds')) {
  260.     if (isBroadcasterOrMod(user)) {
  261.       // Parse the command and set the new odds
  262.       const [command, enteredOdds] = lowerCaseMessage.split(' ');
  263.  
  264.       // Validate and convert the odds to numbers
  265.       const newEnteredOdds = parseFloat(enteredOdds);
  266.       console.log("newodds",newEnteredOdds)
  267.       if (setNewOdds(newEnteredOdds)) {
  268.         odds = newEnteredOdds;
  269.         client.say(
  270.           channel,
  271.           `@${user.username}, the odds have been updated.`
  272.         );
  273.       } else {
  274.         client.say(
  275.           channel,
  276.           `@${user.username}, failed to update odds. Make sure the odds are between 0 and 100.`
  277.         );
  278.       }
  279.     } else {
  280.       client.say(channel, `@${user.username}, you don't have permission to change the odds.`);
  281.     }
  282.   }
  283.  
  284.   console.log("odds",odds)
  285.   
  286.  
  287. });

Editor

You can edit this paste and save as new:


File Description
  • hmm
  • Paste Code
  • 23 Mar-2023
  • 7.66 Kb
You can Share it: