-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.py
More file actions
1211 lines (1104 loc) · 48.2 KB
/
Copy pathmain.py
File metadata and controls
1211 lines (1104 loc) · 48.2 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
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 discord
from discord.ext import commands, tasks
from discord.ext.commands import Bot
import asyncio
import datetime
import re
import api
import settings
import db
import util
import paginator
intents = discord.Intents.default()
intents.members = True
intents.presences = True
SUPERS=[303599885800964097]
logger = util.get_logger("discord")
BOT_VERSION = "1.0"
# Spam Threshold (Seconds) - how long to output certain commands (e.g. price)
SPAM_THRESHOLD=300
# Change command prefix to whatever you want to begin commands with
COMMAND_PREFIX=settings.command_prefix
# HELP menu header
AUTHOR_HEADER="Beatrice v{0} (BA/NANO Utility Bot)".format(BOT_VERSION)
# Command DOC (TRIGGER, CMD, Overview, Info)
'''
CMD: Command trigger
INFO: Command usage
'''
### Commands for everyone
PRICE = {
"CMD" : "{0}price".format(COMMAND_PREFIX),
"INFO" : "Display NANO price information from a few of the top exchanges"
}
MEME = {
"CMD" : "{0}meme".format(COMMAND_PREFIX),
"INFO" : "Display next meme in sequence"
}
MEMELIST = {
"CMD" : "{0}memelist".format(COMMAND_PREFIX),
"INFO" : "Receive private message with a list of all memes stored with the bot"
}
PUP = {
"CMD" : "{0}pup".format(COMMAND_PREFIX),
"INFO" : "Display next pup in sequence"
}
PUPLIST = {
"CMD" : "{0}puplist".format(COMMAND_PREFIX),
"INFO" : "Receive private message with a list of all pups stored with the bot"
}
MEOW = {
"CMD" : "{0}meow".format(COMMAND_PREFIX),
"INFO" : "Display next meow in sequence"
}
MEOWLIST = {
"CMD" : "{0}meowlist".format(COMMAND_PREFIX),
"INFO" : "Receive private message with a list of all meows stored with the bot"
}
FRIDGE = {
"CMD" : "{0}fridge".format(COMMAND_PREFIX),
"INFO" : "Display next fridge in sequence"
}
FRIDGELIST = {
"CMD" : "{0}fridgelist".format(COMMAND_PREFIX),
"INFO" : "Receive private message with a list of all fridges stored with the bot"
}
FODL = {
"CMD" : "{0}fodl".format(COMMAND_PREFIX),
"INFO" : "Verifies Folding@Home Bananominer Client configuration after completing 1 Work Unit in banano-mining channel"
}
FARMS = {
"CMD" : "{0}farms".format(COMMAND_PREFIX),
"INFO" : "Fetches current TVL and APR for all active wrapped banano farms"
}
### Admin commands
ADDPUP = {
"CMD" : "{0}addpup, takes: url, author, title".format(COMMAND_PREFIX),
"INFO" : "Add URL to the bot's pup list",
"USAGE" : "{0}addpup <url> <author> <title>".format(COMMAND_PREFIX)
}
ADDMEME = {
"CMD" : "{0}addmeme, takes: url, author, title".format(COMMAND_PREFIX),
"INFO" : "Add URL to the bot's meme list",
"USAGE" : "{0}addmeme <url> <author> <title>".format(COMMAND_PREFIX)
}
ADDMEOW = {
"CMD" : "{0}addmeow, takes: url, author, title".format(COMMAND_PREFIX),
"INFO" : "Add URL to the bot's meow list",
"USAGE" : "{0}addmeow <url> <author> <title>".format(COMMAND_PREFIX)
}
ADDFRIDGE = {
"CMD" : "{0}addfridge, takes: url, author, title".format(COMMAND_PREFIX),
"INFO" : "Add URL to the bot's fridge list",
"USAGE" : "{0}addfridge <url> <author> <title>".format(COMMAND_PREFIX)
}
REMOVEPUP = {
"CMD" : "{0}removepup, takes: url or id".format(COMMAND_PREFIX),
"INFO" : "Remove pup matching URL or ID from the bot's pup list"
}
REMOVEMEME = {
"CMD" : "{0}removememe, takes: url or id".format(COMMAND_PREFIX),
"INFO" : "Remove meme matching URL or ID from the bot's meme list"
}
REMOVEMEOW = {
"CMD" : "{0}removemeow, takes: url or id".format(COMMAND_PREFIX),
"INFO" : "Remove meow matching URL or ID from the bot's meow list"
}
REMOVEFRIDGE = {
"CMD" : "{0}removefridge, takes: url or id".format(COMMAND_PREFIX),
"INFO" : "Remove fridge matching URL or ID from the bot's fridge list"
}
MUTE = {
"CMD" : "{0}mute or {0}muzzle, takes: user ID(s) or user mention, duration (optional)".format(COMMAND_PREFIX),
"INFO" : "mute @bbedward 60 = mute bbedward for 60 minutes"
}
UNMUTE = {
"CMD" : "{0}unmute or {0}unmuzzle, user ID(s) or user mention".format(COMMAND_PREFIX),
"INFO" : "Unmute mentioned user(s)"
}
NOIMAGES = {
"CMD" : "{0}noimages, user ID(s) or user mention".format(COMMAND_PREFIX),
"INFO" : "Stops user posting images"
}
ALLOWIMAGES = {
"CMD" : "{0}allowimages, user ID(s) or user mention".format(COMMAND_PREFIX),
"INFO" : "Allows user to post images"
}
KICK = {
"CMD" : "{0}kick, takes: user ID(s) or user mention, reason (optional)".format(COMMAND_PREFIX),
"INFO" : "kick 397868283870707713 303599885800964097 reason='You Suck' = kick user 303599885800964097 and user 397868283870707713"
}
BAN = {
"CMD" : "{0}ban, takes: user ID(s) or user mention, reason (optional))".format(COMMAND_PREFIX),
"INFO" : "kick 397868283870707713 303599885800964097 = kick user 303599885800964097 and user 397868283870707713"
}
### Dictionary of different command categories
COMMANDS = {
"USER_COMMANDS" : [PRICE, MEME, MEMELIST, PUP, PUPLIST, MEOW, MEOWLIST, FRIDGE, FRIDGELIST, FODL, FARMS],
"ADMIN_COMMANDS" : [ADDPUP, ADDMEME, ADDMEOW, ADDFRIDGE, REMOVEPUP, REMOVEMEME, REMOVEMEOW, REMOVEFRIDGE, MUTE, UNMUTE, KICK, BAN],
}
# Create discord client
client = Bot(command_prefix=COMMAND_PREFIX, intents=intents)
client.remove_command('help')
# Don't make them wait when bot first launches
initial_ts=datetime.datetime.now() - datetime.timedelta(seconds=SPAM_THRESHOLD)
last_price = {}
last_meme = {}
last_pup = {}
last_meow = {}
last_fridge = {}
last_fodl = {}
last_farms = {}
def create_spam_dicts():
"""map every channel the client can see to datetime objects
this way we can have channel-specific spam prevention"""
global last_price
global last_meme
global last_pup
global last_meow
global last_fridge
global last_fodl
global last_farms
for c in client.get_all_channels():
if not is_private(c):
last_price[c.id] = initial_ts
last_meme[c.id] = initial_ts
last_pup[c.id] = initial_ts
last_meow[c.id] = initial_ts
last_fridge[c.id] = initial_ts
last_fodl[c.id] = initial_ts
last_farms[c.id] = initial_ts
@client.event
async def on_ready():
logger.info("Beatrice v%s started", BOT_VERSION)
logger.info("Discord.py API version %s", discord.__version__)
logger.info("Name: %s", client.user.name)
logger.info("ID: %s", client.user.id)
create_spam_dicts()
await client.change_presence(activity=discord.Game(settings.playing_status))
asyncio.get_event_loop().create_task(unsilence_users())
update_sidebar_status.start() #start the update_sidebar_status() loop
# Store the last unit the status is displayed as
status_unit = None
# Periodic task to update activity status to price (in sats and USD)
@tasks.loop(seconds=10.0)
async def update_sidebar_status():
global status_unit
banano = await api.get_status()
if banano is not None:
if status_unit == 'nano':
await client.change_presence(activity=discord.Game(f"{banano['satoshi']:.1f} sats"))
status_unit = 'ban'
else:
await client.change_presence(activity=discord.Game(f"${banano['usdprice']:.4f}"))
status_unit = 'nano'
else:
await client.change_presence(activity=discord.Game(f"Error checking prices"))
@client.event
async def on_member_join(member):
if db.silenced(member.id):
muzzled = member.guild.get_role(settings.muzzled_role)
await member.add_roles(muzzled)
@client.event
async def on_reaction_add(reaction, user):
if reaction.emoji == '\u274C' and reaction.count >= 5 and reaction.message.channel.id == 585626036574748684:
await reaction.message.delete()
# Periodic check job to unsilence users
async def unsilence_users():
try:
await asyncio.sleep(10)
asyncio.get_event_loop().create_task(unsilence_users())
for s in db.get_silenced():
if s.expiration is None:
continue
elif datetime.datetime.now() >= s.expiration:
for guild in client.guilds:
if guild.id == s.server_id:
muzzled = guild.get_role(settings.muzzled_role)
for member in guild.members:
if member.id == int(s.user_id):
await member.remove_roles(muzzled)
break
db.unsilence(s.user_id)
except Exception as ex:
logger.exception(ex)
def is_private(channel):
"""Check if a discord channel is private"""
return isinstance(channel, discord.abc.PrivateChannel)
def has_admin_role(roles):
"""Check if user has an admin role defined in our settings"""
for r in roles:
if r.id in settings.admin_roles:
return True
return False
def is_admin(member):
"""Returns true if user is an admin"""
if str(member.id) in settings.admin_ids:
return True
elif has_admin_role(member.roles):
return True
return False
def is_bannable(user):
"""Returns true if user does not have any special roles"""
if str(user.id) in settings.admin_ids:
return False
for m in client.get_all_members():
if m.id == user.id:
for role in m.roles:
if role.name.lower() not in ['banano jail', 'muzzled', '@everyone', 'citizens', 'troll', 'Private ^', 'Corporal ^^', 'Sergeant ^^^', 'Officer -', 'Second Lieutenant |', 'First Lieutenant ||', 'Captain *', 'Colonel **', 'General ***']:
return False
return True
def valid_url(url):
# TODO we should check content-type header with aiohttp
return True
### Public Commands
@client.command(aliases=["help"])
async def commandlist(ctx):
message = ctx.message
embed = discord.Embed(colour=discord.Colour.magenta())
embed.title = "Commands"
for cmd in COMMANDS["USER_COMMANDS"]:
embed.add_field(name=cmd['CMD'], value=cmd['INFO'], inline=False)
if is_admin(message.author):
for cmd in COMMANDS["ADMIN_COMMANDS"]:
embed.add_field(name=cmd['CMD'], value=cmd['INFO'], inline=False)
await message.author.send(embed=embed)
@client.command()
async def price(ctx):
message = ctx.message
if is_private(message.channel):
return
# Check spam
global last_price
if message.channel.id not in last_price:
last_price[message.channel.id] = datetime.datetime.now()
tdelta = datetime.datetime.now() - last_price[message.channel.id]
if message.author.id not in SUPERS:
if SPAM_THRESHOLD > tdelta.seconds:
await message.author.send("No more price for {0} seconds".format(SPAM_THRESHOLD - tdelta.seconds))
return
last_price[message.channel.id] = datetime.datetime.now()
msg = await message.channel.send("Retrieving latest prices...")
embed = discord.Embed(colour=discord.Colour.green())
embed.title = "Current Prices"
btc = None
nano = None
banano = None
prices = await api.get_all_prices()
for item, price in prices:
if item == 'BTC':
btc = price
elif item == 'NANO':
nano = price
elif item == 'BANANO':
banano = price
# Display data
banpernan = ""
embed.description = ''
embed.description += '**BANANO**'
if banano is None:
embed.description += '\nCurrently Unavailable\n'
else:
if banano['change'] < 0:
embed.colour=discord.Colour.red()
embed.description += "```"
embed.description += f"Rank : #{banano['rank']}\n"
if nano is not None:
ban_in_nano = banano['usdprice'] / nano['usdprice']
banpernan = 1 / ban_in_nano
embed.description += f"Price (NANO) : {ban_in_nano:.6f} NANO\n"
embed.description += f"Price (BTC) : {banano['satoshi']:.1f} sats\n"
embed.description += f"Price (USD) : ${banano['usdprice']:.6f}\n"
if settings.VESPRICE and 'bolivar' in banano:
embed.description += f"Price (VES) : {banano['bolivar']:.2f} Bs.S\n"
embed.description += f"Volume (24H) : {banano['volume']:,.2f} BTC\n"
embed.description += f"Market Cap : ${int(banano['mcap']):,}\n"
embed.description += "```"
embed.description += "\n**NANO**"
if nano is None:
embed.description += '\nCurrently Unavailable\n'
else:
banpernan = nano['usdprice'] / banano['usdprice']
embed.description += "```"
embed.description += f"Rank : #{nano['rank']}\n"
embed.description += f"Price (BTC) : {nano['btcprice']:.8f} BTC\n"
embed.description += f"Price (USD) : ${nano['usdprice']:.2f}\n"
if settings.VESPRICE and 'bolivar' in nano:
embed.description += f"Price (VES) : {nano['bolivar']:.2f} Bs.S\n"
embed.description += f"Volume (24H) : {nano['volume']:,.2f} BTC\n"
embed.description += f"Market Cap : ${int(nano['mcap']):,}\n"
embed.description += "```"
if btc is not None and banpernan != "":
embed.set_footer(text='1 BTC = ${0:,.2f} | 1 NANO = {1:,.2f} BAN | Market Data Provided by CoinGecko.com'.format(btc['usdprice'], banpernan))
elif btc is not None:
embed.set_footer(text='1 BTC = ${0:,.2f} | Market Data Provided by CoinGecko.com'.format(btc['usdprice']))
await msg.edit(content="", embed=embed)
@client.command()
async def meme(ctx):
message = ctx.message
if is_private(message.channel):
return
elif message.channel.id in settings.no_spam_channels:
return
# Check spam
global last_meme
if message.channel.id not in last_meme:
last_meme[message.channel.id] = datetime.datetime.now()
tdelta = datetime.datetime.now() - last_meme[message.channel.id]
if message.author.id not in SUPERS:
if SPAM_THRESHOLD > tdelta.seconds:
await post_response(message, "No more memes for {0} seconds", (SPAM_THRESHOLD - tdelta.seconds))
return
last_meme[message.channel.id] = datetime.datetime.now()
meme = db.get_next_meme()
if meme is None:
await post_response(message, "There are no memes! Add some with !addmeme")
return
embed = discord.Embed(colour=discord.Colour.green())
embed.title = "Meme #{0} - {1}".format(meme['id'], meme['title'])
embed.set_author(name=meme['author'])
embed.set_image(url=meme['url'])
await message.channel.send(embed=embed)
@client.command(aliases=["memes"])
async def memelist(ctx):
message = ctx.message
memes = db.get_memes()
if len(memes) == 0:
embed = discord.Embed(colour=discord.Colour.red())
embed.title="No Memes"
embed.description="There no memes. Add memes with `{0}addmeme`".format(COMMAND_PREFIX)
await message.author.send(embed=embed)
return
title="Meme List"
description=("Here are all the memes!")
entries = []
for meme in memes:
entries.append(paginator.Entry(str(meme['id']),meme['url']))
# Do paginator for favorites > 10
if len(entries) > 10:
pages = paginator.Paginator.format_pages(entries=entries,title=title,description=description)
p = paginator.Paginator(client,message=message,page_list=pages,as_dm=True)
await p.paginate(start_page=1)
else:
embed = discord.Embed(colour=discord.Colour.teal())
embed.title = title
embed.description = description
for e in entries:
embed.add_field(name=e.name,value=e.value,inline=False)
await message.author.send(embed=embed)
@client.command()
async def meow(ctx):
message = ctx.message
if is_private(message.channel):
return
elif message.channel.id in settings.no_spam_channels:
return
# Check spam
global last_meow
if message.channel.id not in last_meow:
last_meow[message.channel.id] = datetime.datetime.now()
tdelta = datetime.datetime.now() - last_meow[message.channel.id]
if message.author.id not in SUPERS:
if SPAM_THRESHOLD > tdelta.seconds:
await post_response(message, "No more meows for {0} seconds", (SPAM_THRESHOLD - tdelta.seconds))
return
last_meow[message.channel.id] = datetime.datetime.now()
meow = db.get_next_meow()
if meow is None:
await post_response(message, "There are no meows! Add some with !addmeow")
return
embed = discord.Embed(colour=discord.Colour.orange())
embed.title = "Meow #{0} - {1}".format(meow['id'], meow['title'])
embed.set_author(name=meow['author'])
embed.set_image(url=meow['url'])
await message.channel.send(embed=embed)
@client.command(aliases=["meows"])
async def meowlist(ctx):
message = ctx.message
meows = db.get_meows()
if len(meows) == 0:
embed = discord.Embed(colour=discord.Colour.red())
embed.title="No Meows"
embed.description="There no meows. Add meows with `{0}addmeow`".format(COMMAND_PREFIX)
await message.author.send(embed=embed)
return
title="Meow List"
description=("Here are all the meows!")
entries = []
for meow in meows:
entries.append(paginator.Entry(str(meow['id']),meow['url']))
# Do paginator for favorites > 10
if len(entries) > 10:
pages = paginator.Paginator.format_pages(entries=entries,title=title,description=description)
p = paginator.Paginator(client,message=message,page_list=pages,as_dm=True)
await p.paginate(start_page=1)
else:
embed = discord.Embed(colour=discord.Colour.teal())
embed.title = title
embed.description = description
for e in entries:
embed.add_field(name=e.name,value=e.value,inline=False)
await message.author.send(embed=embed)
@client.command()
async def fridge(ctx):
message = ctx.message
if is_private(message.channel):
return
elif message.channel.id in settings.no_spam_channels:
return
# Check spam
global last_fridge
if message.channel.id not in last_fridge:
last_fridge[message.channel.id] = datetime.datetime.now()
tdelta = datetime.datetime.now() - last_fridge[message.channel.id]
if message.author.id not in SUPERS:
if SPAM_THRESHOLD > tdelta.seconds:
await post_response(message, "No more fridges for {0} seconds", (SPAM_THRESHOLD - tdelta.seconds))
return
last_fridge[message.channel.id] = datetime.datetime.now()
fridge = db.get_next_fridge()
if fridge is None:
await post_response(message, "There are no fridges! Add some with !addfridge")
return
embed = discord.Embed(colour=discord.Colour.orange())
embed.title = "fridge #{0} - {1}".format(fridge['id'], fridge['title'])
embed.set_author(name=fridge['author'])
embed.set_image(url=fridge['url'])
await message.channel.send(embed=embed)
@client.command(aliases=["fridges"])
async def fridgelist(ctx):
message = ctx.message
fridges = db.get_fridges()
if len(fridges) == 0:
embed = discord.Embed(colour=discord.Colour.red())
embed.title="No fridges"
embed.description="There no fridges. Add fridges with `{0}addfridge`".format(COMMAND_PREFIX)
await message.author.send(embed=embed)
return
title="fridge List"
description=("Here are all the fridges!")
entries = []
for fridge in fridges:
entries.append(paginator.Entry(str(fridge['id']),fridge['url']))
# Do paginator for favorites > 10
if len(entries) > 10:
pages = paginator.Paginator.format_pages(entries=entries,title=title,description=description)
p = paginator.Paginator(client,message=message,page_list=pages,as_dm=True)
await p.paginate(start_page=1)
else:
embed = discord.Embed(colour=discord.Colour.teal())
embed.title = title
embed.description = description
for e in entries:
embed.add_field(name=e.name,value=e.value,inline=False)
await message.author.send(embed=embed)
@client.command()
async def pup(ctx):
message = ctx.message
if is_private(message.channel):
return
elif message.channel.id in settings.no_spam_channels:
return
# Check spam
global last_pup
if message.channel.id not in last_pup:
last_pup[message.channel.id] = datetime.datetime.now()
tdelta = datetime.datetime.now() - last_pup[message.channel.id]
if message.author.id not in SUPERS:
if SPAM_THRESHOLD > tdelta.seconds:
await post_response(message, "No more pups for {0} seconds", (SPAM_THRESHOLD - tdelta.seconds))
return
last_pup[message.channel.id] = datetime.datetime.now()
pup = db.get_next_pup()
if pup is None:
await post_response(message, "There are no pups! Add some with !addpup")
return
embed = discord.Embed(colour=discord.Colour.blue())
embed.title = "Pup #{0} - {1}".format(pup['id'], pup['title'])
embed.set_author(name=pup['author'])
embed.set_image(url=pup['url'])
await message.channel.send(embed=embed)
@client.command(aliases=["pups"])
async def puplist(ctx):
message = ctx.message
pups = db.get_pups()
if len(pups) == 0:
embed = discord.Embed(colour=discord.Colour.red())
embed.title="No Pups"
embed.description="There no pups. Add pups with `{0}addpup`".format(COMMAND_PREFIX)
await message.author.send(embed=embed)
return
title="Pup List"
description=("Here are all the pups!")
entries = []
for pup in pups:
entries.append(paginator.Entry(str(pup['id']),pup['url']))
# Do paginator for favorites > 10
if len(entries) > 10:
pages = paginator.Paginator.format_pages(entries=entries,title=title,description=description)
p = paginator.Paginator(client,message=message,page_list=pages,as_dm=True)
await p.paginate(start_page=1)
else:
embed = discord.Embed(colour=discord.Colour.teal())
embed.title = title
embed.description = description
for e in entries:
embed.add_field(name=e.name,value=e.value,inline=False)
await message.author.send(embed=embed)
@client.command()
async def fodl(ctx, *, username):
message = ctx.message
#hard-coding mining channel in here for now. no one else should need this command...
#could allow this in private message, but don't want to pollute the global with everyones chat id's
if message.channel.id not in [566268199210057728, 443787679457345536]: # and not is_private(message.channel):
return
global last_fodl
if message.channel.id not in last_fodl:
last_fodl[message.channel.id] = datetime.datetime.now()
tdelta = datetime.datetime.now() - last_fodl[message.channel.id]
if message.author.id not in SUPERS:
if 5 > tdelta.seconds: #i think the global spam limits would be too high.
await message.author.send("No more fodl for {0} seconds".format(5 - tdelta.seconds))
return
last_fodl[message.channel.id] = datetime.datetime.now()
#a pretty safe name check. could be better
if len(username) > 20 or len(username) < 5 or username.isalnum()==False:
await message.author.send("Definitely not a bananominer username.")
await message.add_reaction('\U00002753')
return
await message.add_reaction('\U0001F4C1') #add folder emoji to message
output = ""
isCorrect = True
username = username.lower()
getDataBase = await api.getFODLJSON(username)
fahAPIJSON = getDataBase[0]
bMinerJSON = getDataBase[1]
fahBonusJSON = getDataBase[2]
banUnits = 0
if(bMinerJSON == {} or fahAPIJSON=={} ):
await ctx.send("API Error")
return
#Verify username is valid bananominer username, im not 100% about all the errors that are possible, but thought it was safe to print the error.
if "error" in bMinerJSON:
output+="<:x:835354642308661278> " +username+" not a valid Bananominer username.\nUpdate username by putting banano wallet address into <https://bananominer.com/> and copy/pasting into folding at home client \n"
isCorrect = False
await message.add_reaction('\U0001F58D')
else: #if no error, don't see why wouldn't be valid username...
output+="<:white_check_mark:835347973503451176> "+username+ " is a valid bananominer username\n"
banTeam = {}
nonBanWU = 0
#Verify folding for correct team and last time folded for correct team
if "name" not in fahAPIJSON or "teams" not in fahAPIJSON:
output+="<:x:835354642308661278> User \"" + username + "\" has not completed a Work Unit\n"
isCorrect = False
await message.add_reaction('\U000026D4')
elif "teams" in fahAPIJSON:
for team in fahAPIJSON["teams"]:
if team["team"] == 234980 and "wus" in team:
banTeam = team
elif "wus" in team:
nonBanWU += team["wus"]
if banTeam == {}:
output+="<:x:835354642308661278> User: \""+ username + "\" has not folded for banano team ID 234980\n"
isCorrect = False
await message.add_reaction('\U000026D4')
if (isCorrect):
clickerStr = "<:arrow_right:856238567713800222> Click here for: "
if "last" in banTeam: #might need to investigate further but sometimes fah api doesn't have data...
output+="<:white_check_mark:835347973503451176> " + str(banTeam["last"])+" UTC : Last Completed Banano WU\n"
output+="<:white_check_mark:835347973503451176> "+str(banTeam["wus"])+" work units completed so far.\n"
output+="<:white_check_mark:835347973503451176> "+str(banTeam["score"])+" points received so far.\n"
await message.add_reaction('\U0001F6F0')
if len(bMinerJSON["payments"]) == 0:
output+="<:grey_exclamation:835357988432642049> No payments sent yet. First payment is within 24-36 hours of completing first Work Unit as long as you complete at least 2 work units (progress bar going to 100%) with at least one in each 12 hour period.\n"
output+="<:banana:838483242113957898>Work Units Pending Payment: "+str(banTeam["wus"])+"\n"
output+="<:banana:838483242113957898>Points Pending Payment: "+str(banTeam["score"])+"\n"
await message.add_reaction('\U0001F6F0')
elif len(bMinerJSON["payments"]) > 0: #user has received payments
output+="<:white_check_mark:835347973503451176> " + bMinerJSON["payments"][0]["created_at"] + " UTC was latest payment for user.\n"
output+="<:banana:838483242113957898>Work Units Pending Payment: "+str(banTeam["wus"]-bMinerJSON["payments"][0]["work_units"])+"\n"
output+="<:banana:838483242113957898>Points Pending Payment: "+str(banTeam["score"]-bMinerJSON["payments"][0]["score"])+"\n"
await message.add_reaction('\U0001F34C')
await message.add_reaction('\U00002705')
bonus = False
progresso = False
for cpu in fahBonusJSON:
progresso = True
if cpu["active"]==1:
bonus = True
output += "<:white_check_mark:835347973503451176> Passkey Bonus Active\n"
await message.add_reaction('\U0001F510')#lock/key
break
if bonus ==False and progresso == True: #passkey in porgress
output += "<:grey_exclamation:835357988432642049> Passkey Bonus Not Active, but appears to be in progress\n"+clickerStr+ "[Passkey Bonus Info](https://foldingathome.org/support/faq/points/?lng=en-US#what-are-the-qualifications-for-the-qrb)\nPasskey Requires 10 work units completed after adding to client to activate."
await message.add_reaction('\U0001F6B8')#caution sign?
elif bonus ==False: #if there is no bonus entries, passkey is not entered (the issue here is a timeout could happen and not be deteceted...)
output += "<:grey_exclamation:835357988432642049> Passkey Bonus Not Active and does not appear to be entered \n <:arrow_right:856238567713800222> Click here to: [Get a Passkey](https://apps.foldingathome.org/getpasskey)\n"+clickerStr+ "[Passkey Bonus Info](https://foldingathome.org/support/faq/points/?lng=en-US#what-are-the-qualifications-for-the-qrb)\nPasskey Requires 10 work units completed after adding to client to activate."
await message.add_reaction('\U00002755')#exclamation mark
#add reaction to message
#This is not explicitly an issue, but calling it out in summary may hep in identifying wrong team issues, calling out the date(s) might also be helpful?
if nonBanWU > 0:
output+="<:grey_exclamation:835357988432642049> "+username + " has completed "+ str(nonBanWU) + " number of Work Units for teams other than Banano\n"
if (isCorrect==False):
output+="\nPlease review above errors. After updating client and completing another Work Unit: this test can be ran again to verify your client is set up to track points correctly.\n"
output = output+"\n"
if "id" in fahAPIJSON: output+=clickerStr+ "[F@H Donor Stat Page](https://stats.foldingathome.org/donor/"+str(fahAPIJSON["id"])+") \n"
output+=clickerStr+"[Bananominer JSON Stats](https://bananominer.com/user_name/"+username+")\n"
output+="FODL Check might be cached and may not update immediately.\n"
embed = discord.Embed(colour=discord.Colour.teal())
embed.title = "FODL Check"
embed.description = output
await message.author.send( embed=embed)
@client.command(aliases=["wban"])
async def farms(ctx):
message = ctx.message
global last_farms
if message.channel.id not in last_farms:
last_farms[message.channel.id] = datetime.datetime.now() - datetime.timedelta(seconds=SPAM_THRESHOLD)
tdelta = datetime.datetime.now() - last_farms[message.channel.id]
if message.author.id not in SUPERS:
if SPAM_THRESHOLD > tdelta.seconds:
await message.author.send("No more farms for {0} seconds".format(SPAM_THRESHOLD - tdelta.seconds))
return
last_farms[message.channel.id] = datetime.datetime.now()
#Get the API response
apiResponse = await api.getWbanFarms()
#In case something went wrong
if apiResponse is None:
await ctx.send("API Error")
return
if apiResponse == []:
await ctx.send("No active wBAN farms found")
return
#Sort the response so that the networks are always in the same order
apiResponse.sort(key=lambda y: y[0])
output = ""
#Maps networks to their corresponding wban emoji. This part will need to be updated for future networks (will map to bsc emoji by default)
emoji_map = {
"binance-smart-chain":"<:wbanbsc:835977496389877802>",
"fantom":"<:wbanftm:949720720110419999>",
"polygon":"<:wbanpoly:884560016928043038>",
"ethereum":"<:wbaneth:1037739681401536662>",
"arbitrum":"<:wbanarb:1051565681763688548>"
}
for (network,farms) in apiResponse:
#Get the emoji for this network
if network in emoji_map:
emoji = emoji_map[network]
else:
emoji = emoji_map["binance-smart-chain"]
#Build the output
output += f"\n{emoji} **{str.title(network)}**"
output += "\n```"
for (pair,tvl,apr) in farms:
if apr is not None:
output += f"{pair}: {apr}% APR (${tvl:,} TVL)\n"
else:
output += f"{pair}: Inactive (${tvl:,} TVL)\n"
if len(farms) == 0:
output += f"No pools found\n"
output += "```"
embed = discord.Embed(colour=discord.Colour.green())
embed.title = "wBAN Farms"
embed.description = output
await message.channel.send(embed=embed)
### Admin Commands
@client.command()
async def addmeme(ctx, url: str = None, author: str = None, title: str = None):
message = ctx.message
if not is_admin(message.author):
return
elif url is None or author is None or title is None:
await post_usage(message, ADDMEME)
elif not valid_url(url):
await message.author.send("Invalid URL. Valid urls begin with http:// or https://")
elif db.add_meme(url, author, title):
await message.author.send("Meme added: {0}".format(title))
else:
await message.author.send("Could not add meme {0}. It may already exist".format(url))
@client.command()
async def removememe(ctx, id: str):
message = ctx.message
if not is_admin(message.author):
return
elif db.remove_meme(id):
await message.author.send("Meme {0} removed".format(id))
else:
await message.author.send("Could not remove meme {0}. It may not exist".format(id))
@client.command()
async def addpup(ctx, url: str = None, author: str = None, title: str = None):
message = ctx.message
if not is_admin(message.author):
return
elif url is None or author is None or title is None:
await post_usage(message, ADDPUP)
elif not valid_url(url):
await message.author.send("Invalid URL. Valid urls begin with http:// or https://")
elif db.add_pup(url, author, title):
await message.author.send("Pup added: {0}".format(title))
else:
await message.author.send("Could not add Pup {0}. It may already exist".format(url))
@client.command()
async def removepup(ctx, id: str):
message = ctx.message
if not is_admin(message.author):
return
elif db.remove_pup(id):
await message.author.send("Pup {0} removed".format(id))
else:
await message.author.send("Could not Remove pup {0}. It may not exist".format(id))
@client.command()
async def addmeow(ctx, url: str = None, author: str = None, title: str = None):
message = ctx.message
if not is_admin(message.author):
return
elif url is None or author is None or title is None:
await post_usage(message, ADDMEOW)
elif not valid_url(url):
await message.author.send("Invalid URL. Valid urls begin with http:// or https://")
elif db.add_meow(url, author, title):
await message.author.send("Meow added: {0}".format(title))
else:
await message.author.send("Could not add meow {0}. It may already exist".format(url))
@client.command()
async def removemeow(ctx, id: str):
message = ctx.message
if not is_admin(message.author):
return
elif db.remove_meow(id):
await message.author.send("Meow {0} removed".format(id))
else:
await message.author.send("Could not remove meow {0}. It may not exist".format(id))
@client.command()
async def addfridge(ctx, url: str = None, author: str = None, title: str = None):
message = ctx.message
if not is_admin(message.author):
return
elif url is None or author is None or title is None:
await post_usage(message, ADDFRIDGE)
elif not valid_url(url):
await message.author.send("Invalid URL. Valid urls begin with http:// or https://")
elif db.add_fridge(url, author, title):
await message.author.send("fridge added: {0}".format(title))
else:
await message.author.send("Could not add fridge {0}. It may already exist".format(url))
@client.command()
async def removefridge(ctx, id: str):
message = ctx.message
if not is_admin(message.author):
return
elif db.remove_fridge(id):
await message.author.send("fridge {0} removed".format(id))
else:
await message.author.send("Could not remove fridge {0}. It may not exist".format(id))
@client.command(aliases=['muzzle'])
async def mute(ctx):
message = ctx.message
if is_admin(message.author):
targets = get_all_mentions(message)
if len(targets) > 0:
muzzled = message.guild.get_role(settings.muzzled_role)
duration = find_amount(message.content)
expiration = None
if duration is not None:
try:
expiration = datetime.datetime.now() + datetime.timedelta(minutes=float(duration))
except:
expiration = None
for member in targets:
if not db.silence(member.id, message.guild.id, expiration=expiration):
await post_response(message, '<@{0}> is already muzzled', member.id)
continue
await member.add_roles(muzzled)
if duration is not None:
await post_response(message, '<@{0}> has been muzzled for {1} minutes', member.id, duration)
else:
await post_response(message, '<@{0}> has been muzzled indefinitely', member.id)
await message.add_reaction('\U0001f694')
@client.command(aliases=['unmuzzle'])
async def unmute(ctx):
message = ctx.message
if is_admin(message.author):
targets = get_all_mentions(message)
if len(targets) > 0:
muzzled = message.guild.get_role(settings.muzzled_role)
for member in targets:
await member.remove_roles(muzzled)
if not db.unsilence(member.id):
await post_response(message, '<@{0}> is not muzzled', member.id)
continue
await post_response(message, '<@{0}> has been unmuzzled', member.id)
@client.command()
async def arrest(ctx):
message = ctx.message
if is_admin(message.author):
targets = get_all_mentions(message)
if len(targets) > 0:
jail = message.guild.get_role(settings.ARREST_ROLE)
for member in targets:
await member.add_roles(jail)
await post_response(message, settings.RIGHTS, mention_id=member.id, channel_id=settings.JAIL_ID)
await message.add_reaction('\U0001f694')
@client.command()
async def release(ctx):
message = ctx.message
if is_admin(message.author):
targets = get_all_mentions(message)
if len(targets) > 0:
# Tip unban too
jail = message.guild.get_role(settings.ARREST_ROLE)
for member in targets:
await member.remove_roles(jail)
await post_response(message, settings.RELEASE, mention_id=member.id)
@client.command()
async def troll(ctx):
message = ctx.message
if is_admin(message.author):
targets = get_all_mentions(message)
if len(targets) > 0:
troll = message.guild.get_role(settings.TROLL_ROLE)
citizenship = message.guild.get_role(settings.CITIZEN_ROLE)
for member in targets:
await member.add_roles(troll)
await member.remove_roles(citizenship)
await post_response(message, settings.TROLL, mention_id=member.id)
@client.command()
async def untroll(ctx):
message = ctx.message
if is_admin(message.author):
targets = get_all_mentions(message)
if len(targets) > 0:
troll = message.guild.get_role(settings.TROLL_ROLE)
for member in targets:
await member.remove_roles(troll)
await post_response(message, settings.UNTROLL, mention_id=member.id)
@client.command()
async def citizenship(ctx):
message = ctx.message
if is_admin(message.author):
targets = get_all_mentions(message)
if len(targets) > 0:
citizenship = message.guild.get_role(settings.CITIZEN_ROLE)
for member in targets:
await member.add_roles(citizenship)
await post_response(message, settings.CITIZENSHIP, mention_id=member.id)
await message.add_reaction('\:bananorepublic:429691019538202624')
@client.command()
async def deport(ctx):
message = ctx.message
if is_admin(message.author):
targets = get_all_mentions(message)
if len(targets) > 0:
citizenship = message.guild.get_role(settings.CITIZEN_ROLE)
for member in targets:
await member.remove_roles(citizenship)
await post_response(message, settings.DEPORT, mention_id=member.id)
await message.add_reaction('\U0001F6F3')
@client.command()
async def noimages(ctx):
message = ctx.message
if is_admin(message.author):
targets = get_all_mentions(message)
if len(targets) > 0:
imagesperm = message.guild.get_role(settings.IMAGES_ROLE)
for member in targets:
await member.add_roles(imagesperm)
await message.add_reaction('\U0001F485')