clone from github

This commit is contained in:
Boris
2024-01-15 09:30:27 +00:00
parent cb714d9889
commit 2a47c91dbf
37 changed files with 7581 additions and 0 deletions

View File

@@ -0,0 +1,366 @@
//Command list
const commands = {
'ping': (message, args) =>
{
message.channel.send("pong");
},
'tp': async function (message, args)
{
while ( args.length && args[0].toLowerCase() === namemanager(args[0]) )
{
argv = args.shift();
}
},
'where': (message, args) =>
{
while ( args.length && args[0].toLowerCase() === "is" )
{
argv = args.shift();
}
var username = args.join(' ');
players.findOne({ username: username }, function( err, player ) {
if ( err )
{
console.log( err );
} else if ( !!player && player.lastChunk !== undefined ) {
message.channel.send( '```'+ username +" was last seen at "+ player.lastChunk +'```');
} else {
message.channel.send( '```'+ "No location known for "+ username +'```' );
}
});
},
'who': (message, args) =>
{
while( args.length && args[0].toLowerCase() === "is" )
{
argv = args.shift();
}
var username = args.join(' ');
players.findOne({ username: username }, function( err, player ) {
if ( err )
{
console.log( err );
} else {
if ( !player )
{
message.guild.channel.send('```'+ "Unknown user: "+ username +'```');
} else if ( !player.bio ) {
message.channel.send('```'+ username +" does not have a bio"+ '```');
} else {
message.channel.send('```'+ username +" is "+ player.bio +'```');
}
}
});
},
'bio': (message, args) =>
{
console.log( args );
function updatePlayerBio( playerid, bio )
{
players.update({ id: playerid }, { $set: { bio: bio } }, {}, function( err, numReplaced ) {
if ( err )
{
console.log( err );
} else {
message.channel.send('```'+ username +" is "+ bio +'```');
}
});
}
var username = message.author.username;
players.findOne({ username: username }, function( err, player ) {
if ( err ) {
console.log( err );
}
console.log( player );
if ( player )
{
while ( args[0] === username || args[0] === "is" )
{
args.shift();
}
var bio = args.join(' ');
updatePlayerBio( player.id, bio );
} else {
username = args.shift();
while( args[0] === "is" ) { args.shift(); }
var bio = args.join(' ');
players.findOne({ username, username }, function( err, player ) {
if ( player )
{
updatePlayerBio( player.id, bio )
} else {
message.channel.send('```'+ "Unknown user: "+ username +'```');
}
});
}
});
},
'servers': async function (message, args)
{
var servers = await Servers.getOnline();
if ( !!servers )
{
var longest = 0;
for( var i in servers )
{
if ( servers[i].name.length > longest )
{
longest = servers[i].name.length;
}
}
var serverNameLen = longest + 1;
var listTable = "| Servers"+ strrep(' ', (serverNameLen - 7)) +"| Players\n";
listTable += "|"+ strrep('-', (serverNameLen + 1) ) +"|---------\n";
for ( var i in servers )
{
if ( blacklistServers.includes( servers[i].id ) )
{
continue
}
if ( !showAllServers && !targetServers.includes( servers[i].id ) )
{
continue
}
listTable += "| "+ servers[i].name + strrep(' ', ( serverNameLen - servers[i].name.length )) +"| "+ servers[i].online_players.length +"\n";
}
message.channel.send( '```'+ listTable +'```' );
} else {
message.channel.send("No servers appear to be online, perhaps it's patch day?");
}
},
'players': async function (message, args)
{
var servers = await Servers.getOnline();
var listTable = '';
while ( args.length && ( args[0].toLowerCase() === "online" || args[0].toLowerCase() === "in" || args[0].toLowerCase() === "on" ) )
{
args.shift();
}
var mustMatch = args.join(' ');
for( var i in servers )
{
var pOnline = servers[i].online_players;
if ( pOnline.length <= 0 && !mustMatch )
{
continue
}
if ( blacklistServers.includes( servers[i].id ) )
{
continue;
}
if ( !showAllServers && !targetServers.includes( servers[i].id ) )
{
continue;
}
if ( mustMatch )
{
var re = new RegExp( mustMatch, 'ig' );
if ( !servers[i].name.match( re ) )
{
continue;
}
}
listTable += "| "+ servers[i].name +"\n";
listTable += "|"+ strrep('-', (servers[i].name.length + 1)) +"\n";
if ( pOnline.length <= 0 )
{
listTable += "| No players online\n"
} else {
for( var n in pOnline )
{
listTable += "| "+ pOnline[n].username +"\n";
}
}
listTable += "\n";
}
if ( listTable === '' )
{
if ( mustMatch )
{
message.channel.send('```No server found matching "'+ mustMatch +'"```');
} else {
message.channel.send('```No servers were found online, is it patch day?```');
}
} else {
message.channel.send('```'+ listTable +'```');
}
},
'zone': async function (message, args)
{
switch( args.shift() )
{
case 'history':
var chunkName = args.join(' ');
players.find({}, function( err, playerList ) {
chunkHistory.find({ chunk: chunkName }).sort({ ts: -1 }).exec( function( err, chunklist ) {
if ( err )
{
console.log( err );
} else if ( !chunklist ) {
message.channel.send('```'+ "No history for zone '"+ chunkName +"'"+ '```');
} else {
var response = "| Players who have recently visited zone '"+ chunkName +"'\n";
response += "|--------------------------------"+ strrep( '-', chunkName.length ) +"-\n";
let limit = 15;
if ( chunklist.length < limit ) { limit = chunklist.length; }
for ( var i = 0; i < limit; i++ ) {
ichunk = chunklist[i];
if ( ++i > 10 ) { }
player = playerList.find( x => x.id === ichunk.player );
response += "|["+ moment( ichunk.ts ).format("YYYY/MM/DD HH:mm:ss") +"] "+ player.username +"\n";
};
message.channel.send('```'+ response +'```');
}
});
});
break;
}
},
'player' : async function ( message, args )
{
switch( args.shift() )
{
case 'path':
// Return known history of player movements
var username = args.join(' ');
players.findOne({ username: username }, function( err, player ) {
if ( err )
{
message.channel.send('```'+ "No player data found for "+ username +'```');
} else {
if ( !!player )
{
chunkHistory.find({ player: player.id }).sort({ ts: -1 }).exec( function ( err, chunklist ) {
if ( err )
{
console.log( err );
} else if ( !!chunklist ) {
let limit = 20;
var response = '| Path History for '+ username +"\n";
response += '|------------------'+ strrep('-', username.length+1) +"\n";
if ( chunklist.length < limit ) { limit = chunklist.length; }
for ( var i = 0; i < limit ; i++ ) {
var elem = chunklist[i];
response += "|["+ moment( elem.ts ).format( "YYYY/MM/DD HH:mm:ss" ) +"] "+ elem.chunk +"\n";
}
message.channel.send('```'+ response +'```');
} else {
message.channel.send('```'+ "No path data found for "+ username +'```');
}
});
} else {
message.channel.send('```'+ "No player found for "+ username +'```');
}
}
});
break;
}
},
'load' : async function( message, args )
{
switch( args.shift() )
{
case 'assets':
// First verify the message author has correct permission
if ( message.member.roles.some( x => discordRoles.admin.includes( x.id ) ))
{
console.log( ts()+ "loading assets");
message.channel.send('```'+ "Loading ATT assets, please wait" +'```');
// Add the handler to pendingCommandList
pendingCommandList.push({
"command" : "spawn list",
"module" : "Alta.Console.Commands.SpawnCommandModule",
"handler": function ( response ) {
let countPrefabs = 0;
let responselines = response.split(/\n/)
responselines.forEach( function( line ) {
let found = line.match( /\|([^|]+)\|([^|]+)\|/ );
if ( found )
{
found.shift(); // fulltext of match
let num = new String( found.shift() ).trim() // ID of the prefab
let val = new String( found.shift() ).trim() // The prefab name
if ( num.match( /[0-9]+/ ) )
{
// It's a prefab! Store it
console.log( "found asset: "+ num +" | "+ val )
spawnables.update({ hash: num }, { $set : { hash: num, name: val } }, { upsert: true }, updateHandler );
countPrefabs++;
}
}
});
message.channel.send( '```'+ "Found and stored "+ countPrefabs + " spawnable assets" +'```')
}
});
// Finally, execute the command
try {
botConnection.wrapper.send( "spwan list" );
} catch ( e ) {
console.log( e )
message.channel.send( '```'+ "Cannot send command, is server offline?" +'```')
return;
}
} else {
console.log( "invalid permission to load assets" );
message.channel.send('```'+ "You do not have the required permissions" +'```');
}
break;
}
},
'find' : async function( message, args )
{
switch( args.shift() )
{
case 'asset':
case 'spawnable':
case 'item':
let mustMatch = args.join(' ');
spawnables.find({ name : { $regex: new RegExp( mustMatch, 'gi' ) }}).sort({ name : 1 }).exec( function( err, results ) {
let response = "| Spawnable items matching "+ mustMatch +" ("+ results.length +")\n";
response += "|--------------------------"+ strrep('-', mustMatch.length) + "-----\n";
let itemc = 0;
results.forEach( function( item ) {
let shortsp = '';
if ( item.hash.length < 5 ) { shortsp = ' '; }
response += "| "+ item.hash + shortsp + " | "+ item.name +"\n";
if ( itemc++ > 20 )
{
message.channel.send('```'+ response +'```')
itemc = 0;
response = '';
}
});
message.channel.send( '```'+ response +'```')
})
break;
}
}
}

View File

@@ -0,0 +1,148 @@
"use strict";
exports.namemanager = (name) => {
if(name == undefined) {
name = playername
}
if(name == "") {
name = playername
}
if(name == "poi") {
name = "poiuytrewq4645"
}
if(name == "mansnac") {
name = "mantax"
}
if(name == "ursa") {
name = "Ursidious"
}
/*if(name == "") {
name = ""
}*/
return name
}
exports.splitArgs = (args) => {
let spaceChars = '#s#';
// If an exact match of the space character exists in the string, make it more unique
while( args.indexOf( spaceChars ) > -1 ) { spaceChars += '|'; }
// replace spaces which are inside quotes with the spaceChar placeholder
let mangleargs = args.replace( /[“"]([^“^"]*)[“"]?/g, ( match, cap ) => {
return cap.replace(/\s/g, spaceChars );
});
// split the padded string on actual spaces
let newargs = mangleargs.split( /\ +/ );
// replace the spaceChar in any matching elements with actual spaces
let reg = new RegExp( spaceChars, 'g' );
let argarr = newargs.map( ( x ) => { return x.replace( reg, ' ' ); });
return argarr;
}
exports.teleportmanager = (location) => {
console.log(location)
switch (location) {
//Pope Mountain
case "Mountain":
return [-1259,1000.69,942]
break
//Mystery Roof Place
case "000":
return [0,1000.69,0]
break
//Evinon Empire
case "EE":
return [-174.5,1000.69,-644.5]
break
case "Storage":
return [ -351.975, 209.94, -661.433 ]
break
//Grey Wardens
case "GW":
return [-639.453,1000.69,-82.208]
break
//Sin City
case "SC":
return [-329.748,1000.69,-343.807]
break
//Schmmechee Sentinels
case "SS":
return [-969.479,1000.69,129.304]
break
//Viridium Valour
case "VV":
return [-608.406,1000.69,94.553]
break
//Bounding Foxes
case "BF":
return [-519.507,1000.69,62.1519966]
break
//Town Blacksmith
case "Smithy":
return [-717.2,1000.69,12.7]
break
//Town Hall :V
case "TH":
return [-895.2,1000.69,93.9]
break
//Path between Dust Bowl and Cliffs
case "DB":
return [-581,1000.69,325.3]
break
//Inside Mines
case "Mines":
return [-897.749,1000.69,-160.403]
break
//Mountain outback of camps
case "OM":
return [988.816,1000.69,-736.122]
break
//Mountain outback of the outback mountain of the camps
case "OOM":
return [1019.675,1000.69,-1371.084]
break
//Outside the MP Bridge
case "MP":
return [-1051.641,1000.69,39.53]
break
//Televator Surface TP
case "Televator":
return [-869.021,1000.69,-123.773]
break
//Town Crafting Building
case "Crafting_Building":
return [-799.941,1000.69,103.74]
break
//Skydiving, may die
case "Skydive":
return [-295.713,990,435.593]
break
//
//SHRINES START
//
case "Archery":
return [-835,1000.69,385]
break
case "Blacksmith":
return [-642.704,1000.69,19.363]
break
case "Combat":
return [-1403.3,1000.69,161]
break
case "Woodcutting":
return [-404.3,1000.69,19.6]
break
case "Mining":
return [-825.419,1000.69,-59.953]
break
case "General_Shrine":
return [-1145.647,1000.69,113.898]
break
//
///SHRINES END
//
default:
return null
break
}
}

View File

@@ -0,0 +1,21 @@
module.exports = class Player {
constructor( id, username )
{
this.id = id;
this.username = username;
}
set id( id ) { this._id = id; }
get id() { return _id; }
set username(username) { this._username = username; }
get username() { return this._username; }
set bio(bio) { this._bio = bio; }
get bio() { return _bio; }
set lastLogin(lastLogin) { this._lastLogin = lastLogin; }
get lastLogin() { return _lastLogin; }
}

View File

@@ -0,0 +1,124 @@
const moment = require('moment');
function now()
{
return moment().valueOf();
}
function ts_f()
{
return "["+ moment().format("h:mm:ss A") +"] "
}
// Database helpers
function insertHandler( err, doc )
{
if ( err ) { console.log( err ); }
}
function updateHandler( err, rows )
{
if ( err ) { console.log( err ); }
}
module.exports = class Subscriptions {
constructor( discordChannels, playersDb, killsDb, chunksDb ) {
this.discordChannels = discordChannels;
this.playersDb = playersDb;
this.killsDb = killsDb;
this.chunksDb = chunksDb;
}
PlayerJoined( discord, data )
{
//console.log( data );
this.playersDb.update(
{ id: data.user.id },
{ $set: { username: data.user.username, lastLogin: now() } },
{ upsert: true },
updateHandler
);
discord.channels.get( this.discordChannels["PlayerJoined"] ).send( ts_f() + data.user.username +" joined the server" );
console.log( ts_f() + data.user.username +" joined the server" );
}
PlayerLeft( discord, data )
{
//console.log( data );
discord.channels.get( this.discordChannels["PlayerLeft"] ).send( ts_f() + data.user.username +" left the server" );
console.log( ts_f() + data.user.username +" left the server" );
}
PlayerMovedChunk( discord, data )
{
//console.log( data );
this.playersDb.update({ id: data.player.id }, { $set: { lastChunk: data.newChunk } }, {}, updateHandler );
this.chunksDb.insert({ ts: now(), player: data.player.id, chunk: data.newChunk }, insertHandler );
// also update the zone history for the new chunk
// TODO
console.log( ts_f() + data.player.username +" has moved to chunk "+ data.newChunk );
}
PlayerKilled( discord, data )
{
//console.log( data );
console.log( ts_f() + "player kill" );
if ( data.killerPlayer != undefined )
{
this.killsDb.insert({
ts: now(),
killed : data.killedPlayer.id,
killer: data.killerPlayer.id,
usedTool: data.usedTool,
toolWielder: data.toolWielder
}, insertHandler );
discord.channels.get( this.discordChannels["PlayerKilled"] ).send( ts_f() + data.killerPlayer.username +" has killed "+ data.killedPlayer.username );
discord.channels.get( this.discordChannels["PublicPlayerKilled"] ).send( '```'+ data.killerPlayer.username +" has murdered "+ data.killedPlayer.username +'```' );
} else {
if ( data.toolWielder )
{
this.killsDb.insert({
ts: now(),
killed : data.killedPlayer.id,
usedTool: data.usedTool,
toolWielder: data.toolWielder
}, insertHandler );
let matches = data.toolWielder.match( /[0-9]+\s-\s([^\()]+)/ );
let toolWielder = data.toolWielder;
if ( matches !== null )
{
toolWielder = matches[1];
}
discord.channels.get( this.discordChannels["PlayerKilled"] ).send( ts_f() + data.killedPlayer.username +" was killed by: "+ toolWielder );
discord.channels.get( this.discordChannels["PublicPlayerKilled"] ).send( '```'+ data.killedPlayer.username +" was killed by: "+ toolWielder +'```' );
} else {
this.killsDb.insert({
ts: now(),
killed : data.killedPlayer.id,
}, insertHandler );
discord.channels.get( this.discordChannels["PlayerKilled"] ).send( ts_f() + data.killedPlayer.username +" has suddenly offed themselves" );
discord.channels.get( this.discordChannels["PublicPlayerKilled"] ).send( '```'+ data.killedPlayer.username +" has suddenly offed themselves" +'```');
}
}
}
TradeDeckUsed( discord, data )
{
console.log( ts_f() + "trade deck used" );
console.log( data );
}
CreatureKilled( discord, data )
{
console.log( ts_f() + "creature murdered" );
console.log( data );
}
CreatureSpawned( discord, data )
{
console.log( ts_f() + "creature has spawned" );
console.log( data );
}
}