2023-01-12 18:12:58 +01:00
|
|
|
# Code written by Jocadbz(madureirajoaquim95@gmail.com)
|
|
|
|
# Code revised by BodgeMaster
|
|
|
|
# Code Licensed under GPL 3.0
|
|
|
|
|
2023-01-13 19:34:04 +01:00
|
|
|
import sys, time, json
|
|
|
|
|
2023-01-12 18:12:58 +01:00
|
|
|
import discord
|
|
|
|
from discord import app_commands
|
|
|
|
import typing
|
|
|
|
from discord.ext import commands
|
|
|
|
import discord.utils
|
|
|
|
|
2023-01-13 17:47:23 +01:00
|
|
|
BOOT_TIME = time.time()
|
2023-01-12 18:12:58 +01:00
|
|
|
|
2023-01-13 19:34:24 +01:00
|
|
|
config_file = open("config.json", "r")
|
|
|
|
config = json.loads(config_file.read());
|
|
|
|
config_file.close()
|
|
|
|
|
2023-01-12 18:12:58 +01:00
|
|
|
def seconds_elapsed():
|
2023-01-13 20:31:53 +01:00
|
|
|
return int(time.time() - BOOT_TIME)
|
2023-01-12 18:12:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
class MyClient(discord.Client):
|
|
|
|
def __init__(self, *, intents: discord.Intents):
|
|
|
|
super().__init__(intents=intents)
|
|
|
|
self.tree = app_commands.CommandTree(self)
|
|
|
|
|
|
|
|
async def setup_hook(self):
|
|
|
|
await self.tree.sync()
|
|
|
|
|
|
|
|
|
|
|
|
intents = discord.Intents.default()
|
|
|
|
client = MyClient(intents=intents)
|
|
|
|
bot = commands.Bot(command_prefix='lb!', intents=intents)
|
|
|
|
|
|
|
|
|
|
|
|
@client.event
|
|
|
|
async def on_ready():
|
|
|
|
print(f'Logged in as {client.user} (ID: {client.user.id})')
|
|
|
|
print('------')
|
|
|
|
|
|
|
|
|
2023-01-13 20:31:53 +01:00
|
|
|
@client.tree.command(name="change_hostname")
|
2023-01-12 18:12:58 +01:00
|
|
|
@app_commands.describe(distro='Assign yourself a role')
|
2023-01-13 20:34:50 +01:00
|
|
|
async def distro(interaction: discord.Interaction, distro: eval("typing.Literal[\""+ "\", \"".join(config["roles"].keys()) +"\"]")):
|
2023-01-13 20:31:53 +01:00
|
|
|
if not interaction.guild.id==config["guild"]:
|
|
|
|
print("Role assignment attempted from unknown guild.")
|
|
|
|
return
|
|
|
|
|
2023-01-12 18:12:58 +01:00
|
|
|
user = interaction.user
|
2023-01-13 20:34:50 +01:00
|
|
|
role = discord.utils.get(interaction.guild.roles, id=config["roles"][distro])
|
|
|
|
|
|
|
|
try:
|
2023-01-12 18:12:58 +01:00
|
|
|
await user.add_roles(role)
|
2023-01-13 20:34:50 +01:00
|
|
|
await interaction.response.send_message(content=f'Added {role}.')
|
|
|
|
prnt("Added role.")
|
|
|
|
except:
|
|
|
|
await interaction.response.send_message(content='Something went wrong.')
|
|
|
|
print("Failed to add role. Permissions set correctly?")
|
2023-01-12 18:12:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
# This context menu command only works on messages
|
2023-01-13 20:31:53 +01:00
|
|
|
@client.tree.context_menu(name='Report to Moderators')
|
2023-01-12 18:12:58 +01:00
|
|
|
async def report_message(interaction: discord.Interaction, message: discord.Message):
|
2023-01-13 20:31:53 +01:00
|
|
|
if not interaction.guild.id==config["guild"]:
|
|
|
|
return
|
2023-01-12 18:12:58 +01:00
|
|
|
await interaction.response.send_message(
|
2023-01-13 20:50:57 +01:00
|
|
|
f'Thanks for reporting.', ephemeral=True
|
2023-01-12 18:12:58 +01:00
|
|
|
)
|
2023-01-13 20:50:57 +01:00
|
|
|
log_channel = interaction.guild.get_channel(config["report channel"])
|
2023-01-12 18:12:58 +01:00
|
|
|
embed = discord.Embed(title='Reported Message')
|
|
|
|
if message.content:
|
|
|
|
embed.description = message.content
|
|
|
|
embed.set_author(name=message.author.display_name, icon_url=message.author.display_avatar.url)
|
|
|
|
embed.timestamp = message.created_at
|
|
|
|
url_view = discord.ui.View()
|
|
|
|
url_view.add_item(discord.ui.Button(label='Go to Message', style=discord.ButtonStyle.url, url=message.jump_url))
|
|
|
|
await log_channel.send(embed=embed, view=url_view)
|
|
|
|
|
|
|
|
|
|
|
|
@client.tree.command(name="status")
|
|
|
|
async def status(interaction: discord.Interaction):
|
|
|
|
embed = discord.Embed(title='System Stats')
|
|
|
|
embed.description = f"""Uptime: {seconds_elapsed()}
|
2023-01-13 17:47:58 +01:00
|
|
|
System: {sys.platform}"""
|
2023-01-12 18:12:58 +01:00
|
|
|
url_view = discord.ui.View()
|
|
|
|
await interaction.response.send_message(embed=embed, view=url_view)
|
2023-01-13 20:31:53 +01:00
|
|
|
print("Status queried.")
|
2023-01-12 18:12:58 +01:00
|
|
|
|
|
|
|
|
2023-01-13 17:47:58 +01:00
|
|
|
client.run(sys.argv[1])
|