-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbot.py
More file actions
205 lines (166 loc) · 8.2 KB
/
Copy pathbot.py
File metadata and controls
205 lines (166 loc) · 8.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
# Import important stuff
import discord
import config
from random import shuffle
# Create the client object
client = discord.Client()
# Set the things from the config file
admins = config.admins
cmdprefix = config.cmdprefix
teamsize = config.teamsize
pugsize = config.pugsize
picking = False
entered = []
# When the bot recieves a message
@client.event
async def on_message(msg):
global picking
global entered
# Don't reply to self
if msg.author == client.user:
return
# Ping
if (msg.content.startswith(cmdprefix + "ping")):
await msg.channel.send("pong!")
# About
if (msg.content.startswith(cmdprefix + "about")):
await msg.channel.send("PugBot-for-Discord migration to discord.py v1.0. Forked from NightFury\nhttps://github.com/techlover1/PugBot-for-Discord\nType !help for commands")
# Help
if (msg.content.startswith(cmdprefix + "help")):
await msg.channel.send("```Available Commands:\nabout - Print information about the bot\nadd - Join the queue\n"
+ "help - Print this screen\nping - Test bot functionality\nqueue - Print players currently in the queue\nremove - Leave the queue```")
# Add
if (msg.content.startswith(cmdprefix + "add")):
# If in the picking phase, don't allow !add
if (picking):
await msg.channel.send(msg.author.mention + " You cannot use this command in the picking phase")
# If the user is already in the queue, tell them
elif (msg.author in entered):
await msg.channel.send(msg.author.mention + " You are already in the queue")
# If the pug is full lets get this party started
elif (len(entered) == (pugsize - 1)):
entered.append(msg.author)
picking = True
# Set the captains
shuffle(entered)
captains = [entered[0], entered[1]]
team1 = [captains[0]]
team2 = [captains[1]]
entered.remove(team1[0])
entered.remove(team2[0])
# Send the starting message
startingMsg = "PUG Starting!\nCaptains are " + captains[0].mention + " and " + captains[1].mention + \
"\n" + captains[0].mention + " will have first pick"
await msg.channel.send(startingMsg)
# While teams are not full let captains take turns picking players
while(len(team1) < teamsize and len(team2) < teamsize):
async def team1func(msg):
inputobj = 0
await msg.channel.send(captains[0].mention + " Type @player to pick. Available players are:\n" + ("\n".join(map(str, entered))))
# This block of code checks for a pick from captain1 and
# catches the exception if they send a message that doesn't contain a mention
while True:
try:
def pred(m):
return m.author == msg.server.get_member(captains[0].id)
inputobj = await client.wait_for('message', check=pred)
team1add = inputobj.mentions[0]
except(IndexError):
continue
break
# If the pick isn't on a team, add to team1
if(team1add in entered and team1add not in team1 and team1add not in team2):
team1.append(team1add)
entered.remove(team1add)
await msg.channel.send(team1add.mention + " Added to your team")
# If the pick is already on a team, tell captain1 and let them pick again
elif(team1add in entered and team1add in team1 or team1add in team2):
await msg.channel.send(team1add.mention + " Is already on a team")
await team1func(msg)
# If the pick isn't in the queue, tell captain1 and let them pick again
elif(team1add not in entered):
await msg.channel.send(team1add.mention + " Is not in the queue")
await team1func(msg)
# This probably shouldn't even be here, but whatever
else:
await msg.channel.send("Unknown error")
await team1func(msg)
# Same as above, but for team2
async def team2func(msg):
inputobj = 0
await msg.channel.send(captains[1].mention + " Type @player to pick. Available players are:\n" + ("\n".join(map(str, entered))))
while True:
try:
def pred(m):
return m.author == msg.server.get_member(captains[1].id)
inputobj = await client.wait_for('message', check=pred)
team2add = inputobj.mentions[0]
except(IndexError):
continue
break
if(team2add in entered and team2add not in team1 and team2add not in team2):
team2.append(team2add)
entered.remove(team2add)
await msg.channel.send(team2add.mention + " Added to your team")
elif(team2add in entered and team2add in team1 or team2add in team2):
await msg.channel.send(team2add.mention + " Is already on a team")
await team2func(msg)
elif(team2add not in entered):
await msg.channel.send(team2add.mention + " Is not in the queue")
await team2func(msg)
else:
await msg.channel.send("Unknown error")
await team2func(msg)
await team1func(msg)
await team2func(msg)
# Setup a way to mention the teams
team1mention = []
team2mention = []
for i in team1:
team1mention.append(i.mention)
for i in team2:
team2mention.append(i.mention)
# Send a message containg the teams, GLHF!
await msg.channel.send("Team 1 is: " + "\n".join(map(str, team1mention)) + "\nTeam2 is: " + "\n".join(map(str, team2mention)) + "\n GLHF!")
# Reset to allow for anotherone
entered = []
captains = []
team1 = []
team2 = []
team1mention = []
team2mention = []
picking = False
# Add player to queue if the queue isn't full
else:
entered.append(msg.author)
await msg.channel.send(msg.author.mention + " You successfuly entered into the queue. " + str(len(entered)) + " Players in queue")
# Queue
if (msg.content.startswith(cmdprefix + "queue") and len(entered) < 1):
await msg.channel.send("The queue is currently empty")
if (msg.content.startswith(cmdprefix + "queue") and len(entered) > 0):
await msg.channel.send("Players in queue:\n" + "\n".join(map(str, entered)))
# Remove
if (msg.content.startswith(cmdprefix + "remove")):
if(picking is True):
await msg.channel.send(msg.author.mention + " You cannot use this command in the picking phase")
elif(msg.author in entered):
entered.remove(msg.author)
await msg.channel.send(msg.author.mention + " You successfuly left the queue. " + str(len(entered)) + " Currently in queue")
else:
await msg.channel.send(msg.author.mention + " You are not in the queue")
# Reset
if (msg.content.startswith(cmdprefix + "reset")):
if (msg.author.id in config.admins):
del entered[:]
picking = False
await msg.channel.send("Queue reset")
else:
await msg.channel.send(msg.author.mention + " You do not have access to this command")
# Print when ready
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
# Run the bot
client.run(config.token)