-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
81 lines (58 loc) · 2.18 KB
/
main.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
import discord #type: ignore
from discord.ext import commands, tasks #type: ignore
from clashstat import PlayerStats
import os
Client = commands.Bot(command_prefix='@')
ID = os.environ.get('ID')
PW = os.environ.get('PW')
ChannelID = os.environ.get('Channel')
ChannelID2 = os.environ.get('Channel2')
Token = os.environ.get('Token')
ChannelIDs = [ChannelID, ChannelID2]
coc = PlayerStats(ID, PW, 'player.txt') #type: ignore
coc.GetPlayerList()
#########################
@Client.event
async def on_ready():
print("Bot Login as {}".format(Client))
Main.start()
def MakeUrl(Name: str, Tags: str):
RemoveSpecialChar = ''
for ch in Name:
if ord(ch) == 32:
RemoveSpecialChar += '-'
elif ord(ch) < 128:
RemoveSpecialChar += ch.lower()
Identification = RemoveSpecialChar + "-" + Tags[1:]
Link = f"https://www.clashofstats.com/players/{Identification}/summary"
return Link
def MakeEmbedMessageFormat(Name: str, TrophyChange: str,
Link: str) -> discord.Embed:
if int(TrophyChange) > 0:
TrophyInStr = "+" + TrophyChange
Color = 0x00aaaa
else:
TrophyInStr = TrophyChange
Color = 0xFF8CFF
embed = discord.Embed(title="{} : {}".format(Name, TrophyInStr),
color=Color,
url=Link)
return embed
@tasks.loop(seconds=60)
async def Main():
PlayersUpdate = await coc.Run()
print("Running...")
ChannelIDList = list(
map(lambda channel: Client.get_channel(int(channel)), ChannelIDs))
if len(PlayersUpdate) == 0:
return
print("Size of Update = {}".format(len(PlayersUpdate)))
for tag in PlayersUpdate.keys():
Link = MakeUrl(PlayersUpdate[tag].get('name'),
PlayersUpdate[tag].get('tag'))
embed = MakeEmbedMessageFormat(PlayersUpdate[tag].get('name'),
str(PlayersUpdate[tag].get('trophies')),
Link)
for channelID in ChannelIDList:
await channelID.send(embed=embed)
Client.run(Token)