This commit is contained in:
Hri7566 2022-01-12 03:58:35 -05:00
parent 586e2bde99
commit c85e73908a
16 changed files with 3199 additions and 125 deletions

BIN
bot2022.db/000225.ldb Normal file

Binary file not shown.

BIN
bot2022.db/000227.ldb Normal file

Binary file not shown.

BIN
bot2022.db/000228.log Normal file

Binary file not shown.

1
bot2022.db/CURRENT Normal file
View File

@ -0,0 +1 @@
MANIFEST-000226

0
bot2022.db/LOCK Normal file
View File

5
bot2022.db/LOG Normal file
View File

@ -0,0 +1,5 @@
2022/01/12-03:39:23.660 73e8 Recovering log #224
2022/01/12-03:39:23.660 73e8 Level-0 table #227: started
2022/01/12-03:39:23.664 73e8 Level-0 table #227: 643 bytes OK
2022/01/12-03:39:23.669 73e8 Delete type=0 #224
2022/01/12-03:39:23.670 73e8 Delete type=3 #222

14
bot2022.db/LOG.old Normal file
View File

@ -0,0 +1,14 @@
2022/01/12-03:38:41.098 7054 Recovering log #221
2022/01/12-03:38:41.099 7054 Level-0 table #223: started
2022/01/12-03:38:41.102 7054 Level-0 table #223: 1867 bytes OK
2022/01/12-03:38:41.109 7054 Delete type=0 #221
2022/01/12-03:38:41.109 7054 Delete type=3 #219
2022/01/12-03:38:41.109 5828 Compacting 4@0 + 1@1 files
2022/01/12-03:38:41.112 5828 Generated table #225@0: 24 keys, 1492 bytes
2022/01/12-03:38:41.112 5828 Compacted 4@0 + 1@1 files => 1492 bytes
2022/01/12-03:38:41.114 5828 compacted to: files[ 0 1 0 0 0 0 0 ]
2022/01/12-03:38:41.114 5828 Delete type=2 #210
2022/01/12-03:38:41.114 5828 Delete type=2 #212
2022/01/12-03:38:41.114 5828 Delete type=2 #215
2022/01/12-03:38:41.115 5828 Delete type=2 #220
2022/01/12-03:38:41.115 5828 Delete type=2 #223

BIN
bot2022.db/MANIFEST-000226 Normal file

Binary file not shown.

View File

@ -3,11 +3,11 @@ require('dotenv').config();
globalThis.gBot = require('./src/Bot'); globalThis.gBot = require('./src/Bot');
const level = require('level'); const level = require('level');
const DiscordClient = require('./src/DiscordClient'); const MPPClient = require('./src/MPPClient');
globalThis.db = level("./bot2019.db"); globalThis.db = level("./bot2022.db");
let sendChat = DiscordClient.sendChat; let sendChat = MPPClient.sendChat;
db.getPokemon = function(id, cb) { db.getPokemon = function(id, cb) {
var key = "pokemon collection~"+id; var key = "pokemon collection~"+id;
@ -197,4 +197,4 @@ db.setFruits = function(num_fruits) {
} }
gBot.start(process.env.DISCORD_TOKEN); gBot.start(process.env.MPPCLONE_TOKEN);

1
package-lock.json generated
View File

@ -5,6 +5,7 @@
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "booger",
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {

View File

@ -1,15 +1,17 @@
const { sendChat } = require('./DiscordClient'); const { sendChat } = require('./MPPClient');
const DiscordClient = require('./DiscordClient'); // const DiscordClient = require('./DiscordClient');
const MPPClient = require('./MPPClient');
const StaticEventEmitter = require('./StaticEventEmitter'); const StaticEventEmitter = require('./StaticEventEmitter');
module.exports = class Bot extends StaticEventEmitter { module.exports = class Bot extends StaticEventEmitter {
static start(token) { static start(token) {
DiscordClient.start(token); MPPClient.start(token);
this.bindEventListeners(); this.bindEventListeners();
this.commands = new Map(); this.commands = new Map();
this.admin = [ this.admin = [
"314868372686766080" "2ffc3744fbc1bc6c6ef4a330",
"a41651bf8a46bafc5548dad6"
]; ];
this.prefix = "/"; // never change this this.prefix = "/"; // never change this
@ -18,10 +20,10 @@ module.exports = class Bot extends StaticEventEmitter {
static bindEventListeners() { static bindEventListeners() {
this.on("chat.receive", msg => { this.on("chat.receive", msg => {
console.log(msg.author.username + ": " + msg.content); console.log(msg.p.name + ": " + msg.a);
let m = { let m = {
referer: msg.author, referer: msg.p,
}; };
@ -29,72 +31,67 @@ module.exports = class Bot extends StaticEventEmitter {
}); });
this.on("chat.send", msg => { this.on("chat.send", msg => {
DiscordClient.sendChat(msg); MPPClient.sendChat(msg);
}); });
} }
static runCommand(msg) { static runCommand(msg) {
let role; // let role;
msg.member.guild.roles.cache.forEach(r => { // msg.member.guild.roles.cache.forEach(r => {
if (r.name.toString() == msg.member.user.id.toString()) { // if (r.name.toString() == msg.member.user.id.toString()) {
role = r; // role = r;
} // }
}); // });
msg.p = { // msg.p = {
name: msg.author.username, // name: msg.author.username,
_id: msg.author.id, // _id: msg.author.id,
color: role.color, // color: role.color,
id: msg.author.id // id: msg.author.id
} // }
msg.a = msg.content; // msg.a = msg.content;
if(msg.a[0] == "" && msg.p.id !== client.participantId) { if(msg.a[0] == "" && msg.p.id !== client.participantId) {
msg.a[0] = "/"; msg.a[0] = "/";
} }
function findParticipantByName(name) { function findParticipantByName(name) {
// if(!name || name.trim() == "") return undefined; if(!name || name.trim() == "") return undefined;
// for(var id in client.ppl) { for(var id in client.ppl) {
// if(client.ppl.hasOwnProperty(id) && client.ppl[id].name === name) { if(client.ppl.hasOwnProperty(id) && client.ppl[id].name === name) {
// return client.ppl[id]; return client.ppl[id];
// } }
// } }
return undefined; return undefined;
}; };
function findParticipantByNameCaseInsensitive(name) { function findParticipantByNameCaseInsensitive(name) {
if(!name || name.trim() == "") return undefined; if(!name || name.trim() == "") return undefined;
var part = findParticipantByName(name); var part = findParticipantByName(name);
if(!part) { if(!part) {
name_lc = name.toLowerCase(); name_lc = name.toLowerCase();
DiscordClient.client.guilds.cache.get('841331769051578413').members.cache.forEach(p => { MPPClient.client.ppl.forEach(p => {
if (p.user.username.toLowerCase() === name_lc) { if(p.name.toLowerCase() === name_lc) {
part = p.user; part = p;
part.name = p.user.name;
part._id = p.user.id;
DiscordClient.client.guilds.cache.get('841331769051578413').roles.cache.forEach(r => {
if (r.name === part._id) {
part.color = r.color;
}
});
} }
}); });
} }
return part; return part;
}; };
function findParticipantByNameFuzzy(name) { function findParticipantByNameFuzzy(name) {
if(!name || name.trim() == "") return undefined; if(!name || name.trim() == "") return undefined;
name = name.toLowerCase(); name = name.toLowerCase();
var part = findParticipantByNameCaseInsensitive(name); var part = findParticipantByNameCaseInsensitive(name);
// for(var id in client.ppl) { for(var id in MPPClient.client.ppl) {
// if(client.ppl.hasOwnProperty(id) && client.ppl[id].name.toLowerCase().indexOf(name) === 0) { if(client.ppl.hasOwnProperty(id) && client.ppl[id].name.toLowerCase().indexOf(name) === 0) {
// part = client.ppl[id]; part = client.ppl[id];
// break; break;
// } }
// } }
// for(var id in client.ppl) { for(var id in MPPClient.client.ppl) {
// if(client.ppl.hasOwnProperty(id) && client.ppl[id].name.toLowerCase().indexOf(name) !== -1) { if(client.ppl.hasOwnProperty(id) && client.ppl[id].name.toLowerCase().indexOf(name) !== -1) {
// part = client.ppl[id]; part = MPPClient.client.ppl[id];
// break; break;
// } }
// } }
return part; return part;
}; };
if (msg.cmd.startsWith("give_")) { if (msg.cmd.startsWith("give_")) {

View File

@ -1,4 +1,4 @@
const DiscordClient = require("./DiscordClient"); const MPPClient = require("./MPPClient");
const Color = require('./Color'); const Color = require('./Color');
const crypto = require('crypto'); const crypto = require('crypto');
const fs = require('fs'); const fs = require('fs');
@ -17,11 +17,14 @@ module.exports = (bot) => {
var fish = ["Angelfish", "Arapaima", "Arowana", "Barbel Steed", "Barred Knifejaw", "Bitterling", "Black Bass", "Blowfish", "Blue Marlin", "Bluegill", "Brook Trout", "Butterflyfish", "Can", "Carp", "Catfish", "Char", "Cherry Salmon", "Clownfish", "Coelacanth", "Crawfish", "Crucian Carp", "Dab", "Dace", "Dorado", "Eel", "Football fish", "Freshwater Goby", "Frog", "Gar", "Giant Snakehead", "Giant Trevally", "Goldfish", "Guppy", "Hammerhead Shark", "Horse Mackerel", "Jellyfish", "Key", "Killifish", "King Salmon", "Koi", "Large Bass", "Loach", "Lobster", "Mitten Crab", "Moray Eel", "Napoleonfish", "Neon Tetra", "Nibble Fish", "Oarfish", "Ocean Sunfish", "Octopus", "Olive Flounder", "Pale Chub", "Pike", "Piranha", "Pond Smelt", "Popeyed Goldfish", "Puffer Fish", "Rainbow Trout", "Ray", "Red Snapper", "Ribbon Eel", "Saddled Bichir", "Salmon", "Saw Shark", "Sea Bass", "Sea Butterfly", "Seahorse", "Shark", "Small Bass", "Softshell Turtle", "Squid", "Stringfish", "Surgeonfish", "Sweetfish", "Tadpole", "Tuna", "Whale Shark", "Yellow Perch", "Zebra Turkeyfish"]; var fish = ["Angelfish", "Arapaima", "Arowana", "Barbel Steed", "Barred Knifejaw", "Bitterling", "Black Bass", "Blowfish", "Blue Marlin", "Bluegill", "Brook Trout", "Butterflyfish", "Can", "Carp", "Catfish", "Char", "Cherry Salmon", "Clownfish", "Coelacanth", "Crawfish", "Crucian Carp", "Dab", "Dace", "Dorado", "Eel", "Football fish", "Freshwater Goby", "Frog", "Gar", "Giant Snakehead", "Giant Trevally", "Goldfish", "Guppy", "Hammerhead Shark", "Horse Mackerel", "Jellyfish", "Key", "Killifish", "King Salmon", "Koi", "Large Bass", "Loach", "Lobster", "Mitten Crab", "Moray Eel", "Napoleonfish", "Neon Tetra", "Nibble Fish", "Oarfish", "Ocean Sunfish", "Octopus", "Olive Flounder", "Pale Chub", "Pike", "Piranha", "Pond Smelt", "Popeyed Goldfish", "Puffer Fish", "Rainbow Trout", "Ray", "Red Snapper", "Ribbon Eel", "Saddled Bichir", "Salmon", "Saw Shark", "Sea Bass", "Sea Butterfly", "Seahorse", "Shark", "Small Bass", "Softshell Turtle", "Squid", "Stringfish", "Surgeonfish", "Sweetfish", "Tadpole", "Tuna", "Whale Shark", "Yellow Perch", "Zebra Turkeyfish"];
var fish_without_images = ["Blowfish", "Brook Trout", "Butterflyfish", "Can", "Giant Trevally", "Key", "Large Bass", "Lobster", "Mitten Crab", "Moray Eel", "Napoleonfish", "Neon Tetra", "Nibble Fish", "Oarfish", "Pike", "Ray", "Ribbon Eel", "Saddled Bichir", "Saw Shark", "Small Bass", "Softshell Turtle", "Surgeonfish", "Tadpole", "Whale Shark"]; var fish_without_images = ["Blowfish", "Brook Trout", "Butterflyfish", "Can", "Giant Trevally", "Key", "Large Bass", "Lobster", "Mitten Crab", "Moray Eel", "Napoleonfish", "Neon Tetra", "Nibble Fish", "Oarfish", "Pike", "Ray", "Ribbon Eel", "Saddled Bichir", "Saw Shark", "Small Bass", "Softshell Turtle", "Surgeonfish", "Tadpole", "Whale Shark"];
var newfish = require("./newfish.json"); var newfish = require("./newfish.json");
var pokedex = []; 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'];
var sendChat = DiscordClient.sendChat; var sendChat = MPPClient.sendChat;
var blockHelpUntil = 0; var blockHelpUntil = 0;
var locations = ["sleep", "outside", "inside"]
function underline(text) { function underline(text) {
var result = ""; var result = "";
for(var i = 0; i < text.length; i++) { for(var i = 0; i < text.length; i++) {
@ -72,8 +75,8 @@ module.exports = (bot) => {
} }
function startupSound() { function startupSound() {
// client.sendArray([{m: "n", t: Date.now()+client.serverTimeOffset, MPPClient.client.sendArray([{m: "n", t: Date.now()+MPPClient.client.serverTimeOffset,
// n: [{n:"e6",v:0.1},{d:50, n:"c7",v:0.2}]}]); n: [{n:"e6",v:0.1},{d:50, n:"c7",v:0.2}]}]);
} }
function rando(arr) { function rando(arr) {
@ -275,12 +278,12 @@ module.exports = (bot) => {
}; };
function findParticipantByName(name) { function findParticipantByName(name) {
// if(!name || name.trim() == "") return undefined; if(!name || name.trim() == "") return undefined;
// for(var id in client.ppl) { for(var id in MPPClient.client.ppl) {
// if(client.ppl.hasOwnProperty(id) && client.ppl[id].name === name) { if(MPPClient.client.ppl.hasOwnProperty(id) && MPPClient.client.ppl[id].name === name) {
// return client.ppl[id]; return MPPClient.client.ppl[id];
// } }
// } }
return undefined; return undefined;
}; };
@ -289,18 +292,11 @@ module.exports = (bot) => {
var part = findParticipantByName(name); var part = findParticipantByName(name);
if(!part) { if(!part) {
name_lc = name.toLowerCase(); name_lc = name.toLowerCase();
DiscordClient.client.guilds.cache.get('841331769051578413').members.cache.forEach(p => { for (let p of Object.values(MPPClient.client.ppl)) {
if (p.user.username.toLowerCase() === name_lc) { if(p.name.toLowerCase() === name_lc) {
part = p.user; part = p;
part.name = p.user.name;
part._id = p.user.id;
DiscordClient.client.guilds.cache.get('841331769051578413').roles.cache.forEach(r => {
if (r.name === part._id) {
part.color = r.color;
} }
});
} }
});
} }
return part; return part;
}; };
@ -309,18 +305,38 @@ module.exports = (bot) => {
if(!name || name.trim() == "") return undefined; if(!name || name.trim() == "") return undefined;
name = name.toLowerCase(); name = name.toLowerCase();
var part = findParticipantByNameCaseInsensitive(name); var part = findParticipantByNameCaseInsensitive(name);
// for(var id in client.ppl) { for(var id in MPPClient.client.ppl) {
// if(client.ppl.hasOwnProperty(id) && client.ppl[id].name.toLowerCase().indexOf(name) === 0) { if(MPPClient.client.ppl.hasOwnProperty(id) && MPPClient.client.ppl[id].name.toLowerCase().indexOf(name) === 0) {
// part = client.ppl[id]; part = MPPClient.client.ppl[id];
// break; break;
// } }
// } }
// for(var id in client.ppl) { for(var id in MPPClient.client.ppl) {
// if(client.ppl.hasOwnProperty(id) && client.ppl[id].name.toLowerCase().indexOf(name) !== -1) { if(MPPClient.client.ppl.hasOwnProperty(id) && MPPClient.client.ppl[id].name.toLowerCase().indexOf(name) !== -1) {
// part = client.ppl[id]; part = MPPClient.client.ppl[id];
break;
}
}
// new
if (!part) {
// for (var id in MPPClient.client.ppl) {
// let p = MPPClient.client.ppl[id];
// if (!p) continue;
// if (p._id.toLowerCase().includes(name.toLowerCase())) {
// part = p;
// break; // break;
// } // }
// } // }
for (var p of Object.values(MPPClient.client.ppl)) {
if (!p) continue;
if (p._id.toLowerCase().includes(name.toLowerCase())) {
part = p;
break;
}
}
}
return part; return part;
}; };
@ -361,23 +377,44 @@ module.exports = (bot) => {
db.put("look.outside.◍Sand", "We don't talk about that."); db.put("look.outside.◍Sand", "We don't talk about that.");
}, 6000); }, 6000);
function randomizeAllColors() {
for (let p of Object.values(MPPClient.client.ppl)) {
MPPClient.client.sendArray([{m:'setcolor', id:p._id, color:randomColor()}]);
}
}
function swapAllColors() {
let colorList = [];
for (let p of Object.values(MPPClient.client.ppl)) {
colorList.push(p.color);
}
let index = 0;
let lastColor = colorList[colorList.length - 1];
for (let p of Object.values(MPPClient.client.ppl)) {
MPPClient.client.sendArray([{m:'setcolor', id:p._id, color:lastColor}]);
lastColor = colorList[index];
}
}
bot.addCommand(['help', 'about', 'commands'], 0, msg => { bot.addCommand(['help', 'about', 'commands'], 0, msg => {
if (Date.now() < blockHelpUntil) return; if (Date.now() < blockHelpUntil) return;
blockHelpUntil = Date.now() + 10000; 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)"); //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)");
// sendChat(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), /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)"); // sendChat(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), /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)");
sendChat(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), ~~/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)"); // sendChat(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), ~~/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)");
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); }, false);
bot.addCommand('qmyid', 0, (msg, admin) => { bot.addCommand('qmyid', 0, (msg, admin) => {
if (!admin) return; if (!admin) return;
console.log(DiscordClient.client.user.id); console.log(MPPClient.client.user.id);
sendChat(`Friend ${msg.p.name}: Your ID is ${msg.p.id}`);
}, false); }, false);
bot.addCommand('name', 0, (msg, admin) => { bot.addCommand('name', 0, (msg, admin) => {
if (!admin) return; if (!admin) return;
DiscordClient.client.guilds.cache.get('841331769051578413').members.cache.get(DiscordClient.client.user.id).setNickname(msg.argcat()); // DiscordClient.client.guilds.cache.get('841331769051578413').members.cache.get(DiscordClient.client.user.id).setNickname(msg.argcat());
MPPClient.client.sendArray([{m:'userset', set: {name: msg.argcat()}}]);
}, false); }, false);
bot.addCommand('ch', 0, (msg, admin) => { bot.addCommand('ch', 0, (msg, admin) => {
@ -419,13 +456,14 @@ module.exports = (bot) => {
}, false); }, false);
bot.addCommand(['ppl'], 0, msg => { bot.addCommand(['ppl'], 0, msg => {
var list = "sorry :("; // var list = "sorry :(";
// for(var id in client.ppl) { var list = "";
// if(client.ppl.hasOwnProperty(id)) { for(var id in MPPClient.client.ppl) {
// list += ", " + client.ppl[id].name; if(MPPClient.client.ppl.hasOwnProperty(id)) {
// } list += ", " + MPPClient.client.ppl[id].name;
// } }
list = list.substr(2); }
// list = list.substring(0, list.length - 2);
sendChat("ppl: " + list); sendChat("ppl: " + list);
return; return;
}, false); }, false);
@ -444,7 +482,8 @@ module.exports = (bot) => {
}, false); }, false);
bot.addCommand(['pokedex', 'dex'], 0, msg => { bot.addCommand(['pokedex', 'dex'], 0, msg => {
var pkmn = pokedex[msg.args[0]]; // var pkmn = pokedex[msg.args[0]];
var pkmn = pokedex.find(pk => pk.id == msg.argcat() || pk.name.toLowerCase() == msg.argcat().toLowerCase());
if(pkmn && pkmn.id) { if(pkmn && pkmn.id) {
var text = pkmn.id + ", " + pkmn.name + " ("; var text = pkmn.id + ", " + pkmn.name + " (";
var n = 0; var n = 0;
@ -454,6 +493,7 @@ module.exports = (bot) => {
++n; ++n;
} }
text += ") (\"" + pkmn.classification + "\")"; text += ") (\"" + pkmn.classification + "\")";
sendChat(text);
} }
}, false); }, false);
@ -609,7 +649,7 @@ module.exports = (bot) => {
bot.addCommand('put', 0, (msg, admin) => { bot.addCommand('put', 0, (msg, admin) => {
if (!admin) return; if (!admin) return;
db.put(args[0], msg.argcat(1), function(err) { db.put(msg.args[0], msg.argcat(1), function(err) {
if(err) { if(err) {
sendChat("our friend " + msg.p.name + " put ERR: " + err); sendChat("our friend " + msg.p.name + " put ERR: " + err);
} else { } else {
@ -647,9 +687,9 @@ module.exports = (bot) => {
var count = 0; var count = 0;
var result_count = 0; var result_count = 0;
db.createReadStream({ db.createReadStream({
start: args[0] || undefined, start: msg.args[0] || undefined,
end: args[1] || undefined, end: msg.args[1] || undefined,
reverse: args[2] === "reverse" || undefined reverse: msg.args[2] === "reverse" || undefined
}) })
.on("data", function(data) { .on("data", function(data) {
++count; ++count;
@ -668,6 +708,7 @@ module.exports = (bot) => {
}, false); }, false);
bot.addCommand('startup_sound', 0, msg => { bot.addCommand('startup_sound', 0, msg => {
startupSound();
return; return;
}, false); }, false);
@ -805,13 +846,19 @@ module.exports = (bot) => {
var color = "#"+rrggbbrand()+rrggbbrand()+rrggbbrand(); var color = "#"+rrggbbrand()+rrggbbrand()+rrggbbrand();
// client.sendArray([{m: "admin message", password: "amogus", // client.sendArray([{m: "admin message", password: "amogus",
// msg: {m: "color", _id: msg.p._id, color: color}}]); // msg: {m: "color", _id: msg.p._id, color: color}}]);
DiscordClient.client.guilds.cache.get("841331769051578413").roles.cache.forEach(r => { // DiscordClient.client.guilds.cache.get("841331769051578413").roles.cache.forEach(r => {
if (r.name == msg.p._id) { // if (r.name == msg.p._id) {
r.edit({ // r.edit({
// color: color
// });
// }
// })
MPPClient.client.sendArray([{
m: 'setcolor',
_id: msg.p._id,
color: color color: color
}); }]);
}
})
sendChat("Our friend " + msg.p.name+" ate his/her "+food+" and it made him/her turn "+(new Color(color).getName().toLowerCase())+"."); sendChat("Our friend " + msg.p.name+" ate his/her "+food+" and it made him/her turn "+(new Color(color).getName().toLowerCase())+".");
} }
@ -831,7 +878,7 @@ module.exports = (bot) => {
bot.addCommand(['go'], 0, msg => { bot.addCommand(['go'], 0, msg => {
db.getLocation(msg.p._id, location => { db.getLocation(msg.p._id, location => {
var target = msg.argcat().toLowerCase().trim(); var target = msg.argcat().toLowerCase().trim();
if(!["outside", "sleep"].includes(target)) { if(!locations.includes(target)) {
sendChat("Where is "+target+"?"); sendChat("Where is "+target+"?");
return; return;
} }
@ -979,9 +1026,19 @@ module.exports = (bot) => {
return; return;
} }
} else {
if (location == 'inside') {
sendChat(`Excuse me, ${msg.p.name}: Yeeting ${location} is most certainly rude.`);
return;
}
if (!['inside', 'outside'].includes(location)) {
sendChat("Guy/girl "+msg.p.name+": doing that whilst at "+location+" is currently prohibited.");
} else if (location == 'sleep') {
sendChat("Guy/girl "+msg.p.name+": doing that whilst "+location+"ing is currently prohibited.");
} else { } else {
sendChat("Guy/girl "+msg.p.name+": doing that whilst "+location+" is currently prohibited."); sendChat("Guy/girl "+msg.p.name+": doing that whilst "+location+" is currently prohibited.");
} }
}
}); });
return; return;
}); });
@ -989,7 +1046,7 @@ module.exports = (bot) => {
bot.addCommand('grow_fruit', 0, (msg, admin) => { bot.addCommand('grow_fruit', 0, (msg, admin) => {
if (!admin) return; if (!admin) return;
var how_many = ~~args[0]; var how_many = ~~msg.args[0];
if(!how_many) how_many = 1; if(!how_many) how_many = 1;
db.getFruits(function(num_fruits) { db.getFruits(function(num_fruits) {
db.setFruits(num_fruits + how_many); db.setFruits(num_fruits + how_many);
@ -1016,6 +1073,10 @@ module.exports = (bot) => {
} else { } else {
var fish = entry.key; var fish = entry.key;
fish = fish.substr(fish.indexOf("◍")+1); fish = fish.substr(fish.indexOf("◍")+1);
if (['bed'].includes(fish.toLowerCase()) || location == 'sleep') {
sendChat("Friend "+msg.p.name+": You can't take the " + fish + ".");
return;
}
myfish.push(fish); myfish.push(fish);
db.putFish(msg.p._id, myfish); db.putFish(msg.p._id, myfish);
db.del(entry.key); db.del(entry.key);
@ -1029,7 +1090,7 @@ module.exports = (bot) => {
bot.addCommand('give', 0, msg => { bot.addCommand('give', 0, msg => {
var thief = msg.p; var thief = msg.p;
var victim = findParticipantByNameFuzzy(args[0]); var victim = findParticipantByNameFuzzy(msg.args[0]);
if(!victim) { if(!victim) {
sendChat("Friend " +thief.name+" missed"); sendChat("Friend " +thief.name+" missed");
return; return;
@ -1038,7 +1099,7 @@ module.exports = (bot) => {
sendChat("Friendly friend " +thief.name+" fudged"); sendChat("Friendly friend " +thief.name+" fudged");
return; return;
} }
var target_fish = argcat(1); var target_fish = msg.argcat(1);
db.getFish(thief._id, function(thief_fish) { db.getFish(thief._id, function(thief_fish) {
db.getFish(victim._id, function(victim_fish) { db.getFish(victim._id, function(victim_fish) {
if(victim_fish.length >= TOO_MANY_FISH) { if(victim_fish.length >= TOO_MANY_FISH) {
@ -1074,6 +1135,7 @@ module.exports = (bot) => {
setInterval(function() { setInterval(function() {
db.put("look.outside.◍Sand", "We don't talk about that."); db.put("look.outside.◍Sand", "We don't talk about that.");
db.put("look.sleep.◍Bed", "*snuggles*");
}, 6000); }, 6000);
var FISHING_CHANCE = 0.02; var FISHING_CHANCE = 0.02;
@ -1094,22 +1156,34 @@ module.exports = (bot) => {
db.del(winner); db.del(winner);
var user_id = winner.substr(8); var user_id = winner.substr(8);
var part; var part;
DiscordClient.client.guilds.cache.get('841331769051578413').members.cache.forEach(p => { // DiscordClient.client.guilds.cache.get('841331769051578413').members.cache.forEach(p => {
if (p.user.id === user_id) { // if (p.user.id === user_id) {
part = p.user; // part = p.user;
part.name = p.user.username; // part.name = p.user.username;
part._id = p.user.id; // part._id = p.user.id;
// if(typeof part !== 'undefined') {
// catchSomething(part);
// }
// }
// });
for (let p of Object.values(MPPClient.client.ppl)) {
if (p.id === user_id) {
part = p;
part.name = p.name;
part._id = p.id;
if(typeof part !== 'undefined') { if(typeof part !== 'undefined') {
catchSomething(part); catchSomething(part);
} }
} }
}); }
} }
}); });
}, 5000); }, 5000);
setInterval(function() { setInterval(function() {
return; // stop auto-fishing // return; // stop auto-fishing
var client = MPPClient.client;
if(!client.isConnected()) return; if(!client.isConnected()) return;
@ -1119,7 +1193,7 @@ module.exports = (bot) => {
var key = "fishing~"+part._id; var key = "fishing~"+part._id;
db.get(key, function(err, value) { db.get(key, function(err, value) {
if(!value) { if(!value) {
sendChat("/fish"); sendChat("/fish", true);
} else { } else {
db.getFish(part._id, function(myfish) { db.getFish(part._id, function(myfish) {
if(!myfish.length) return; if(!myfish.length) return;
@ -1131,7 +1205,7 @@ module.exports = (bot) => {
else dest = client.ppl[i]; else dest = client.ppl[i];
} }
if(dest && dest.id !== client.participantId) { if(dest && dest.id !== client.participantId) {
sendChat("/give "+dest.name.split(" ")[0]); sendChat("/give "+dest.name.split(" ")[0], true);
} }
}); });
/*if(findParticipantByNameFuzzy("potato")) { /*if(findParticipantByNameFuzzy("potato")) {
@ -1473,7 +1547,7 @@ module.exports = (bot) => {
}); });
}, false); }, false);
bot.addCommand(['/hug'], 0, msg => { bot.addCommand(['hug'], 0, msg => {
var part = findParticipantByNameFuzzy(msg.argcat()); var part = findParticipantByNameFuzzy(msg.argcat());
if (part) { if (part) {
let hug = rando("a squeeze", "an affectionate hug", let hug = rando("a squeeze", "an affectionate hug",
@ -1490,7 +1564,41 @@ module.exports = (bot) => {
} }
}, false); }, false);
bot.addCommand(['/give'], 0, msg => { bot.addCommand(['kiss'], 0, msg => {
var part = findParticipantByNameFuzzy(msg.argcat());
if (part) {
let kiss = rando("a kiss", "a sloppy smooch",
"a deep, passionate french kiss", `a big grandma kiss on the cheek`, "a big smooch on the cheek", "a new kiss", "a lasting mark on their face", "caring kiss");
sendChat(`Our friend ` + msg.p.name + ` gave ` + part.name + ' ' + kiss);
} else {
db.getLocation(msg.p._id, location => {
var message = "Friend " + msg.p.name + " missed and the kiss went everywhere.";
if (location == 'outside' && Math.random() < 0.25) {
message += " Some of it went into the water and love was felt by the fish inside.";
}
sendChat(message);
});
}
});
bot.addCommand(['bonk'], 0, msg => {
var part = findParticipantByNameFuzzy(msg.argcat());
if (part) {
let bonk = rando("a bonk", "a slap",
"a deep, passionate bonk", `a "normal" bonk`, "a bonk on the cheek", "a new bonk", "a lasting mark on their face", "caring bonk");
sendChat(`Our friend ` + msg.p.name + ` gave ` + part.name + ' ' + bonk);
} else {
db.getLocation(msg.p._id, location => {
var message = "Friend " + msg.p.name + " missed and the bonk went everywhere.";
if (location == 'outside' && Math.random() < 0.25) {
message += " Some of it went into the water and love was felt by the fish inside.";
}
sendChat(message);
});
}
});
bot.addCommand(['give'], 0, msg => {
var thief = msg.p; var thief = msg.p;
var victim = findParticipantByNameFuzzy(msg.args[0]); var victim = findParticipantByNameFuzzy(msg.args[0]);
if (!victim) { if (!victim) {
@ -1503,7 +1611,7 @@ module.exports = (bot) => {
} }
var target_fish = msg.argcat(1); var target_fish = msg.argcat(1);
db.getFish(thief._id, function (thief_fish) { db.getFish(thief._id, function (thief_fish) {
db.getFish(victim_id, function (victim_fish) { db.getFish(victim._id, function (victim_fish) {
if (victim_fish.length >= TOO_MANY_FISH) { if (victim_fish.length >= TOO_MANY_FISH) {
sendChat("Friend " + victim.name + " is carrying too much."); sendChat("Friend " + victim.name + " is carrying too much.");
return; return;

79
src/MPPClient.js Normal file
View File

@ -0,0 +1,79 @@
// const Discord = require('discord.js');
const Client = require('./mppt-client.js');
module.exports = class MPPClient {
static start(token) {
this.client = new Client('wss://mppclone.com:8443', token);
this.client.start();
this.client.setChannel('✧𝓓𝓔𝓥 𝓡𝓸𝓸𝓶✧');
this.bindEventListeners();
}
static bindEventListeners() {
this.client.on('hi', () => {
process.stdout.write("\n********************************START********************************\n");
});
// this.client.on('messageUpdate', msg => {
// if (msg.system) return;
// if (msg.author.bot) return;
// this.handleMessage(msg);
// });
this.client.on('a', msg => {
// if (msg.system) return;
// if (msg.author.bot) return;
// if (msg.p.tag)
this.handleMessage(msg);
});
// this.client.on('guildMemberAdd', async guildMember => {
// let role;
// guildMember.guild.roles.cache.forEach(r => {
// if (r.name.toString() == guildMember.user.id.toString()) {
// role = r;
// }
// });
// if (typeof role !== 'undefined') console.log('found role: ' + role.name);
// if (!role) console.log('creating role');
// if (!role) role = await guildMember.guild.roles.create({
// data: {
// name: guildMember.user.id,
// color: Math.floor(Math.random()*16777215).toString(16)
// },
// reason: guildMember.user.id
// });
// if (role) guildMember.roles.add(role);
// });
}
static handleMessage(msg) {
msg.args = msg.a.split(' ');
msg.cmd = msg.a.startsWith(gBot.prefix) ? msg.args[0].substring(gBot.prefix.length).trim() : "";
msg.args = msg.args.slice(1);
msg.argcat = function(start, end) {
var parts = msg.args.slice(start || 0, end || undefined);
var result = "";
for(var i = 0; i < parts.length; i++) {
result += parts[i];
if(i + 1 < parts.length) {
result += " ";
}
}
return result;
};
msg.rank = gBot.getRank(msg.p._id);
gBot.emit('chat.receive', msg);
}
static sendChat(str, skip = false) {
// DiscordClient.client.channels.cache.get('841331769658703954').send(str);
MPPClient.client.sendArray([{
m:'a',
message: skip == true ? str : `\u034f${str}`
}]);
}
}

69
src/RateLimit.js Normal file
View File

@ -0,0 +1,69 @@
var RateLimit = function(interval_ms) {
this._interval_ms = interval_ms || 0; // (0 means no limit)
this._after = 0;
};
RateLimit.prototype.attempt = function(time) {
var time = time || Date.now();
if(time < this._after) return false;
this._after = time + this._interval_ms;
return true;
};
RateLimit.prototype.setInterval = function(interval_ms) {
this._after += interval_ms - this._interval_ms;
this._interval_ms = interval_ms;
};
var RateLimitChain = function(num, interval_ms) {
this.setNumAndInterval(num, interval_ms);
};
RateLimitChain.prototype.attempt = function(time) {
var time = time || Date.now();
for(var i = 0; i < this._chain.length; i++) {
if(this._chain[i].attempt(time)) return true;
}
return false;
};
RateLimitChain.prototype.setNumAndInterval = function(num, interval_ms) {
this._chain = [];
for(var i = 0; i < num; i++) {
this._chain.push(new RateLimit(interval_ms));
}
};
var DataRateLimit = function(limit, interval_ms) {
this._limit = limit;
this._interval_ms = interval_ms || 0; // 0: per-attempt
this._after = 0;
this._size = 0;
};
DataRateLimit.prototype.attempt = function(size, time) {
var time = time || Date.now();
if(time >= this._after) {
this._size = 0;
this._after = time + this._interval_ms;
}
if(this._size + size <= this._limit) {
this._size += size;
return true;
} else {
return false;
}
};
var exports = typeof module !== "undefined" ? module.exports : this;
exports.RateLimit = RateLimit;
exports.RateLimitChain = RateLimitChain;
exports.DataRateLimit = DataRateLimit;

315
src/mppt-client.js Normal file
View File

@ -0,0 +1,315 @@
if(typeof module !== "undefined") {
module.exports = Client;
WebSocket = require("ws");
EventEmitter = require("events").EventEmitter;
} else {
this.Client = Client;
}
function mixin(obj1, obj2) {
for(var i in obj2) {
if(obj2.hasOwnProperty(i)) {
obj1[i] = obj2[i];
}
}
};
function Client(uri, token) {
EventEmitter.call(this);
this.uri = uri;
this.ws = undefined;
this.serverTimeOffset = 0;
this.user = undefined;
this.participantId = undefined;
this.channel = undefined;
this.ppl = {};
this.connectionTime = undefined;
this.connectionAttempts = 0;
this.desiredChannelId = undefined;
this.desiredChannelSettings = undefined;
this.pingInterval = undefined;
this.canConnect = false;
this.noteBuffer = [];
this.noteBufferTime = 0;
this.noteFlushInterval = undefined;
this.token = token;
this.bindEventListeners();
this.emit("status", "(Offline mode)");
};
mixin(Client.prototype, EventEmitter.prototype);
Client.prototype.constructor = Client;
Client.prototype.isSupported = function() {
return typeof WebSocket === "function";
};
Client.prototype.isConnected = function() {
return this.isSupported() && this.ws && this.ws.readyState === WebSocket.OPEN;
};
Client.prototype.isConnecting = function() {
return this.isSupported() && this.ws && this.ws.readyState === WebSocket.CONNECTING;
};
Client.prototype.start = function() {
this.canConnect = true;
this.connect();
};
Client.prototype.stop = function() {
this.canConnect = false;
this.ws.close();
};
Client.prototype.connect = function() {
if(!this.canConnect || !this.isSupported() || this.isConnected() || this.isConnecting())
return;
this.emit("status", "Connecting...");
this.ws = new WebSocket(this.uri);
this.ws.binaryType = "arraybuffer";
var self = this;
this.ws.addEventListener("close", function(evt) {
self.user = undefined;
self.participantId = undefined;
self.channel = undefined;
self.setParticipants([]);
clearInterval(self.pingInterval);
clearInterval(self.noteFlushInterval);
self.emit("disconnect");
self.emit("status", "Offline mode");
// reconnect!
if(self.connectionTime) {
self.connectionTime = undefined;
self.connectionAttempts = 0;
} else {
++self.connectionAttempts;
}
var ms_lut = [50, 2950, 7000, 10000];
var idx = self.connectionAttempts;
if(idx >= ms_lut.length) idx = ms_lut.length - 1;
var ms = ms_lut[idx];
setTimeout(self.connect.bind(self), ms);
});
this.ws.addEventListener("open", function(evt) {
self.connectionTime = Date.now();
self.sendArray([{m: "hi", token: self.token}]);
self.pingInterval = setInterval(function() {
self.sendArray([{m: "t", e: Date.now()}]);
}, 20000);
//self.sendArray([{m: "t", e: Date.now()}]);
self.noteBuffer = [];
self.noteBufferTime = 0;
self.noteFlushInterval = setInterval(function() {
if(self.noteBufferTime && self.noteBuffer.length > 0) {
self.sendArray([{m: "n", t: self.noteBufferTime + self.serverTimeOffset, n: self.noteBuffer}]);
self.noteBufferTime = 0;
self.noteBuffer = [];
}
}, 200);
self.emit("connect");
self.emit("status", "Joining channel...");
});
this.ws.addEventListener("message", function(evt) {
if(typeof evt.data !== 'string') return;
var transmission = JSON.parse(evt.data);
for(var i = 0; i < transmission.length; i++) {
var msg = transmission[i];
self.emit(msg.m, msg);
}
});
};
Client.prototype.bindEventListeners = function() {
var self = this;
this.on("hi", function(msg) {
self.user = msg.u;
self.receiveServerTime(msg.t, msg.e || undefined);
if(self.desiredChannelId) {
self.setChannel();
}
});
this.on("t", function(msg) {
self.receiveServerTime(msg.t, msg.e || undefined);
});
this.on("ch", function(msg) {
self.desiredChannelId = msg.ch._id;
self.channel = msg.ch;
if(msg.p) self.participantId = msg.p;
self.setParticipants(msg.ppl);
});
this.on("p", function(msg) {
self.participantUpdate(msg);
self.emit("participant update", self.findParticipantById(msg.id));
});
this.on("m", function(msg) {
if(self.ppl.hasOwnProperty(msg.id)) {
self.participantUpdate(msg);
}
});
this.on("bye", function(msg) {
self.removeParticipant(msg.p);
});
};
Client.prototype.send = function(raw) {
if(this.isConnected()) this.ws.send(raw);
};
Client.prototype.sendArray = function(arr) {
this.send(JSON.stringify(arr));
};
Client.prototype.setChannel = function(id, set) {
this.desiredChannelId = id || this.desiredChannelId || "lobby";
this.desiredChannelSettings = set || this.desiredChannelSettings || undefined;
this.sendArray([{m: "ch", _id: this.desiredChannelId, set: this.desiredChannelSettings}]);
};
Client.prototype.offlineChannelSettings = {
lobby: true,
visible: false,
chat: false,
crownsolo: false,
color:"#ecfaed"
};
Client.prototype.getChannelSetting = function(key) {
if(!this.isConnected() || !this.channel || !this.channel.settings) {
return this.offlineChannelSettings[key];
}
return this.channel.settings[key];
};
Client.prototype.offlineParticipant = {
name: "",
color: "#777"
};
Client.prototype.getOwnParticipant = function() {
return this.findParticipantById(this.participantId);
};
Client.prototype.setParticipants = function(ppl) {
// remove participants who left
for(var id in this.ppl) {
if(!this.ppl.hasOwnProperty(id)) continue;
var found = false;
for(var j = 0; j < ppl.length; j++) {
if(ppl[j].id === id) {
found = true;
break;
}
}
if(!found) {
this.removeParticipant(id);
}
}
// update all
for(var i = 0; i < ppl.length; i++) {
this.participantUpdate(ppl[i]);
}
};
Client.prototype.countParticipants = function() {
var count = 0;
for(var i in this.ppl) {
if(this.ppl.hasOwnProperty(i)) ++count;
}
return count;
};
Client.prototype.participantUpdate = function(update) {
var part = this.ppl[update.id] || null;
if(part === null) {
part = update;
this.ppl[part.id] = part;
this.emit("participant added", part);
this.emit("count", this.countParticipants());
} else {
if(update.x) part.x = update.x;
if(update.y) part.y = update.y;
if(update.color) part.color = update.color;
if(update.name) part.name = update.name;
}
};
Client.prototype.removeParticipant = function(id) {
if(this.ppl.hasOwnProperty(id)) {
var part = this.ppl[id];
delete this.ppl[id];
this.emit("participant removed", part);
this.emit("count", this.countParticipants());
}
};
Client.prototype.findParticipantById = function(id) {
return this.ppl[id] || this.offlineParticipant;
};
Client.prototype.isOwner = function() {
return this.channel && this.channel.crown && this.channel.crown.participantId === this.participantId;
};
Client.prototype.preventsPlaying = function() {
return this.isConnected() && !this.isOwner() && this.getChannelSetting("crownsolo") === true;
};
Client.prototype.receiveServerTime = function(time, echo) {
var self = this;
var now = Date.now();
var target = time - now;
//console.log("Target serverTimeOffset: " + target);
var duration = 1000;
var step = 0;
var steps = 50;
var step_ms = duration / steps;
var difference = target - this.serverTimeOffset;
var inc = difference / steps;
var iv;
iv = setInterval(function() {
self.serverTimeOffset += inc;
if(++step >= steps) {
clearInterval(iv);
//console.log("serverTimeOffset reached: " + self.serverTimeOffset);
self.serverTimeOffset=target;
}
}, step_ms);
// smoothen
//this.serverTimeOffset = time - now; // mostly time zone offset ... also the lags so todo smoothen this
// not smooth:
//if(echo) this.serverTimeOffset += echo - now; // mostly round trip time offset
};
Client.prototype.startNote = function(note, vel) {
if(this.isConnected()) {
var vel = typeof vel === "undefined" ? undefined : +vel.toFixed(3);
if(!this.noteBufferTime) {
this.noteBufferTime = Date.now();
this.noteBuffer.push({n: note, v: vel});
} else {
this.noteBuffer.push({d: Date.now() - this.noteBufferTime, n: note, v: vel});
}
}
};
Client.prototype.stopNote = function(note) {
if(this.isConnected()) {
if(!this.noteBufferTime) {
this.noteBufferTime = Date.now();
this.noteBuffer.push({n: note, s: 1});
} else {
this.noteBuffer.push({d: Date.now() - this.noteBufferTime, n: note, s: 1});
}
}
};

2485
src/pokedex.json Normal file

File diff suppressed because it is too large Load Diff