diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e6a6259 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +DISCORD_TOKEN=MYTOKEN +LINK_URL=https://l.woodburn.au +LINK_API_KEY=MYAPIKEY +ADMIN_ID=DISCORDID diff --git a/README.md b/README.md index 72e5f88..b76c3c3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,25 @@ # Woodburn Bot Discord bot for the Woodburn server. This bot adds some Handshake related commands to the server. + +## Commands +- `/shortlink ` - Shorten a URL using Kutt.it (requires a Kutt API key) only allowed for specied user + +# Setup + +## Docker +The easiest way to run this bot is to use Docker. You can use the following command to run the bot: +```bash +docker run -d -e DISCORD_TOKEN= -e LINK_API_KEY= -e LINK_URL= -e ADMIN= -e LOG_CHANNEL= git.woodburn.au/nathanwoodburn/woodburn-bot:latest +``` + +## Manual +If you don't want to use Docker, you can run the bot manually. +```bash +git clone https://git.woodburn.au/nathanwoodburn/woodburn-bot.git +cd woodburn-bot +python3 -m pip install -r requirements.txt +cp .env.example .env +# Edit .env and fill in your info +python3 main.py +``` \ No newline at end of file diff --git a/bot.py b/bot.py index 0c9b481..e46c9f6 100644 --- a/bot.py +++ b/bot.py @@ -7,13 +7,17 @@ import dns.resolver load_dotenv() TOKEN = os.getenv('DISCORD_TOKEN') +ADMINID = os.getenv('ADMIN_ID') +KUTT_APIKEY=os.getenv('LINK_API_KEY') +KUTT_URL=os.getenv('LINK_URL') +LOG_CHANNEL = os.getenv('LOG_CHANNEL') intents = discord.Intents.default() client = discord.Client(intents=intents) tree = app_commands.CommandTree(client) activityMessage="over the server" statusType="watching" -logChannel=1139449826287824996 + # Commands @tree.command(name="ping", description="Check bot connection") @@ -23,13 +27,12 @@ async def ping(ctx): @tree.command(name="shortlink", description="Shorten a link") async def shortlink(ctx, link: str, name: str = None): - if (ctx.user.id != 892672018917519370): + if (ctx.user.id != ADMINID): await log("User: " + str(ctx.user.name) + " tried to use the shortlink command") await ctx.response.send_message("You don't have permission to use this command",ephemeral=True) else: - APIKEY=os.getenv('LINK_API_KEY') - url="https://l.woodburn.au/api/v2/links" - headers = {'X-API-KEY' : APIKEY} + url=f"https://{KUTT_URL}/api/v2/links" + headers = {'X-API-KEY' : KUTT_APIKEY} data = {'target' : link, 'customurl' : name} if (name == None): @@ -43,7 +46,7 @@ async def shortlink(ctx, link: str, name: str = None): @tree.command(name="botstatus", description="Set the bot status") async def botstatus(ctx, message: str, statusmethod: str = None): - if (ctx.user.id != 892672018917519370): + if (ctx.user.id != ADMINID): await log("User: " + str(ctx.user.name) + " tried to use the botstatus command") await ctx.response.send_message("You don't have permission to use this command",ephemeral=True) else: @@ -60,8 +63,8 @@ async def botstatus(ctx, message: str, statusmethod: str = None): @tree.command(name="dig", description="Dig a dns record") async def dig(ctx, domain: str, record_type: str = "A"): record_type = record_type.upper() - # Format dig @100.74.29.146 -p 5350 - + + # Format dig @100.74.29.146 -p 5350 resolver = dns.resolver.Resolver() resolver.nameservers = ["100.74.29.146"] resolver.port = 5350 @@ -98,9 +101,8 @@ async def curl(ctx, url: str): async def invite(ctx): await ctx.response.send_message("https://discord.com/api/oauth2/authorize?client_id=1006128164218621972&permissions=0&scope=bot",ephemeral=True) - async def log(message): - channel=client.get_channel(logChannel) + channel=client.get_channel(LOG_CHANNEL) await channel.send(message) def updateStatus():