Repository navigation
Expand file tree
/
Copy pathstats.py
More file actions
166 lines (147 loc) · 7.2 KB
/
Copy pathstats.py
File metadata and controls
166 lines (147 loc) · 7.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
import discord
from discord.ext import commands
import logging
import asyncio
from espnff import League
import requests
import json
import os
import time
from operator import attrgetter
class Stats():
def __init__(self, bot, league_id, year):
self.bot = bot
self.league_id = 273350
self.year = 2017
self.league = League(league_id, year)
'Pulled the server channel ID to be stored in the database'
async def on_server_join(self, server):
print("test")
print("Joining server: {0.id} ({0.name})".format(server))
'League Info'
@commands.has_permissions(administrator=True)
@commands.command(pass_context=True)
async def leagueid(self, ctx, *, id: str):
try:
try:
self.league = League(int(id), 2017)
except:
await bot.say("Unable to find a league with ID \"" + id +"\".")
print("New League ID: " + str(self.league.league_id))
await self.bot.say("The league has been changed to: " + self.league.settings.name)
except discord.errors.Forbidden:
await self.bot.say("Missing Permissions.")
'Team Data Commands'
@commands.command()
async def teams(self):
teamList = []
await self.bot.say("Teams:\n==================")
for team in self.league.teams:
teamList.append(team.team_name)
await self.bot.say('\n '.join(teamList))
@commands.command()
async def east(self):
eastList = []
await self.bot.say("East Division:\n==================")
for team in self.league.teams:
if team.division_id == 0:
eastList.append(team.team_name)
#await self.bot.say(team.team_name)
await self.bot.say('\n'.join(eastList))
@commands.command()
# @commands.has_permissions(manage_messages=True)
async def west(self):
westList = []
await self.bot.say("West Division:\n==================")
for team in self.league.teams:
if team.division_id == 1:
westList.append(team.team_name)
#await self.bot.say(team.team_name)
await self.bot.say('\n'.join(westList))
@commands.command(pass_context=True)
async def won(self, ctx, *, name: str):
for team in self.league.teams:
if team.team_name.lower() == name.lower():
await self.bot.say(team.team_name + " has won " + str(team.wins) + " games!")
return
elif name.lower() in team.owner.lower():
await self.bot.say(team.owner + "'s team has won " + str(team.wins) + " games!")
return
await self.bot.say("Hmm...I couldn't find a team or owner named \"" + name + "\".")
@commands.command(pass_context=True)
async def lost(self, ctx, *, name: str):
for team in self.league.teams:
if team.team_name.lower() == name.lower():
await self.bot.say(team.team_name + " has lost " + str(team.losses) + " games!")
return
elif name.lower() in team.owner.lower():
await self.bot.say(team.owner + "'s team has lost " + str(team.losses) + " games!")
return
await self.bot.say("Hmm...I couldn't find a team or owner named \"" + name + "\".")
@commands.command(pass_context=True)
async def schedule(self, ctx, *, name: str):
for team in self.league.teams:
if team.team_name.lower() == name.lower():
await self.bot.say(team.owner + "'s Schedule")
await self.bot.say("==========================")
await self.bot.say('\n'.join('Week {}:\t{}'.format(*k) for k in enumerate(ctx.message.author.roles, 1)))
return
elif name.lower() in team.owner.lower():
await self.bot.say(team.owner + "'s Schedule")
await self.bot.say("==========================")
await self.bot.say('\n'.join('Week {}:\t{}'.format(*k) for k in enumerate(map(attrgetter('owner'), team.schedule), 1)))
return
await self.bot.say("Hmm...I couldn't find a team or owner named \"" + name + "\".")
@commands.command(pass_context=True)
async def points_for(self, ctx, *, name: str):
for team in self.league.teams:
if team.team_name.lower() == name.lower():
await self.bot.say(team.owner + " has scored " + str(team.points_for) + " total points")
return
elif name.lower() in team.owner.lower():
await self.bot.say(team.owner + " has scored " + str(team.points_for) + " total points")
return
await self.bot.say("Hmm...I couldn't find a team or owner named \"" + name + "\".")
@commands.command(pass_context=True)
async def points_against(self, ctx, *, name: str):
for team in self.league.teams:
if team.team_name.lower() == name.lower():
await self.bot.say(team.owner + " has had " + str(team.points_for) + " total points scored against them.")
return
elif name.lower() in team.owner.lower():
await self.bot.say(team.owner + " has had " + str(team.points_for) + " total points scored against them.")
return
await self.bot.say("Hmm...I couldn't find a team or owner named \"" + name + "\".")
@commands.command(pass_context=True)
async def scores(self, ctx, *, name: str):
for team in self.league.teams:
if team.team_name.lower() == name.lower():
await self.bot.say(team.owner + "'s Scores\n==========================")
await self.bot.say('\n'.join('Week {}:\t{}'.format(*k) for k in enumerate(team.scores, 1)))
return
elif name.lower() in team.owner.lower():
await self.bot.say(team.owner + "'s Scores\n==========================")
await self.bot.say('\n'.join('Week {}:\t{}'.format(*k) for k in enumerate(team.scores, 1)))
return
await self.bot.say("Hmm...I couldn't find a team or owner named \"" + name + "\".")
@commands.command(pass_context=True)
async def ranking(self, ctx, *, week_num):
'Need to fix the ranking output'
await self.bot.say('\n'.join('{}:\t{}'.format(*k) for k in enumerate(league.power_rankings(week=int(week_num)), 1)))
@commands.command()
async def scoreboard(self):
scoreboard = self.league.scoreboard()
counter = 0
await self.bot.say("Current Week Matchups\n==========================")
for score in scoreboard:
matchup = scoreboard[counter]
await self.bot.say(matchup.home_team.owner + ":\t" + str(matchup.home_score) + " pts\tvs.\t" + matchup.away_team.owner + ":\t" + str(matchup.away_score) + "pts ")
counter = counter + 1
@commands.command(pass_context=True)
async def ping(self, ctx):
pingtime = time.time()
pingms = await self.bot.say("Pinging... `{}'s` location".format(ctx.message.author.mention))
ping = time.time() - pingtime
await self.bot.edit_message(pingms, "The ping time is `%.01f seconds`" % ping)
def setup(bot):
bot.add_cog(Stats(bot, 273350, 2017))