Compare commits

..

6 Commits

Author SHA1 Message Date
BodgeMaster 00f787ba31 Load roles from config instead of hard-coding them 2023-01-13 20:34:50 +01:00
BodgeMaster 0aade0c6fd Make things actually work
+ minor improvement of ststus command though that will be revised soon anyway
2023-01-13 20:32:39 +01:00
BodgeMaster c48b45d9bf Read guild from config file 2023-01-13 19:39:02 +01:00
BodgeMaster 21384b9a35 Improve code readability 2023-01-13 19:34:04 +01:00
BodgeMaster 25c3d57fe2 Ignore nano’s .swp files 2023-01-13 19:32:21 +01:00
BodgeMaster 1e8c6a1e1b Remove (theoretically) redundant call 2023-01-13 19:22:30 +01:00
3 changed files with 34 additions and 133 deletions

1
.gitignore vendored
View File

@ -160,3 +160,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
*.swp

158
bot.py
View File

@ -2,18 +2,22 @@
# Code revised by BodgeMaster
# Code Licensed under GPL 3.0
import sys, time, json
import discord
from discord import app_commands
import typing
from discord.ext import commands
import discord.utils
import time
import sys
BOOT_TIME = time.time()
config_file = open("config.json", "r")
config = json.loads(config_file.read());
config_file.close()
def seconds_elapsed():
return time.time() - BOOT_TIME
return int(time.time() - BOOT_TIME)
class MyClient(discord.Client):
@ -36,142 +40,30 @@ async def on_ready():
print('------')
@client.tree.command(guild=discord.Object(id=813127962881818624), name="change_hostname")
@client.tree.command(name="change_hostname")
@app_commands.describe(distro='Assign yourself a role')
async def distro(interaction: discord.Interaction, distro: typing.Literal['LFS', 'Kiss', 'Gentoo', 'Void', 'NixOS', 'Alpine', 'Arch', 'Arch-based', 'Red Hat', 'Bedrock', 'SuSE Based', 'OpenSuSE',
'Debian', 'Debian based', 'Solus', 'Fedora', 'Ubuntu', 'Ubuntu Based', 'BSD', 'MacOS', 'Windows']):
async def distro(interaction: discord.Interaction, distro: eval("typing.Literal[\""+ "\", \"".join(config["roles"].keys()) +"\"]")):
if not interaction.guild.id==config["guild"]:
print("Role assignment attempted from unknown guild.")
return
user = interaction.user
if distro == 'LFS':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=813200239778856971)
role = discord.utils.get(interaction.guild.roles, id=config["roles"][distro])
try:
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Kiss':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=884819839212982342)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Gentoo':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=1813139495049232384)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Void':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=813139633797988394)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'NixOS':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=827228988585279538)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Alpine':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=932684264967925850)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Arch':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=813139868678225991)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Arch-based':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=813186782534828043)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Red Hat':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=816823482318979094)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Bedrock':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=825427559604027412)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'SuSE Based':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=1034793985715224587)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'OpenSuSE':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=813147179367661589)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Debian':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=813142935247388672)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Debian based':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=842882283504926756)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Solus':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=820840553704325160)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Fedora':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=820621219040591884)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Ubuntu':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=813139746180038697)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Ubuntu Based':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=813581408052183042)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'BSD':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=879444277330055228)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'MacOS':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=813147204772167680)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
if distro == 'Windows':
user = interaction.user
role = discord.utils.get(user.guild.roles, id=813147019631788083)
await user.add_roles(role)
await interaction.response.send_message(content=f'`{role}` assigned to {user.mention}.')
print(f"`{role}` assigned to {user.mention}.")
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?")
# This context menu command only works on messages
@client.tree.context_menu(guild=discord.Object(id=813127962881818624), name='Report to Moderators')
@client.tree.context_menu(name='Report to Moderators')
async def report_message(interaction: discord.Interaction, message: discord.Message):
if not interaction.guild.id==config["guild"]:
return
await interaction.response.send_message(
f'Thanks for reporting this message by {message.author.mention} to our moderators.', ephemeral=True
)
@ -193,7 +85,7 @@ async def status(interaction: discord.Interaction):
System: {sys.platform}"""
url_view = discord.ui.View()
await interaction.response.send_message(embed=embed, view=url_view)
print("Status queried.")
client.tree.sync()
client.run(sys.argv[1])

8
config.json Normal file
View File

@ -0,0 +1,8 @@
{
"guild": 750955881348464651,
"roles": {
"assign0": 1063506453308125274,
"assign1": 1063506544962064414
},
"report channel": 1063507041697677312
}