Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Python by bob ( 6 years ago )
#Discord.py#

import discord
from discord.ext import commands
from discord.ext.commands import when_mentioned_or


#Default Libraries#

import time
import asyncio
from math import pow
from math import sqrt
import binascii as en
import datetime
import os
import random



bot = commands.Bot(command_prefix="sb!", case_insensitive = True)
bot.remove_command('help')



@bot.event
async def status_task():
    while True:
    	count = 0
    	game = discord.Game(f"Checking through records!")
    	await bot.change_presence(status=discord.Status.dnd, activity=game)
    	await asyncio.sleep(120)
    	file = open("IPDB.txt", "r")
    	lines = file.readlines()
    	for line in lines:
    		count = count + 1
    	await bot.change_presence(status=discord.Status.dnd, activity=discord.Activity(type=discord.ActivityType.watching, name=f"{count} records!"))
    	await asyncio.sleep(120)

 

@bot.event
async def on_ready():
    bot.loop.create_task(status_task())


    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')


@bot.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandNotFound):
        if ctx.message.author == bot.user:
            pass
        else:
            embed = discord.Embed(title='Error!', description="Hey! That is not a command! Use the '!sbhelp' command for a list you can use!",color = 0x36393E)
            await ctx.send(embed=embed)

@bot.command()
async def help(ctx):
    embed = discord.Embed(title='vHack IP Database Commands!', description = 'Type sb!(commandname) to use a command!', color=0x36393E)
    embed.add_field(name='sb!sp', value='`Search by player name`', inline=False)
    embed.add_field(name='sb!si', value='`Search by player IP`', inline = False)
    embed.add_field(name='sb!sc', value='`Search for records by crew tag`', inline=False)
    embed.add_field(name='sb!addip', value='`Add a new player record`', inline=False)
    embed.add_field(name='sb!up', value='`Update a record`', inline=False)
    embed.add_field(name='sb!un', value='`Update a name using an IP`', inline=False)
    embed.add_field(name='sb!rr', value='`Remove a record using their IP`', inline=False)
    pic = ctx.guild.get_member(667083992234983424)
    embed.set_footer(text = f"This bot has been powered by ShivBot!", icon_url = pic.avatar_url)
    await ctx.send(embed=embed)


@bot.command()
async def sp(ctx, *, name):
	if ctx.message.channel.id == 690622871386718248:
		file = open("IPDB.txt", "r")
		lines = file.readlines()
		found = False
		matches = []
		for line in lines:
			playername, playerip, crew = line.split("|||")
			if name in playername:
				found = True
				matches.append(line)

		if found == True:
			for x in matches:
				playername, playerip, crew = x.split("|||")
				embed = discord.Embed(title=f'{playername}!', description=f":notepad_spiral: {playerip}\n\n:globe_with_meridians: {crew}\n", color=0x36393E)
				embed.set_footer(text=playerip)
				await ctx.send(embed=embed)
		else:
			embed = discord.Embed(title=f'I have not been able to find them!', color=0x36393E)
			embed.set_footer(text="Have their IP? Add it using the `addip` command!")
			await ctx.send(embed=embed)   
		file.close() 	
	else:
		embed = discord.Embed(title="Hey! You can't use that here!" , color=0x36393E)
		await ctx.send(embed=embed) 
	 

@sp.error
async def sp_error(ctx, error):
    if isinstance(error, commands.BadArgument):
        embed = discord.Embed(title='Error!', description="There seems to be an error with the information you gave!",color=0x36393E)
        await ctx.send(embed=embed)
    if isinstance(error, commands.MissingRequiredArgument):
        embed = discord.Embed(title='Error!', description='You seem not to have given me enough information!',color=0x36393E)
        await ctx.send(embed=embed)

@bot.command()
async def si(ctx, ip):
	if ctx.guild != None and ctx.guild.id == 703822508805193748:
		file = open("IPDB.txt", "r")
		lines = file.readlines()
		found = False
		for line in lines:
			playername, playerip, crew = line.split("|||")
			if playerip == ip:
				found = True
				foundplayer = playername
				foundip = playerip
				foundcrew = crew


		if found == True:
				embed = discord.Embed(title=f'{playername}!', description=f":notepad_spiral: {foundip}\n\n:globe_with_meridians: {foundcrew}\n", color=0x36393E)
				embed.set_footer(text=foundip)
				await ctx.send(embed=embed)
		else:
			embed = discord.Embed(title=f'I have not been able to find them!', color=0x36393E)
			embed.set_footer(text="Want to add the IP? Use `sb!add_ip`")
			await ctx.send(embed=embed)
		file.close()


	else:
		embed = discord.Embed(title="Hey! You can't use that here!" , color=0x36393E)
		await ctx.send(embed=embed) 
	


@si.error
async def si_error(ctx, error):
    if isinstance(error, commands.BadArgument):
        embed = discord.Embed(title='Error!', description="There seems to be an error with the information you gave!",color=0x36393E)
        await ctx.send(embed=embed)
    if isinstance(error, commands.MissingRequiredArgument):
        embed = discord.Embed(title='Error!', description='You seem not to have given me enough information!',color=0x36393E)
        await ctx.send(embed=embed)


@bot.command()
async def addip(ctx, ip, name, crew=None):
	if ctx.guild != None and ctx.guild.id == 703822508805193748:
		file = open("IPDB.txt", "r")
		lines = file.readlines()
		found = False
		for line in lines:
			playername, playerip, playercrew = line.split("|||")
			if playerip == ip:
				found = True
				foundplayer = playername
				foundcrew = playercrew
				foundip = playerip

		file.close()
		if found == False:
			if crew == None:
				crew = "-"
			file = open("IPDB.txt", "a")
			file.write(f"{name}|||{ip}|||{crew}\n")
			file.close()



			file = open("IPDB.txt", "r")
			lines = file.readlines()
			found = False
			for line in lines:
				playername, playerip, crew = line.split("|||")
				if playername == name:
					found = True
					foundplayer = name
					foundip = playerip
					foundcrew = crew

			if found == True:
				embed = discord.Embed(title=f'{foundplayer}!', description=f":notepad_spiral: {foundip}\n\n:globe_with_meridians: {foundcrew}\n", color=0x36393E)
				embed.set_footer(text=foundip)
				await ctx.send(embed=embed)
		else:
			embed = discord.Embed(title=f'{foundplayer}!', description=f":notepad_spiral: {foundip}\n\n:globe_with_meridians: {foundcrew}\n", color=0x36393E)
			embed.set_footer(text=foundip)
			await ctx.send(embed=embed)	
		file.close() 
	else:
		embed = discord.Embed(title="Hey! You can't use that here!" , color=0x36393E)
		await ctx.send(embed=embed)

@addip.error
async def addip_error(ctx, error):
    if isinstance(error, commands.BadArgument):
        embed = discord.Embed(title='Error!', description="There seems to be an error with the information you gave!",color=0x36393E)
        await ctx.send(embed=embed)
    if isinstance(error, commands.MissingRequiredArgument):
        embed = discord.Embed(title='Error!', description='You seem not to have given me enough information!',color=0x36393E)
        await ctx.send(embed=embed)



@bot.command()
async def up(ctx, name, newip):
	if ctx.guild != None and ctx.guild.id == 703822508805193748:
		file = open("IPDB.txt", "r")
		lines = file.readlines()
		found = False
		loaded = []
		for line in lines:
			playername, playerip, crew = line.split("|||")
			if playername == name:
				found = True
				foundplayer = playername
				oldip = playerip
				t = line
				foundcrew = crew


			loaded.append(line)
		if found == True:
			loaded.remove(t)
			newrecord = f"{name}|||{newip}|||{foundcrew}"
			loaded.append(newrecord)
			file.close()

			file = open("IPDB.txt", "w")
			file.write("")
			file.close()

			file = open("IPDB.txt", "a")
			for x in loaded:
				file.write(f"{x}")
				file.close()


			embed = discord.Embed(title=f'Record Updated For {name}!', description=f":notepad_spiral: {newip}\n\n:globe_with_meridians: {foundcrew}\n", color=0x36393E)
			embed.set_footer(text=playerip)
			await ctx.send(embed=embed)		
		else:
			embed = discord.Embed(title=f'Wait a minute!', description="There seems to be no record of that IP!", color=0x36393E)
			await ctx.send(embed=embed)
	else:
		embed = discord.Embed(title="Hey! You can't use that here!" , color=0x36393E)
		await ctx.send(embed=embed) 

	
@up.error
async def up_error(ctx, error):
    if isinstance(error, commands.BadArgument):
        embed = discord.Embed(title='Error!', description="There seems to be an error with the information you gave!",color=0x36393E)
        await ctx.send(embed=embed)
    if isinstance(error, commands.MissingRequiredArgument):
        embed = discord.Embed(title='Error!', description='You seem not to have given me enough information!',color=0x36393E)
        await ctx.send(embed=embed)

@bot.command()
async def sc(ctx, crewtag):
	if ctx.guild != None and ctx.guild.id == 703822508805193748:
		file = open("IPDB.txt", "r")
		lines = file.readlines()
		matches = []
		for line in lines:
			playername, playerip, playercrew = line.split("|||")
			if crewtag in playercrew:
				matches.append(line)
				print(line)

		if matches == []:
			embed = discord.Embed(title=f'I could not find anyone in {crewtag}',color=0x36393E)
			await ctx.send(embed=embed)
		else:
			for match in matches:
				playername, playerip, playercrew = match.split("|||")
				embed = discord.Embed(title=f'{playername}!', description=f":notepad_spiral: {playerip}\n\n:globe_with_meridians: {playercrew}\n", color=0x36393E)
				embed.set_footer(text=playerip)
				await ctx.send(embed=embed)
		file.close() 
	else:
		embed = discord.Embed(title="Hey! You can't use that here!" , color=0x36393E)
		await ctx.send(embed=embed) 

@bot.command()
async def all_ips(ctx):
	if ctx.guild != None and ctx.guild.id == 703822508805193748:
		file = open("IPDB.txt", "r")
		lines = file.readlines()
		embed = discord.Embed(title="All the IPs in the database!", color=0x36393E)
		for line in lines:
			playername, playerip, playercrew = line.split("|||")
			embed.add_field(name=f'{playername} | IP: {playerip}\nCrew: {playercrew}\n', inline = True)


		embed.set_footer(text="If any IPs have been changed, report it to a (staff person thing??)!")
		await ctx.send(embed=embed)
	else:
		embed = discord.Embed(title="Hey! You can't use that here!" , color=0x36393E)
		await ctx.send(embed=embed) 





@bot.command()
async def rr(ctx, ip):
	if ctx.guild != None and ctx.guild.id == 703822508805193748:
		file = open("IPDB.txt", "r")
		lines = file.readlines()
		found = False
		loaded = []
		for line in lines:
			playername, playerip, crew = line.split("|||")
			if ip == playerip:
				found = True
				oldname = playername
				t = line
				foundcrew = crew


			loaded.append(line)
		if found == True:
			loaded.remove(t)
			file.close()

			file = open("IPDB.txt", "w")
			file.write("")
			file.close()

			file = open("IPDB.txt", "a")
			for x in loaded:
				file.write(f"{x}")
			file.close()


			embed = discord.Embed(title='Record removed!', color=0x36393E)
			await ctx.send(embed=embed)

		else:
			embed = discord.Embed(title=f'Wait a minute!', description="There seems to be no record of that IP!", color=0x36393E)
			await ctx.send(embed=embed)	

		file.close() 
	else:
		embed = discord.Embed(title="Hey! You can't use that here!" , color=0x36393E)
		await ctx.send(embed=embed)

@bot.command(aliases=["clear"])
async def purge(ctx, amount: int):
    if ctx.guild != None and ctx.guild.id == 703822508805193748:
        if ctx.message.author.guild_permissions.administrator or ctx.author.id == ctx.guild.owner.id:
            await ctx.message.channel.purge(limit=amount)
        else:
            embed = discord.Embed(title = "Error!", description = f"Hey! You aren't of a high enough epicness to purge..yet!", color=0x36393E)
            await ctx.send(embed=embed)
    else:
    	embed = discord.Embed(title="Hey! You can't use that here!" , color=0x36393E)
    	await ctx.send(embed=embed)





@bot.command()
async def bp(ctx):
	if ctx.guild != None and ctx.guild.id == 703822508805193748:
		from github import Github
		import datetime
		g = Github("username", "pw")
		repo = g.get_repo("Shivster2401/vhackbot1")
		time = datetime.datetime.now()
		file = open("IPDB.txt", "r")
		x = []
		lines = file.readlines()
		for line in lines:
			x.append(line)
		x = ''.join([y for y in x])
		repo.create_file(f"ipdb{time}.txt", "NEW", x, branch="master")


		await ctx.send("Done!")


	


bot.run('token here')

 

Revise this Paste

Your Name: Code Language: