[javascript] ig 1.05
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.
- 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],
- };
- const client = new tmi.Client(options);
- let odds = 1;
- let base_odds = 10;
- let daily_odds = (odds * 100);
- if (odds === 1) {
- daily_odds = 0;
- }
- let emotes = [];
- 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 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';
- }
- }
- 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);
- const userPointsAndRods = {};
- 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();
- 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();
- const currentTime = Date.now();
- const lastTimestamp = userTimestamps[user.username];
- if (lowerCaseMessage === 'fishing') {
- handleFishing();
- }
- function handleFishing() {
- 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, user.username)) {
- 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.`);
- }
- }
- });
Editor
You can edit this paste and save as new:
File Description
- ig 1.05
- Paste Code
- 23 Mar-2023
- 5.42 Kb
You can Share it:
Latest Code Pastes