console rewrite and chat packet types rewrite. v6.0.1 build: 990
This commit is contained in:
parent
b295cc2d0f
commit
e5741ffac1
2 changed files with 0 additions and 250 deletions
|
@ -1,91 +0,0 @@
|
|||
const CommandSource = require('../util/command_source');
|
||||
function CommandConsole (bot, options, config) {
|
||||
const ChatMessage = require('prismarine-chat')(options.version);
|
||||
// let ratelimit = 0;
|
||||
bot.console = {
|
||||
readline: null,
|
||||
consoleServer: 'all',
|
||||
useReadlineInterface (rl) {
|
||||
this.readline = rl
|
||||
rl.on('line', line => {
|
||||
if (bot.options.serverName !== this.consoleServer && this.consoleServer !== 'all') return
|
||||
if (line.startsWith(config.console.prefix)) {
|
||||
return bot.commandManager.executeString(bot.console.source, line.substring(config.console.prefix.length))
|
||||
} if (line.startsWith("")) {
|
||||
return bot.commandManager.executeString(bot.console.source, `console say ${line.substring(0)}`)
|
||||
}
|
||||
})
|
||||
|
||||
rl.on('close', () => {
|
||||
this.readline = null
|
||||
})
|
||||
log = function (...args) {
|
||||
rl.output.write("\x1b[2K\r");
|
||||
console.log.apply(console, arguments);
|
||||
rl._refreshLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
bot.console.logs = function (message) {
|
||||
log(ChatMessage.fromNotch(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §6logs§8] §8[${options.serverName}§8] `)?.toAnsi() + message)
|
||||
}
|
||||
bot.console.info = function (message) {
|
||||
log(ChatMessage.fromNotch(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §2info§8] §8[${options.serverName}§8] `)?.toAnsi() + message)
|
||||
}
|
||||
bot.console.warn = function (message) {
|
||||
console.log(ChatMessage.fromNotch(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §ewarn§8] §8[${options.serverName}§8] `)?.toAnsi() + message)
|
||||
}
|
||||
bot.console.source = new CommandSource(bot.options.username, { console: true, discord: false });
|
||||
bot.console.source.sendFeedback = message => {
|
||||
const ansi = bot.getMessageAsPrismarine(message)?.toAnsi(bot.registry.language).replaceAll('BlackStone Mafia On Top!', "Fuck off you god damn cunt")
|
||||
if (!options.logging) return
|
||||
bot.console.logs(ChatMessage.fromNotch('§8[§6Command§8] ')?.toAnsi() + ansi);
|
||||
}
|
||||
bot.console.error = function (message) {
|
||||
console.log(ChatMessage.fromNotch(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §4error§8] §8[${options.serverName}§8] `)?.toAnsi() + message)
|
||||
}
|
||||
bot.console.customChat = {
|
||||
enabled: false,
|
||||
chat (message) {
|
||||
const prefix = {
|
||||
translate: '[%s] %s \u203a %s',
|
||||
color:'dark_gray',
|
||||
with: [
|
||||
{
|
||||
text: 'FNFBoyfriendBot Console',
|
||||
color:'#00FFFF'
|
||||
},
|
||||
{
|
||||
selector: `${bot.username}`, color:'#00FFFF',
|
||||
clickEvent: { action: 'suggest_command', value: '~help' }
|
||||
},
|
||||
{
|
||||
text: '',
|
||||
extra: [`${message}`],
|
||||
color:'white'
|
||||
},
|
||||
],
|
||||
hoverEvent: { action:"show_text", value: 'FNF Sky is a fangirl but a simp for boyfriend confirmed??'},
|
||||
clickEvent: 'https://doin-your.mom' ?
|
||||
{ action: 'open_url', value: 'https://doin-your.mom' } : undefined,
|
||||
}
|
||||
bot.tellraw('@a', prefix)
|
||||
}
|
||||
}
|
||||
// setInterval(() => ratelimit = 0, 1000)
|
||||
bot.on('message', message => {
|
||||
/* if (ratelimit > 300) {
|
||||
// bot.console.warn('WTF spam detected not logging')
|
||||
bot.options.logging = false;
|
||||
return;
|
||||
}*/
|
||||
// options.logging = true;
|
||||
// if (ratelimit++ >= 300) return
|
||||
const ansi = bot.getMessageAsPrismarine(message)?.toAnsi(bot.registry.language).replaceAll('BlackStone Mafia On Top!', "Fuck off you god damn cunt")
|
||||
const string = bot.getMessageAsPrismarine(message)?.toString(bot.registry.language).replaceAll('BlackStone Mafia On Top!', "Fuck off you god damn cunt")
|
||||
// if (!options.logging) return
|
||||
// bot.console.logs(`${ansi}`)
|
||||
// bot.console.filelogging(`[${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} logs] [${options.serverName}] ${string}`)
|
||||
})
|
||||
}
|
||||
module.exports = CommandConsole;
|
159
src/discord.js
159
src/discord.js
|
@ -1,159 +0,0 @@
|
|||
// TODO: Maybe move client creation elsepwhere
|
||||
const { Client, GatewayIntentBits, interaction } = require('discord.js')
|
||||
const { MessageContent, GuildMessages, Guilds } = GatewayIntentBits
|
||||
const fixansi = require('../util/ansi');
|
||||
const CommandSource = require('../util/command_source')
|
||||
|
||||
const client = new Client({ intents: [Guilds, GuildMessages, MessageContent] })
|
||||
const util = require('util')
|
||||
|
||||
function discord(bot, options, config) {
|
||||
if (!config.discord.enabled) return;
|
||||
client.login(config.discord.token)
|
||||
if (!options?.channelId) {
|
||||
bot.discord = {
|
||||
invite: config.discord?.invite
|
||||
}
|
||||
return
|
||||
}
|
||||
bot.discord = {
|
||||
client,
|
||||
channel: undefined,
|
||||
invite: config.discord.invite || undefined,
|
||||
prefix: config.discord.prefix,
|
||||
// presence: bot.discord.presence,
|
||||
// token: config.discord.token,
|
||||
}
|
||||
client.once('ready', (context) => {
|
||||
bot.discord.channel = client.channels.cache.get(options.discord.channelId)
|
||||
client.user.setPresence({
|
||||
activities: [{
|
||||
name: `your mother`,
|
||||
type: 0
|
||||
}],
|
||||
status: `dnd`
|
||||
});
|
||||
})
|
||||
|
||||
let discordQueue = []
|
||||
setInterval(() => {
|
||||
if (discordQueue.length === 0) return
|
||||
try {
|
||||
bot?.discord?.channel?.send(`\`\`\`ansi\n${discordQueue.join('\n').substring(0, 1984)}\n\`\`\``)
|
||||
} catch (error) {
|
||||
bot.console.warn(error.toString())
|
||||
}
|
||||
discordQueue = []
|
||||
}, 2000)
|
||||
|
||||
function sendDiscordMessage(message) {
|
||||
discordQueue.push(message)
|
||||
}
|
||||
|
||||
function sendComponent(message) {
|
||||
const ansi = bot.getMessageAsPrismarine(message)?.toAnsi(bot.registry.language).replaceAll('```\u001b[9```' + '```\u001b[3```').replaceAll('https://discord','https:\rdiscord')?.replaceAll('discord.gg', 'discord.\rgg').replaceAll('BlackStone Mafia On Top!', "Fuck off you god damn cunt");
|
||||
try {
|
||||
sendDiscordMessage(fixansi(ansi?.replaceAll('`', '`\u200b')))
|
||||
} catch (e) {
|
||||
bot.console.error(`Error sending a message to Discord:\n${e.message}`)
|
||||
sendDiscordMessage(e.message)
|
||||
}
|
||||
}
|
||||
bot.on('message', message => {
|
||||
sendComponent(message)
|
||||
})
|
||||
|
||||
function messageCreate(message, source) {
|
||||
bot.discord.message = message;
|
||||
if (message.author.id === bot.discord.client.user.id) return
|
||||
|
||||
if (message.channel.id !== bot.discord.channel.id) return
|
||||
|
||||
if (message.content.startsWith(config.discord.prefix)) { // TODO: Don't hardcode this
|
||||
const source = new CommandSource({
|
||||
profile: {
|
||||
name: message?.member?.displayName
|
||||
}
|
||||
}, {
|
||||
discord: true,
|
||||
console: false
|
||||
}, false, message)
|
||||
|
||||
bot.sendFeedback = message => {
|
||||
sendComponent(message)
|
||||
}
|
||||
|
||||
bot.commandManager.executeString(source, message.content.substring(config.discord.prefix.length))
|
||||
return
|
||||
}
|
||||
const tag = {
|
||||
translate: '[%s] %s \u203a %s',
|
||||
with: [{
|
||||
translate: '%s%s%s %s',
|
||||
bold: false,
|
||||
with: [{
|
||||
text: 'FNF',
|
||||
bold: false,
|
||||
color: 'blue'
|
||||
},
|
||||
{
|
||||
text: 'Boyfriend',
|
||||
bold: false,
|
||||
color: 'dark_aqua'
|
||||
},
|
||||
{
|
||||
text: 'Bot',
|
||||
bold: false,
|
||||
color: 'dark_blue'
|
||||
},
|
||||
{
|
||||
text: 'Discord',
|
||||
bold: false,
|
||||
color: 'dark_blue'
|
||||
}
|
||||
],
|
||||
clickEvent: bot.discord.invite ? {
|
||||
action: 'open_url',
|
||||
value: bot.discord.invite
|
||||
} : undefined,
|
||||
hoverEvent: {
|
||||
action: 'show_text',
|
||||
contents: 'Click to join the discord'
|
||||
}
|
||||
},
|
||||
{
|
||||
text: message?.member?.displayName
|
||||
},
|
||||
message.content
|
||||
]
|
||||
}
|
||||
if (message.attachments.size > 0) {
|
||||
message.attachments.forEach(Attachment => {
|
||||
bot.tellraw('@a', [tag, {
|
||||
text: ' ' ? ' [Attachment] ' : ' [Attachment] ',
|
||||
hoverEvent: {
|
||||
action: 'show_text',
|
||||
contents: 'Click here to view attachment'
|
||||
},
|
||||
clickEvent: {
|
||||
action: 'open_url',
|
||||
value: `${Attachment.url}`
|
||||
}
|
||||
}])
|
||||
})
|
||||
} else {
|
||||
if (options.useChat || options.isSavage || options.isCreayun) {
|
||||
bot.chat.message(bot.getMessageAsPrismarine(`&7[&9FNF&3Boyfriend&1Bot Discord&7] ${message?.member?.displayName} \u203a ${message?.content}`)?.toMotd().replaceAll('§','&'))
|
||||
} else {
|
||||
bot.tellraw('@a', tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
client.on('messageCreate', messageCreate)
|
||||
|
||||
process.on("uncaughtException", (e) => {
|
||||
// sendDiscordMessage("uncaught " + e.stack);
|
||||
});
|
||||
|
||||
}
|
||||
module.exports = discord;
|
Loading…
Reference in a new issue