Guest User

Untitled

a guest
Oct 31st, 2023
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 25.80 KB | None | 0 0
  1. import discord, json, datetime, random, requests
  2. from discord.ext import commands
  3. from discord import app_commands, ui
  4. from discord.app_commands import Choice
  5.  
  6. client = commands.Bot(command_prefix="!", intents=discord.Intents.all())
  7. client.remove_command("help")
  8. tree = client.tree
  9. rosec = "nostealing"
  10.  
  11. db = "D:/nUSA/PDS/Bot/db.json"
  12. logs = "D:/nUSA/PDS/Bot/logs.txt"
  13.  
  14.  
  15.  
  16. class Colours:
  17.     class Brand:
  18.         red = 0xBC3131
  19.         blue = 0x2E3E60
  20.         gray = 0x383838
  21.     class Logs:
  22.         red = 0xF1CACC
  23.         orange = 0xFFD2BA
  24.         yellow = 0xFDF2CF
  25.         green = 0xBAE2CE
  26.         blurple = 0xD9D2E8
  27.  
  28.  
  29.  
  30. def precheck():
  31.     async def thecheck(interaction : discord.Interaction):
  32.         actorid = isconnected(interaction.user)
  33.         if not actorid:
  34.             await interaction.response.send_message(embed=discord.Embed(title="Command Error", colour=Colours.Brand.red, description="Uh-oh, it doesn't look like you've connected your **roblox** account"), ephemeral=True)
  35.             return False
  36.         actorrank = iscommand(actorid)
  37.         if actorrank == None:
  38.             await interaction.response.send_message(embed=discord.Embed(title="Command Error", colour=Colours.Brand.red, description="Uh-oh, it doesn't look like you're in the group"), ephemeral=True)
  39.             return False
  40.         return True
  41.     return app_commands.check(thecheck)
  42.  
  43. def historylog(actorid, userid, timestamp, action, txtaction):
  44.     userid = str(userid)
  45.     with open(db, "r+") as f:
  46.         data = json.load(f)
  47.         if userid in data["history"]:
  48.             data["history"][userid]["employment"][timestamp] = action
  49.         else:
  50.             data["history"][userid] = {
  51.                 "employment": {
  52.                     timestamp: action
  53.                 },
  54.                 "packages": {
  55.                     "total": 0
  56.                 }
  57.             }
  58.         f.seek(0)
  59.         f.truncate()
  60.         json.dump(data, f, indent=4)
  61.     with open(logs, "a") as f:
  62.         f.write(f"[{timestamp}] {txtaction}" + "\n")
  63.  
  64.  
  65.  
  66. #roblox
  67. def getuser(user):
  68.     if isinstance(user, int):
  69.         user = json.loads(requests.get(f"https://users.roblox.com/v1/users/{user}").text)
  70.         if "errors" in user:
  71.             return None
  72.     else:
  73.         user = json.loads(requests.post("https://users.roblox.com/v1/usernames/users", json={"usernames": [user], "excludeBannedUsers": True}).text)
  74.         if not user["data"]:
  75.             return None
  76.         user = user["data"][0]
  77.     return user
  78.  
  79. def getmugshot(userid):
  80.     pic = json.loads(requests.get(f"https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds={userid}&size=720x720&format=Png&isCircular=false").text)["data"][0]["imageUrl"]
  81.     return pic
  82.  
  83. #returns roid
  84. def isconnected(discorduser):
  85.     with open(db, "r+") as f:
  86.         data = json.load(f)
  87.         if str(discorduser.id) in data["connections"]:
  88.             return data["connections"][str(discorduser.id)]
  89.     return False
  90.  
  91. #returns whether in group and if command
  92. def iscommand(userid):
  93.     user = [el for el in json.loads(requests.get(f"https://groups.roblox.com/v1/users/{userid}/groups/roles").text)["data"] if el["group"]["id"] == 16367093]
  94.     if user:
  95.         if user[0]["role"]["rank"] >= 30:
  96.             return (True, user[0]["role"])
  97.         else:
  98.             return (False, user[0]["role"])
  99.     else:
  100.         return None
  101.  
  102.  
  103.  
  104. @client.event
  105. async def on_ready():
  106.     print(f"Packages now online with {round(client.latency * 1000)}ms ping.")
  107.  
  108. @tree.command(name="link", description="Link your Roblox and Discord", guilds=[discord.Object(1145424590152151091)])
  109. async def link(interaction : discord.Interaction, username : str):
  110.     with open(db, "r+") as f:
  111.         data = json.load(f)
  112.         if str(interaction.user.id) in data["connections"]:
  113.             await interaction.response.send_message(embed=discord.Embed(title="Link Error", colour=Colours.Brand.red, description="Uh-oh, it looks like you've already connected your Roblox & Discord together\nIf you believe this is a mistake or wish to unlink your accounts, use the `/unlink` command"), ephemeral=True)
  114.             return
  115.     user = getuser(username)
  116.     if not user:
  117.         await interaction.response.send_message(embed=discord.Embed(title="Link Error", colour=Colours.Brand.red, description="Uh-oh, it looks like the username you entered is not a valid __Roblox__ account"), ephemeral=True)
  118.     userid = user["id"]
  119.     colours = ["black", "blue", "brown", "green", "orange", "purple", "red", "white", "yellow"]
  120.     animals = ["sheep", "cow", "pig", "dog", "cat", "fish", "panda", "rabbit"]
  121.     code = f"{random.choice(colours)} {random.choice(animals)} {random.choice(colours)} {random.choice(animals)} {random.choice(colours)} {random.choice(animals)}"
  122.  
  123.     #Create View
  124.     class ConfirmButton(discord.ui.View):
  125.         #Setup View
  126.         def __init__(self, *, clicked=False, timeout=180):
  127.             #Globalise
  128.             super().__init__(timeout=timeout)
  129.             self.value = None
  130.        
  131.         #Add button to view
  132.         @discord.ui.button(emoji="✔", label="Done", style=discord.ButtonStyle.green)
  133.         #Button onclick function
  134.         async def donebutton(self, button : discord.ui.Button, interaction : discord.Interaction):
  135.             self.value = True
  136.             self.stop()
  137.    
  138.     confirmChange = ConfirmButton()
  139.     await interaction.response.send_message(embed=discord.Embed(title="Link Code", colour=Colours.Brand.gray, description=f"Set your Roblox **About** section to;```\n{code}\n```If the code ends up being tagged, just click \"Dismiss message\" and try the command again").set_footer(text="This prompt will expire after 3 minute"), view=confirmChange, ephemeral=True)
  140.     await confirmChange.wait()
  141.     if confirmChange.value:
  142.         user = getuser(user["id"])
  143.         if code not in user["description"]:
  144.             await interaction.edit_original_response(embed=discord.Embed(title="Link Error", colour=Colours.Brand.red, description=f"Uh-oh, it looks like you haven't put in the correct code.\nTry again"), view=None)
  145.             return
  146.         mugshot = getmugshot(user["id"])
  147.         await interaction.edit_original_response(embed=discord.Embed(title="Link Success", colour=Colours.Brand.blue, description=f"You have successfully connected {interaction.user.mention} to `{username}`").set_thumbnail(url=json.loads(requests.get(f"https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds={user['id']}&size=720x720&format=Png&isCircular=false").text)["data"][0]["imageUrl"]), view=None)
  148.         with open(db, "r+") as f:
  149.             data = json.load(f)
  150.             data["connections"][str(interaction.user.id)] = user["id"]
  151.             f.seek(0)
  152.             f.truncate()
  153.             json.dump(data, f, indent=4)
  154.     else:
  155.         await interaction.edit_original_response(embed=discord.Embed(title="Link Error", colour=Colours.Brand.red, description=f"3 Minute link timer expired"), view=None)
  156.  
  157. @tree.command(name="unlink", description="Unlink your Roblox and Discord", guilds=[discord.Object(1145424590152151091)])
  158. @precheck()
  159. async def unlink(interaction : discord.Interaction, username : str):
  160.     with open(db, "r+") as f:
  161.         data = json.load(f)
  162.         del data["connections"][str(interaction.user.id)]
  163.         f.seek(0)
  164.         f.truncate()
  165.         json.dump(data, f, indent=4)
  166.     await interaction.response.send_message(embed=discord.Embed(title="Unlinked", colour=Colours.Brand.blue, description="Your Roblox and Discord accounts have successfully been unlinked"), ephemeral=True)
  167.  
  168. @tree.command(name="submit", description="Submit packages", guilds=[discord.Object(1145424590152151091)])
  169. @precheck()
  170. async def submit(interaction : discord.Interaction, amount : int, startsc : str, endsc : str):
  171.     user = str(isconnected(interaction.user))
  172.     timestamp = datetime.datetime.now().strftime("%m/%d/%Y %H:%M:%S")
  173.     with open(db, "a") as f:
  174.         data = json.load(f)
  175.         if user in data["history"]:
  176.             data["history"][user]["packages"][rntime] = {
  177.                 "amount": amount,
  178.                 "startsc": startsc,
  179.                 "endsc": endsc,
  180.                 "verified": False
  181.             }
  182.         else:
  183.             data["history"][user] = {
  184.                 "employment": {},
  185.                 "packages": {
  186.                     "total": 0,
  187.                     rntime: {
  188.                         "amount": amount,
  189.                         "startsc": startsc,
  190.                         "endsc": endsc,
  191.                         "verified": False
  192.                     }
  193.                 }
  194.             }
  195.         f.seek(0)
  196.         f.truncate()
  197.         json.dump(data, f, indent=4)
  198.     mugshot = getmugshot(user)
  199.     submitchannel = client.get_channel(1159248926684221571)
  200.     await submitchannel.send(embed=discord.Embed(title=user, colour=Colours.Brand.blue, description=f"{timestamp}\n{amount}\n[{startsc}]({startsc})\n[{endsc}]({endsc})").set_thumbnail(url=mugshot))
  201.     await interaction.response.send_message(embed=discord.Embed(title="Package Submission", colour=Colours.Brand.blue, description="Your packages have successfully been submitted").set_thumbnail(url=mugshot), ephemeral=True)
  202.  
  203. @tree.command(name="approve", description="Approve packages", guilds=[discord.Object(1145424590152151091)])
  204. @precheck()
  205. async def approve(interaction : discord.Interaction, msgid : int):
  206.     try:
  207.         packages = await interaction.channel.fetch_message(msgid)
  208.     except Exception as e:
  209.         await interaction.response.send_message(embed=discord.Embed(title="Approve Packages Error", colour=Colours.Brand.red, description=f"Uh-oh, it looks like we ran into the following error;```\n{e}\n```"), ephemeral=True)
  210.         return
  211.     if packages.author.id != 1143679506842931231 or not packages.embeds:
  212.         await interaction.response.send_message(embed=discord.Embed(title="Approve Packages Error", colour=Colours.Brand.red, description="Uh-oh, it doesn't look like that message is a package submission"), ephemeral=True)
  213.     info = packages.embeds[0]
  214.     userid = info.title
  215.     timestamp = info.description.split("\n")[0]
  216.     amount = info.description.split("\n")[1]
  217.     actorid = isconnected(interaction.user)
  218.     actorname = getuser(actorid)["name"]
  219.     await interaction.response.send_message(embed=discord.Embed(title="Packages Approved", colour=Colours.Brand.blue, description=f"`{username}`'s `{amount}` packages have been approved"), ephemeral=True)
  220.     with open(db, "r+") as f:
  221.         data = json.load(f)
  222.         data["history"][userid]["packages"][timestamp]["verified"] = actorid
  223.         data["history"][userid]["packages"]["total"] += amount
  224.         f.seek(0)
  225.         f.truncate()
  226.         json.dump(data, f, indent=4)
  227.     user = getuser(userid)["name"]
  228.     with open(logs, "r+") as f:
  229.         f.write(f"[{timestamp}] {user} ({userid}) {amount} PACKGES APPROVED BY {actorname} ({actorid})\n")
  230.  
  231. action = app_commands.Group(name="action", description="Everything related to performing group actions")
  232. action = app_commands.guilds(discord.Object(1145424590152151091))(action)
  233. tree.add_command(action)
  234.  
  235. @action.command(name="hire", description="Hire a user")
  236. @precheck()
  237. @app_commands.choices(rank = [
  238.     Choice(name="Manager", value="40"),
  239.     Choice(name="Supervisor", value="30"),
  240.     Choice(name="Senior Delivery Driver", value="20"),
  241.     Choice(name="Delivery Driver", value="17"),
  242.     Choice(name="Trainee Delivery Driver", value="15")
  243. ])
  244. @app_commands.choices(division = [
  245.     Choice(name="Management", value="Mgmt"),
  246.     Choice(name="Human Resources", value="HR"),
  247.     Choice(name="Delivery", value="Dlvry")
  248. ])
  249. async def hire(interaction : discord.Interaction, user : str, rank : Choice[str]=None, division : Choice[str]=None, notes : str=None):
  250.     #actor checks
  251.     actorid = isconnected(interaction.user)
  252.     actorname = getuser(actorid)["name"]
  253.     actorrank = iscommand(actorid)
  254.     if not actorrank[0]:
  255.         await interaction.response.send_message(embed=discord.Embed(title="Action Rank Error", colour=Colours.Brand.red, description="Uh-oh, it doesn't look like you can do that"), ephemeral=True)
  256.         return
  257.     #checks
  258.     user = getuser(user)
  259.     if not user:
  260.         await interaction.response.send_message(embed=discord.Embed(title="Action Rank Error", colour=Colours.Brand.red, description="Uh-oh, it doesn't look like that user exists"), ephemeral=True)
  261.         return
  262.     userid = user["id"]
  263.     username = user["name"]
  264.     #code
  265.     embed = discord.Embed(
  266.         title="PDS Business Actions",
  267.         colour=Colours.Logs.green,
  268.         description=f"**User Hired**\n`{username}` has been **hired** into the business."
  269.     )
  270.     mugshot = getmugshot(userid)
  271.     embed.set_thumbnail(url=mugshot)
  272.     embed.set_footer(text=interaction.user.nick, icon_url="https://cdn.discordapp.com/emojis/1165632658492100748.webp?size=96&quality=lossless")
  273.     if not rank:
  274.         class rank:
  275.             name = "Trainee Delivery Driver"
  276.             value = "15"
  277.     embed.add_field(name="Rank", value=rank.name, inline=False)
  278.     if not division:
  279.         class division:
  280.             name = "Delivery"
  281.             value = "Dlvry"
  282.     embed.add_field(name="Division", value=division.name, inline=False)
  283.     if notes:
  284.         embed.add_field(name="Notes", value=notes, inline=False)
  285.     actionchannel = client.get_channel(1145424593213988967)
  286.     actionlink = await actionchannel.send(embed=embed)
  287.     actionlink = actionlink.jump_url
  288.     await interaction.response.send_message(embed=discord.Embed(title="Action Hire Successful", colour=Colours.Brand.blue, description=f"User has successfully been hired\n{actionlink}"), ephemeral=True)
  289.     log = {
  290.         "hired": {
  291.             "rank": rank.name,
  292.             "division": division.name
  293.         }
  294.     }
  295.     if notes:
  296.         log["hired"]["notes"] = notes
  297.     log["hired"]["by"] = actorid
  298.     timestamp = datetime.datetime.now().strftime("%m/%d/%Y %H:%M:%S")
  299.     historylog(actorid, userid, timestamp, log, f"{username} ({userid}) HIRED BY {actorname} ({actorid}) AS {rank.name} IN {division} EXTRA {notes}")
  300.     el = requests.post(f"https://groups.roblox.com/v1/groups/16367093/join-requests/users/{userid}", cookies={".ROBLOSECURITY": rosec})
  301.     el = requests.post(f"https://groups.roblox.com/v1/groups/16367093/join-requests/users/{userid}", cookies={".ROBLOSECURITY": rosec}, headers={"x-csrf-token": el.headers["x-csrf-token"]})
  302.     if rank.name == "Trainee Delivery Driver":
  303.         return
  304.     roleId = {"40": 100735232, "30": 100735223, "20": 100735217, "17": 91563673, "15": 101369050}[rank.value]
  305.     el = requests.patch(f"https://groups.roblox.com/v1/groups/16367093/users/{userid}", data={"roleId": roleId}, cookies={".ROBLOSECURITY": rosec})
  306.     el = requests.patch(f"https://groups.roblox.com/v1/groups/16367093/users/{userid}", data={"roleId": roleId}, cookies={".ROBLOSECURITY": rosec}, headers={"x-csrf-token": el.headers["x-csrf-token"]})
  307.  
  308.  
  309. @action.command(name="rank", description="Rank a user")
  310. @precheck()
  311. @app_commands.choices(rank = [
  312.     Choice(name="Manager", value="40"),
  313.     Choice(name="Supervisor", value="30"),
  314.     Choice(name="Senior Delivery Driver", value="20"),
  315.     Choice(name="Delivery Driver", value="17"),
  316.     Choice(name="Trainee Delivery Driver", value="15")
  317. ])
  318. async def rank(interaction : discord.Interaction, user : str, rank : Choice[str], notes : str=None):
  319.     #actor checks
  320.     actorid = isconnected(interaction.user)
  321.     actorname = getuser(actorid)["name"]
  322.     actorrank = iscommand(actorid)
  323.     if not actorrank[0]:
  324.         await interaction.response.send_message(embed=discord.Embed(title="Action Rank Error", colour=Colours.Brand.red, description="Uh-oh, it doesn't look like you can do that"), ephemeral=True)
  325.         return
  326.     #user checks
  327.     user = getuser(user)
  328.     if not user:
  329.         await interaction.response.send_message(embed=discord.Embed(title="Action Rank Error", colour=Colours.Brand.red, description="Uh-oh, it doesn't look like that user exists"), ephemeral=True)
  330.         return
  331.     userid = user["id"]
  332.     username = user["name"]
  333.     userrank = iscommand(userid)
  334.     if userrank[0] == None:
  335.         await interaction.response.send_message(embed=discord.Embed(title="Action Rank Error", colour=Colours.Brand.red, description="Uh-oh, it doesn't look like that user is employed in PDS"), ephemeral=True)
  336.         return
  337.     #vars
  338.     actorrankrank = actorrank[1]["rank"]
  339.     userrankrank = userrank[1]["rank"]
  340.     userrankname = userrank[1]["name"]
  341.     #code
  342.     if actorrankrank <= userrankrank:
  343.         await interaction.response.send_message(embed=discord.Embed(title="Action Rank Error", colour=Colours.Brand.red, description=f"Uh-oh, you can't change the rank of a user that has the same or a higher rank than you"), ephemeral=True)
  344.         return
  345.     if actorrankrank <= int(rank.value):
  346.         await interaction.response.send_message(embed=discord.Embed(title="Action Rank Error", colour=Colours.Brand.red, description=f"Uh-oh, you can't rank someone to the same or a higher rank than yours"), ephemeral=True)
  347.         return
  348.     mugshot = getmugshot(userid)
  349.     embed = discord.Embed(
  350.         title="PDS Business Actions",
  351.         colour=Colours.Logs.green,
  352.         description=""
  353.     )
  354.     embed.set_thumbnail(url=mugshot)
  355.     embed.set_footer(text=interaction.user.nick, icon_url="https://cdn.discordapp.com/emojis/1165632658492100748.webp?size=96&quality=lossless")
  356.     promotion = None
  357.     if int(rank.value) > userrankrank:
  358.         promotion = True
  359.         embed.description=f"**User Promoted**\n`{username}` has been **promoted** in the business."
  360.     else:
  361.         promotion = False
  362.         embed.colour=Colours.Logs.red
  363.         embed.description=f"**User Demoted**\n`{username}` has been **demoted** in the business."
  364.     embed.add_field(name="Current", value=rank.name, inline=False)
  365.     embed.add_field(name="Previous", value=userrankname, inline=False)
  366.     if notes:
  367.         embed.add_field(name="Notes", value=notes, inline=False)
  368.     actionchannel = client.get_channel(1145424593213988967)
  369.     actionlink = await actionchannel.send(embed=embed)
  370.     actionlink = actionlink.jump_url
  371.     await interaction.response.send_message(embed=discord.Embed(title="Action Rank Successful", colour=Colours.Brand.blue, description=f"User rank has successfully been logged\n{actionlink}"), ephemeral=True)
  372.     log = {
  373.         "ranked": {
  374.             "beforerank": userrankname,
  375.             "afterrank": rank.name,
  376.             "type": {"True": "Promotion", "False": "Demotion"}[str(promotion)]
  377.         }
  378.     }
  379.     if notes:
  380.         log["ranked"]["notes"] = notes
  381.     log["ranked"]["by"] = actorid
  382.     timestamp = datetime.datetime.now().strftime("%m/%d/%Y %H:%M:%S")
  383.     historylog(actorid, user["id"], timestamp, log, f"{username} ({userid}) { {'True': 'PROMOTED', 'False': 'DEMOTED'}[str(promotion)]} BY {actorname} ({actorid}) FROM {userrankname} TO {rank.name} EXTRA {notes}")
  384.     roleId = {"40": 100735232, "30": 100735223, "20": 100735217, "17": 91563673, "15": 101369050}[rank.value]
  385.     el = requests.patch(f"https://groups.roblox.com/v1/groups/16367093/users/{userid}", data={"roleId": roleId}, cookies={".ROBLOSECURITY": rosec})
  386.     el = requests.patch(f"https://groups.roblox.com/v1/groups/16367093/users/{userid}", data={"roleId": roleId}, cookies={".ROBLOSECURITY": rosec}, headers={"x-csrf-token": el.headers["x-csrf-token"]})
  387.  
  388. @action.command(name="warn", description="Warn a user")
  389. @precheck()
  390. @app_commands.choices(warntype = [
  391.     Choice(name="Verbal", value="Vrbl"),
  392.     Choice(name="Record", value="Rcrd")
  393. ])
  394. async def warn(interaction : discord.Interaction, user : str, warntype : Choice[str], notes : str):
  395.     #actor checks
  396.     actorid = isconnected(interaction.user)
  397.     actorname = getuser(actorid)["name"]
  398.     actorrank = iscommand(actorid)
  399.     if not actorrank[0]:
  400.         await interaction.response.send_message(embed=discord.Embed(title="Action Rank Error", colour=Colours.Brand.red, description="Uh-oh, it doesn't look like you can do that"), ephemeral=True)
  401.         return
  402.     #user checks
  403.     user = getuser(user)
  404.     if not user:
  405.         await interaction.response.send_message(embed=discord.Embed(title="Action Rank Error", colour=Colours.Brand.red, description="Uh-oh, it doesn't look like that user exists"), ephemeral=True)
  406.         return
  407.     userid = user["id"]
  408.     username = user["name"]
  409.     userrank = iscommand(userid)
  410.     if userrank == None:
  411.         await interaction.response.send_message(embed=discord.Embed(title="Action Warn Error", colour=Colours.Brand.red, description="Uh-oh, it doesn't look like that user is employed in PDS"), ephemeral=True)
  412.         return
  413.     #vars
  414.     userrank = iscommand(userid)
  415.     actorrankrank = actorrank[1]["rank"]
  416.     userrankrank = userrank[1]["rank"]
  417.     #code
  418.     if actorrankrank <= userrankrank:
  419.         await interaction.response.send_message(embed=discord.Embed(title="Action Rank Error", colour=Colours.Brand.red, description=f"Uh-oh, you can't warn a user that has the same or a higher rank than you"), ephemeral=True)
  420.         return
  421.     mugshot = getmugshot(userid)
  422.     embed = discord.Embed(
  423.         title="PDS Business Actions",
  424.         colour=Colours.Logs.orange,
  425.         description=f"**User Warned**\n`{username}` has been **warned** in the business."
  426.     )
  427.     embed.set_thumbnail(url=mugshot)
  428.     embed.set_footer(text=interaction.user.nick, icon_url="https://cdn.discordapp.com/emojis/1165632658492100748.webp?size=96&quality=lossless")
  429.     embed.add_field(name="Type", value=warntype.name, inline=False)
  430.     embed.add_field(name="Notes", value=notes, inline=False)
  431.     actionchannel = client.get_channel(1145424593213988967)
  432.     actionlink = await actionchannel.send(embed=embed)
  433.     actionlink = actionlink.jump_url
  434.     await interaction.response.send_message(embed=discord.Embed(title="Action Warn Successful", colour=Colours.Brand.blue, description=f"User warn has successfully been logged\n{actionlink}"), ephemeral=True)
  435.     log = {
  436.         "warned": {
  437.             "type": warntype.name
  438.         }
  439.     }
  440.     if notes:
  441.         log["warned"]["notes"] = notes
  442.     log["warned"]["by"] = actorid
  443.     timestamp = datetime.datetime.now().strftime("%m/%d/%Y %H:%M:%S")
  444.     historylog(actorid, user["id"], timestamp, log, f"{username} ({userid}) {warntype.name} WARNED BY {actorname} ({actorid}) FOR {notes}")
  445.  
  446. @action.command(name="term", description="Terminate a user")
  447. @precheck()
  448. @app_commands.choices(termtype = [
  449.     Choice(name="Honourable", value="Hnrbl"),
  450.     Choice(name="General", value="Gnrl"),
  451.     Choice(name="Dishonourable", value="Dshnrbl"),
  452.     Choice(name="Blacklist", value="Blklst")
  453. ])
  454. async def term(interaction : discord.Interaction, user : str, termtype : Choice[str], notes : str):
  455.     #actor checks
  456.     actorid = isconnected(interaction.user)
  457.     actorname = getuser(actorid)["name"]
  458.     actorrank = iscommand(actorid)
  459.     if not actorrank[0]:
  460.         await interaction.response.send_message(embed=discord.Embed(title="Action Rank Error", colour=Colours.Brand.red, description="Uh-oh, it doesn't look like you can do that"), ephemeral=True)
  461.         return
  462.     #user checks
  463.     user = getuser(user)
  464.     if not user:
  465.         await interaction.response.send_message(embed=discord.Embed(title="Action Rank Error", colour=Colours.Brand.red, description="Uh-oh, it doesn't look like that user exists"), ephemeral=True)
  466.         return
  467.     userid = user["id"]
  468.     username = user["name"]
  469.     userrank = iscommand(userid)
  470.     if userrank == None:
  471.         await interaction.response.send_message(embed=discord.Embed(title="Action Term Error", colour=Colours.Brand.red, description="Uh-oh, it doesn't look like that user is employed in PDS"), ephemeral=True)
  472.         return
  473.     #vars
  474.     actorrankrank = actorrank[1]["rank"]
  475.     userrankrank = userrank[1]["rank"]
  476.     #code
  477.     if actorrankrank <= userrankrank:
  478.         await interaction.response.send_message(embed=discord.Embed(title="Action Rank Error", colour=Colours.Brand.red, description=f"Uh-oh, you can't terminate a user that has the same or a higher rank than you"), ephemeral=True)
  479.         return
  480.     embed = discord.Embed(
  481.         title="PDS Business Actions",
  482.         colour=Colours.Logs.red,
  483.         description=f"**User Terminated**\n`{username}` has been **terminated** from the business."
  484.     )
  485.     mugshot = getmugshot(userid)
  486.     embed.set_thumbnail(url=mugshot)
  487.     embed.set_footer(text=interaction.user.nick, icon_url="https://cdn.discordapp.com/emojis/1165632658492100748.webp?size=96&quality=lossless")
  488.     embed.add_field(name="Type", value=termtype.name, inline=False)
  489.     embed.add_field(name="Notes", value=notes, inline=False)
  490.     actionchannel = client.get_channel(1145424593213988967)
  491.     actionlink = await actionchannel.send(embed=embed)
  492.     actionlink = actionlink.jump_url
  493.     await interaction.response.send_message(embed=discord.Embed(title="Action Term Successful", colour=Colours.Brand.blue, description=f"User term has successfully been logged\n{actionlink}"), ephemeral=True)
  494.     log = {
  495.         "terminated": {
  496.             "type": termtype.name
  497.         }
  498.     }
  499.     if notes:
  500.         log["terminated"]["notes"] = notes
  501.     log["terminated"]["by"] = actorid
  502.     timestamp = datetime.datetime.now().strftime("%m/%d/%Y %H:%M:%S")
  503.     historylog(actorid, userid, timestamp, log, f"{username} ({userid}) {termtype.name} TERMINATED BY {actorname} ({actorid}) FOR {notes}")
  504.     el = requests.delete(f"https://groups.roblox.com/v1/groups/16367093/users/{userid}", cookies={".ROBLOSECURITY": rosec})
  505.     el = requests.delete(f"https://groups.roblox.com/v1/groups/16367093/users/{userid}", cookies={".ROBLOSECURITY": rosec}, headers={"x-csrf-token": el.headers["x-csrf-token"]})
  506.  
  507. @client.command()
  508. @commands.check(lambda ctx : ctx.author.id == 301014178703998987)
  509. async def connect(ctx):
  510.     await tree.sync()
  511.     await tree.sync(guild=discord.Object(1145424590152151091))
  512.  
  513. client.run("nostealing")
  514.  
  515. #nostealing
Advertisement
Add Comment
Please, Sign In to add comment