This repository has been 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
/
commands.py
1296 lines (1037 loc) · 33.6 KB
/
commands.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sys
import asyncpraw
import random
from discord.ext import commands
import datetime
import math
# import custom
from custom import *
from Account import Account
from Accessory import Accessory
bot = config.bot
reddit_client = asyncpraw.Reddit(
client_id=config.R_CLIENT_ID,
client_secret=config.R_CLIENT_SECRET,
username=config.R_USERNAME,
password=config.R_PASSWORD,
user_agent=config.R_USER_AGENT
)
gold_emote = " <:gold:884085535965065266>"
platinum_emote = " <:platinum:884147435709030440>"
@bot.command(
aliases=["latency"],
help="Used for getting the bot's ping.",
hidden=True
)
async def ping(ctx):
if not await bot.is_owner(ctx.author):
return
latency = round(bot.latency, 3) * 1000 # in ms to 3 d.p.
await ctx.send(f"Pong! ({latency}ms)")
# closes the bot (only bot owners)
@bot.command(
help="Used for restarting the bot.",
hidden=True
)
async def cease(ctx):
if not await bot.is_owner(ctx.author):
return
await ctx.send("Farewell...")
# await custom.terminate()
sys.exit()
def get_help_pages(dev):
commands_list = []
for command in bot.commands:
if not dev:
if not command.hidden:
commands_list.append(command)
else:
if command.hidden:
commands_list.append(command)
commands_list.sort(key=lambda command_in: command_in.name)
grouped_commands_list = [
commands_list[i:i + 10] for i in range(0, len(commands_list), 10)
]
pages = []
i = 0
total_pages = len(grouped_commands_list)
for group in grouped_commands_list:
page = discord.Embed(
title=f"Commands",
color=0xff4500 # orangered
).set_footer(
text=f"Showing page {i + 1} of {total_pages}, "
f"use reactions to switch pages."
)
for command in group:
page.add_field(
name=command.name,
value=(
command.help +
(
f"\n*Usage:* `{command.usage}`" if command.usage
else ""
) +
(
f"\n*Alias"
f"{'' if len(command.aliases) == 1 else 'es'}"
f":* `{'`, `'.join(command.aliases)}`"
if command.aliases
else ""
)
),
inline=False
)
pages.append(page)
i += 1
return pages
bot.remove_command("help")
@bot.command(
name="help",
aliases=["h"],
help="Used for getting this message."
)
@commands.cooldown(1, 5, type=commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.user)
async def help_(ctx):
pages = help_pages
total_pages = len(pages)
n = 0
help_message = await ctx.send(embed=pages[n])
react_emotes = ("◀️", "❌", "▶️")
for react_emote in react_emotes:
await help_message.add_reaction(react_emote)
def check(reaction_in, user_in):
return (
user_in == ctx.author and str(reaction_in) in react_emotes and
reaction_in.message == help_message
)
while True:
try:
reaction, user = await bot.wait_for(
"reaction_add",
check=check,
timeout=60
)
if str(reaction) == "▶️":
if n + 2 > total_pages:
pass
else:
n += 1
await help_message.edit(embed=pages[n])
try:
await help_message.remove_reaction(reaction, user)
except discord.errors.Forbidden:
pass
elif str(reaction) == "◀️":
if n == 0:
pass
else:
n -= 1
await help_message.edit(embed=pages[n])
try:
await help_message.remove_reaction(reaction, user)
except discord.errors.Forbidden:
pass
else:
try:
await help_message.clear_reactions()
except discord.errors.Forbidden:
pass
break
except asyncio.TimeoutError:
try:
await help_message.clear_reactions()
except discord.errors.Forbidden:
pass
break
@bot.command(
name="devhelp",
aliases=["dh"],
help="Used for getting this message.",
hidden=True
)
@commands.cooldown(1, 5, type=commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.user)
async def developer_help(ctx):
if not await bot.is_owner(ctx.author):
return
pages = dev_help_pages
total_pages = len(pages)
n = 0
help_message = await ctx.send(embed=pages[n])
react_emotes = ("◀️", "❌", "▶️")
for react_emote in react_emotes:
await help_message.add_reaction(react_emote)
def check(reaction_in, user_in):
return (
user_in == ctx.author and str(reaction_in) in react_emotes and
reaction_in.message == help_message
)
while True:
try:
reaction, user = await bot.wait_for(
"reaction_add",
check=check,
timeout=60
)
if str(reaction) == "▶️":
if n + 2 > total_pages:
pass
else:
n += 1
await help_message.edit(embed=pages[n])
try:
await help_message.remove_reaction(reaction, user)
except discord.errors.Forbidden:
pass
elif str(reaction) == "◀️":
if n == 0:
pass
else:
n -= 1
await help_message.edit(embed=pages[n])
try:
await help_message.remove_reaction(reaction, user)
except discord.errors.Forbidden:
pass
else:
try:
await help_message.clear_reactions()
except discord.errors.Forbidden:
pass
break
except asyncio.TimeoutError:
try:
await help_message.clear_reactions()
except discord.errors.Forbidden:
pass
break
@bot.command(
aliases=["information"],
help="Used for getting information about the bot."
)
async def info(ctx):
developers = []
app_info = await bot.application_info()
for owner in app_info.team.members:
developers.append(f"`{str(owner)}`")
developers.sort()
developers_string = "\n".join(developers)
await ctx.send(
embed=discord.Embed(
title="Information",
color=0xff4500 # orangered
).add_field(
name="GitHub repository",
value="http://github.bedditbot.eu",
inline=False
).add_field(
name="Discord server",
value="https://discord.gg/HjT3YpU",
inline=False
).add_field(
name="Bot invite",
value="http://invite.bedditbot.eu",
inline=False
).add_field(
name="Developers",
value=developers_string,
inline=False
)
)
@bot.command(
name="postinfo",
aliases=["pi", "pinfo"],
help="Used for getting information (number of upvotes and "
"downvotes) about a Reddit post."
)
async def post_information(ctx, link):
post = await reddit_client.submission(url=link)
score = post.score
ratio = post.upvote_ratio
upvotes = round(
(ratio * score) / (2 * ratio - 1)
)
downvotes = round(
(score * (1 - ratio)) / (2 * ratio - 1)
)
timedelta = (
datetime.datetime.utcnow() -
datetime.datetime.utcfromtimestamp(post.created_utc)
)
def express_time(time):
days = time.days
hours = math.floor(time.seconds / 3600)
minutes = math.floor(time.seconds % 3600 / 60)
seconds = time.seconds % 60
if days != 0:
return (
f"{days} {'days' if days != 1 else 'day'} "
f"{hours} {'hours' if hours != 1 else 'hour'} "
f"{minutes} {'minutes' if minutes != 1 else 'minute'} "
f"ago"
)
else:
return (
f"{hours} {'hours' if hours != 1 else 'hour'} "
f"{minutes} {'minutes' if minutes != 1 else 'minute'} "
f"{seconds} {'seconds' if seconds != 1 else 'second'} "
f"ago"
)
await ctx.send(
embed=discord.Embed(
title="Post information",
url=link,
colour=0xff4500 # orangered
).add_field(
name="Title",
value=post.title,
inline=False
).add_field(
name="Created",
value=express_time(timedelta),
inline=False
).add_field(
name="Score",
value=separate_digits(score),
inline=False
).add_field(
name="Upvotes",
value=separate_digits(upvotes),
inline=False
).add_field(
name="Downvotes",
value=separate_digits(downvotes),
inline=False
).add_field(
name="Comments",
value=separate_digits(post.num_comments),
inline=False
)
)
@bot.command(
name="balance",
aliases=["bal"],
help=f"Used for getting the gold{gold_emote} "
"balance of a user."
)
async def balance_(ctx, user_attr=None):
if not user_attr:
user = ctx.author
else:
user = find_user(ctx, user_attr)
if not user:
return
account = await Account.get(user)
await ctx.send(
embed=discord.Embed(
title="Balance",
color=0xffd700 # gold
).add_field(
name="Gold",
value=f"{separate_digits(account.gold)}{gold_emote}",
inline=False
).add_field(
name="Platinum",
value=f"{separate_digits(account.platinum)}{platinum_emote}",
inline=False
).set_thumbnail(
url="https://static.wikia.nocookie.net/reddit/images/1/10/Gold.png"
"/revision/latest/scale-to-width-down/512?cb=20200815001830"
).set_footer(
text=str(user),
icon_url=str(user.avatar_url)
)
)
# @bot.command(
# name="editaccount",
# aliases=["ea"],
# help="Used for manually editing account information.",
# hidden=True
# )
# async def edit_account(ctx, user_attr, field, value):
# if not await bot.is_owner(ctx.author):
# return
#
# if not user_attr:
# user = ctx.author
# else:
# user = find_user(ctx, user_attr)
# if not user:
# await ctx.send("This user wasn't found!")
#
# return
#
# account = await Account.get(user)
#
# if field not in account:
# await ctx.send("Field not found.")
#
# return
#
# if not value.replace(".", "").isdigit() and value != "None":
# await ctx.send("Invalid value.")
#
# return
#
# if "." in value:
# value = round(float(value), 3)
# elif value == "None":
# value = None
# else:
# value = int(value)
#
# account[field] = value
#
# await store_user_account(account)
#
# await ctx.send(
# f"Edited {str(user)}'s bank account {field} field to {value}!"
# )
@bot.command(
pass_context=True,
help="Used for collecting your daily reward."
)
@commands.cooldown(1, 60 * 60 * 24, commands.BucketType.user)
async def daily(ctx):
user = ctx.author
account = await Account.get(user)
account.gold += 100
await account.store()
await ctx.send(
embed=discord.Embed(
title="Balance (+Daily reward)",
color=0xffd700 # gold
).add_field(
name="Gold",
value=(separate_digits(account.gold) + " (+100)"),
inline=False
).add_field(
name="Platinum",
value=separate_digits(account.platinum),
inline=False
).set_thumbnail(
url="https://i.imgur.com/9aAfwcJ.png"
).set_footer(
text=str(user),
icon_url=str(user.avatar_url)
)
)
TRANSFER_TAX_RATE = 0.05 # 5%
@bot.command(
help=f"Used for transferring gold{gold_emote} "
f"to another user (with a {TRANSFER_TAX_RATE * 100}% tax)."
)
async def transfer(ctx, *, args):
args_list = args.split()
amount = args_list[-1]
receiver_attr = " ".join(args_list[:-1])
sender = ctx.author
sender_account = await Account.get(sender)
if sender_account.active_bets > 0:
await send_error(
ctx,
f"Can't transfer gold{gold_emote} between users with active bets."
)
return
if not amount.isdigit():
return
amount = int(amount)
if amount == 0:
return
receiver = find_user(ctx, receiver_attr)
if not receiver:
return
if sender == receiver:
return
if amount > sender_account.gold:
return
receiver_account = await Account.get(receiver)
if receiver_account.active_bets > 0:
await send_error(
ctx,
f"Can't transfer gold{gold_emote} between users with active bets."
)
return
sender_account.gold -= amount
receiver_account.gold += int(amount - TRANSFER_TAX_RATE * amount)
await sender_account.store()
await receiver_account.store()
await ctx.send(
embed=discord.Embed(
title="Transfer",
color=0xffd700, # gold
description=f"Transferred {amount} "
f"gold{gold_emote} "
f"from `{str(sender)}` to `{str(receiver)}` "
f"with a {round(TRANSFER_TAX_RATE * 100)}% tax rate."
).set_footer(
text=str(sender),
icon_url=str(sender.avatar_url)
)
)
@bot.command(
help=f"Used to gamble 50 gold{gold_emote}. "
f"(Try it out and hope for the jackpot!)"
)
@commands.cooldown(1, 1, commands.BucketType.user)
async def gamble(ctx):
user = ctx.author
account = await Account.get(user)
gold = account.gold
if gold < 50:
return
outcome = random.randint(1, 100)
if outcome <= 25:
winnings = random.randint(1, 25)
elif outcome <= 75:
winnings = random.randint(25, 50)
elif outcome <= 99:
winnings = random.randint(50, 100)
else:
winnings = 500
true_winnings = winnings - 50
account.gold += true_winnings
await account.store()
await ctx.send(
embed=discord.Embed(
title="Gambling",
color=0x39ff14, # neon green
description=f"Gambled 50 gold{gold_emote} "
f"and won {winnings} "
f"gold{gold_emote}."
).set_footer(
text=str(user),
icon_url=str(user.avatar_url)
)
)
hidden_balance_tracker = dict()
@bot.command(
name="convert",
aliases=["con", "c"],
help=f"Used for converting gold{gold_emote} to platinum{platinum_emote}."
)
@commands.cooldown(1, 30, commands.BucketType.user)
async def convert_(ctx):
user = ctx.author
account = await Account.get(user)
gold = account.gold
platinum = account.platinum
price_1 = platinum ** 3
price_2 = 2 * price_1
price_3 = 3 * price_1
message = await ctx.send(
embed=discord.Embed(
title="Platinum Conversion",
description=f"React to convert gold{gold_emote} to "
f"platinum{platinum_emote}.",
color=0xe5e4e2 # platinum
).add_field(
name="Option 1️⃣",
value=f"{separate_digits(price_1)}{gold_emote} to "
f"1{platinum_emote}",
inline=False
).add_field(
name="Option 2️⃣",
value=f"{separate_digits(price_2)}{gold_emote} to "
f"2{platinum_emote}",
inline=False
).add_field(
name="Option 3️⃣",
value=f"{separate_digits(price_3)}{gold_emote} to "
f"3{platinum_emote}",
inline=False
).set_footer(
text=str(user),
icon_url=str(user.avatar_url)
).set_thumbnail(
url="https://static.wikia.nocookie.net/reddit/images/a/ac/"
"Platinum.png/revision/latest/scale-to-width-down/512"
"?cb=20200815001756"
)
)
await message.add_reaction("1️⃣")
await message.add_reaction("2️⃣")
await message.add_reaction("3️⃣")
async def update(price, amount):
nonlocal account, gold, platinum, price_1, price_2, price_3
account = await Account.get(user)
gold = account.gold
platinum = account.platinum
price_1 = platinum ** 3
price_2 = 2 * price_1
price_3 = 3 * price_1
await message.edit(
embed=discord.Embed(
title="Platinum Conversion",
description=f"Converted {price}{gold_emote} to "
f"{amount}{platinum_emote}.",
color=0xe5e4e2 # platinum
).add_field(
name="Option 1️⃣",
value=f"{separate_digits(price_1)}{gold_emote} to "
f"1{platinum_emote}",
inline=False
).add_field(
name="Option 2️⃣",
value=f"{separate_digits(price_2)}{gold_emote} to "
f"2{platinum_emote}",
inline=False
).add_field(
name="Option 3️⃣",
value=f"{separate_digits(price_3)}{gold_emote} to "
f"3{platinum_emote}",
inline=False
).set_footer(
text=str(user),
icon_url=str(user.avatar_url)
).set_thumbnail(
url="https://static.wikia.nocookie.net/reddit/images/a/ac/"
"Platinum.png/revision/latest/scale-to-width-down/512"
"?cb=20200815001756"
)
)
def check(reaction_in, user_in):
return (
user_in == ctx.author and str(reaction_in.emoji) in
("1️⃣", "2️⃣", "3️⃣") and reaction_in.message == message
)
while True:
try:
reaction, user = await bot.wait_for(
"reaction_add",
check=check,
timeout=45
)
if str(reaction.emoji) == "1️⃣":
if gold >= price_1:
account.gold -= price_1
account.platinum += 1
await account.store()
await update(price_1, 1)
else:
await send_error(
ctx,
f"Insufficient gold{gold_emote} for conversion."
)
return
elif str(reaction.emoji) == "2️⃣":
if gold >= price_2:
account.gold -= price_2
account.platinum += 2
await account.store()
await update(price_2, 2)
else:
await send_error(
ctx,
f"Insufficient gold{gold_emote} for conversion."
)
return
elif str(reaction.emoji) == "3️⃣":
if gold >= price_3:
account.gold -= price_3
account.platinum += 3
await account.store()
await update(price_3, 3)
else:
await send_error(
ctx,
f"Insufficient gold{gold_emote} for conversion."
)
return
try:
await message.remove_reaction(reaction, user)
except discord.errors.Forbidden:
pass
except asyncio.TimeoutError:
try:
await message.clear_reactions()
except discord.errors.Forbidden:
pass
break
@bot.command(
help=f"Used to bet on Reddit posts. *Use as [Reddit post URL] "
f"[bet amount (in gold{gold_emote})] "
f"[time (in s/m/h)] "
f"[predicted upvotes on that post after that time].*"
)
@commands.cooldown(1, 5, commands.BucketType.user)
async def bet(ctx, link, amount, time, predicted_ups):
user = ctx.author
if not amount.rstrip("%").isdigit() or not predicted_ups.isdigit():
await ctx.send("You can't bet that!")
return
account = await Account.get(user)
if "%" in amount:
if not 0 < float(amount.rstrip("%")) <= 100:
await ctx.send("You can't bet that!")
return
amount = int(
float(amount.rstrip("%")) * account.gold / 100
)
else:
amount = int(amount)
predicted_ups = int(predicted_ups)
initial_post = await reddit_client.submission(url=link)
age = int(
datetime.datetime.utcnow().timestamp() - initial_post.created_utc
)
if age > 86400:
await ctx.send("You can't bet on posts older than 24 hours!")
return
if initial_post.archived or initial_post.locked:
await ctx.send("You can't bet on archived or locked posts!")
return
# if not ctx.channel.is_nsfw() and initial_post.nsfw:
# await ctx.send("You can't bet on NSFW posts here!")
#
# return
initial_ups = initial_post.ups
if predicted_ups <= initial_ups + 1:
await ctx.send(
"Your predicted upvotes can't be lower than or equal to "
"the current amount of upvotes (plus 1)!"
)
return
if account.gold < amount:
await ctx.send("You do not have enough chips to bet this much!")
return
if account.active_bets >= 3:
await ctx.send("You already have 3 bets running!")
return
# gets time unit, then removes it and converts time to seconds
if "s" in time:
time_in_seconds = time.rstrip("s")
if not time_in_seconds.isdigit():
await ctx.send("You can't use that as time!")
return
time_in_seconds = int(time_in_seconds)
elif "m" in time:
time_in_seconds = time.rstrip("m")
if not time_in_seconds.isdigit():
await ctx.send("You can't use that as time!")
return
time_in_seconds = int(time_in_seconds) * 60
elif "h" in time:
time_in_seconds = time.rstrip("h")
if not time_in_seconds.isdigit():
await ctx.send("You can't use that as time!")
return
time_in_seconds = int(time_in_seconds) * 3600
elif time.isdigit():
await ctx.send("Please specify a time unit.")
return
else:
await ctx.send("You can't use that as time!")
return
predicted_ups_difference = predicted_ups - initial_ups
# sends initial message with specifics
await ctx.send(
f"This post has {separate_digits(initial_ups)} "
f"upvotes right now! "
f"You bet {separate_digits(amount)} "
f"gold{gold_emote} on it reaching "
f"{separate_digits(predicted_ups)} upvotes in {time}!"
)
account.active_bets += 1
account.gold -= amount
try:
hidden_balance_tracker[user.id] += amount
except KeyError:
hidden_balance_tracker[user.id] = 0
hidden_balance_tracker[user.id] += amount
await account.store()
# waits until the chosen time runs out, then calculates the accuracy
await asyncio.sleep(time_in_seconds)
final_post = await reddit_client.submission(url=link)
final_ups = final_post.ups
# pct means percent
try:
if predicted_ups > final_ups:
accuracy = abs(final_ups / predicted_ups)
else:
accuracy = abs(predicted_ups / final_ups)
except ZeroDivisionError:
await ctx.send("Oops! Something went wrong.")
return
accuracy = round(accuracy, 3)
accuracy_in_pct = accuracy * 100
account = await Account.get(user)
true_balance = account.gold + hidden_balance_tracker[user.id]
# multiplier formula
multiplier = (
(625 / 676) * math.exp(- true_balance / (10_000_000 / math.log(2)))
* (accuracy - 0.4) ** 3 * time_in_seconds ** (2 / 7) *
math.log(predicted_ups_difference, 15)
)
winnings = int(amount * multiplier)
true_winnings = winnings - amount
account.gold += winnings
hidden_balance_tracker[user.id] -= amount
if account.gold >= 2147483647:
await ctx.send(
f"Hello {user.mention}! Great job! You have hit the limits of "
f"time and space! (Or possibly our programming...)"
)
account.gold -= winnings
account.active_bets -= 1
account.gold += amount
await account.store()
return
account.active_bets -= 1
account.mean_accuracy = calculate_mean_accuracy(
account.mean_accuracy,
account.total_bets,
accuracy
)
account.total_bets += 1
await account.store()
if true_winnings > 0:
await ctx.send(
f"Hello {user.mention}! It's {time} later, and the post has "
f"{separate_digits(final_ups)} upvotes right now! "
f"You were {accuracy_in_pct}% "
f"accurate and won {separate_digits(true_winnings)} "
f"gold{gold_emote}!"