2020-10-13 21:02:40 +02:00
|
|
|
import math
|
|
|
|
|
|
|
|
import discord
|
|
|
|
from discord import utils, Member, User
|
|
|
|
from discord.ext import commands
|
|
|
|
from data import constants
|
|
|
|
import requests
|
|
|
|
from functions.database import currency
|
|
|
|
|
|
|
|
|
2021-04-14 18:07:09 +02:00
|
|
|
# Checks if caller of a command is the owner of the bot
|
|
|
|
async def isMe(ctx):
|
|
|
|
# return str(ctx.author.id) == constants.myId
|
|
|
|
return await ctx.bot.is_owner(ctx.author)
|
2020-10-13 21:02:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Checks if the caller of a command is an admin
|
2021-04-14 18:07:09 +02:00
|
|
|
async def isMod(ctx):
|
2020-10-13 21:02:40 +02:00
|
|
|
if ctx.guild is None:
|
2021-04-14 18:07:09 +02:00
|
|
|
return await isMe(ctx)
|
2020-10-13 21:02:40 +02:00
|
|
|
|
|
|
|
return ctx.author.id in constants.mods[ctx.guild.id]
|
|
|
|
|
|
|
|
|
|
|
|
# Checks if a command is allowed to be used in this channel
|
2021-04-14 18:07:09 +02:00
|
|
|
async def allowedChannels(ctx):
|
|
|
|
return (await isMe(ctx)) or ctx.channel.type == discord.ChannelType.private or int(ctx.channel.id) in constants.allowedChannels.values()
|
2020-10-13 21:02:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
# TODO find a better way to check for legit links because reddit posts return a 502
|
|
|
|
def freeGamesCheck(ctx):
|
|
|
|
if str(ctx.channel.id) != str(constants.allowedChannels["freegames"]):
|
|
|
|
return True
|
|
|
|
|
|
|
|
# Replace newlines with spaces
|
|
|
|
noNewLines = ctx.content.replace("\n", " ")
|
|
|
|
|
|
|
|
link = ""
|
|
|
|
for word in noNewLines.split(" "):
|
|
|
|
if "http" in word and "://" in word:
|
|
|
|
link = word.strip()
|
|
|
|
break
|
|
|
|
|
|
|
|
if link == "":
|
|
|
|
return False
|
|
|
|
request = requests.get(link)
|
|
|
|
if request.status_code != 200:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
# Checks if a user can invest/gamble/... [amount]
|
|
|
|
def isValidAmount(ctx, amount):
|
|
|
|
if not amount:
|
|
|
|
return [False, "Geef een geldig bedrag op."]
|
|
|
|
dinks = float(currency.dinks(ctx.author.id))
|
|
|
|
if amount == "all":
|
|
|
|
if dinks > 0:
|
|
|
|
return [True, dinks]
|
|
|
|
else:
|
|
|
|
return [False, "Je hebt niet genoeg Didier Dinks om dit te doen."]
|
|
|
|
# Check if it's a number <= 0 or text != all
|
|
|
|
if (all(char.isalpha() for char in str(amount)) and amount != "all") or \
|
|
|
|
(all(char.isdigit() for char in str(abs(int(amount)))) and int(amount) <= 0):
|
|
|
|
return [False, "Geef een geldig bedrag op."]
|
|
|
|
if int(amount) > dinks:
|
|
|
|
return [False, "Je hebt niet genoeg Didier Dinks om dit te doen."]
|
|
|
|
return [True, amount]
|
|
|
|
|
|
|
|
|
|
|
|
def pluralS(amount):
|
|
|
|
return "s" if round(float(amount)) != 1 else ""
|