Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############## package installation guide ###############
- # Install python 3.6 (3.5 to 3.7 will work)
- # Open Command Prompt as Administrator and run the 3 commands below:
- # python -m pip install -U --upgrade pip
- # python -m pip install -U discord.py[voice]
- # python -m pip install -U numpy
- import asyncio, os, time, re
- import discord
- from numpy import random
- username = "" # the default username/email to use (not required)
- password = "" # the default password to use (not required)
- serverName = "My Discord Dungeons" # server to bot in
- channelName = "rpg" # channel to bot in
- drpgBotName = "DiscordRPG".lower() # name of the bot to parse text from
- safeMode = 1 # uses humanizers and randomess to avoid suspicion
- passiveMode = 0 # does not attack in order to not lose hp
- commandTimer = 1 # wait 1 second per command
- advTimer = 14.34
- catchTimer = 30.34
- forageTimer = mineTimer = chopTimer = fishTimer = 300.34
- searchTimer = 600.34
- shortRestDuration = 50 # pause for 50 seconds
- shortRestFrequency = 600 # every 10 minutes
- longRestDuration = 1260 # 21 min rest
- longRestFrequency = 5800 # every 80 minutes
- restSchedule = ((22,24),(0,6)) # times when script is resting (not botting)
- slowMultiplier = 4 # multiply all timer and varience by this number during slowmode
- slowSchedule = ((9,11),(1,5)) # times when slowmode is active, ((start, stop),(start, stop))
- currHealth = 100
- totalHealth = 100
- healthLock = 0
- healPerun = 0.34 # health perun to use potions at
- healthPattern = None
- channel = None
- utf8name = None
- client = discord.Client()
- startTime = time.time()
- class Queue(object):
- def __init__(self, maxSize):
- self.maxSize = maxSize
- self.items = []
- def __iter__(self):
- return self.items.__iter__()
- def __repr__(self):
- return self.items.__repr__()
- def __str__(self):
- return self.items.__str__()
- def __getitem__(self,key):
- return self.items[key]
- def queue(self, item):
- if len(self.items) == 10:
- self.items = self.items[1:self.maxSize]
- self.items.append(item)
- guiUpdateTimer = 1
- textGui = """Botting as {} on server {} in channel {}
- Time since start: {}
- Time spent
- normal botting: {}
- slow botting: {}
- resting: {}
- Rest schedule: {}
- Slow mode schedule: {} <- not yet implemented
- Safe mode: {}
- Passive mode: {}
- Bot current status: {}
- Health: {}/{} (%{:0.2f})
- Heal when health is below: %{:0.2f}
- Potions used: {}
- Commands sent - total: {}
- adv: {: 8d} catch: {: 8d} forage: {: 8d} mine: {: 8d}
- chop: {: 8d} fish: {: 8d} search: {: 8d}
- Timers
- nextCommand: {: 12.2f}
- shortRest: {: 12.2f} shortRestDuration: {: 12.2f}
- longRest: {: 12.2f} longRestDuration: {: 12.2f}
- adv: {: 7.2f} forage: {: 7.2f} mine: {: 7.2f}
- fish: {: 7.2f} chop: {: 7.2f} search: {: 7.2f}
- Last 10 logs:
- """
- logs = Queue(8)
- # clears the terminal
- def clear_screen():
- if os.name == "nt": # windows/dos
- os.system("cls")
- elif os.name == "posix": # linux/unix
- os.system("clear")
- else:
- print("\n"*128)
- # generate a random number in a bell cuve (normal distribution)
- # if lowest is None, there will be no floor
- # if highest is None, there will be no ceiling
- # target(float)the target value to generate around
- # return(float)the randomly generate number
- def safe_random(target):
- if safeMode:
- normalRand = random.normal(target*1.15, target*0.3)
- normalRand = max(target*0.9, normalRand)
- normalRand = min(target*1.4, normalRand)
- return normalRand
- return target
- # get the hour of day as local time
- # return(float)the hour of day as a fraction
- def get_hour():
- return float(time.strftime('%H')) + float(time.strftime('%M'))/60.
- def log(text):
- date = format_time(time.time() - startTime)
- logs.queue(date + " - " + text)
- def format_time(seconds):
- days = int(seconds // 86400)
- seconds %= 86400
- hours = int(seconds // 3600)
- seconds %= 3600
- minutes = int(seconds // 60)
- seconds %= 60
- return "{:02d}:{:02d}:{:02d}:{:05.2f}".format(days,hours,minutes,seconds)
- # on client start
- @client.event
- async def on_ready():
- global channel, utf8name, currHealth, totalHealth, healthLock, healthPattern, startTime
- print("Log in successful")
- utf8name = client.user.name.encode("utf8") # encode utf8 because unicode crashes everything
- healthPattern = re.compile(r"" + client.user.name + r" has ([0-9]{1,999})\/([0-9]{1,999}) HP left")
- # set the server and channels
- server = None
- for _server in client.servers:
- if _server.name.lower() == serverName.lower():
- server = _server
- break
- for _channel in server.channels:
- if _channel.name.lower() == channelName.lower() and _channel.type != "voice":
- channel = _channel
- break
- state = "botting"
- potionsUsed = 0
- timeSpentBotting = 0
- timeSpentSlow = 0
- timeSpentResting = 0
- startTime = time.time()
- stateStartTime = time.time() # keep track how long in each state
- healPerunRand = safe_random(healPerun)
- shortRestDurationRand = safe_random(shortRestDuration)
- shortRestFrequencyRand = safe_random(shortRestFrequency)
- longRestDurationRand = safe_random(longRestDuration)
- longRestFrequencyRand = safe_random(longRestFrequency)
- commandTime = 0
- advTime = 0
- catchTime = 0
- forageTime = 0
- mineTime = 0
- chopTime = 0
- fishTime = 0
- searchTime = 0
- shortRestTime = 0
- longRestTime = 0
- commandCount = [0,0,0,0,0,0,0] # counter for the commands sent
- guiTime = 0
- prevTime = time.time()
- log("script started")
- while 1:
- await asyncio.sleep(0.05)
- missingHealth = totalHealth - currHealth
- currHour = get_hour()
- currTime = time.time()
- timePassed = currTime - prevTime
- if state == "botting": timeSpentBotting += timePassed
- elif state == "slow botting": timeSpentSlow += timePassed
- else: timeSpentResting += timePassed
- prevTime = currTime
- if currTime > guiTime:
- output = textGui.format(client.user.name, server, channel,
- format_time(currTime - startTime),
- format_time(timeSpentBotting),
- format_time(timeSpentSlow),
- format_time(timeSpentResting),
- restSchedule, slowSchedule,
- bool(safeMode), bool(passiveMode), state,
- currHealth, totalHealth,
- currHealth/totalHealth*100,
- healPerunRand*100, potionsUsed,
- sum(commandCount),
- commandCount[0],commandCount[1],
- commandCount[2],commandCount[3],
- commandCount[4],commandCount[5],
- commandCount[6],
- commandTime - currTime,
- max(shortRestTime-shortRestDurationRand-currTime, 0),
- min(shortRestDurationRand, shortRestTime-currTime),
- max(longRestTime-longRestDurationRand-currTime, 0),
- min(longRestDurationRand, longRestTime-currTime),
- advTime - currTime,
- forageTime - currTime,
- mineTime - currTime,
- chopTime - currTime,
- fishTime - currTime,
- searchTime - currTime)
- for record in logs:
- output += "\t"+record+"\n"
- clear_screen()
- print(output)
- guiTime = currTime + guiUpdateTimer
- if safeMode:
- shouldSkip = 0
- for span in restSchedule:
- if currHour >= span[0] and currHour <= span[1]:
- shouldSkip = 1
- break
- if currTime > shortRestTime:
- shortRestDurationRand = safe_random(shortRestDuration)
- shortRestFrequencyRand = safe_random(shortRestFrequency)
- shortRestTime = currTime + shortRestFrequencyRand + shortRestDurationRand
- elif shortRestTime - currTime < shortRestDurationRand:
- shouldSkip = 1
- if currTime > longRestTime:
- longRestDurationRand = safe_random(longRestDuration)
- longRestFrequencyRand = safe_random(longRestFrequency)
- longRestTime = currTime + longRestFrequencyRand + longRestDurationRand
- elif longRestTime - currTime < longRestDurationRand:
- shouldSkip = 1
- if shouldSkip:
- if state == "botting": # if was botting but now resting
- log("resting initiated")
- state = "resting"
- continue
- if state == "resting": # if the bot was resting but is not botting
- log("botting initiated")
- state = "botting"
- if currTime > commandTime:
- commandTime = currTime + safeMode*safe_random(commandTimer)
- if healthLock == 0 and currHealth/totalHealth <= healPerunRand:
- healthLock = 1
- healPerunRand = safe_random(healPerun)
- if totalHealth > 50: potions = missingHealth // 50
- else: potions = 1
- try:
- await client.send_message(channel, "#!use health potion "+str(potions))
- potionsUsed += potions
- except:
- log("No response from server")
- healthLock = 0
- elif currTime > advTime:
- try:
- await client.send_message(channel, "#!adv")
- commandCount[0] += 1
- except: log("No response from server")
- advTime = currTime + safe_random(advTimer)
- elif currTime > catchTime:
- try:
- await client.send_message(channel, "#!catch")
- commandCount[1] += 1
- except: log("No response from server")
- catchTime = currTime + safe_random(catchTimer)
- elif currTime > forageTime:
- try:
- await client.send_message(channel, "#!forage")
- commandCount[2] += 1
- except: log("No response from server")
- forageTime = currTime + safe_random(forageTimer)
- elif currTime > mineTime:
- try:
- await client.send_message(channel, "#!mine")
- commandCount[3] += 1
- except: log("No response from server")
- mineTime = currTime + safe_random(mineTimer)
- elif currTime > chopTime:
- try:
- await client.send_message(channel, "#!chop")
- commandCount[4] += 1
- except: log("No response from server")
- chopTime = currTime + safe_random(chopTimer)
- elif currTime > fishTime:
- try:
- await client.send_message(channel, "#!fish")
- commandCount[5] += 1
- except: log("No response from server")
- fishTime = currTime + safe_random(fishTimer)
- elif currTime > searchTime:
- try:
- await client.send_message(channel, "#!search")
- commandCount[6] += 1
- except: log("No response from server")
- searchTime = currTime + safe_random(searchTimer)
- # on message recieved
- @client.event
- async def on_message(message):
- global currHealth, totalHealth, healthLock
- utf8msg = message.content.encode("utf8")
- if message.author.name.lower() == drpgBotName and message.channel == channel:
- if utf8msg.startswith(b"```diff\n!========[ " + utf8name):
- result = healthPattern.search(message.content.replace(",",""))
- if result:
- newHealth = int(result.group(1))
- totalHealth = int(result.group(2))
- if newHealth > currHealth:
- healthLock = 0
- if healthLock == 0:
- currHealth = newHealth
- if not username: username = input("username(email): ") # get username if not defined
- if not password: password = input("password: ") # get password if not defined
- clear_screen() # clear user info from screen
- print("Trying to log in, please wait")
- client.run(username, password, bot = False) # start client
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement