bot: Added easier install
All checks were successful
Build Docker / Build Docker (push) Successful in 20s
All checks were successful
Build Docker / Build Docker (push) Successful in 20s
This commit is contained in:
parent
21e3ab690c
commit
2b0477aee2
4
.env.example
Normal file
4
.env.example
Normal file
@ -0,0 +1,4 @@
|
||||
DISCORD_TOKEN=MYTOKEN
|
||||
LINK_URL=https://l.woodburn.au
|
||||
LINK_API_KEY=MYAPIKEY
|
||||
ADMIN_ID=DISCORDID
|
22
README.md
22
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 <url>` - 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=<YOUR-BOT-TOKEN> -e LINK_API_KEY=<KUTT-API-KEY> -e LINK_URL=<KUTT-URL> -e ADMIN=<your-discord-userid> -e LOG_CHANNEL=<DISCORD-CHANNEL-ID> 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
|
||||
```
|
20
bot.py
20
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 <domain> <type>
|
||||
|
||||
# Format dig @100.74.29.146 -p 5350 <domain> <type>
|
||||
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():
|
||||
|
Loading…
Reference in New Issue
Block a user