Advertisement
tommarek_CZE

Untitled

Mar 12th, 2023
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.01 KB | None | 0 0
  1. import discord
  2. import json
  3. from discord.ext import tasks
  4. import sqlite3
  5. from discord.ext import commands
  6. import random
  7.  
  8. intents = discord.Intents.all()
  9.  
  10. conn = sqlite3.connect('users.db')
  11.  
  12. bot = commands.Bot(command_prefix="gm!", intents=intents)
  13.  
  14. discord_token = "MTA4NDQ5MjM4NTE1MDU3ODc3OA.GBTDga.Vzpq7WXzyy-1UbPSBEs3LrvQtCkG_X-yyeuTe8"
  15.  
  16. async def addrole(user, message):
  17. with open('roles.json') as f:
  18. data = json.load(f)
  19.  
  20. cursor = conn.cursor()
  21. query = f"SELECT copies FROM users WHERE name='{str(user)}'"
  22. cursor.execute(query)
  23. result = cursor.fetchone()
  24.  
  25. for role in data['roles']:
  26. if int(result[0]) == int(role["copies"]):
  27. roleobj = discord.utils.get(message.guild.roles, id=int(role["roleid"]))
  28. await user.add_roles(roleobj)
  29.  
  30. cursor.close()
  31.  
  32. def checkusr(user):
  33. cursor = conn.cursor()
  34.  
  35. query = f"SELECT COUNT(*) FROM users WHERE name = '{user}'"
  36. cursor.execute(query)
  37. result = cursor.fetchone()[0]
  38.  
  39. if result == 0:
  40. query = f"INSERT INTO users (name, copies, rate, disabled) VALUES ('{user}', 0, 1.0, 0)"
  41. cursor.execute(query)
  42. conn.commit()
  43. cursor.close()
  44. else:
  45. return
  46.  
  47. @bot.event
  48. async def on_ready():
  49. print("Bot Is Ready And Online!")
  50. myLoop.start()
  51.  
  52. @bot.command()
  53. async def ping(ctx):
  54. latency = round(bot.latency * 1000)
  55. embed = discord.Embed(title='Pong 🏓', description=f'The latency is `{latency}`')
  56. await ctx.send(ctx.author.mention ,embed=embed)
  57.  
  58. @bot.command()
  59. @commands.cooldown(1, 180, commands.BucketType.user)
  60. async def end(ctx, target: discord.User):
  61. if not ctx.channel.id == 1084139934111244338:
  62. channel = bot.get_channel(1084139934111244338)
  63. raise Exception(f"Wrong channel, use '{channel}' channel")
  64.  
  65. if target == ctx.author:
  66. raise Exception("You cannot perform command `gm!end` on yourself")
  67.  
  68. if target.bot:
  69. raise Exception("You cannot perform balance commands on bot")
  70.  
  71. with open('roles.json') as f:
  72. data = json.load(f)
  73.  
  74. global has_role
  75. has_role = False
  76. for role in data['roles']:
  77. roleobj = discord.utils.get(ctx.guild.roles, id=int(role["roleid"]))
  78. if roleobj in ctx.author.roles:
  79. has_role = True
  80. print(has_role)
  81. break
  82.  
  83. print(has_role)
  84. if not has_role:
  85. raise Exception("You require at least one Milestone role")
  86.  
  87. cursor = conn.cursor()
  88.  
  89. query = "SELECT name, copies FROM users ORDER BY copies DESC"
  90. cursor.execute(query)
  91.  
  92. results = cursor.fetchall()
  93.  
  94. global i
  95. my_list = []
  96. i = 1
  97. for row in results:
  98. if i == 16:
  99. break
  100. if not int(row[1]) == 0:
  101. my_list.append(str(row[0]))
  102. i=i+1
  103.  
  104. cursor.close()
  105.  
  106. global amount
  107.  
  108. if str(ctx.author) in my_list:
  109. amount = 10
  110. else:
  111. amount = 5
  112.  
  113. checkusr(str(ctx.author))
  114. checkusr(str(target))
  115. cursor = conn.cursor()
  116.  
  117. query = f"UPDATE users SET copies = copies + {amount} WHERE name = '{str(ctx.author)}'"
  118. query = f"UPDATE users SET disabled = 20 WHERE name = '{str(target)}'"
  119. cursor.execute(query)
  120. conn.commit()
  121. cursor.close()
  122.  
  123. await addrole(ctx.author, ctx)
  124. embed = discord.Embed(description=f"🔥 You have ended {target} store.\n**`[User will not recive any copies for 20 Minutes]`**")
  125. embed2 = discord.Embed(description=f"+{amount} <:gamecontroller:1083081966833914006>")
  126. await ctx.send(ctx.author.mention, embeds=[embed, embed2])
  127.  
  128.  
  129. @bot.command()
  130. async def addmsr(ctx, role: discord.Role, copies: int):
  131. if not ctx.channel.permissions_for(ctx.author).administrator:
  132. raise Exception("You dont have administrator permissions")
  133.  
  134. with open('roles.json', 'r') as f:
  135. data = json.load(f)
  136.  
  137. new_role = {
  138. "roleid": str(role.id),
  139. "copies": str(copies)
  140. }
  141. data['roles'].append(new_role)
  142.  
  143. with open('roles.json', 'w') as f:
  144. json.dump(data, f, indent=4)
  145.  
  146. embed = discord.Embed(title='✅ Succes ✅', description=f'`msr` Roles Updated')
  147. await ctx.send(ctx.author.mention, embed=embed)
  148.  
  149.  
  150. @bot.command()
  151. async def clearmsr(ctx):
  152. if not ctx.channel.permissions_for(ctx.author).administrator:
  153. raise Exception("You dont have administrator permissions")
  154. data = {"roles": []}
  155. with open('roles.json', 'w') as f:
  156. json.dump(data, f, indent=4)
  157.  
  158. embed = discord.Embed(title='✅ Succes ✅', description=f'`msr` Roles Cleared')
  159. await ctx.send(ctx.author.mention, embed=embed)
  160.  
  161. @bot.command()
  162. async def add(ctx, user: discord.User, amount: int):
  163. if user.bot:
  164. raise Exception("You cannot perform balance commands on bot")
  165.  
  166. if not ctx.channel.permissions_for(ctx.author).administrator:
  167. raise Exception("You dont have administrator permissions")
  168.  
  169. checkusr(str(user))
  170. cursor = conn.cursor()
  171. query = f"UPDATE users SET copies = copies + {amount} WHERE name = '{str(user)}'"
  172. cursor.execute(query)
  173. conn.commit()
  174. cursor.close()
  175. await addrole(ctx.author, ctx)
  176. embed = discord.Embed(title='✅ Succes ✅', description=f"Added `{amount}` <:gamecontroller:1083081966833914006> to `{user}`")
  177. print("passed")
  178. await ctx.send(ctx.author.mention, embed=embed)
  179.  
  180. @bot.command()
  181. async def balance(ctx, user: discord.User = None):
  182. if user == None:
  183. checkusr(str(ctx.author))
  184. cursor = conn.cursor()
  185. query = f"SELECT copies FROM users WHERE name='{ctx.author}'"
  186. cursor.execute(query)
  187. result = cursor.fetchone()
  188. cursor.close()
  189. embed = discord.Embed(title='💰 Balance 💰', description=f"You have `{result[0]}` <:gamecontroller:1083081966833914006>")
  190. await ctx.send(ctx.author.mention, embed=embed)
  191. else:
  192. if user.bot:
  193. raise Exception("You cannot perform balance commands on bot")
  194.  
  195. checkusr(str(user))
  196. cursor = conn.cursor()
  197. query = f"SELECT copies FROM users WHERE name='{user}'"
  198. cursor.execute(query)
  199. result = cursor.fetchone()
  200. embed = discord.Embed(title='💰 Balance 💰', description=f"User `{user}` have `{result[0]}` <:gamecontroller:1083081966833914006>")
  201. await ctx.send(ctx.author.mention, embed=embed)
  202.  
  203. @bot.command()
  204. async def leaderboard(ctx):
  205. cursor = conn.cursor()
  206.  
  207. query = "SELECT name, copies FROM users ORDER BY copies DESC"
  208. cursor.execute(query)
  209.  
  210. results = cursor.fetchall()
  211.  
  212. embed = discord.Embed(title="TOP COPIES LEADERBOARD")
  213.  
  214. global s
  215. global leaderboardSTR
  216. leaderboardSTR = ""
  217. print(leaderboardSTR)
  218. s = 1
  219. for row in results:
  220. if s == 16:
  221. break
  222. if not int(row[1]) == 0:
  223. leaderboardSTR="\n".join((leaderboardSTR, f"{s}. {row[0]}, {row[1]} <:gamecontroller:1083081966833914006>"))
  224. print(leaderboardSTR)
  225. s=s+1
  226.  
  227. print(leaderboardSTR)
  228. print(len(leaderboardSTR))
  229. if(len(leaderboardSTR) == 0):
  230. embed.add_field(name="❌ Nothing to see ❌", value="", inline=True)
  231. else:
  232. embed.add_field(name="", value=leaderboardSTR, inline=True)
  233.  
  234. cursor.close()
  235.  
  236. await ctx.send(ctx.author.mention, embed=embed)
  237.  
  238. @tasks.loop(minutes=1)
  239. async def myLoop():
  240. cursor = conn.cursor()
  241.  
  242. query = "SELECT name, disabled FROM users"
  243. cursor.execute(query)
  244.  
  245. results = cursor.fetchall()
  246.  
  247. for row in results:
  248. if not int(row[1]) == 0:
  249. query = f"UPDATE users SET disabled = disabled - 1 WHERE name = '{row[0]}'"
  250.  
  251. cursor.execute(query)
  252. print(f"User: {row[0]}, Disabled: {row[1]}")
  253.  
  254. conn.commit()
  255. cursor.close()
  256.  
  257. @bot.event
  258. async def on_message(message):
  259. if message.author.bot:
  260. raise Exception("You cannot perform balance commands on bot")
  261.  
  262. num = random.randint(1, 3)
  263. if num == 3:
  264. checkusr(message.author)
  265.  
  266. cursor = conn.cursor()
  267. query = f"SELECT disabled FROM users WHERE name='{message.author}'"
  268. cursor.execute(query)
  269. result = cursor.fetchone()
  270.  
  271. if not int(result[0]) == 0:
  272. return
  273.  
  274. with open('roles.json') as f:
  275. data = json.load(f)
  276.  
  277. global rolei
  278. rolei = 10
  279. for role in data['roles']:
  280. roleobj = discord.utils.get(message.guild.roles, id=int(role["roleid"]))
  281. if roleobj in message.author.roles:
  282. rolei = rolei + 5
  283. print(rolei)
  284. break
  285.  
  286. query = f"UPDATE users SET copies = copies + {rolei} WHERE name = '{str(message.author)}'"
  287. cursor.execute(query)
  288. conn.commit()
  289. cursor.close()
  290. await addrole(message.author, message)
  291. await message.add_reaction("⭐")
  292.  
  293. @addmsr.error
  294. async def addmsrErr(ctx, error):
  295. embed = discord.Embed(title='🟥 Error 🟥', description=f'Error while executing `gm!addmsr`')
  296. embed.set_footer(test=str(error))
  297. await ctx.send(ctx.author.mention, embed=embed)
  298.  
  299. @add.error
  300. async def addErr(ctx, error):
  301. embed = discord.Embed(title='🟥 Error 🟥', description=f'Error while executing `gm!add`')
  302. embed.set_footer(text=str(error))
  303. await ctx.send(ctx.author.mention, embed=embed)
  304.  
  305. @end.error
  306. async def endErr(ctx, error):
  307. embed = discord.Embed(title='🟥 Error 🟥', description=f'Error while executing `gm!end`')
  308. embed.set_footer(text=str(error))
  309. await ctx.send(ctx.author.mention, embed=embed)
  310.  
  311. bot.run(discord_token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement