This repository has been archived by the owner on Dec 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.js
84 lines (64 loc) · 2.26 KB
/
func.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
module.exports = {};
module.exports.offerSideToText = function(offer, side, current){
var retn = "";
if( offer.items.hasOwnProperty(side) ){
var items = offer.items[side];
var itmtxts = [];
Object.keys(items).forEach(function(v){
var topush = entities.decode(items[v].title);
if( ! current.hasOwnProperty("metadata") || current.metadata == true ) topush += " (" + items[v].user_reviews_positive + "% " + items[v].tradeable + "⇄ " + items[v].wishlist + "★ " + items[v].cards + "🃏)";
itmtxts.push(topush);
});
retn+=itmtxts.join("; ");
} else {
retn+="(no items) for ";
}
return retn;
}
module.exports.offerToText = function(offer, current, oid){
var retn = entities.decode(offer.from_username) + " https://barter.vg/u/" + offer.from_user_id + " proposed an offer: ";
if( offer.from_and_or === null || offer.from_and_or == 0 ) retn+="all";
else retn+=offer.from_and_or;
retn+=" of their ";
retn+=module.exports.offerSideToText(offer, "from", current);
retn+=" for ";
if( offer.to_and_or === null || offer.to_and_or == 0 ) retn+="all";
else retn+=offer.to_and_or;
retn+=" of your ";
retn+=module.exports.offerSideToText(offer, "to", current);
retn+=". Respond to this offer at https://barter.vg/u/" + current.barterID + "/o/" + oid + "/";
return retn;
}
module.exports.doProfileLink = function(steamid, callback){
request("https://barter.vg/u/json/", function(e,r,b){
if( e ) return callback("ERROR");
b = JSON.parse(b);
var i = null;
Object.keys(b).every(function(v, k){
if( b[v].steam_id == steamid.toString() ){
i=v;
console.log("Linking " + i + " and " + steamid.toString());
return false;
}
return true;
});
callback(i);
});
}
module.exports.getPollTime = function(){
if( ! fs.existsSync("poll.time") ) return 0;
else return parseInt(fs.readFileSync("poll.time").toString());
}
module.exports.getDatabaseEntry = function(barterID){
var barter = null;
Object.keys(database).every(function(v,k){
if( database[v].barterID == barterID ){
barter = database[v];
return false;
} else return true;
});
return barter;
}
module.exports.commit = function(){
fs.writeFileSync("sasara.db", JSON.stringify(database));
}