-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.py
137 lines (107 loc) · 5.71 KB
/
commands.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
import asyncio
import discord
from discord.ext import commands
class Moveset(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(name='splash', help='Cosmog\'s best attack!')
async def splash(self, ctx):
await ctx.send("Cosmog used splash!")
await asyncio.sleep(1) # dont use time.sleep, causes blocking
await ctx.send("But nothing happened!")
@commands.command(name='teleport', help='Cosmog\'s second best attack!')
async def teleport(self, ctx):
await ctx.send("Cosmog used teleport!")
await ctx.send(file=discord.File('content/teleport.gif'))
await asyncio.sleep(2)
await ctx.send("Cosmog fled from battle!")
class Spreadsheets(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.group(name='doc', help='Gets the current league spreadsheet for both divisions', pass_context=True, invoke_without_command=True)
async def doc(self, ctx):
if ctx.invoked_subcommand is None:
await ctx.send('Solgaleo Division:\n<https://docs.google.com/spreadsheets/d/1LYqMD8aLMLdkVL1bDrmk5QYRoaFCr0zdJq4JQvIc6TA/edit#gid=253592106>\nLunala Division:\n<https://docs.google.com/spreadsheets/d/1L7_Vr7LMjmIC-zMY6YPTc31wVhjG_a1CkmzVONrvXdM/edit#gid=253592106>')
@doc.command(pass_context=True, name='solgaleo', help='Gets the Solgaleo division spreadsheet',)
async def doc_solgaleo(self, ctx):
await ctx.send('Solgaleo Division:\n<https://docs.google.com/spreadsheets/d/1LYqMD8aLMLdkVL1bDrmk5QYRoaFCr0zdJq4JQvIc6TA/edit#gid=253592106>')
@doc.command(pass_context=True, name='lunala', help='Gets the Lunala division spreadsheet')
async def doc_lunala(self, ctx):
await ctx.send('Lunala Division:\n<https://docs.google.com/spreadsheets/d/1L7_Vr7LMjmIC-zMY6YPTc31wVhjG_a1CkmzVONrvXdM/edit#gid=253592106>')
class TeamManagement(commands.Cog, name='Team Management'):
def __init__(self, bot):
self.bot = bot
@commands.command(name='support', help='Gives a user with no team the team role for the provided team')
async def support(self, ctx, *, args):
# Check for illegal roles
team_name = args
if team_name in ['MBTL Bronze Medalist', 'MBTL Silver Medalist', 'MBTL Gold Medalist', 'Bot']:
await ctx.send("Can't do that, this is a medalist role!")
return
# Check that team role exists
guild = ctx.message.guild
team_role = discord.utils.get(guild.roles, name=team_name)
if team_role is None:
await ctx.send("Could not find the specified team")
return
# Remove No Team role
no_team = discord.utils.get(guild.roles, name='No Team')
member = ctx.message.author
await member.remove_roles(no_team)
# Add team role
await member.add_roles(team_role)
await ctx.send(member.name + " is now supporting " + team_name + "!")
@commands.command(name='unsupport', help='Removes a team role from a user, wow harsh...')
async def unsupport(self, ctx, *, args):
# Check for illegal roles
team_name = args
if team_name in ['MBTL Bronze Medalist', 'MBTL Silver Medalist', 'MBTL Gold Medalist', 'Bot']:
await ctx.send("Can't do that, this is a medalist role!")
return
# Check that team role exists
guild = ctx.message.guild
team_role = discord.utils.get(guild.roles, name=team_name)
if team_role is None:
await ctx.send("Could not find the specified team")
return
# Remove team role
member = ctx.message.author
await member.remove_roles(team_role)
# Add No Team role
no_team = discord.utils.get(guild.roles, name='No Team')
await member.add_roles(no_team)
await ctx.send(member.name + " is no longer supporting " + team_name + "...")
@commands.command(name='createteam', help='Usage: .createteam @User, Hex, Team Name')
@commands.has_permissions(manage_roles=True)
async def createteam(self, ctx, *, message):
if not ctx.message.author.guild_permissions.administrator:
await ctx.send("Lacking sufficient privileges; not an Administrator")
return
# split message into individual arguments and format
args = message.split(',')
if len(args) < 3:
await ctx.send("Incorrect/missing arguments. Format should be '.createteam @User, Hex, Team Name")
return
user_id = int(args[0].strip()[3:-1])
hex_code = int(args[1].strip(), 16)
# remove only leading space
team_name = args[2]
if team_name[0] == ' ':
team_name = team_name[1:]
guild = ctx.message.guild
duplicate = discord.utils.get(guild.roles, name=team_name)
if duplicate is not None:
await ctx.send("This team already exists!")
return
# Create role with specified name and color
perms=discord.Permissions(administrator=False)
await guild.create_role(name=team_name, color=discord.Color(hex_code), permissions=perms)
# Remove No Team role from user using id
no_team = discord.utils.get(guild.roles, name='No Team')
member = guild.get_member(user_id)
await member.remove_roles(no_team)
# Add newly created role to user using id
team_role = discord.utils.get(guild.roles, name=team_name)
await member.add_roles(team_role)
output = "Team " + team_name + " has been created for Coach " + member.name +"!"
await ctx.send(output)