Tidy up main
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 2m36s

This commit is contained in:
Nexus 2024-06-09 02:03:08 +01:00
parent ea23b453f5
commit b5622504c9
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -1,20 +1,15 @@
import asyncio
import datetime
import glob
import json
import logging
import os
import redis
import random
import shutil
import sys
import logging
import time
import traceback
import typing
from logging import FileHandler
from threading import Event, Thread
import aiofiles
import discord
import httpx
from discord.ext import commands
@ -24,14 +19,8 @@ from rich.logging import RichHandler
from conf import CONFIG
class KillableThread(Thread):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.kill = Event()
class KumaThread(KillableThread):
def __init__(self, url: str, interval: float = 60.0):
class KumaThread(Thread):
def __init__(self, url: str, interval: int = 60):
super().__init__(target=self.run)
self.daemon = True
self.log = logging.getLogger("jimmy .status")
@ -45,7 +34,7 @@ class KumaThread(KillableThread):
def calculate_backoff(self) -> float:
rnd = random.uniform(0, 1)
retries = min(self.retries, 1000)
t = (2 * 2**retries) + rnd
t: int = round((2 * 2**retries) + rnd)
self.log.debug("Backoff: 2 * (2 ** %d) + %f = %f", retries, rnd, t)
# T can never exceed self.interval
return max(0, min(self.interval, t))
@ -113,7 +102,6 @@ for logger in CONFIG["logging"].get("suppress", []):
class Client(commands.Bot):
def __init_(self, *args, **kwargs):
self.uptime_thread = None
super().__init__(*args, **kwargs)
async def on_connect(self):
@ -217,6 +205,7 @@ async def on_application_command_error(ctx: discord.ApplicationContext, exc: Exc
@bot.listen()
async def on_application_command_completion(ctx: discord.ApplicationContext):
# noinspection PyUnresolvedReferences
time_taken = discord.utils.utcnow() - ctx.start_time
log.info(
f"Completed command [b]{ctx.command}[/] from {ctx.author} in "
@ -232,9 +221,9 @@ async def delete_message(ctx: discord.ApplicationContext, message: discord.Messa
return await ctx.respond("I don't have permission to delete messages in this channel.", delete_after=30)
log.info("%s deleted message %s>%s: %r", ctx.author, ctx.channel.name, message.id, message.content)
await message.delete(delay=3)
await message.delete(delay=1)
await ctx.respond(f"\N{white heavy check mark} Deleted message by {message.author.display_name}.")
await ctx.delete(delay=15)
await ctx.delete(delay=5)
@bot.slash_command(name="about")