Skip to content

Commit

Permalink
Updated gas API. Currently untested.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamT20054 authored and AdamT20054 committed Aug 13, 2023
1 parent 2edd8a8 commit fd2c977
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 95 deletions.
104 changes: 104 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/GasWatch.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/prettier.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

194 changes: 99 additions & 95 deletions src/Structures/Client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @format */
// @ts-check
const { default: axios } = require('axios');
const {default: axios} = require('axios');
const Discord = require("discord.js");
const Command = require("./Command.js");
const Event = require("./Event.js");
Expand All @@ -10,116 +10,120 @@ const config = require("../Data/config.json");
const cooldown = new Set();

function cooldownfunc() {
var cooldownvalue = fs.readFileSync("cooldownvalue.json").toString();
cooldown.add("1");
setTimeout(() => {
cooldown.delete("1");
// @ts-ignore
}, cooldownvalue);
};
var cooldownvalue = fs.readFileSync("cooldownvalue.json").toString();
cooldown.add("1");
setTimeout(() => {
cooldown.delete("1");
// @ts-ignore
}, cooldownvalue);
}


function ping() {
if (cooldown.has("1")) {
return false
}
else {
return true
}
};
if (cooldown.has("1")) {
return false
} else {
return true
}
}

class Client extends Discord.Client {
constructor() {
super({ intents, allowedMentions: { repliedUser: false} });
constructor() {
super({intents, allowedMentions: {repliedUser: false}});

/**
* @type {Discord.Collection<string, Command>}
*/
this.commands = new Discord.Collection();
/**
* @type {Discord.Collection<string, Command>}
*/
this.commands = new Discord.Collection();

this.prefix = config.prefix;
this.prefix = config.prefix;

this.once('ready', () => { this.watchGas(); });
}
this.once('ready', () => {
this.watchGas();
});
}

get endpoint() {
return `https://data.spiceai.io/eth/v0.1/gasfees`;
}


async watchGas() {
const res = await axios.get(this.endpoint).catch(console.error);
const gasvalue = fs.readFileSync("gasvalue.json").toString();
async watchGas() {
const res = await axios.get(this.endpoint).catch(console.error);
const gasvalue = fs.readFileSync("gasvalue.json").toString();
console.log(res)

if (!res)
return setTimeout(() => { this.watchGas(); }, 500000);

const gas = res.data.average;

if ((gas) <= gasvalue && (ping() == true )) {
cooldownfunc()
const slow = res.data.safelow;
const standard = res.data.average;
const fastest = res.data.fastest;

// Construct embed
const pingEmbed = new Discord.MessageEmbed();
return setTimeout(() => {
this.watchGas();
}, 500000);

const gas = res.data.normal;

if ((gas) <= gasvalue && (ping() == true)) {
cooldownfunc()
const slow = res.data.slow;
const standard = res.data.normal;
const fastest = res.data.instant;

// Construct embed
const pingEmbed = new Discord.MessageEmbed();
pingEmbed.setTitle(`Ethereum has low gas!`)
.setDescription(`<@&${config.RoleID}> ETH gas value is less than **${gasvalue}** *gwei*!`)
.setColor("#00FFFF")
.addFields({
name: "Fastest",
value: `${fastest}`,
inline: true
},{
name: "Standard",
value: `${standard}`,
inline: true
}, {
name: "Slowest",
value: `${slow}`,
inline: true
});


this.channels.fetch(`${config.ChannelID}`)
// @ts-ignore
.then(channel =>channel.send({ embeds: [pingEmbed] }))
.catch(console.error);
};

setTimeout(() => { this.watchGas(); }, 300000); // 3600000 = 1hr 900000 = 15min 300000 = 5min
}

get endpoint() {
return `https://www.ethgasstation.info/api/ethgasAPI.json`;
}

start(token) {
console.log(`Bot is starting up...`);

fs.readdirSync("./src/Commands")
.filter(file => file.endsWith(".js"))
.forEach(file => {
/**
* @type {Command}
*/
const command = require(`../Commands/${file}`);
console.log(`Command ${command.name} loaded`);
this.commands.set(command.name, command);
});

fs.readdirSync("./src/Events")
.filter(file => file.endsWith(".js"))
.forEach(file => {
/**
* @type {Event}
*/
const event = require(`../Events/${file}`);
console.log(`Event ${event.event} loaded`);
this.on(event.event, event.run.bind(null, this));
});

this.login(token);
}
.addFields({
name: "Fastest",
value: `${fastest}`,
inline: true
}, {
name: "Standard",
value: `${standard}`,
inline: true
}, {
name: "Slowest",
value: `${slow}`,
inline: true
});


this.channels.fetch(`${config.ChannelID}`)
// @ts-ignore
.then(channel => channel.send({embeds: [pingEmbed]}))
.catch(console.error);
}


setTimeout(() => {
this.watchGas();
}, 300000); // 3600000 = 1hr 900000 = 15min 300000 = 5min
}

start(token) {
console.log(`Bot is starting up...`);

fs.readdirSync("./src/Commands")
.filter(file => file.endsWith(".js"))
.forEach(file => {
/**
* @type {Command}
*/
const command = require(`../Commands/${file}`);
console.log(`Command ${command.name} loaded`);
this.commands.set(command.name, command);
});

fs.readdirSync("./src/Events")
.filter(file => file.endsWith(".js"))
.forEach(file => {
/**
* @type {Event}
*/
const event = require(`../Events/${file}`);
console.log(`Event ${event.event} loaded`);
this.on(event.event, event.run.bind(null, this));
});

this.login(token);
}
}

module.exports = Client;

0 comments on commit fd2c977

Please sign in to comment.