-
Notifications
You must be signed in to change notification settings - Fork 7
/
mogi_objects.py
144 lines (122 loc) · 4.03 KB
/
mogi_objects.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
import discord
class Mogi:
def __init__ (self, sq_id:int, size:int, mogi_channel:discord.TextChannel,
is_automated=False, start_time=None, discord_event=None):
self.started = False
self.gathering = False
self.making_rooms_run = False
self.sq_id = sq_id
self.size = size
self.mogi_channel = mogi_channel
self.teams = []
self.rooms = []
self.is_automated = is_automated
self.discord_event = discord_event
if not is_automated:
self.start_time = None
else:
self.start_time = start_time
def check_player(self, member:discord.Member):
for team in self.teams:
if team.has_player(member):
return team
return None
def count_registered(self):
count = 0
for team in self.teams:
if team.is_registered():
count += 1
return count
def confirmed_list(self):
confirmed = []
for team in self.teams:
if team.is_registered():
confirmed.append(team)
return confirmed
def remove_id(self, squad_id:int):
confirmed = self.confirmed_list()
if squad_id < 1 or squad_id > len(confirmed):
return None
squad = confirmed[squad_id-1]
self.teams.remove(squad)
return squad
def is_room_thread(self, channel_id:int):
for room in self.rooms:
if room.thread.id == channel_id:
return True
return False
def get_room_from_thread(self, channel_id:int):
for room in self.rooms:
if room.thread.id == channel_id:
return room
return None
class Room:
def __init__(self, teams, room_num:int, thread:discord.Thread):
self.teams = teams
self.room_num = room_num
self.thread = thread
self.finished = False
def get_player(self, member):
for team in self.teams:
player = team.get_player(member)
if player:
return player
class Team:
def __init__ (self, players):
self.players = players
self.avg_mmr = sum([p.mmr for p in self.players]) / len(self.players)
def recalc_avg(self):
self.avg_mmr = sum([p.mmr for p in self.players]) / len(self.players)
def is_registered(self):
for player in self.players:
if player.confirmed is False:
return False
return True
def has_player(self, member):
for player in self.players:
if player.member.id == member.id:
return True
return False
def get_player(self, member):
for player in self.players:
if player.member.id == member.id:
return player
return None
def sub_player(self, sub_out, sub_in):
for i, player in enumerate(self.players):
if player == sub_out:
self.players[i] = sub_in
self.recalc_avg()
return
def num_confirmed(self):
count = 0
for player in self.players:
if player.confirmed:
count += 1
return count
def get_unconfirmed(self):
unconfirmed = []
for player in self.players:
if not player.confirmed:
unconfirmed.append(player)
return unconfirmed
def __lt__(self, other):
if self.avg_mmr < other.avg_mmr:
return True
if self.avg_mmr > other.avg_mmr:
return False
def __gt__(self, other):
return other.__lt__(self)
# def __eq__(self, other):
# if self.avg_mmr == other.avg_mmr:
# return True
# return False
def __str__(self):
return ", ".join([p.lounge_name for p in self.players])
class Player:
def __init__ (self, member:discord.Member, lounge_name, mmr):
self.member = member
self.lounge_name = lounge_name
self.mmr = mmr
self.confirmed = False
self.score = 0