This commit is contained in:
parent
790872f92c
commit
4fb98b6f59
54
bot.py
54
bot.py
@ -2,6 +2,7 @@ import os
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import discord
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
@ -10,24 +11,61 @@ TOKEN = os.getenv('DISCORD_TOKEN')
|
|||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
client = discord.Client(intents=intents)
|
client = discord.Client(intents=intents)
|
||||||
tree = app_commands.CommandTree(client)
|
tree = app_commands.CommandTree(client)
|
||||||
|
activityMessage="over the server"
|
||||||
|
statusType="watching"
|
||||||
|
|
||||||
# Commands
|
# Commands
|
||||||
@tree.command(name="ping", description="Check bot connection")
|
@tree.command(name="ping", description="Check bot connection")
|
||||||
async def ping(ctx):
|
async def ping(ctx):
|
||||||
await ctx.response.send_message("Pong!",ephemeral=True)
|
await ctx.response.send_message("Pong!",ephemeral=True)
|
||||||
|
|
||||||
|
@tree.command(name="shortlink", description="Shorten a link")
|
||||||
|
async def shortlink(ctx, link: str, name: str = None):
|
||||||
|
if (ctx.user.id != 892672018917519370):
|
||||||
|
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}
|
||||||
|
|
||||||
|
data = {'target' : link, 'customurl' : name}
|
||||||
|
if (name == None):
|
||||||
|
data = {'target' : link}
|
||||||
|
x = requests.post(url, data = data, headers = headers)
|
||||||
|
print(x.text)
|
||||||
|
if (x.status_code != 200 and x.status_code != 201):
|
||||||
|
await ctx.response.send_message("ERROR: " + x.text,ephemeral=True)
|
||||||
|
link=x.json()['link']
|
||||||
|
await ctx.response.send_message("Link: " + link,ephemeral=False)
|
||||||
|
|
||||||
|
@tree.command(name="botstatus", description="Set the bot status")
|
||||||
|
async def botstatus(ctx, message: str, statusmethod: str = None):
|
||||||
|
if (ctx.user.id != 892672018917519370):
|
||||||
|
await ctx.response.send_message("You don't have permission to use this command",ephemeral=True)
|
||||||
|
else:
|
||||||
|
global activityMessage
|
||||||
|
activityMessage=message
|
||||||
|
global statusType
|
||||||
|
if (statusmethod == None):
|
||||||
|
statusmethod="watching"
|
||||||
|
else:
|
||||||
|
statusType=statusmethod.lower()
|
||||||
|
updateStatus()
|
||||||
|
await ctx.response.send_message("Status updated",ephemeral=True)
|
||||||
|
|
||||||
def updateStatus():
|
def updateStatus():
|
||||||
activity = discord.Activity(name="Nathan try to get set me up", type=discord.ActivityType.watching)
|
global activityMessage
|
||||||
|
global statusType
|
||||||
|
if (statusType == "watching"):
|
||||||
|
activity=discord.Activity(type=discord.ActivityType.watching, name=activityMessage)
|
||||||
|
elif (statusType == "playing"):
|
||||||
|
activity=discord.Activity(type=discord.ActivityType.playing, name=activityMessage)
|
||||||
|
elif (statusType == "listening"):
|
||||||
|
activity=discord.Activity(type=discord.ActivityType.listening, name=activityMessage)
|
||||||
|
elif (statusType == "competing"):
|
||||||
|
activity=discord.Activity(type=discord.ActivityType.competing, name=activityMessage)
|
||||||
|
else:
|
||||||
|
activity=discord.Activity(type=discord.ActivityType.watching, name=activityMessage)
|
||||||
client.loop.create_task(client.change_presence(activity=activity))
|
client.loop.create_task(client.change_presence(activity=activity))
|
||||||
|
|
||||||
# When the bot is ready
|
# When the bot is ready
|
||||||
|
Loading…
Reference in New Issue
Block a user