[V3] Change presence (continued fixes) (#1438)

* This better fixes the root issue rather than attempting to work around it

* move bot_in_guild to checks, and use the correct syntax
This commit is contained in:
Michael H 2018-03-20 20:12:40 -04:00 committed by Kowlin
parent 749af89e9f
commit 01b9843883
2 changed files with 17 additions and 12 deletions

View File

@ -54,6 +54,12 @@ def admin_or_permissions(**perms):
return commands.check(predicate) return commands.check(predicate)
def bot_in_a_guild(**kwargs):
async def predicate(ctx):
return len(ctx.bot.guilds) > 0
return commands.check(predicate)
def guildowner_or_permissions(**perms): def guildowner_or_permissions(**perms):
async def predicate(ctx): async def predicate(ctx):
has_perms_or_is_owner = await check_permissions(ctx, perms) has_perms_or_is_owner = await check_permissions(ctx, perms)

View File

@ -386,6 +386,7 @@ class Core:
await ctx.send(_("Done.")) await ctx.send(_("Done."))
@_set.command(name="game") @_set.command(name="game")
@checks.bot_in_a_guild()
@checks.is_owner() @checks.is_owner()
async def _game(self, ctx, *, game: str=None): async def _game(self, ctx, *, game: str=None):
"""Sets Red's playing status""" """Sets Red's playing status"""
@ -396,11 +397,11 @@ class Core:
game = None game = None
status = ctx.bot.guilds[0].me.status if len(ctx.bot.guilds) > 0 \ status = ctx.bot.guilds[0].me.status if len(ctx.bot.guilds) > 0 \
else discord.Status.online else discord.Status.online
for shard in ctx.bot.shards:
await ctx.bot.change_presence(status=status, activity=game) await ctx.bot.change_presence(status=status, activity=game)
await ctx.send(_("Game set.")) await ctx.send(_("Game set."))
@_set.command(name="listening") @_set.command(name="listening")
@checks.bot_in_a_guild()
@checks.is_owner() @checks.is_owner()
async def _listening(self, ctx, *, listening: str=None): async def _listening(self, ctx, *, listening: str=None):
"""Sets Red's listening status""" """Sets Red's listening status"""
@ -411,11 +412,11 @@ class Core:
activity = discord.Activity(name=listening, type=discord.ActivityType.listening) activity = discord.Activity(name=listening, type=discord.ActivityType.listening)
else: else:
activity = None activity = None
for shard in ctx.bot.shards:
await ctx.bot.change_presence(status=status, activity=activity) await ctx.bot.change_presence(status=status, activity=activity)
await ctx.send(_("Listening set.")) await ctx.send(_("Listening set."))
@_set.command(name="watching") @_set.command(name="watching")
@checks.bot_in_a_guild()
@checks.is_owner() @checks.is_owner()
async def _watching(self, ctx, *, watching: str=None): async def _watching(self, ctx, *, watching: str=None):
"""Sets Red's watching status""" """Sets Red's watching status"""
@ -426,11 +427,11 @@ class Core:
activity = discord.Activity(name=watching, type=discord.ActivityType.watching) activity = discord.Activity(name=watching, type=discord.ActivityType.watching)
else: else:
activity = None activity = None
for shard in ctx.bot.shards:
await ctx.bot.change_presence(status=status, activity=activity) await ctx.bot.change_presence(status=status, activity=activity)
await ctx.send(_("Watching set.")) await ctx.send(_("Watching set."))
@_set.command() @_set.command()
@checks.bot_in_a_guild()
@checks.is_owner() @checks.is_owner()
async def status(self, ctx, *, status: str): async def status(self, ctx, *, status: str):
"""Sets Red's status """Sets Red's status
@ -455,11 +456,11 @@ class Core:
except KeyError: except KeyError:
await ctx.send_help() await ctx.send_help()
else: else:
for shard in ctx.bot.shards:
await ctx.bot.change_presence(status=status, activity=game) await ctx.bot.change_presence(status=status, activity=game)
await ctx.send(_("Status changed to %s.") % status) await ctx.send(_("Status changed to %s.") % status)
@_set.command() @_set.command()
@checks.bot_in_a_guild()
@checks.is_owner() @checks.is_owner()
async def stream(self, ctx, streamer=None, *, stream_title=None): async def stream(self, ctx, streamer=None, *, stream_title=None):
"""Sets Red's streaming status """Sets Red's streaming status
@ -473,13 +474,11 @@ class Core:
if "twitch.tv/" not in streamer: if "twitch.tv/" not in streamer:
streamer = "https://www.twitch.tv/" + streamer streamer = "https://www.twitch.tv/" + streamer
activity = discord.Streaming(url=streamer, name=stream_title) activity = discord.Streaming(url=streamer, name=stream_title)
for shard in ctx.bot.shards:
await ctx.bot.change_presence(status=status, activity=activity) await ctx.bot.change_presence(status=status, activity=activity)
elif streamer is not None: elif streamer is not None:
await ctx.send_help() await ctx.send_help()
return return
else: else:
for shard in ctx.bot.shards:
await ctx.bot.change_presence(activity=None, status=status) await ctx.bot.change_presence(activity=None, status=status)
await ctx.send(_("Done.")) await ctx.send(_("Done."))