Compare commits
2 commits
13146256ba
...
4a091fd9fd
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a091fd9fd | |||
| 82a21ec8c3 |
5 changed files with 102 additions and 33 deletions
|
|
@ -4,8 +4,8 @@
|
|||
"token": "discord bot token",
|
||||
"pterodactyl_domain": "https://panel.pterodactyl.com/",
|
||||
"pterodactyl_apikey": "user api key",
|
||||
"guild_id": "169256939211980800",
|
||||
"guild_admin_id": "169256939211980800"
|
||||
"mod_roles": [273600757264023553, 1168422950685384765, 286965023249793046],
|
||||
"admin_roles": [807336816863739925]
|
||||
}
|
||||
]
|
||||
}
|
||||
27
main.py
27
main.py
|
|
@ -11,34 +11,41 @@ from discord.ext import slash
|
|||
token = init.config().get_token()
|
||||
domain = init.config().get_pterodactyl_domain()
|
||||
apikey = init.config().get_pterodactyl_apikey()
|
||||
guild_id = init.config().get_guild_id()
|
||||
|
||||
bot = slash.SlashBot(command_prefix='!', help_command=None)
|
||||
# msg_opt = slash.Option(description="Dein Minecraft Name", , required=True)
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print('Bot wurde gestartet')
|
||||
print('Bot started succesfully')
|
||||
return
|
||||
|
||||
@bot.slash_cmd(aliases=["hilfe"])
|
||||
async def help(ctx:slash.Context):
|
||||
"Hilfe für alle verwendbaren Befehle"
|
||||
"Hilfe für alle verwendbaren Befehle" #Help for all usable commands
|
||||
await functions.cmdhelp(ctx)
|
||||
|
||||
@bot.slash_cmd(aliases=["minecraft"], guild_id=1210285934248198244)
|
||||
async def mc(ctx:slash.Context, name:slash.Option(description="Dein Minecraftname", required=True)):
|
||||
"Registriere deinen Minecraft Namen"
|
||||
@bot.slash_cmd(aliases=["minecraft"])
|
||||
async def mc(ctx:slash.Context, name:slash.Option(description="Dein Minecraftname", required=True)): #Your Minecraft name
|
||||
"Registriere deinen Minecraft Namen" #Register your Minecraft name
|
||||
await functions.cmdmc(ctx, name.strip(), bot)
|
||||
|
||||
@bot.slash_cmd()
|
||||
async def mcname(ctx:slash.Context):
|
||||
"Gibt deinen aktuellen Minecraft Namen an"
|
||||
"Gibt deinen aktuellen Minecraft Namen an" #Outputs your linked Minecraft name
|
||||
await functions.cmdmcname(ctx)
|
||||
|
||||
@bot.slash_cmd(guild_id=guild_id, hidden=True)
|
||||
@bot.slash_cmd()
|
||||
async def shutdown(ctx:slash.Context):
|
||||
"Will shutdown the bot if you are mighty enough."
|
||||
await functions.cmdshutdown(ctx, bot)
|
||||
if await functions.isAdmin(ctx, bot):
|
||||
await functions.cmdshutdown(ctx, bot)
|
||||
|
||||
@bot.slash_cmd(guild_id=1210285934248198244)
|
||||
async def allow(ctx:slash.Context, user:slash.Option(description="der zu whitelistene Nutzuer (@<Discordname>)", required=True)):
|
||||
"Fügt Spieler der Whitelist hinzu." #Add Players to whitelist
|
||||
if await functions.isMod(ctx, bot):
|
||||
await functions.cmdallow(ctx, user.strip(), bot)
|
||||
|
||||
|
||||
|
||||
bot.run(token)
|
||||
|
|
@ -11,6 +11,8 @@ from discord.ext import slash
|
|||
from modules import init
|
||||
|
||||
con, cur = init.getdb()
|
||||
mod_roles = init.config().get_mod_roles()
|
||||
admin_roles = init.config().get_admin_roles()
|
||||
|
||||
async def cmdhelp(ctx:slash.Context):
|
||||
embed = discord.Embed(title="Hilfe",
|
||||
|
|
@ -37,7 +39,8 @@ async def cmdmc(ctx:slash.Context, name:str, client):
|
|||
cur.execute(f"UPDATE user SET mcname = '{mcinfo['name']}', uuid = '{uuid}' WHERE id = {ctx.author.id}")
|
||||
await ctx.respond(f'Dein Minecraftname **{name}** wurde erfolgreich aktualisiert.')
|
||||
else:
|
||||
cur.execute(f"INSERT INTO user VALUES ({ctx.author.id}, '{ctx.author.nick}', '{ctx.author.avatar_url}', '{mcinfo['name']}', '{uuid}', {True})")
|
||||
cur.execute(f"INSERT INTO user VALUES ({ctx.author.id}, '{ctx.author.nick}', '{ctx.author.avatar_url}', '{mcinfo['name']}', '{uuid}', {False
|
||||
})")
|
||||
await ctx.respond(f'Dein Minecraftname **{name}** wurde erfolgreich hinzugefügt.')
|
||||
con.commit()
|
||||
await syncWhitelist()
|
||||
|
|
@ -69,6 +72,25 @@ async def cmdshutdown(ctx:slash.Context, bot):
|
|||
else:
|
||||
await ctx.respond('You are not as mighty as you may think you are.')
|
||||
|
||||
async def cmdallow(ctx:slash.Context, user:str, bot:discord.ext.commands.Bot):
|
||||
user_id = user.removeprefix('<@').removesuffix('>')
|
||||
try:
|
||||
user = str(await bot.fetch_user(user_id)).removesuffix('#0')
|
||||
except:
|
||||
await ctx.respond(f"Eingabe ungültig. \nErhaltene Eingabe: **{user}**. Es wurde **@<username>** oder **<Nutzer id>** erwartet. \nBitte versuche es erneut.", ephemeral=True)
|
||||
return
|
||||
|
||||
result = cur.execute(f"SELECT * FROM user WHERE id = '{user_id}'")
|
||||
result = cur.fetchone()
|
||||
|
||||
if result:
|
||||
cur.execute(f"UPDATE user SET iswhitelisted = {True} WHERE id = '{user_id}'")
|
||||
con.commit()
|
||||
await ctx.respond(f'Der Nutzer **{user}** wurde erfolgreich gewhitelisted.')
|
||||
await syncWhitelist()
|
||||
else:
|
||||
await ctx.respond(f'Der Nutzer **{user}** existiert nicht im System. Damit er vom System registriert wird, muss er zunächst seinen Minecraftnamen hinzufügen.', ephemeral=True)
|
||||
|
||||
async def syncWhitelist():
|
||||
results = cur.execute("SELECT mcname, uuid, iswhitelisted FROM user")
|
||||
results = cur.fetchall()
|
||||
|
|
@ -104,4 +126,36 @@ async def syncWhitelistPterodactyl(whitelist):
|
|||
|
||||
async def pterodactylWriteFile(serverid, path, data, apikey):
|
||||
url = f'{init.config().get_pterodactyl_domain()}api/client/servers/{serverid}/files/write?file={urllib.parse.quote(path)}'
|
||||
requests.post(url, data=data, headers={"Accept": "application/json", "Authorization": f"Bearer {apikey}"})
|
||||
requests.post(url, data=data, headers={"Accept": "application/json", "Authorization": f"Bearer {apikey}"})
|
||||
|
||||
async def isMod(ctx:slash.Context, bot):
|
||||
allowed = False
|
||||
for id in mod_roles:
|
||||
guild = bot.get_guild(ctx.guild.id)
|
||||
role = guild.get_role(id)
|
||||
member = await guild.fetch_member(ctx.author.id)
|
||||
if role in member.roles:
|
||||
allowed = True
|
||||
break
|
||||
|
||||
if allowed:
|
||||
return True
|
||||
else:
|
||||
await ctx.respond("Du hast nicht die nötigen Rechte um diesen Befehl auszuführen.", ephemeral=True) #You are not allowed to perform this command
|
||||
return
|
||||
|
||||
async def isAdmin(ctx:slash.Context, bot):
|
||||
allowed = False
|
||||
for id in admin_roles:
|
||||
guild = bot.get_guild(ctx.guild.id)
|
||||
role = guild.get_role(id)
|
||||
member = await guild.fetch_member(ctx.author.id)
|
||||
if role in member.roles:
|
||||
allowed = True
|
||||
break
|
||||
|
||||
if allowed:
|
||||
return True
|
||||
else:
|
||||
await ctx.respond("You are not mighty enough to perform this operation.", ephemeral=True)
|
||||
return
|
||||
|
|
@ -11,8 +11,8 @@ class config():
|
|||
self.token = p['token']
|
||||
self.pterodactyl_domain = p['pterodactyl_domain']
|
||||
self.pterodactyl_apikey = p['pterodactyl_apikey']
|
||||
self.guild_id = p['guild_id']
|
||||
self.guild_admin_id = p['guild_admin_id']
|
||||
self.mod_roles = p['mod_roles']
|
||||
self.admin_roles = p['admin_roles']
|
||||
|
||||
def get_token(self):
|
||||
return self.token
|
||||
|
|
@ -20,10 +20,10 @@ class config():
|
|||
return self.pterodactyl_domain
|
||||
def get_pterodactyl_apikey(self):
|
||||
return self.pterodactyl_apikey
|
||||
def get_guild_id(self):
|
||||
return self.guild_id
|
||||
def get_guild_admin_id(self):
|
||||
return self.guild_admin_id
|
||||
def get_mod_roles(self):
|
||||
return self.mod_roles
|
||||
def get_admin_roles(self):
|
||||
return self.admin_roles
|
||||
|
||||
|
||||
con = sqlite3.connect('data/database.sqlite')
|
||||
|
|
|
|||
|
|
@ -13,27 +13,35 @@ if not path.exists('config/config.json'):
|
|||
jsonstructure = {} # Platzhalter
|
||||
jsonstructure['discord'] = []
|
||||
wronginput = False
|
||||
print("Möchtest du das automatisierte Setup nutzen? y/n")
|
||||
print("Do you want to use the automated setup? Y/n")
|
||||
input1 = input()
|
||||
|
||||
if input1.lower().strip() == 'y':
|
||||
print("Bitte geben Sie den Token ein:")
|
||||
print("Please insert your token:")
|
||||
token = input()
|
||||
print("Bitte geben Sie die Pterodactyl Domain ein (Form: https://example.com/ | optional):")
|
||||
print("Please insert your pterodactyl domain here (Format: https://example.com/ | optional):")
|
||||
pterodactyl_domain = input()
|
||||
print("Bitte geben Sie den Pterodactyl API Key ein (optional):")
|
||||
print("Please insert your pterodactyl API key (optional):")
|
||||
pterodactyl_api_key = input()
|
||||
print("Bitte geben Sie die Guild ID ein:")
|
||||
guild_id = input()
|
||||
print("Bitte geben Sie die ID des Admin Channels ein:")
|
||||
guild_admin_id = input()
|
||||
print("Please state how many moderator roles you are using (Roles which are able to modify the whitelist or user):")
|
||||
mod_count = input()
|
||||
mod_roles = []
|
||||
print("Please insert the id of every moderating role:")
|
||||
for i in mod_count:
|
||||
mod_roles.append(input())
|
||||
print("Please state how many admin roles you are using (Roles which are able to stop the bot):")
|
||||
admin_count = input()
|
||||
admin_roles = []
|
||||
print("Please insert the id of every admin role:")
|
||||
for i in admin_count:
|
||||
admin_roles.append(input())
|
||||
|
||||
jsonstructure['discord'].append({
|
||||
'token': token,
|
||||
'pterodactyl_domain': pterodactyl_domain,
|
||||
'pterodactyl_apikey': pterodactyl_api_key,
|
||||
'guild_id': guild_id,
|
||||
'guild_admin_id': guild_admin_id
|
||||
'mod_roles': mod_roles,
|
||||
'admin_roles': admin_roles
|
||||
})
|
||||
|
||||
elif input1.lower().strip() == 'n':
|
||||
|
|
@ -42,8 +50,8 @@ if not path.exists('config/config.json'):
|
|||
'token': 'Platzhalter',
|
||||
'pterodactyl_domain': '',
|
||||
'pterodactyl_apikey': '',
|
||||
'guild_id': '',
|
||||
'guild_admin_id': ''
|
||||
'mod_roles': [],
|
||||
'admin_roles': []
|
||||
})
|
||||
|
||||
else:
|
||||
|
|
@ -55,7 +63,7 @@ if not path.exists('config/config.json'):
|
|||
os.mkdir('config')
|
||||
with open('config/config.json', 'w') as outfile:
|
||||
json.dump(jsonstructure, outfile, indent=4)
|
||||
print("Config erfolgreich erzeugt")
|
||||
print("Config created succesfully")
|
||||
|
||||
if not os.path.exists('whitelist/paths.txt'):
|
||||
if not os.path.exists('whitelist'):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue