This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
util.py
65 lines (49 loc) · 1.61 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
File: /lib/utils/util.py
Info: Standard utilility file.
"""
from quart import request
from nextcord import ui, Interaction, SelectOption, ButtonStyle
from nextcord.ext import commands
from .api import getuserfromdiscord
import json
import functools
with open("./BOT/lib/bot/config.json") as config_file:
config = json.load(config_file)
# Are you sure?
class AreYouSureView(ui.View):
def __init__(self, context):
super().__init__(timeout=None)
self.context = context
self.Return = None
@ui.button(
label="Yes", custom_id="products:yes_I_am_sure", style=ButtonStyle.success
)
async def iamsure(self, _, interaction: Interaction):
self.Return = True
self.stop()
@ui.button(
label="No", custom_id="products:no_I_am_not_sure", style=ButtonStyle.danger
)
async def noiamnotsure(self, _, interaction: Interaction):
self.Return = False
self.stop()
def require_apikey(view):
# Makes it so I dont repeat if apikey in every website base.
@functools.wraps(view)
async def wrapper(*args, **kwargs):
apikey = request.headers["apikey"]
if not apikey == config["apikey"]:
return {"errors": [{"message": "Improper API key passed"}]}
return await view(*args, **kwargs)
return wrapper
def RequiresVerification():
def predicate(ctx):
if getuserfromdiscord(ctx.author.id) is None:
raise UserNotVerified
return True
return commands.check(predicate)
class UserNotVerified(commands.errors.CheckFailure):
pass
class UserOwnsProduct(Exception):
pass