Skip to content
This repository was archived by the owner on Oct 18, 2020. It is now read-only.

Commit 0f1e756

Browse files
committed
add custom check is_owner_or_to
1 parent d5eabb8 commit 0f1e756

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

bot.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# Custom modules
1111
from utils.json_hooks import dateconverter, dateparser, int_keys
12-
from utils.command_checks import tournament_is_pending, tournament_is_underway, tournament_is_underway_or_pending, in_channel, is_streaming
12+
from utils.command_checks import tournament_is_pending, tournament_is_underway, tournament_is_underway_or_pending, in_channel, is_streaming, is_owner_or_to
1313
from utils.stream import is_on_stream, is_queued_for_stream
1414
from utils.rounds import is_top8, nom_round
1515
from utils.game_specs import get_access_stream
@@ -139,7 +139,7 @@ async def init_tournament(url_or_id):
139139

140140
### Ajouter un tournoi
141141
@bot.command(name='setup')
142-
@commands.has_role(to_id)
142+
@commands.check(is_owner_or_to)
143143
async def setup_tournament(ctx, arg):
144144

145145
if re.compile(r"^(https?\:\/\/)?(challonge.com)\/.+$").match(arg):
@@ -218,7 +218,7 @@ async def auto_setup_tournament():
218218

219219
### Démarrer un tournoi
220220
@bot.command(name='start')
221-
@commands.has_role(to_id)
221+
@commands.check(is_owner_or_to)
222222
@commands.check(tournament_is_pending)
223223
async def start_tournament(ctx):
224224
with open(tournoi_path, 'r+') as f: tournoi = json.load(f, object_hook=dateparser)
@@ -280,7 +280,7 @@ async def start_tournament(ctx):
280280

281281
### Terminer un tournoi
282282
@bot.command(name='end')
283-
@commands.has_role(to_id)
283+
@commands.check(is_owner_or_to)
284284
@commands.check(tournament_is_underway)
285285
async def end_tournament(ctx):
286286
with open(tournoi_path, 'r+') as f: tournoi = json.load(f, object_hook=dateparser)
@@ -747,7 +747,7 @@ async def flipcoin(ctx):
747747

748748
### Ajout manuel
749749
@bot.command(name='add')
750-
@commands.has_role(to_id)
750+
@commands.check(is_owner_or_to)
751751
@commands.check(tournament_is_pending)
752752
async def add_inscrit(ctx):
753753
for member in ctx.message.mentions:
@@ -757,7 +757,7 @@ async def add_inscrit(ctx):
757757

758758
### Suppression/DQ manuel
759759
@bot.command(name='rm')
760-
@commands.has_role(to_id)
760+
@commands.check(is_owner_or_to)
761761
@commands.check(tournament_is_underway_or_pending)
762762
async def remove_inscrit(ctx):
763763
for member in ctx.message.mentions:
@@ -1624,7 +1624,7 @@ async def send_help(ctx):
16241624

16251625
### Set preference
16261626
@bot.command(name='set', aliases=['turn'])
1627-
@commands.has_role(to_id)
1627+
@commands.check(is_owner_or_to)
16281628
async def set_preference(ctx, arg1, arg2):
16291629
with open(preferences_path, 'r+') as f: preferences = yaml.full_load(f)
16301630

@@ -1655,7 +1655,7 @@ async def set_preference(ctx, arg1, arg2):
16551655

16561656
### See preferences
16571657
@bot.command(name='settings', aliases=['preferences', 'config'])
1658-
@commands.has_role(to_id)
1658+
@commands.check(is_owner_or_to)
16591659
async def check_settings(ctx):
16601660
with open(preferences_path, 'r+') as f: preferences = yaml.full_load(f)
16611661

utils/command_checks.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ async def predicate(ctx):
3939
return True
4040
return commands.check(predicate)
4141

42+
# Is owner or TO
43+
async def is_owner_or_to(ctx):
44+
return to_id in [y.id for y in ctx.author.roles] or await ctx.bot.is_owner(ctx.author)
45+
4246
# Is streaming?
4347
def is_streaming(ctx):
4448
with open(stream_path, 'r+') as f: stream = json.load(f, object_pairs_hook=int_keys)

0 commit comments

Comments
 (0)