Skip to content

Instantly share code, notes, and snippets.

@at15four2020
Last active September 23, 2022 15:27
Show Gist options
  • Save at15four2020/7a380485e641fb48e9a30593869c1150 to your computer and use it in GitHub Desktop.
Save at15four2020/7a380485e641fb48e9a30593869c1150 to your computer and use it in GitHub Desktop.
if (typeof PrivateChatManager == "undefined") {
PrivateChatManager = (function() {
let botCount = 0
let botIds = 99999999
function blockMessage(message) {
message.setBlocked(true)
}
interceptToServer('GetExtendedProfile', blockMessage)
interceptToClient('ErrorReport', blockMessage)
function matchCommand(command, message) {
var rx = new RegExp(command.prefix + "(" + command.command + ")( .+)?")
var packet = message.getPacket()
packet.resetReadIndex()
packet.readInteger() // user id
var result = rx.exec(packet.readString())
packet.resetReadIndex()
if (result) {
return {
command: result[1],
extra: (result[2] || "").trim()
}
}
}
function defaultMessageHandler(message, commands) {
for (var i = 0; i < commands.length; i++) {
var command = matchCommand(commands[i], message)
if (command) {
if (typeof commands[i].handler == 'function') {
commands[i].handler.call(null, message, command)
}
}
}
}
function init(id, name, figure, handleMessage) {
sendToClient(HPacketToClient('FriendListUpdate', [
1,
// category id, category name
123456, "BOTS",
1,
// update type, user id, user name, 1,
// appear offline, hide in room, figure, caterogy id, motto,
// facebook username, "", allow offline messaging, ?, uses phone, relationship
0, id, name, 1,
true, false, figure, 123456, "",
"", "", true, false, false, 65537
]))
interceptToServer('SendMsg', handleMessage)
}
return function(name, figure) {
name = name || "ConsoleBot"+botCount
figure = figure || "hd-4015-27.ch-4025-1408-81.lg-4017-1408-1408.sh-4016-1408-1408.he-3385-1427-1408-1408.ea-3270-1408-1408.fa-3350"
botCount++
const myId = ++botIds
const commands = []
function sendMessage(message) {
sendToClient(HPacketToClient("NewConsole", [myId, message, 0, ""]))
}
function handleMessage(message) {
const packet = message.getPacket()
packet.resetReadIndex()
const userId = packet.readInteger()
if (userId == myId) {
message.setBlocked(true)
defaultMessageHandler(message, commands)
}
}
function handleCommand(command, handler, prefix) {
if (typeof handler != 'function') return print(new Error("You must provide a function in the handler param."))
prefix = prefix || ":"
commands.push({
command: command,
handler: handler,
prefix: prefix
})
}
function hideBot() {
sendToClient(HPacketToClient("FriendListUpdate", [0, 1, -1, myId]))
}
init(myId, name, figure, handleMessage)
return {
sendMessage: sendMessage,
handleCommand: handleCommand,
hideBot: hideBot,
}
}
})()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment