This commit is contained in:
Hri7566 2022-03-19 05:06:42 +01:00
parent b234fc26f7
commit 2cd388a094
13 changed files with 259 additions and 251 deletions

Binary file not shown.

Binary file not shown.

BIN
bot2022.db/000590.log Normal file

Binary file not shown.

BIN
bot2022.db/000591.ldb Normal file

Binary file not shown.

View File

@ -1 +1 @@
MANIFEST-000518
MANIFEST-000588

View File

@ -1,29 +1,11 @@
2022/03/16-00:24:53.383751 7f931c8e1700 Recovering log #516
2022/03/16-00:24:53.406715 7f931c8e1700 Level-0 table #519: started
2022/03/16-00:24:53.420613 7f931c8e1700 Level-0 table #519: 78678 bytes OK
2022/03/16-00:24:53.425008 7f931c8e1700 Delete type=0 #516
2022/03/16-00:24:53.426093 7f931c8e1700 Delete type=3 #514
2022/03/16-02:07:00.678172 7f92fed88700 Compacting 1@0 + 1@1 files
2022/03/16-02:07:00.717364 7f92fed88700 Generated table #521@0: 1748 keys, 71526 bytes
2022/03/16-02:07:00.717398 7f92fed88700 Compacted 1@0 + 1@1 files => 71526 bytes
2022/03/16-02:07:00.719197 7f92fed88700 compacted to: files[ 0 1 0 0 0 0 0 ]
2022/03/16-02:07:00.719967 7f92fed88700 Delete type=2 #519
2022/03/16-02:07:00.720207 7f92fed88700 Delete type=2 #517
2022/03/16-15:07:09.229805 7f92fed88700 Level-0 table #523: started
2022/03/16-15:07:09.320146 7f92fed88700 Level-0 table #523: 391229 bytes OK
2022/03/16-15:07:09.331903 7f92fed88700 Delete type=0 #520
2022/03/16-21:08:43.357784 7f92fed88700 Compacting 1@0 + 1@1 files
2022/03/16-21:08:43.391672 7f92fed88700 Generated table #524@0: 1827 keys, 74712 bytes
2022/03/16-21:08:43.391702 7f92fed88700 Compacted 1@0 + 1@1 files => 74712 bytes
2022/03/16-21:08:43.397356 7f92fed88700 compacted to: files[ 0 1 0 0 0 0 0 ]
2022/03/16-21:08:43.397803 7f92fed88700 Delete type=2 #521
2022/03/16-21:08:43.398618 7f92fed88700 Delete type=2 #523
2022/03/17-03:48:54.971905 7f92fed88700 Level-0 table #526: started
2022/03/17-03:48:55.203197 7f92fed88700 Level-0 table #526: 370049 bytes OK
2022/03/17-03:48:55.213505 7f92fed88700 Delete type=0 #522
2022/03/17-08:29:10.564024 7f92fed88700 Compacting 1@0 + 1@1 files
2022/03/17-08:29:10.585438 7f92fed88700 Generated table #527@0: 1901 keys, 77758 bytes
2022/03/17-08:29:10.585470 7f92fed88700 Compacted 1@0 + 1@1 files => 77758 bytes
2022/03/17-08:29:10.589675 7f92fed88700 compacted to: files[ 0 1 0 0 0 0 0 ]
2022/03/17-08:29:10.589898 7f92fed88700 Delete type=2 #524
2022/03/17-08:29:10.590224 7f92fed88700 Delete type=2 #526
2022/03/18-23:04:04.727111 7f9441ffb700 Recovering log #585
2022/03/18-23:04:04.783176 7f9441ffb700 Level-0 table #589: started
2022/03/18-23:04:04.805688 7f9441ffb700 Level-0 table #589: 261738 bytes OK
2022/03/18-23:04:04.810132 7f9441ffb700 Delete type=0 #585
2022/03/18-23:04:04.810879 7f9441ffb700 Delete type=3 #582
2022/03/18-23:08:46.813166 7f94337fe700 Compacting 1@0 + 1@1 files
2022/03/18-23:08:46.828228 7f94337fe700 Generated table #591@0: 2112 keys, 87310 bytes
2022/03/18-23:08:46.828268 7f94337fe700 Compacted 1@0 + 1@1 files => 87310 bytes
2022/03/18-23:08:46.835465 7f94337fe700 compacted to: files[ 0 1 0 0 0 0 0 ]
2022/03/18-23:08:46.835720 7f94337fe700 Delete type=2 #587
2022/03/18-23:08:46.836010 7f94337fe700 Delete type=2 #589

View File

@ -1,13 +1,15 @@
2022/03/15-21:26:15.525619 7ff7c9e8e700 Recovering log #513
2022/03/15-21:26:15.525734 7ff7c9e8e700 Level-0 table #515: started
2022/03/15-21:26:15.527757 7ff7c9e8e700 Level-0 table #515: 556 bytes OK
2022/03/15-21:26:15.531301 7ff7c9e8e700 Delete type=0 #513
2022/03/15-21:26:15.531350 7ff7c9e8e700 Delete type=3 #511
2022/03/15-22:32:49.678402 7ff7c8c17700 Compacting 3@0 + 1@1 files
2022/03/15-22:32:49.698039 7ff7c8c17700 Generated table #517@0: 1733 keys, 70649 bytes
2022/03/15-22:32:49.698074 7ff7c8c17700 Compacted 3@0 + 1@1 files => 70649 bytes
2022/03/15-22:32:49.699779 7ff7c8c17700 compacted to: files[ 0 1 0 0 0 0 0 ]
2022/03/15-22:32:49.699950 7ff7c8c17700 Delete type=2 #507
2022/03/15-22:32:49.700154 7ff7c8c17700 Delete type=2 #512
2022/03/15-22:32:49.700231 7ff7c8c17700 Delete type=2 #515
2022/03/15-22:32:49.700322 7ff7c8c17700 Delete type=2 #509
2022/03/18-01:47:49.224740 7f86fffff700 Recovering log #581
2022/03/18-01:47:49.224873 7f86fffff700 Level-0 table #583: started
2022/03/18-01:47:49.226850 7f86fffff700 Level-0 table #583: 391 bytes OK
2022/03/18-01:47:49.229720 7f86fffff700 Delete type=3 #580
2022/03/18-01:47:49.229757 7f86fffff700 Delete type=0 #581
2022/03/18-13:58:51.323540 7f86fe7fc700 Level-0 table #586: started
2022/03/18-13:58:51.356576 7f86fe7fc700 Level-0 table #586: 314056 bytes OK
2022/03/18-13:58:51.361493 7f86fe7fc700 Delete type=0 #584
2022/03/18-14:03:51.384734 7f86fe7fc700 Compacting 2@0 + 1@1 files
2022/03/18-14:03:51.395676 7f86fe7fc700 Generated table #587@0: 2074 keys, 85424 bytes
2022/03/18-14:03:51.395712 7f86fe7fc700 Compacted 2@0 + 1@1 files => 85424 bytes
2022/03/18-14:03:51.396901 7f86fe7fc700 compacted to: files[ 0 1 0 0 0 0 0 ]
2022/03/18-14:03:51.397452 7f86fe7fc700 Delete type=2 #586
2022/03/18-14:03:51.397778 7f86fe7fc700 Delete type=2 #579
2022/03/18-14:03:51.397991 7f86fe7fc700 Delete type=2 #583

Binary file not shown.

BIN
bot2022.db/MANIFEST-000588 Normal file

Binary file not shown.

202
index.js
View File

@ -2,212 +2,12 @@ require('dotenv').config();
globalThis.gBot = require('./src/Bot');
const level = require('level');
const MPPClient = require('./src/MPPClient');
globalThis.db = level("./bot2022.db");
const db = require('./src/Database');
let sendChat = MPPClient.sendChat;
db.getPokemon = function(id, cb) {
var key = "pokemon collection~"+id;
db.get(key, function(err, value) {
if(err || !value || value == "") {
cb([]);
return;
}
var result = [];
value = value.split("\xff");
for(var i = 0; i < value.length; i++) {
var v = value[i].trim();
if(v.length) result.push(v);
}
cb(result);
});
}
db.putPokemon = function(id, arr) {
var result = "";
for(var i = 0; i < arr.length; i++) {
var v = arr[i];
if(!v) continue;
v = v.trim();
if(v.length > 0) {
if(i) result += "\xff";
result += v;
}
}
var key = "pokemon collection~"+id;
if(result.length)
db.put(key, result);
else
db.del(key);
}
db.getTime = function(cb) {
db.get('time', (err, value) => {
if (err !== null) cb(err, value);
cb(undefined, value);
});
}
db.setTime = function(time) {
db.put('time', time);
}
db.readArray = function(start, end, cb) {
var results = [];
db.createReadStream({
start: start,
end: end
})
.on("data", function(data) {
results.push(data);
})
.on("end", function() {
cb(results);
});
};
function listArray(arr) {
var result = "";
for(var i = 0; i < arr.length; i++) {
if(i && i !== arr.length - 1) result += ", ";
if(i && i === arr.length - 1) result += ", and ";
result += arr[i];
}
return result;
}
// tries to find the thing by text
// calls cb with undefined or entry
db.look = function(location, text, cb) {
text = text.toLowerCase().trim();
if(text == "") {
// "/look" with no search text
db.get("look."+location, function(err, value) {
var response = "";
if(err) response = "Well...";
else response = value;
var sel = "look."+location+".◍";
db.readArray(sel, sel+"\xff", function(results) {
var results = results.map(data=>data.key.substr(sel.length));
if(results.length) response += " There's "+listArray(results)+ ", about.";
sendChat(response);
});
});
} else {
var entry = undefined;
var sel = "look."+location+".";
db.createReadStream({
start: sel,
end: sel+"◍\xff"
})
.on("data", function(data) {
if(data.key.substr(sel.length).toLowerCase().indexOf(text) > -1) {
entry = data;
}
})
.on("end", function() {
cb(entry);
});
}
}
db.take = function(location, text, cb) {
text = text.toLowerCase().trim();
var sel = "look."+location+".◍";
var entry = undefined;
db.createReadStream({
start: sel,
end: sel+"\xff"
})
.on("data", function(data) {
if(data.key.substr(sel.length).toLowerCase().indexOf(text) > -1) {
entry = data;
}
})
.on("end", function() {
cb(entry);
});
}
db.getLocation = function(id, cb) {
var key = "location~"+id;
db.get(key, function(err, value) {
if(err || !value || value == "") {
return cb("outside");
}
return cb(value);
});
}
db.setLocation = function(id, location) {
if(!location || location === "") {
location = "outside";
}
db.put("location~"+id, location);
}
db.getFish = function(id, cb) {
var key = "fish sack~"+id;
db.get(key, function(err, value) {
if(err || !value || value == "") {
cb([]);
return;
}
var result = [];
value = value.split("\xff");
for(var i = 0; i < value.length; i++) {
var v = value[i].trim();
if(v.length) result.push(v);
}
cb(result);
});
}
db.putFish = function(id, arr) {
var result = "";
for(var i = 0; i < arr.length; i++) {
var v = arr[i];
if(!v) continue;
v = v.trim();
if(v.length > 0) {
if(i) result += "\xff";
result += v;
}
}
var key = "fish sack~"+id;
if(result.length)
db.put(key, result);
else
db.del(key);
}
db.appendFish = function(id, arr) {
db.getFish(id, function(myfish) {
myfish = myfish.concat(arr);
//console.log(id, myfish);
db.putFish(id, myfish);
});
}
db.getFruits = function(cb) {
var key = "kekklefruit tree";
db.get(key, function(err, value) {
if(err || !value || value == "") {
cb(0);
return;
}
cb(parseInt(value));
});
}
db.setFruits = function(num_fruits) {
var key = "kekklefruit tree";
db.put(key, num_fruits);
}
gBot.start(process.env.MPPCLONE_TOKEN);
process.stdin.on('data', data => {

View File

@ -2,6 +2,7 @@ const { sendChat } = require('./MPPClient');
// const DiscordClient = require('./DiscordClient');
const MPPClient = require('./MPPClient');
const StaticEventEmitter = require('./StaticEventEmitter');
const db = require('./Database');
module.exports = class Bot extends StaticEventEmitter {
static start(token) {
@ -117,7 +118,7 @@ module.exports = class Bot extends StaticEventEmitter {
return part;
};
var TOO_MANY_FISH = 50;
var TOO_MANY_FISH = 2500;
if (msg.cmd.startsWith("give_")) {
var amt = parseInt(msg.cmd.substr(5));
console.log(msg.cmd.substr(5));

View File

@ -2,6 +2,7 @@ const MPPClient = require("./MPPClient");
const Color = require('./Color');
const crypto = require('crypto');
const fs = require('fs');
const db = require('./Database');
module.exports = (bot) => {
bot.addCommand = async (cmd, minargs, func, hidden) => {
@ -20,6 +21,7 @@ module.exports = (bot) => {
var pokedex = require("./pokedex.json");
var untakeable = ['bed', 'chair', 'couch', 'desk', 'dining table', 'fireplace', 'floor lamp', 'flower pot', 'food cart', 'garden', 'grand piano', 'lamp', 'lawn mower', 'mailbox', 'potted plant', 'refrigerator', 'sink', 'sofa', 'stairs', 'stool', 'table', 'television', 'toilet', 'tv', 'vase', 'wardrobe', 'window', 'workbench', 'Trees'];
var sendChat = MPPClient.sendChat;
var blockHelpUntil = 0;
@ -198,7 +200,8 @@ module.exports = (bot) => {
function catchSomething(part) {
db.getFish(part._id, function(myfish) {
if(myfish.length > 10 && Math.random() < 0.1) {
// if(myfish.length > 10 && Math.random() < 0.1) {
if(myfish.length > TOO_MANY_FISH && Math.random() < 0.1) {
catchTrap(part);
} else {
catchFish(part);
@ -447,7 +450,7 @@ module.exports = (bot) => {
}
}
bot.addCommand(['help', 'about', 'commands'], 0, msg => {
bot.addCommand(['help', /*'about',*/ 'commands'], 0, msg => {
if (Date.now() < blockHelpUntil) return;
blockHelpUntil = Date.now() + 10000;
//sendChat("This is a test to see what leveldb is like. Commands: /put <key> <value>, /get <key>, /del <key>, /read [<start> [<end>]] \t"+underline("Fishing")+": \t/fish, /cast (starts fishing), /reel (stops fishing), /caught [name] (shows fish you've caught), /eat (eats one of your fish), /give [name] (gives fish to someone else), /steal [name] (steals fish from someone else)");
@ -456,6 +459,12 @@ module.exports = (bot) => {
sendChat(underline("Fishing")+": /fish, /cast (starts fishing), /reel (stops fishing), /caught [name] (shows fish you've caught), /eat (eats one of your fish), /give [name] (gives fish to someone else), /give_[number] [name] (give up to 100 at a time), /pick (picks fruit from the tree), /look [object] (look at surroundings), /yeet [item] (yeet items into surroundings), /take [object] (take items from surroundings)");
}, false);
bot.addCommand(['about'], 0, msg => {
if (Date.now() < blockHelpUntil) return;
blockHelpUntil = Date.now() + 10000;
sendChat(`${underline("Fishing")} was made by Brandon Lockaby from late 2013-2017, then again in 2019. This is an updated version by Hri7566 (https://github.com/Hri7566) for use on MPPClone. This bot is capable of ${underline("changing your color")}.`);
});
bot.addCommand('qmyid', 0, (msg, admin) => {
if (!admin) return;
console.log(MPPClient.client.user.id);
@ -477,7 +486,7 @@ module.exports = (bot) => {
}, i * 100);
}
}, false);
0
bot.addCommand('_20k', 0, (msg, admin) => {
if (!admin) return;
var keks = ["butter kek", "rice kek", "chocolate kek", "chocolate covered kek", "strawberry kek", "strawbarry kek", "sugar kek", "banana kek", "apple kek", "fish kek"];
@ -734,6 +743,7 @@ module.exports = (bot) => {
}, false);
bot.addCommand('del', 0, (msg, admin) => {
if (!admin) return;
db.del(msg.argcat(), function(err) {
if(err) {
sendChat("our friend " + msg.p.name + " del ERR: " + err);
@ -745,6 +755,7 @@ module.exports = (bot) => {
}, false);
bot.addCommand('read', 0, (msg, admin) => {
if (!admin) return;
var max_len = 2048;
var result = "";
var count = 0;
@ -1133,7 +1144,7 @@ module.exports = (bot) => {
});
}, false);
var TOO_MANY_FISH = 50;
var TOO_MANY_FISH = 2500;
bot.addCommand('take', 0, msg => {
db.getLocation(msg.p._id, location => {
@ -1251,8 +1262,8 @@ module.exports = (bot) => {
db.put("look.sleep.◍Bed", "*snuggles*");
db.put("look.inside.◍Couch", "Let's sit down and have a talk.");
db.put("look.inside.◍Grand Piano", "Maybe you could play a song or two for us.");
db.putNonexistent("look.inside.◍Couch", "Let's sit down and have a talk.");
db.putNonexistent("look.inside.◍Grand Piano", "Maybe you could play a song or two for us.");
}, 6000);
var FISHING_CHANCE = 0.02;

212
src/Database.js Normal file
View File

@ -0,0 +1,212 @@
const level = require('level');
const MPPClient = require('./MPPClient');
let db = level('./bot2022.db');
db.getPokemon = function(id, cb) {
var key = "pokemon collection~"+id;
db.get(key, function(err, value) {
if(err || !value || value == "") {
cb([]);
return;
}
var result = [];
value = value.split("\xff");
for(var i = 0; i < value.length; i++) {
var v = value[i].trim();
if(v.length) result.push(v);
}
cb(result);
});
}
db.putPokemon = function(id, arr) {
var result = "";
for(var i = 0; i < arr.length; i++) {
var v = arr[i];
if(!v) continue;
v = v.trim();
if(v.length > 0) {
if(i) result += "\xff";
result += v;
}
}
var key = "pokemon collection~"+id;
if(result.length)
db.put(key, result);
else
db.del(key);
}
db.getTime = function(cb) {
db.get('time', (err, value) => {
if (err !== null) cb(err, value);
cb(undefined, value);
});
}
db.setTime = function(time) {
db.put('time', time);
}
db.readArray = function(start, end, cb) {
var results = [];
db.createReadStream({
start: start,
end: end
})
.on("data", function(data) {
results.push(data);
})
.on("end", function() {
cb(results);
});
};
db.putNonexistent = function(key, val) {
db.get(key, (err, value) => {
if (err || value == null || typeof value == 'undefined') {
db.put(key, val);
}
});
}
function listArray(arr) {
var result = "";
for(var i = 0; i < arr.length; i++) {
if(i && i !== arr.length - 1) result += ", ";
if(i && i === arr.length - 1) result += ", and ";
result += arr[i];
}
return result;
}
// tries to find the thing by text
// calls cb with undefined or entry
db.look = function(location, text, cb) {
text = text.toLowerCase().trim();
if(text == "") {
// "/look" with no search text
db.get("look."+location, function(err, value) {
var response = "";
if(err) response = "Well...";
else response = value;
var sel = "look."+location+".◍";
db.readArray(sel, sel+"\xff", function(results) {
var results = results.map(data=>data.key.substr(sel.length));
if(results.length) response += " There's "+listArray(results)+ ", about.";
MPPClient.sendChat(response);
});
});
} else {
var entry = undefined;
var sel = "look."+location+".";
db.createReadStream({
start: sel,
end: sel+"◍\xff"
})
.on("data", function(data) {
if(data.key.substr(sel.length).toLowerCase().indexOf(text) > -1) {
entry = data;
}
})
.on("end", function() {
cb(entry);
});
}
}
db.take = function(location, text, cb) {
text = text.toLowerCase().trim();
var sel = "look."+location+".◍";
var entry = undefined;
db.createReadStream({
start: sel,
end: sel+"\xff"
})
.on("data", function(data) {
if(data.key.substr(sel.length).toLowerCase().indexOf(text) > -1) {
entry = data;
}
})
.on("end", function() {
cb(entry);
});
}
db.getLocation = function(id, cb) {
var key = "location~"+id;
db.get(key, function(err, value) {
if(err || !value || value == "") {
return cb("outside");
}
return cb(value);
});
}
db.setLocation = function(id, location) {
if(!location || location === "") {
location = "outside";
}
db.put("location~"+id, location);
}
db.getFish = function(id, cb) {
var key = "fish sack~"+id;
db.get(key, function(err, value) {
if(err || !value || value == "") {
cb([]);
return;
}
var result = [];
value = value.split("\xff");
for(var i = 0; i < value.length; i++) {
var v = value[i].trim();
if(v.length) result.push(v);
}
cb(result);
});
}
db.putFish = function(id, arr) {
var result = "";
for(var i = 0; i < arr.length; i++) {
var v = arr[i];
if(!v) continue;
v = v.trim();
if(v.length > 0) {
if(i) result += "\xff";
result += v;
}
}
var key = "fish sack~"+id;
if(result.length)
db.put(key, result);
else
db.del(key);
}
db.appendFish = function(id, arr) {
db.getFish(id, function(myfish) {
myfish = myfish.concat(arr);
//console.log(id, myfish);
db.putFish(id, myfish);
});
}
db.getFruits = function(cb) {
var key = "kekklefruit tree";
db.get(key, function(err, value) {
if(err || !value || value == "") {
cb(0);
return;
}
cb(parseInt(value));
});
}
db.setFruits = function(num_fruits) {
var key = "kekklefruit tree";
db.put(key, num_fruits);
}
module.exports = db;