commit after a long days tapping away at the magical letter board

This commit is contained in:
Expand-sys 2021-06-10 14:55:37 +10:00
parent 49d74de4be
commit 81b54603c1
9 changed files with 1048 additions and 367 deletions

View file

@ -0,0 +1,14 @@
const { checkbal } = require("../../helpers/ccash");
module.exports = {
name: "checkbal",
description: "check your ccash balance",
async execute(message, args) {
let bal = await checkbal(message.author, args[0]);
if (bal == -1) {
message.reply("User not found fucko");
} else {
message.reply(bal.toString() + " urination station tokens");
}
},
};

17
commands/ccash/link.js Normal file
View file

@ -0,0 +1,17 @@
const { link } = require("../../helpers/ccash");
module.exports = {
name: "link",
description: "link your ccash account",
async execute(message, args) {
let result = await link(message.author, args[0], args[1]);
console.log(result);
if (result == true) {
message.reply(
"Linked your discord account to user " + args[0] + " successfully"
);
} else {
message.reply("Could not verify your CCash user, please check spelling");
}
},
};

View file

@ -1,197 +0,0 @@
const steamer = require('../../helpers/steamer.js')
const Discord = require('discord.js');
const appid = require('appid')
const request = require("request-promise-cache");
const fs = require("fs")
function getID(input){
return new Promise (async (resolve, reject) => {
let result = await appid(input)
resolve(result)
})
}
const api = "https://api.steampowered.com/ISteamApps/GetAppList/v0002/";
let options = {
url: api,
cacheKey: api,
cacheTLL: 1000*60*60
};
function name_exact(name) {
return new Promise((resolve, reject) => {
request(options).then(data => {
data = JSON.parse(data);
resolve(data.applist.apps.filter(a => a.name === name)[0]);
}).catch(e => reject(e));
})
}
module.exports = {
name: 'steam',
description: 'steam getter!',
async execute(message, args) {
if(args[0] == 'game'){
let input = "";
for(i=1; i<args.length;i++){
input += args[i]+' '
}
input = input.slice(0, input.length-1)
console.log(input)
let appID
try{
appID = await name_exact(input)
} catch(error){
console.log(error)
message.reply('Couldnt find game')
}
if (!appID){
message.reply('oi couldnt find game')
}else {
let game
try{
game = await steamer.game(appID.appid)
} catch(error){
console.log(error);
message.reply('Couldnt find game')
}
console.log(game)
if (game[appID.appid] == undefined){
message.reply('ahhh fuck cant find shit with these eyes')
}else{
const embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Game: '+game[appID.appid].data.name)
.setURL(game[appID.appid].data.website)
.setDescription(game[appID.appid].data.short_description)
.addFields(
{ name: 'Steam app ID', value: game[appID.appid].data.steam_appid },
)
.setTimestamp()
.setFooter('heh nice');
message.reply(embed)
}
}
}
if(args[0] == "ownedGames"){
let steamID = args[1]
if(args[1] = 'url'){
let response = await steamer.getSteamID(args[2])
steamID = response.response.steamid
}
if (!steamID) {
return res.status(500).send("SteamID parameter required.");
}
let games
try{
games = await steamer.ownedGames(steamID)
} catch(error){
console.log(error)
}
if(games == null){
message.reply("could not find player "+ args[1] )
}else{
message.reply(steamID+" Owns "+games.response.game_count+" games on steam")
}
}
if(args[0] == "recentgames"){
let steamID = args[1]
if(args[1] = 'url'){
let response = await steamer.getSteamID(args[2])
steamID = response.response.steamid
}
if (!steamID) {
return res.status(500).send("SteamID parameter required.");
}
let games
try{
games = await steamer.recentGames(steamID)
} catch(error){
console.log(error)
}
if (games.response.total_count == 0){
message.reply('Sad bois, no games played in the last 2 weeks')
}else{
let gameslist = games.response.games
let description = '';
for(games in gameslist){
description += gameslist[games].name+'\n'
}
const embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(args[2]+'\'s recent games')
.setDescription(description)
.setTimestamp()
.setFooter('heh nice');
message.reply(embed)
}
}
if (args[0] == 'user'){
let steamID = args[1]
if(args[1] = 'url'){
let response = await steamer.getSteamID(args[2])
steamID = response.response.steamid
}
if (!steamID) {
return res.status(500).send("SteamID parameter required.");
}
let user
try{
user = await steamer.user(steamID)
} catch(error){
console.log(error)
}
console.log(user.response.players[0])
player = user.response.players[0]
let created = new Date(player.timecreated * 1000).toLocaleDateString('en-au')
let online = new Date(player.lastlogoff * 1000).toLocaleDateString('en-au')
const embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(player.profileurl)
.setURL(player.profileurl)
.setAuthor(player.personaname)
.setThumbnail(player.avatarfull)
.addFields(
{ name: 'Date Created', value: created },
{ name: 'Last online', value: online}
)
.setTimestamp()
.setFooter('heh made by expand#0001');
message.reply(embed)
}
if(args[0] == 'gamenews'){
let input = "";
for(i=1; i<args.length;i++){
input += args[i]+' '
}
input = input.slice(0, input.length-1)
console.log(input)
let appID
try{
appID = await name_exact(input)
} catch(error){
console.log(error)
message.reply('Couldnt find game')
}
let news = await steamer.gameNews(appID.appid)
console.log(news.appnews.newsitems[0])
time = new Date(news.appnews.newsitems[0].date*1000).toLocaleDateString('en-au')
const embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(news.appnews.newsitems[0].title)
.setURL(news.appnews.newsitems[0].url)
.setTimestamp(time)
.setFooter(news.appnews.newsitems[0].feedlabel);
message.reply(embed)
}
},
};
//gameNews,

50
helpers/ccash.js Normal file
View file

@ -0,0 +1,50 @@
const db = require("quick.db");
const got = require("got");
async function link(disc, user, pass) {
let verified = await got.post(process.env.CCASHAPIURL + "BankF/vpass", {
json: {
name: user,
attempt: pass,
},
responseType: "json",
});
if (verified.body.value == 1) {
console.log("verified");
if (db.get("links", { discorduser: disc.id }).ccashuser != user) {
db.delete("links", {
discorduser: disc.id,
});
db.push("links", {
discorduser: disc.id,
ccashuser: user,
attempt: pass,
});
return true;
} else {
db.push("links", {
discorduser: disc.id,
ccashuser: user,
attempt: pass,
});
}
}
return false;
}
async function checkbal(disc, user) {
if (user != undefined) {
balance = await got(process.env.CCASHAPIURL + "BankF/" + user + "/bal");
balance = JSON.parse(balance.body);
return balance.value;
} else {
let usernm = db.get("links").filter((a) => a.discorduser == disc.id)[0]
.ccashuser;
console.log(usernm);
balance = await got(process.env.CCASHAPIURL + "BankF/" + usernm + "/bal");
balance = JSON.parse(balance.body);
return balance.value;
}
console.log(balance);
}
module.exports = { link, checkbal };

View file

@ -1,168 +0,0 @@
const baseURL = "https://api.steampowered.com/"
const token = '6CF857296B7A47108E148C40164822B2'
var http = require("http");
const superagent = require("superagent")
async function createRequest(interfaceName, method, version) {
let url = `${baseURL}/${interfaceName}/${method}/v${version}/?key=${token}&format=json`;
return url;
}
async function ownedGames(steamID) {
return new Promise((resolve, reject) => {
let req = http.get(`http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=${token}&steamid=${steamID}&format=json`, function(res){
var body = ""
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
let json
try{
json = JSON.parse(body)
} catch(error){
console.log(error)
}
resolve(json);
});
});
req.on('error', (e) => {
reject(e.message);
});
// send the request
req.end();
})
}
async function getSteamID(vanityUrl) {
return new Promise((resolve, reject) => {
let req = http.get(`http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=${token}&vanityurl=${vanityUrl}&format=json`, function(res){
var body = ""
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
let json
try{
json = JSON.parse(body)
} catch(error){
console.log(error)
}
resolve(json);
});
});
req.on('error', (e) => {
reject(e.message);
});
// send the request
req.end();
})
}
async function recentGames(steamID) {
return new Promise((resolve, reject) => {
let req = http.get(`http://api.steampowered.com/IPlayerService/GetRecentlyPlayedGames/v0001/?key=${token}&steamid=${steamID}&format=json`, function(res){
var body = ""
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
let json
try{
json = JSON.parse(body)
} catch(error){
console.log(error)
}
resolve(json);
});
});
req.on('error', (e) => {
reject(e.message);
});
// send the request
req.end();
})
}
async function user(steamID) {
return new Promise((resolve, reject) => {
let req = http.get(`http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=${token}&steamids=${steamID}`, function(res){
var body = ""
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
let json
try{
json = JSON.parse(body)
} catch(error){
console.log(error)
}
resolve(json);
});
});
req.on('error', (e) => {
reject(e.message);
});
// send the request
req.end();
})
}
async function gameNews(appID) {
return new Promise((resolve, reject) => {
let req = http.get(`http://api.steampowered.com/ISteamNews/GetNewsForApp/v0002/?appid=${appID}&count=1&maxlength=300&format=json`, function(res){
var body = ""
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
let json
try{
json = JSON.parse(body)
} catch(error){
console.log(error)
}
resolve(json);
});
});
req.on('error', (e) => {
reject(e.message);
});
// send the request
req.end();
})
}
async function game(appID) {
return new Promise((resolve, reject) => {
let req = http.request(`https://store.steampowered.com/api/appdetails?appids=${appID}`, function(res){
var body = [];
res.on('data', function(chunk) {
body.push(chunk);
});
res.on('end', function() {
try {
body = JSON.parse(Buffer.concat(body).toString());
} catch(e) {
reject(e);
}
resolve(body);
});
});
req.on('error', (e) => {
reject(e.message);
});
// send the request
req.end();
})
}
module.exports = {
getSteamID,
game,
gameNews,
user,
createRequest,
ownedGames,
recentGames,
}

View file

@ -2,6 +2,7 @@ const fs = require("fs");
const fetch = require("node-fetch"); const fetch = require("node-fetch");
const { Client, MessageAttachment, Collection } = require("discord.js"); const { Client, MessageAttachment, Collection } = require("discord.js");
const dotenv = require("dotenv"); const dotenv = require("dotenv");
dotenv.config(); dotenv.config();
const prefix = process.env.PREFIX; const prefix = process.env.PREFIX;

BIN
json.sqlite Normal file

Binary file not shown.

966
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -23,7 +23,7 @@
"got": "^11.8.2", "got": "^11.8.2",
"moment": "^2.29.1", "moment": "^2.29.1",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"request-promise-cache": "^2.0.1", "quick.db": "^7.1.3",
"superagent": "^6.1.0", "superagent": "^6.1.0",
"unirest": "^0.6.0" "unirest": "^0.6.0"
} }