Enable permissions check for the hello function

This commit is contained in:
Daniel Krastev 2025-02-05 20:10:03 +02:00
parent 92eaba45d1
commit 6fa02ebc78

View file

@ -1,9 +1,9 @@
import asyncio import asyncio
import os import os
from datetime import datetime, timezone
import requests import requests
import discord import discord
from discord.ext import commands, tasks from discord.ext.commands import Bot, has_permissions, CheckFailure
from datetime import datetime
from apscheduler.schedulers.asyncio import AsyncIOScheduler from apscheduler.schedulers.asyncio import AsyncIOScheduler
import logging import logging
@ -23,7 +23,7 @@ intents.presences = True
intents.message_content = True intents.message_content = True
# Discord client # Discord client
bot = commands.Bot(command_prefix="!", intents=intents) bot = Bot(command_prefix="!", intents=intents)
# Scheduler # Scheduler
scheduler = AsyncIOScheduler() scheduler = AsyncIOScheduler()
@ -44,10 +44,17 @@ async def on_ready():
scheduler.start() scheduler.start()
@bot.command(name='hello', help='Say hello to the bot') @bot.command(name='hello', help='Say hello to the bot')
@has_permissions(administrator=True)
async def hello(ctx): async def hello(ctx):
author_name = ctx.author.name author_name = ctx.author.name
await ctx.channel.send(f'hi, `{author_name}` :blush:') await ctx.channel.send(f'hi, `{author_name}` :blush:')
@hello.error
async def hello_error(ctx, error):
if isinstance(error, CheckFailure):
msg = "{} access denied!".format(ctx.message.author.mention)
await ctx.send(msg)
@bot.command(name='epg', help='Lists scheduled streams') @bot.command(name='epg', help='Lists scheduled streams')
async def epg(ctx): async def epg(ctx):
global database global database
@ -69,14 +76,13 @@ async def epg(ctx):
@bot.command(name='time', help='Show current time') @bot.command(name='time', help='Show current time')
async def time(ctx): async def time(ctx):
await ctx.channel.send(f'The time is: `{datetime.now()} UTC`') await ctx.channel.send(f'The time is: `{datetime.now(timezone.utc)} UTC`')
@bot.command(name='now', help='Displays whats playing right now') @bot.command(name='now', help='Displays whats playing right now')
async def now(ctx): async def now(ctx):
head = await query_playhead() head = await query_playhead()
await ctx.channel.send(head) await ctx.channel.send(head)
# Helper functions
async def query_playhead(): async def query_playhead():
head_url = f'https://{scheduler_hostname}/playhead' head_url = f'https://{scheduler_hostname}/playhead'
if requests.get(head_url).status_code == 200: if requests.get(head_url).status_code == 200: