Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import struct
- import random
- import threading
- class SABot:
- def __init__(self, Username, Password, IP, Port):
- self.NullByte = struct.pack('B', 0)
- self.BufSize = 4096
- self.CommandChar = '$'
- self.OnlineUsers = {}
- self.OnlineUserMap = {}
- self.Dead = []
- self.NameToIP = {'2D Central': '74.86.43.9:1138', 'Paper Thin City': '74.86.43.8:1138', 'Fine Line Island': '198.58.106.101:1138', 'U of SA': '69.164.207.72:1138',
- 'Amsterdam': '139.162.151.57:1138', 'Mobius Metro': '45.56.72.83:1138', 'Cartesian': '198.58.106.101:1139'}
- self.IPToName = {'74.86.43.9:1138': '2D Central', '74.86.43.8:1138': 'Paper Thin City', '198.58.106.101:1138': 'Fine Line Island', '69.164.207.72:1138': 'U of SA',
- '139.162.151.57:1138': 'Amsterdam', '45.56.72.83:1138': 'Mobius Metro', '198.58.106.101:1139': 'Cartesian'}
- self.ServerIP = IP
- self.ServerPort = Port
- self.Commands = True
- self.BotAdmin = 'Seminary9500' # SET THIS TO THE account you want to be able to use admin commands with
- self.BotServer = self.IPToName[ '{}:{}'.format(self.ServerIP, self.ServerPort)]
- self.BotPassword = Password
- self.connectToServer(Username, Password, self.ServerIP, self.ServerPort)
- def sendPacket(self, Socket, PacketData, Receive = False):
- Packet = bytes(PacketData, 'utf-8')
- if Socket:
- Socket.send(Packet + self.NullByte)
- if Receive:
- return Socket.recv(self.BufSize).decode('utf-8')
- def startKeepAlive(self, TimerSeconds = 20):
- if hasattr(self, 'SocketConn'):
- KeepAliveTimer = threading.Timer(TimerSeconds, self.startKeepAlive)
- KeepAliveTimer.daemon = True
- KeepAliveTimer.start()
- self.sendPacket(self.SocketConn, '0')
- def sendPrivateMessage(self, UserID, Message):
- if UserID != self.BotID:
- if UserID in self.OnlineUsers:
- self.sendPacket(self.SocketConn, '00' + UserID + 'P' + Message)
- def sendPublicMessage(self, Message):
- self.sendPacket(self.SocketConn, '9' + Message)
- def connectionHandler(self):
- Buffer = b''
- while hasattr(self, 'SocketConn'):
- try:
- Buffer += self.SocketConn.recv(self.BufSize)
- except ConnectionAbortedError:
- return
- if len(Buffer) == 0:
- print('{} has disconnected'.format(self.BotUsername))
- self.SocketConn.shutdown(socket.SHUT_RD)
- self.SocketConn.close()
- break
- elif Buffer.endswith(self.NullByte):
- Receive = Buffer.split(self.NullByte)
- Buffer = b''
- for Data in Receive:
- Data = Data.decode('utf-8')
- if Data.startswith('U'):
- UserID = Data[1:][:3]
- Username = Data[4:][:20].replace('#', '')
- self.parseUserData(Data)
- elif Data.startswith('D'):
- UserID = Data[1:][:3]
- Username = self.OnlineUsers[UserID]
- del self.OnlineUserMap[Username]
- del self.OnlineUsers[UserID]
- elif Data.startswith('M'):
- UserID = Data[1:][:3]
- self.parseUserMessage(UserID, Data)
- elif Data.startswith('0g') or Data.startswith('0j'):
- print('{{Server}}: {}'.format(Data[2:]))
- elif Data.startswith('0f') or Data.startswith('0e'):
- Time, Reason = Data[2:].split(';')
- print('This account has just been banned [Time: {} / Reason: {}]'.format(Time, Reason))
- def connectToServer(self, Username, Password, ServerIP, ServerPort):
- try:
- self.SocketConn = socket.create_connection((self.ServerIP, self.ServerPort))
- except Exception as Error:
- print(Error)
- return
- Handshake = self.sendPacket(self.SocketConn, '08HxO9TdCC62Nwln1P', True).strip(self.NullByte.decode('utf-8'))
- if Handshake == '08':
- Credentials = '09{};{}'.format(Username, Password)
- RawData = self.sendPacket(self.SocketConn, Credentials, True).split(self.NullByte.decode('utf-8'))
- for Data in RawData:
- if Data.startswith('A'):
- self.BotID = Data[1:][:3]
- self.BotUsername = Data[4:][:20].replace('#', '')
- self.BotCred = Data[43:].split(';')[8]
- print('Bot Username: {} | Bot ID: {} | Bot Cred: {} | Located in {}'.format(self.BotUsername, self.BotID, self.BotCred, self.BotServer))
- EntryPackets = ['02Z900_', '03_', '0a', '01']
- for Packet in EntryPackets:
- self.sendPacket(self.SocketConn, Packet)
- self.startKeepAlive()
- ConnectionThread = threading.Thread(target=self.connectionHandler)
- ConnectionThread.start()
- break
- elif Data == '09':
- print('Incorrect password')
- break
- elif Data == '091':
- print('Currently banned')
- break
- else:
- print('Server capacity check failed')
- def parseUserData(self, Packet, Password = None):
- StatsString = Packet.replace('\x00', '')
- UserID = StatsString[1:][:3]
- Type = StatsString[:1]
- if Type == 'U':
- Username = StatsString[4:][:20].replace('#', '')
- StatsString = StatsString[24:]
- self.OnlineUsers[UserID] = Username
- self.OnlineUserMap[Username] = UserID
- def parseUserMessage(self, SenderID, Packet):
- if SenderID in self.OnlineUsers:
- Sender = self.OnlineUsers[SenderID]
- NoUseTypes = ['1', '2', '4', '5', '6', '7', '8', '~']
- MessageType = Packet[4:][:1]
- SenderMessage = Packet[5:]
- RawMessage = Packet[1:].replace(SenderID, '')
- if MessageType in NoUseTypes:
- return
- elif MessageType == '9':
- if self.Commands:
- self.handleCommand(SenderID, Sender, SenderMessage, False)
- elif MessageType == 'P':
- if self.Commands:
- self.handleCommand(SenderID, Sender, SenderMessage, True)
- else:
- self.handleCommand(SenderID, Sender, RawMessage, True)
- try:
- print('[' + Sender + ']: ' + RawMessage)
- except:
- pass
- def handleCommand(self, SenderID, Sender, SenderMessage, Private):
- RespondByPM = (False if Private == False else True)
- Message = SenderMessage.strip()
- MessageCheck = Message.split()
- if Message.startswith(self.CommandChar):
- Command = MessageCheck[0][1:].lower()
- HasArguments = (True if len(MessageCheck) > 1 else False)
- Arguments = (' '.join(MessageCheck[1:]) if HasArguments else None)
- if Command == 'reset':
- RespondByPM = True
- self.Dead = []
- Response = 'RR list has been reset.'
- elif Command == 'users':
- RespondByPM = True
- UserList = []
- for User in self.OnlineUserMap:
- UserList .append(User)
- Response = 'There are {} people in the lobby. Users: {}'.format(len(UserList), ', '.join(UserList))
- elif Command == 'addcol' or Command == 'getcol':
- RespondByPM = True
- if Private:
- if HasArguments:
- SpinnerType = Arguments.split()[0]
- RGB = Arguments.split()[1]
- Password = Arguments.replace(' ', '')[12:]
- Response = 'Color hackin aint cool but I don\'t give a fuck'
- ColorRequest = threading.Thread(target=self.handleColorRequest, args=(SenderID, Sender, SpinnerType, RGB, Password))
- ColorRequest.daemon = True
- ColorRequest.start()
- elif Command == 'rr':
- if Sender not in self.Dead:
- GoodNumber = random.randint(0, 2)
- BadNumber = random.randint(0, 2)
- if GoodNumber == BadNumber:
- self.Dead.append(Sender)
- Response = 'Bang'
- else:
- Response = 'Click'
- if Command == 'blacklist':
- RespondByPM = True
- if HasArguments:
- Target = Arguments.replace(' ', '').lower()
- Username = Sender
- Results = self.executeDatabaseQuery("SELECT * FROM blacklist WHERE username = ?", [(Username)], False, True)
- if Results:
- if Target == 'color':
- Blacklisted = Results[0][1]
- if Blacklisted:
- self.executeDatabaseQuery("UPDATE blacklist SET color = 0 WHERE username = ?", [(Username)])
- Response = 'Your color codes can now be publicly requested.'
- else:
- self.executeDatabaseQuery("UPDATE blacklist SET color = 1 WHERE username = ?", [(Username)])
- Response = 'Your color codes can no longer be publicly requested.'
- elif Target == 'location':
- Blacklisted = Results[0][2]
- if Blacklisted:
- self.executeDatabaseQuery("UPDATE blacklist SET location = 0 WHERE username = ?", [(Username)])
- Response = 'Your location can now be publicly requested.'
- else:
- self.executeDatabaseQuery("UPDATE blacklist SET location = 1 WHERE username = ?", [(Username)])
- Response = 'Your location can no longer be publicly requested.'
- else:
- Username = Sender
- Results = self.executeDatabaseQuery("SELECT * FROM blacklist WHERE username = ?", [(Username)], False, True)
- if Results:
- ColorBlacklisted = Results[0][1]
- LocationBlacklisted = Results[0][2]
- if ColorBlacklisted:
- ColorBlacklisted = 0
- self.executeDatabaseQuery("UPDATE blacklist SET color = 0 WHERE username = ?", [(Username)])
- else:
- ColorBlacklisted = 1
- self.executeDatabaseQuery("UPDATE blacklist SET color = 1 WHERE username = ?", [(Username)])
- if LocationBlacklisted:
- LocationBlacklisted = 0
- self.executeDatabaseQuery("UPDATE blacklist SET location = 0 WHERE username = ?", [(Username)])
- else:
- LocationBlacklisted = 1
- self.executeDatabaseQuery("UPDATE blacklist SET location = 1 WHERE username = ?", [(Username)])
- ColorBlacklisted = ('Your color codes can no longer be publicly requested' if ColorBlacklisted else 'Your color codes can be publicly requested')
- LocationBlacklisted = ('Your location can no longer be publicly requested' if LocationBlacklisted else 'Your location can be publicly requested')
- Response = '{}; {}'.format(ColorBlacklisted, LocationBlacklisted)
- elif Command == 'ajkdhakdhaw' or Command == 'awdjkhda':
- RespondByPM = True
- if HasArguments:
- Arguments = Arguments.replace(' ', '')
- Target = Arguments
- else:
- Target = Sender
- Results = self.executeDatabaseQuery("SELECT * FROM blacklist WHERE lower(username) = ?", [(Target.lower())], False, True)
- if Results:
- Username = Results[0][0]
- Blacklisted = Results[0][1]
- else:
- Username = Target
- Blacklisted = 0
- Results = self.executeDatabaseQuery("SELECT * FROM users WHERE lower(username) = ?", [(Username.lower())], False, True)
- if Results:
- RGB = Results[0][1]
- Hex = Results[0][2]
- if Sender.lower() == Username.lower():
- BlacklistCheck = ('blacklisted.' if Blacklisted else 'not blacklisted.')
- Response = 'Your color codes: [RGB]: {} | [Hex]: {} / You are {}'.format(RGB, Hex, BlacklistCheck)
- else:
- if Blacklisted:
- if Sender == self.BotAdmin:
- Response = '[Blacklisted] {}\'s color codes: [RGB]: {} | [Hex]: {}'.format(Username, RGB, Hex)
- else:
- Response = '{} isn\'t allowing requests for their color.'.format(Username)
- else:
- Response = '{}\'s color codes: [RGB]: {} | [Hex]: {}'.format(Username, RGB, Hex)
- else:
- Response = 'There are currently no color codes stored for "{}"'.format(Target)
- elif Command == 'mud':
- Response = 'muddy shit goin down'
- elif Command == 'congrats':
- if HasArguments:
- Response = 'Congratulations on Your new rank, {}!'.format(Arguments.split()[0])
- elif Command == 'muddy':
- Response = 'so muddy'
- elif Command == 'fuckmods':
- Response = 'fuck mods and there pussy ass shit'
- elif Command == 'carlos':
- Response = 'that bitch a power hungry nnniiiggggaaaa'
- elif Command == 'luis':
- Response = 'worst guy you could ever pick 4 mod'
- elif Command == 'krux':
- Response = 'that nigga aint done nothin to me'
- elif Command == 'lawjax':
- Response = 'I wear color hacked spinners infront of him'
- elif Command == 'kendry':
- Response = 'His afro be lookin like my pubes.'
- elif Command == 'sin':
- Response = 'he ight'
- elif Command == 'ava':
- Response = 'nigga got stitched lips'
- elif Command == 'getmoney':
- Response = 'he cool i guess nigga needs to come online more'
- elif Command == 'shot':
- Response = 'hit him up for color hacks'
- elif Command == 'lileep':
- Response = 'He trolled me :\'('
- elif Command == 'schallmeister':
- Response = 'SCHALLNOOBSTA'
- elif Command == 'neo':
- Response = 'wait dis nigga inactive but a mod?'
- elif Command == 'mousy':
- Response = 'Mousy = Big Rat'
- elif Command == 'glitch1':
- Response = '%' * 135
- if 'Response' in locals():
- try:
- if Private:
- print('[PM from {} in {}] Response: {}'.format(Sender, self.BotServer, Response))
- else:
- print('[{} in {}] Response: {}'.format(Sender, self.BotServer, Response))
- except:
- print("failure on print; passing the exception")
- if RespondByPM:
- self.sendPrivateMessage(SenderID, Response)
- else:
- self.sendPublicMessage(Response)
- def handleColorRequest(self, SenderID, Sender, SpinnerType, RGB, Password):
- SocketConn = socket.create_connection((self.ServerIP, self.ServerPort))
- Handshake = self.sendPacket(SocketConn, '08HxO9TdCC62Nwln1P', False).strip(self.NullByte.decode('utf-8'))
- if Handshake == '08':
- Credentials = '09{};{}'.format(Sender, Password)
- RawData = self.sendPacket(SocketConn, Credentials, True)
- for Data in RawData:
- if Data.startswith('A'):
- self.sendPacket(SocketConn, '02Z900_')
- self.sendPacket(SocketConn, '03_')
- self.sendPacket(SocketConn, '0b' + SpinnerType + RGB + RGB)
- elif Data == '09':
- SentMessage = False
- while not SentMessage:
- if SenderID in self.OnlineUsers:
- SentMessage = True
- self.sendPrivateMessage(SenderID, 'Incorrect password')
- break
- break
- SocketConn.shutdown(socket.SHUT_RD)
- SocketConn.close()
- del SocketConn
- if __name__ == '__main__':
- Username = '' #username
- Password = '' #password
- SABot(Username, Password, '198.58.106.101', 1139)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement