This repository was archived by the owner on Oct 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.py
More file actions
105 lines (89 loc) · 3.23 KB
/
Account.py
File metadata and controls
105 lines (89 loc) · 3.23 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import discord
import config
class Account:
def __init__(
self,
user_id,
gold,
active_bets,
total_bets,
mean_accuracy,
platinum
):
self.user_id = user_id
self.gold = gold
self.active_bets = active_bets
self.total_bets = total_bets
self.mean_accuracy = mean_accuracy
self.platinum = platinum
@staticmethod
async def open(user):
await user.send(
embed=discord.Embed(
title="Warning",
colour=0xffffff,
description="Gambling addiction can develop from gambling fake"
" virtual currency, like in Beddit, and negatively"
" affects self-esteem, relationships, "
"physical/mental health, school/work performance "
"and social life.\nBeddit **does not encourage or "
"promote** any kind of **gambling** with real "
"currency, **we discourage it**.\nIn case you "
"think you may have developed gambling addiction, "
"please seek help from [professionals]"
"(https://www.ncpgambling.org/5475-2/)."
)
)
async with config.connection.transaction():
await config.connection.execute(
"INSERT INTO accounts VALUES ($1, $2, $3, $4, $5, $6);",
user.id,
250,
0,
0,
None,
0
)
@staticmethod
async def get(user):
async with config.connection.transaction():
values = tuple(await config.connection.fetchrow(
"SELECT * FROM accounts WHERE user_id=$1;",
user.id
))
if not values:
await Account.open(user)
async with config.connection.transaction():
values = tuple(config.connection.fetchrow(
"SELECT * FROM accounts WHERE user_id=$1;",
user.id
))
account = Account(*values)
if account.mean_accuracy:
account.mean_accuracy = float(account.mean_accuracy)
return account
async def store(self):
if self.gold < 0:
self.gold = 0
if self.gold > 2147483647:
self.gold = 2147483647
async with config.connection.transaction():
await config.connection.execute(
"UPDATE accounts SET gold = $2, platinum = $3, "
"active_bets = $4, total_bets = $5, mean_accuracy = $6 "
"WHERE user_id = $1;",
self.user_id,
self.gold,
self.platinum,
self.active_bets,
self.total_bets,
self.mean_accuracy
)
@staticmethod
async def check(user):
async with config.connection.transaction():
account_ = await config.connection.fetchrow(
"SELECT * FROM accounts WHERE user_id=$1;",
user.id
)
return bool(account_)