mirror of
https://wiilab.wiimart.org/wiimart/WiiMartBot
synced 2025-09-03 20:11:08 +02:00
sum deletion
This commit is contained in:
parent
cb88ebea5f
commit
e6c63eda6a
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
.env
|
*.env
|
||||||
|
*.db
|
61
bot.py
61
bot.py
@ -2,6 +2,13 @@ import discord
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
import sqlite3
|
||||||
|
import re
|
||||||
|
import threading
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class Bot(commands.Bot):
|
class Bot(commands.Bot):
|
||||||
def __init__(self, intents: discord.Intents, **kwargs):
|
def __init__(self, intents: discord.Intents, **kwargs):
|
||||||
@ -17,13 +24,49 @@ bot = Bot(intents=intents)
|
|||||||
client = discord.Client(intents=intents)
|
client = discord.Client(intents=intents)
|
||||||
token = os.getenv("token")
|
token = os.getenv("token")
|
||||||
status = os.getenv("status")
|
status = os.getenv("status")
|
||||||
|
url_status = "Unknown"
|
||||||
|
url = "https://oss-auth.blinklab.com/"
|
||||||
|
stop_event = threading.Event()
|
||||||
|
|
||||||
|
def matches_wildcard(code, wildcard_code):
|
||||||
|
pattern = wildcard_code.replace('X', '[0-9]')
|
||||||
|
return re.fullmatch(pattern, str(code)) is not None
|
||||||
|
|
||||||
|
def get_error_message(code):
|
||||||
|
# Connect to the SQLite database
|
||||||
|
conn = sqlite3.connect('error_codes.db')
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Check for exact matches
|
||||||
|
cursor.execute('SELECT message FROM error_codes WHERE code = ?', (str(code),))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
|
||||||
|
if result:
|
||||||
|
return f"{code}: {result[0]}"
|
||||||
|
|
||||||
|
# Check for wildcard matches
|
||||||
|
cursor.execute('SELECT code, message FROM error_codes')
|
||||||
|
for row in cursor.fetchall():
|
||||||
|
if matches_wildcard(code, row[0]):
|
||||||
|
return f"{code}: {row[1]}"
|
||||||
|
|
||||||
|
return f"{code}: Error code not found."
|
||||||
|
|
||||||
|
def check_url():
|
||||||
|
global url_status # Declare the global variable to modify it
|
||||||
|
try:
|
||||||
|
response = requests.get(url, verify=False, timeout=10) # Disable SSL verification and set a timeout
|
||||||
|
url_status = ":green_square: Up" # If we get a response, set status to "Up"
|
||||||
|
except requests.exceptions.RequestException:
|
||||||
|
url_status = ":red_square: Down" # If there's an exception, set status to "Down"
|
||||||
|
|
||||||
@bot.hybrid_command(name="status",description="Gets the status of WiiMart")
|
@bot.hybrid_command(name="status",description="Gets the status of WiiMart")
|
||||||
async def statusy(ctx):
|
async def statusy(ctx):
|
||||||
|
check_url()
|
||||||
if status == "Not Set":
|
if status == "Not Set":
|
||||||
await ctx.send("The status hasnt been set by an admin yet, please check again later.")
|
await ctx.send(f"WiiMart Status: {url_status}\nAdmin Status: :person_shrugging: Currently Unset")
|
||||||
else:
|
else:
|
||||||
await ctx.send(f"The Current status is: {status}")
|
await ctx.send(f"WiiMart Status: {url_status}\nAdmin Status: {status}")
|
||||||
|
|
||||||
@bot.hybrid_command(name="setstatus",description="Sets the current server status to your liking")
|
@bot.hybrid_command(name="setstatus",description="Sets the current server status to your liking")
|
||||||
@commands.has_any_role("Owner", "Admin", "Moderators")
|
@commands.has_any_role("Owner", "Admin", "Moderators")
|
||||||
@ -32,5 +75,19 @@ async def setstatus(ctx, stat: str):
|
|||||||
status = stat
|
status = stat
|
||||||
await ctx.send(f"Status has been set to: {status}")
|
await ctx.send(f"Status has been set to: {status}")
|
||||||
|
|
||||||
|
@bot.hybrid_command(name="unsetstatus", description="Unsets the current status")
|
||||||
|
@commands.has_any_role("Owner", "Admin", "Moderators")
|
||||||
|
async def unset(ctx):
|
||||||
|
global status
|
||||||
|
status = "Not Set"
|
||||||
|
await ctx.send("Status has been unset.")
|
||||||
|
|
||||||
|
@bot.hybrid_command(name="error", description="Gets the error message linked with the shop error code")
|
||||||
|
async def geterror(ctx, errorcode: commands.Range[int, 204000, 250943]):
|
||||||
|
try:
|
||||||
|
errormessage = get_error_message(errorcode)
|
||||||
|
except ValueError:
|
||||||
|
errormessage = "Error Code was not found."
|
||||||
|
await ctx.send(errormessage)
|
||||||
|
|
||||||
bot.run(token)
|
bot.run(token)
|
Loading…
x
Reference in New Issue
Block a user