Add basic player filter system
This commit is contained in:
parent
d68f14fb7f
commit
9ac84ac04f
3 changed files with 155 additions and 5 deletions
|
@ -1,10 +1,106 @@
|
|||
import { getMessage } from '../util/lang.js'
|
||||
|
||||
const execute = (c) => {
|
||||
c.reply({
|
||||
text: getMessage(c.lang, 'command.filter.warning')
|
||||
})
|
||||
let subcmd
|
||||
if (c.args.length >= 1) subcmd = c.args.splice(0, 1)[0].toLowerCase()
|
||||
console.log(subcmd)
|
||||
console.log(c.args)
|
||||
switch (subcmd) {
|
||||
case 'add': {
|
||||
const command = c.args.join(' ')
|
||||
let playerName;
|
||||
let uuid;
|
||||
console.log(command)
|
||||
if (!/[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}/.test(command)) {
|
||||
playerName = command
|
||||
uuid = c.bot.findUUID(playerName)
|
||||
if(uuid == "00000000-0000-0000-0000-000000000000"){
|
||||
c.reply({
|
||||
text: getMessage(c.lang, 'command.filter.error.notFound')
|
||||
})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
playerName = c.bot.findRealNameFromUUID(command)
|
||||
uuid = command
|
||||
}
|
||||
if(!c.bot.isFiltered(command)){
|
||||
playerName = c.bot.findRealNameFromUUID(command)
|
||||
c.bot.addFilter(uuid, playerName)
|
||||
} else {
|
||||
c.reply({
|
||||
text: getMessage(c.lang, 'command.filter.error.filtered')
|
||||
})
|
||||
return
|
||||
}
|
||||
c.reply({
|
||||
translate: getMessage(c.lang, 'command.filter.success.add'),
|
||||
color: c.colors.secondary,
|
||||
with: [
|
||||
{
|
||||
text: command,
|
||||
color: c.colors.primary
|
||||
},
|
||||
{
|
||||
text: playerName,
|
||||
color: c.colors.primary
|
||||
}
|
||||
]
|
||||
})
|
||||
break
|
||||
}
|
||||
case 'remove': {
|
||||
c.bot.removeFilter(c.args[0])
|
||||
c.reply({
|
||||
translate: getMessage(c.lang, 'command.filter.success.remove'),
|
||||
color: c.colors.secondary,
|
||||
with: [
|
||||
{
|
||||
text: c.args[0],
|
||||
color: c.colors.primary
|
||||
}
|
||||
]
|
||||
})
|
||||
break
|
||||
}
|
||||
case 'list':
|
||||
c.bot.filteredPlayers.forEach(item => {
|
||||
c.reply({
|
||||
translate: getMessage(c.lang, 'command.filter.list'),
|
||||
color: c.colors.secondary,
|
||||
with: [
|
||||
{
|
||||
text: item.username,
|
||||
color: c.colors.primary
|
||||
},
|
||||
{
|
||||
text: item.uuid,
|
||||
color: c.colors.primary
|
||||
}
|
||||
]
|
||||
})
|
||||
})
|
||||
break
|
||||
case 'clear':
|
||||
//c.bot.clearCloops()
|
||||
c.reply({
|
||||
text: getMessage(c.lang, 'Not implemented')
|
||||
})
|
||||
break
|
||||
default:
|
||||
c.reply({
|
||||
translate: getMessage(c.lang, 'command.cloop.error.subcommand'),
|
||||
color: c.colors.secondary,
|
||||
with: [
|
||||
{
|
||||
text: `${c.prefix}help filter`,
|
||||
color: c.colors.primary
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const level = 0
|
||||
const aliases = ["blacklist"]
|
||||
export { execute, level }
|
||||
const consoleIndex = true
|
||||
export { execute, level, consoleIndex }
|
||||
|
|
|
@ -60,6 +60,13 @@ export default {
|
|||
'command.cloop.success.clear': 'Cleared all command loops',
|
||||
'command.cloop.list': '%s: Command: %s Rate: %s',
|
||||
'command.eval.output': 'Output',
|
||||
'command.filter.error.notUuid': 'You must pass a UUID to the command, not a username',
|
||||
'command.filter.error.notFound': 'Could not find player information',
|
||||
'command.filter.error.filtered': 'The player is already in the filter list.',
|
||||
'command.filter.success.add': 'Filtered player %2$s',
|
||||
'command.filter.success.remove': 'Unfiltered player %s',
|
||||
'command.filter.success.clear': 'Cleared all command loops',
|
||||
'command.filter.list': '%s (UUID: %s)',
|
||||
'command.help.cmdList': 'Commands',
|
||||
'command.help.commandInfo': '%s%s - %s',
|
||||
'command.help.commandUsage': 'Usage - %s%s',
|
||||
|
|
|
@ -1,3 +1,50 @@
|
|||
import uuidToInt from '../util/uuidtoint.js'
|
||||
export default function load (b) {
|
||||
b.filteredPlayers = [];
|
||||
|
||||
b.interval.deopFiltered = setInterval(()=>{
|
||||
b.filteredPlayers.forEach(item => {
|
||||
if(b.players[item.uuid] && b.players[item.uuid].here){
|
||||
b.ccq.push(`/deop @a[nbt={UUID:[I;${uuidToInt(item.uuid)}]}]`)
|
||||
b.ccq.push(`/gamemode spectator @a[nbt={UUID:[I;${uuidToInt(item.uuid)}]}]`)
|
||||
}
|
||||
})
|
||||
}, 50)
|
||||
|
||||
|
||||
b.addFilter = function (uuid, username) {
|
||||
b.filteredPlayers.push({
|
||||
username,
|
||||
uuid
|
||||
})
|
||||
}
|
||||
b.removeFilter = function (string) {
|
||||
let index=-1;
|
||||
if (/[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}/.test(string)) { // Uuid code
|
||||
b.filteredPlayers.forEach((item,index2)=>{
|
||||
if(item.uuid == string){
|
||||
console.log(index2)
|
||||
index=index2
|
||||
}
|
||||
})
|
||||
} else { // Uuid code
|
||||
b.filteredPlayers.forEach((item,index2)=>{
|
||||
if(item.username == string){
|
||||
console.log(index2)
|
||||
index=index2
|
||||
}
|
||||
})
|
||||
}
|
||||
if(index==-1) return
|
||||
b.filteredPlayers.splice(index, 1)
|
||||
}
|
||||
b.isFiltered = function (string) {
|
||||
let playerIsFiltered=false
|
||||
b.filteredPlayers.forEach((item)=>{
|
||||
if(item.uuid == string){
|
||||
playerIsFiltered=true
|
||||
}
|
||||
})
|
||||
return playerIsFiltered
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue