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 pathcustom.py
More file actions
130 lines (96 loc) · 3.08 KB
/
Copy pathcustom.py
File metadata and controls
130 lines (96 loc) · 3.08 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import asyncio
from sys import exit as sys_exit
import discord
import config
bot = config.bot
# clears active bets on every restart (runs in main.py)
async def clear_active_bets():
async with config.connection.transaction():
await config.connection.execute(
"UPDATE accounts SET active_bets = 0 WHERE active_bets > 0;"
)
async def disconnect_database():
await config.connection.close()
# async def terminate():
# print("Terminating...")
#
# await bot.logout()
#
# print("test1")
#
# await disconnect_database()
#
# print("test2")
#
# asyncio.get_event_loop().stop()
#
# print("test3")
#
# sys_exit()
async def send_error(ctx, message):
await ctx.send(
embed=discord.Embed(
title="Error",
color=0x000000, # black
description=message
).set_footer(
text=str(ctx.author),
icon_url=str(ctx.author.avatar_url)
)
)
# argument user_attr (user attribute) is something related to the user
# like ID, name or name with discriminator
def find_user(ctx, user_attr):
user = None
def not_mention(text):
return text.replace("<@", "").replace(">", "").replace("!", "")
not_mention_user_attr = not_mention(user_attr)
# checks if user_attr is an ID
if not_mention_user_attr.isdigit() and len(not_mention_user_attr) >= 17:
user = bot.get_user(int(not_mention_user_attr))
# checks if user_attr is a name with discriminator (tag)
elif "#" in user_attr:
for member in ctx.guild.members:
if str(member) == user_attr:
user = member
break
else:
potential_users = []
for member in ctx.guild.members:
# looks for user with the same lower case name
if member.name.lower() == user_attr.lower():
potential_users.append(member)
if len(potential_users) == 1:
user = potential_users[0]
elif not potential_users:
pass
else:
potential_users.clear()
for member in ctx.guild.members:
# looks for user with the same name
if member.name == user_attr:
potential_users.append(member)
if len(potential_users) == 1:
user = potential_users[0]
else:
pass
return user
# ini_amount is the initial amount of accuracies used for ini_mean
def calculate_mean_accuracy(ini_mean, ini_amount, new_accuracy):
if not ini_mean:
ini_mean = 0
fin_amount = ini_amount + 1
fin_mean = (ini_mean * ini_amount + new_accuracy) / fin_amount
return round(fin_mean, 3)
def separate_digits(num):
num_list = list(str(num))
reversed_final_list = []
i = 0
for num in reversed(num_list):
if (i + 1) % 3 == 0:
reversed_final_list.append("{}{}".format(u'\u2009', num))
else:
reversed_final_list.append(num)
i += 1
final_list = reversed(reversed_final_list)
return "".join(final_list).strip(u'\u2009')