Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- import json
- from discord.ext import tasks
- import sqlite3
- from discord.ext import commands
- import random
- intents = discord.Intents.all()
- conn = sqlite3.connect('users.db')
- bot = commands.Bot(command_prefix="gm!", intents=intents)
- discord_token = "MTA4NDQ5MjM4NTE1MDU3ODc3OA.GBTDga.Vzpq7WXzyy-1UbPSBEs3LrvQtCkG_X-yyeuTe8"
- async def addrole(user, message):
- with open('roles.json') as f:
- data = json.load(f)
- cursor = conn.cursor()
- query = f"SELECT copies FROM users WHERE name='{str(user)}'"
- cursor.execute(query)
- result = cursor.fetchone()
- for role in data['roles']:
- if int(result[0]) == int(role["copies"]):
- roleobj = discord.utils.get(message.guild.roles, id=int(role["roleid"]))
- await user.add_roles(roleobj)
- cursor.close()
- def checkusr(user):
- cursor = conn.cursor()
- query = f"SELECT COUNT(*) FROM users WHERE name = '{user}'"
- cursor.execute(query)
- result = cursor.fetchone()[0]
- if result == 0:
- query = f"INSERT INTO users (name, copies, rate, disabled) VALUES ('{user}', 0, 1.0, 0)"
- cursor.execute(query)
- conn.commit()
- cursor.close()
- else:
- return
- @bot.event
- async def on_ready():
- print("Bot Is Ready And Online!")
- myLoop.start()
- @bot.command()
- async def ping(ctx):
- latency = round(bot.latency * 1000)
- embed = discord.Embed(title='Pong 🏓', description=f'The latency is `{latency}`')
- await ctx.send(ctx.author.mention ,embed=embed)
- @bot.command()
- @commands.cooldown(1, 180, commands.BucketType.user)
- async def end(ctx, target: discord.User):
- if not ctx.channel.id == 1084139934111244338:
- channel = bot.get_channel(1084139934111244338)
- raise Exception(f"Wrong channel, use '{channel}' channel")
- if target == ctx.author:
- raise Exception("You cannot perform command `gm!end` on yourself")
- if target.bot:
- raise Exception("You cannot perform balance commands on bot")
- with open('roles.json') as f:
- data = json.load(f)
- global has_role
- has_role = False
- for role in data['roles']:
- roleobj = discord.utils.get(ctx.guild.roles, id=int(role["roleid"]))
- if roleobj in ctx.author.roles:
- has_role = True
- print(has_role)
- break
- print(has_role)
- if not has_role:
- raise Exception("You require at least one Milestone role")
- cursor = conn.cursor()
- query = "SELECT name, copies FROM users ORDER BY copies DESC"
- cursor.execute(query)
- results = cursor.fetchall()
- global i
- my_list = []
- i = 1
- for row in results:
- if i == 16:
- break
- if not int(row[1]) == 0:
- my_list.append(str(row[0]))
- i=i+1
- cursor.close()
- global amount
- if str(ctx.author) in my_list:
- amount = 10
- else:
- amount = 5
- checkusr(str(ctx.author))
- checkusr(str(target))
- cursor = conn.cursor()
- query = f"UPDATE users SET copies = copies + {amount} WHERE name = '{str(ctx.author)}'"
- query = f"UPDATE users SET disabled = 20 WHERE name = '{str(target)}'"
- cursor.execute(query)
- conn.commit()
- cursor.close()
- await addrole(ctx.author, ctx)
- embed = discord.Embed(description=f"🔥 You have ended {target} store.\n**`[User will not recive any copies for 20 Minutes]`**")
- embed2 = discord.Embed(description=f"+{amount} <:gamecontroller:1083081966833914006>")
- await ctx.send(ctx.author.mention, embeds=[embed, embed2])
- @bot.command()
- async def addmsr(ctx, role: discord.Role, copies: int):
- if not ctx.channel.permissions_for(ctx.author).administrator:
- raise Exception("You dont have administrator permissions")
- with open('roles.json', 'r') as f:
- data = json.load(f)
- new_role = {
- "roleid": str(role.id),
- "copies": str(copies)
- }
- data['roles'].append(new_role)
- with open('roles.json', 'w') as f:
- json.dump(data, f, indent=4)
- embed = discord.Embed(title='✅ Succes ✅', description=f'`msr` Roles Updated')
- await ctx.send(ctx.author.mention, embed=embed)
- @bot.command()
- async def clearmsr(ctx):
- if not ctx.channel.permissions_for(ctx.author).administrator:
- raise Exception("You dont have administrator permissions")
- data = {"roles": []}
- with open('roles.json', 'w') as f:
- json.dump(data, f, indent=4)
- embed = discord.Embed(title='✅ Succes ✅', description=f'`msr` Roles Cleared')
- await ctx.send(ctx.author.mention, embed=embed)
- @bot.command()
- async def add(ctx, user: discord.User, amount: int):
- if user.bot:
- raise Exception("You cannot perform balance commands on bot")
- if not ctx.channel.permissions_for(ctx.author).administrator:
- raise Exception("You dont have administrator permissions")
- checkusr(str(user))
- cursor = conn.cursor()
- query = f"UPDATE users SET copies = copies + {amount} WHERE name = '{str(user)}'"
- cursor.execute(query)
- conn.commit()
- cursor.close()
- await addrole(ctx.author, ctx)
- embed = discord.Embed(title='✅ Succes ✅', description=f"Added `{amount}` <:gamecontroller:1083081966833914006> to `{user}`")
- print("passed")
- await ctx.send(ctx.author.mention, embed=embed)
- @bot.command()
- async def balance(ctx, user: discord.User = None):
- if user == None:
- checkusr(str(ctx.author))
- cursor = conn.cursor()
- query = f"SELECT copies FROM users WHERE name='{ctx.author}'"
- cursor.execute(query)
- result = cursor.fetchone()
- cursor.close()
- embed = discord.Embed(title='💰 Balance 💰', description=f"You have `{result[0]}` <:gamecontroller:1083081966833914006>")
- await ctx.send(ctx.author.mention, embed=embed)
- else:
- if user.bot:
- raise Exception("You cannot perform balance commands on bot")
- checkusr(str(user))
- cursor = conn.cursor()
- query = f"SELECT copies FROM users WHERE name='{user}'"
- cursor.execute(query)
- result = cursor.fetchone()
- embed = discord.Embed(title='💰 Balance 💰', description=f"User `{user}` have `{result[0]}` <:gamecontroller:1083081966833914006>")
- await ctx.send(ctx.author.mention, embed=embed)
- @bot.command()
- async def leaderboard(ctx):
- cursor = conn.cursor()
- query = "SELECT name, copies FROM users ORDER BY copies DESC"
- cursor.execute(query)
- results = cursor.fetchall()
- embed = discord.Embed(title="TOP COPIES LEADERBOARD")
- global s
- global leaderboardSTR
- leaderboardSTR = ""
- print(leaderboardSTR)
- s = 1
- for row in results:
- if s == 16:
- break
- if not int(row[1]) == 0:
- leaderboardSTR="\n".join((leaderboardSTR, f"{s}. {row[0]}, {row[1]} <:gamecontroller:1083081966833914006>"))
- print(leaderboardSTR)
- s=s+1
- print(leaderboardSTR)
- print(len(leaderboardSTR))
- if(len(leaderboardSTR) == 0):
- embed.add_field(name="❌ Nothing to see ❌", value="", inline=True)
- else:
- embed.add_field(name="", value=leaderboardSTR, inline=True)
- cursor.close()
- await ctx.send(ctx.author.mention, embed=embed)
- @tasks.loop(minutes=1)
- async def myLoop():
- cursor = conn.cursor()
- query = "SELECT name, disabled FROM users"
- cursor.execute(query)
- results = cursor.fetchall()
- for row in results:
- if not int(row[1]) == 0:
- query = f"UPDATE users SET disabled = disabled - 1 WHERE name = '{row[0]}'"
- cursor.execute(query)
- print(f"User: {row[0]}, Disabled: {row[1]}")
- conn.commit()
- cursor.close()
- @bot.event
- async def on_message(message):
- if message.author.bot:
- raise Exception("You cannot perform balance commands on bot")
- num = random.randint(1, 3)
- if num == 3:
- checkusr(message.author)
- cursor = conn.cursor()
- query = f"SELECT disabled FROM users WHERE name='{message.author}'"
- cursor.execute(query)
- result = cursor.fetchone()
- if not int(result[0]) == 0:
- return
- with open('roles.json') as f:
- data = json.load(f)
- global rolei
- rolei = 10
- for role in data['roles']:
- roleobj = discord.utils.get(message.guild.roles, id=int(role["roleid"]))
- if roleobj in message.author.roles:
- rolei = rolei + 5
- print(rolei)
- break
- query = f"UPDATE users SET copies = copies + {rolei} WHERE name = '{str(message.author)}'"
- cursor.execute(query)
- conn.commit()
- cursor.close()
- await addrole(message.author, message)
- await message.add_reaction("⭐")
- @addmsr.error
- async def addmsrErr(ctx, error):
- embed = discord.Embed(title='🟥 Error 🟥', description=f'Error while executing `gm!addmsr`')
- embed.set_footer(test=str(error))
- await ctx.send(ctx.author.mention, embed=embed)
- @add.error
- async def addErr(ctx, error):
- embed = discord.Embed(title='🟥 Error 🟥', description=f'Error while executing `gm!add`')
- embed.set_footer(text=str(error))
- await ctx.send(ctx.author.mention, embed=embed)
- @end.error
- async def endErr(ctx, error):
- embed = discord.Embed(title='🟥 Error 🟥', description=f'Error while executing `gm!end`')
- embed.set_footer(text=str(error))
- await ctx.send(ctx.author.mention, embed=embed)
- bot.run(discord_token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement