- const tmi = require('tmi.js');
- const axios = require('axios');
- const { channel, username, password } = require('./settings.json');
- const options = {
- options: { debug: true },
- connection: {
- reconnect: true,
- secure: true,
- },
- identity: {
- username,
- password,
- },
- channels: [channel],
- };
- let odds = 1
- //for showing odds at the begging of bot initlaization has no effect on actual odds
- let base_odds = 10
- daily_odds = (odds*100)
- if (odds === 1){
- daily_odds = 0
- }
- const client = new tmi.Client(options);
- // Define a function to fetch emotes from the 7TV API
- async function fetchEmotes() {
- try {
- const response = await axios.get('https://api.7tv.app/v2/users/wantep/emotes');
- return response.data.map((emote) => ({
- name: emote.name,
- rarity: assignRarity()
- }));
- } catch (error) {
- console.error(`Failed to fetch emotes: ${error.message}`);
- return [];
- }
- }
- // Function to assign rarity to emotes
- function assignRarity() {
- const rand = Math.random();
- if (rand < 0.6) {
- return 'common';
- } else if (rand < 0.85) {
- return 'rare';
- } else if (rand < 0.98) {
- return 'epic';
- } else {
- return 'legendary';
- }
- }
- let emotes = [];
- // Fetch emotes from the API and store them in the emotes array
- fetchEmotes()
- .then((fetchedEmotes) => {
- emotes = fetchedEmotes;
- console.log(`Fetched ${emotes.length} emotes from the API`);
- })
- .catch((error) => {
- console.error(`Failed to fetch emotes: ${error.message}`);
- });
- const userTimestamps = {};
- const emoteleaderboard = {};
- setInterval(() => {
- const threshold = 60 * 60 * 1000;
- const now = Date.now();
- for (const user in userTimestamps) {
- if (userTimestamps.hasOwnProperty(user)) {
- const timestamp = userTimestamps[user];
- if (now - timestamp > threshold) {
- delete userTimestamps[user];
- }
- }
- }
- }, 60 * 60 * 1000);
- function updateLeaderboard(username, rarity) {
- if (!emoteleaderboard[username]) {
- emoteleaderboard[username] = 0;
- }
- switch (rarity) {
- case 'common':
- emoteleaderboard[username] += 1;
- break;
- case 'rare':
- emoteleaderboard[username] += 5;
- break;
- case 'epic':
- emoteleaderboard[username] += 10;
- break;
- case 'legendary':
- emoteleaderboard[username] += 20;
- break;
- }
- }
- // Add a new object to store user points and rods
- const userPointsAndRods = {};
- // Update this function to also update user points based on the emote rarity
- function updateLeaderboard(username, rarity) {
- if (!emoteleaderboard[username]) {
- emoteleaderboard[username] = 0;
- }
- if (!userPointsAndRods[username]) {
- userPointsAndRods[username] = { points: 0, rod: 1 };
- }
- let pointsToAdd;
- switch (rarity) {
- case 'common':
- pointsToAdd = 1;
- break;
- case 'rare':
- pointsToAdd = 5;
- break;
- case 'epic':
- pointsToAdd = 10;
- break;
- case 'legendary':
- pointsToAdd = 20;
- break;
- }
- emoteleaderboard[username] += pointsToAdd;
- userPointsAndRods[username].points += pointsToAdd;
- }
- function upgradeRod(username) {
- const userData = userPointsAndRods[username];
- if (!userData) {
- userPointsAndRods[username] = { points: 1, rod: 1 };
- return;
- }
- const rodCost = userData.rod * 5
- ;
- if (userData.points >= rodCost) {
- userData.points -= rodCost;
- userData.rod += 1;
- return `Upgraded your rod to level ${userData.rod}! Your new balance is ${userData.points} points.`;
- } else {
- return `You need ${rodCost} points to upgrade your rod. You currently have ${userData.points} points.`;
- }
- }
- function catchEmote(emote, username) {
- const rodLevel = userPointsAndRods[username]?.rod || 1;
- const catchRateMultiplier = 1 + (rodLevel - 1) * 0.1;
- const rand = Math.random();
- console.log("catchRateMultiplier",catchRateMultiplier)
- switch (emote.rarity) {
- case 'common':
- return rand < 0.06 * odds * catchRateMultiplier;
- case 'rare':
- return rand < 0.025 * odds * catchRateMultiplier;
- case 'epic':
- return rand < 0.013 * odds * catchRateMultiplier;
- case 'legendary':
- return rand < 0.002 * odds * catchRateMultiplier;
- default:
- return false;
- }
- }
- function isBroadcasterOrMod(user) {
- return user.badges?.broadcaster === '1' || user.mod;
- }
- function setNewOdds(odds2) {
- if (odds2 >= 0 && odds2 <= 10) {
- return true;
- } else {
- return false;
- }
- }
- function displayLeaderboard(channel) {
- const sortedLeaderboard = Object.entries(emoteleaderboard)
- .sort((a, b) => b[1] - a[1])
- .slice(0, 10);
- let leaderboardMessage = '🎣 Fishing Leaderboard 🎣\n';
- sortedLeaderboard.forEach(([username, score], index) => {
- leaderboardMessage += `${index + 1}. ${username} - ${score} points\n`;
- });
- client.say(channel, leaderboardMessage);
- }
- client.connect().catch(console.error);
- client.on('connected', () => {
- 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`);
- });
- client.on('message', (channel, user, message, self) => {
- if (self) return;
- const lowerCaseMessage = message.toLowerCase();
- if (message.toLowerCase().startsWith('fishing')) {
- const currentTime = Date.now();
- const lastTimestamp = userTimestamps[user.username];
- if (!lastTimestamp || currentTime - lastTimestamp > 100) {
- userTimestamps[user.username] = currentTime;
- const randFakeChance = Math.floor(Math.random()*10)+ 1;
- const emoterange = Math.floor(Math.random() * emotes.length);
- const selectedEmote = emotes[emoterange];
- if (catchEmote(selectedEmote)) {
- updateLeaderboard(user.username, selectedEmote.rarity);
- client.say(channel, `@${user.username}, WOHOOOO YOU CAUGHT A ${selectedEmote.rarity.toUpperCase()} EMOTE! HERE IT IS --> ${selectedEmote.name}`);
- } else {
- client.say(channel, `@${user.username}, No luck... (${randFakeChance} cm. away)`);
- }
- } else {
- client.say(channel, `@${user.username}, please wait a bit longer before triggering the command again.`);
- }
- } else if (message.toLowerCase().startsWith('!emoteleaderboard')) {
- displayLeaderboard(channel);
- } else if (message.toLowerCase().startsWith('!upgraderod')) {
- const upgradeResult = upgradeRod(user.username);
- client.say(channel, `@${user.username}, ${upgradeResult}`);
- } else if (lowerCaseMessage.startsWith('!setodds')) {
- if (isBroadcasterOrMod(user)) {
- // Parse the command and set the new odds
- const [command, enteredOdds] = lowerCaseMessage.split(' ');
- // Validate and convert the odds to numbers
- const newEnteredOdds = parseFloat(enteredOdds);
- console.log("newodds",newEnteredOdds)
- if (setNewOdds(newEnteredOdds)) {
- odds = newEnteredOdds;
- client.say(
- channel,
- `@${user.username}, the odds have been updated.`
- );
- } else {
- client.say(
- channel,
- `@${user.username}, failed to update odds. Make sure the odds are between 0 and 100.`
- );
- }
- } else {
- client.say(channel, `@${user.username}, you don't have permission to change the odds.`);
- }
- }
- console.log("odds",odds)
- });
[text] hmm
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
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:
Latest Code Pastes