-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBot.py
193 lines (149 loc) · 5.82 KB
/
Bot.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
from ast import alias
from tokenize import Name
from unicodedata import name
import discord
#import pandas as pd
from discord.ext import commands
import json
import os
from dotenv import load_dotenv, find_dotenv
import csv
# Roster = pd.read_excel('Roster.xlsx')
# Names_List = Roster[Roster.columns[4]].tolist()
# print(Names_List)
client = commands.Bot(command_prefix='$')
LINEUP_CHANNEL = 'Gcc-Lineup'
load_dotenv()
DISCORD_TOKEN_ID = os.environ.get("BOT_TOKEN")
@client.event
async def on_ready():
print('ready')
print(client.guilds)
@client.command()
async def makechannels(ctx, category_name):
global Names_List
print('hi')
B = discord.utils.get(ctx.guild.channels, name=category_name)
for i in Names_List[50:59]:
await ctx.guild.create_text_channel(i, category=B)
@client.command()
async def ping(ctx):
await ctx.send('pong')
@client.command()
async def move(ctx, current_cat: discord.CategoryChannel, target_cat: discord.CategoryChannel, *Accounts):
current_cat_channels = current_cat.channels
iter = 0
for i in range(len(current_cat_channels)):
temp = str(current_cat_channels[i])
print(temp[1:-3])
print(Accounts[1])
if temp[1:-3] == Accounts[iter].lower():
#move channel
await current_cat_channels[i].edit(category=target_cat)
#await ctx.channel.edit(category=target_cat)
iter = iter+1
@client.command()
async def setlineupchannel(channel_name):
global LINEUP_CHANNEL
LINEUP_CHANNEL = channel_name
@client.command()
async def green(ctx):
previous_name = ctx.channel.name
await ctx.channel.edit(name = '🟢' + previous_name[1:])
@client.command()
async def red(ctx):
previous_name = ctx.channel.name
await ctx.channel.edit(name = '🔴' + previous_name[1:])
@client.command(aliases=['ul'])
async def updatelineup(ctx, *Accounts):
global LINEUP_CHANNEL
Lineup_Category = discord.utils.get(ctx.guild.channels, name= LINEUP_CHANNEL)
for i in range(len(Accounts)):
if Accounts[i][0] == '#':
try:
channel_id = int(rosteredAccounts[Accounts[i]])
except Exception:
pass
channelname = discord.utils.get(ctx.guild.channels, id = channel_id)
await channelname.edit(category = Lineup_Category)
@client.command()
async def revert(ctx):
Lineup_Category = discord.utils.get(ctx.guild.channels, name= LINEUP_CHANNEL)
ROSTER_Category = discord.utils.get(ctx.guild.channels, name= 'gcc')
R11_Category = discord.utils.get(ctx.guild.channels, name= 'GCC 11s')
channels = Lineup_Category.channels
for i in range(len(channels)):
if channels[i].name[-2:] == '11':
await channels[i].edit(category = R11_Category)
else:
await channels[i].edit(category = ROSTER_Category)
@client.command(aliases=['gc'])
async def getchannels(ctx, *, category: discord.CategoryChannel):
channels = category.channels
for i in range(len(channels)):
await ctx.send(channels[i].name + ' ' + str(channels[i].id))
print(channels[i].id)
@client.command(aliases=['hr'])
async def hitrate(ctx, MODE, TARGET_CLAN='us'):
if str(ctx.message.attachments) == "[]": # Checks if there is an attachment on the message
return
else: # If there is it gets the filename from message.attachments
split_v1 = str(ctx.message.attachments).split("filename='")[1]
filename = str(split_v1).split("' ")[0]
if filename.endswith(".csv"): # Checks if it is a .csv file
await ctx.message.attachments[0].save(fp="HRsheets\\{}".format(filename)) # saves the file
ATTACKS, TRIPLES = hrcalculation("HRsheets\\{}".format(filename), TARGET_CLAN, MODE )
Output = "\n"
for i in ATTACKS.keys():
Output = Output + "\n" + i.rjust(20) + "\t" + str(TRIPLES.get(i,0)) + '/' + str(ATTACKS.get(i,0))
Embed_Output = discord.Embed(title="{0} \n {1} \t {2}".format(filename, TARGET_CLAN, MODE), description="```{0}```".format(Output))
os.remove("HRsheets\\{}".format(filename)) #cleanup
await ctx.send(embed=Embed_Output)
def hrcalculation(FilePath, TARGET, MODE):
# Variables for interface with minion bot csv output, These are actually the corresponding column values in the csv
# Maybe I should make these in a json outside the script so that they are easier to change if mb updates
Att_Clan = 0
Def_Clan = 1
Att = 2
Def = 3
Att_Tag = 18
Def_Tag = 19
Clan_Tag = 14
Opp_Tag = 15
Att_Clan_Tag = 25
Def_Clan_Tag = 26
Fresh = 24
Att_Th = 29
Def_Th = 30
Stars = 20
Stars_Gained = 21
#initializers dicts for HRs, Occurences records attacks and Triples records triples
Triples = {}
Occurences = {}
with open(FilePath , encoding='utf8') as File:
readtemp = csv.reader(File)
read = sorted(readtemp, key=lambda elem: elem[Att_Th], reverse=True)
if TARGET.lower() == 'us':
TARGET_CLAN = read[1][Att_Clan_Tag]
else:
TARGET_CLAN = read[1][Def_Clan_Tag]
for row in read:
if MODE.lower() == 'attack':
mode = Att_Clan_Tag
name = Att
else:
mode = Def_Clan_Tag
name = Def
if row[mode] != TARGET_CLAN:
continue
if row[Stars_Gained] == '' or row[Att_Th] != row[Def_Th]:
continue
Occurences.setdefault(row[name], 0)
Occurences[row[name]] = Occurences[row[name]] + 1
if int(row[Stars]) == 3 and int(row[Stars_Gained]) != 0:
Triples.setdefault(row[name], 0)
Triples[row[name]] = Triples[row[name]] + 1
return (Occurences, Triples)
with open('Roster_Data.json') as j:
rosteredAccounts = json.load(j)
client.run(DISCORD_TOKEN_ID)