[V3] Re-allow using presence modifying commands without being in a guild (#1345)

Actually update on all shards (we need to do this even with autoshardedbot as base)
This commit is contained in:
Michael H 2018-02-26 01:10:59 -05:00 committed by palmtree5
parent e13de0950c
commit 09ddfe4250

View File

@ -376,51 +376,45 @@ class Core:
@_set.command(name="game") @_set.command(name="game")
@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"""
Can only be run if the bot is in a server."""
if len(ctx.bot.guilds) == 0:
await ctx.send_help()
return
status = ctx.bot.guilds[0].me.status
if game: if game:
game = discord.Game(name=game) game = discord.Game(name=game)
else: else:
game = None game = None
status = ctx.bot.guilds[0].me.status if len(ctx.bot.guilds) > 0 \
else discord.Status.online
for shard in ctx.bot.shards:
await ctx.bot.change_presence(status=status, game=game) await ctx.bot.change_presence(status=status, game=game)
await ctx.send(_("Game set.")) await ctx.send(_("Game set."))
@_set.command(name="listening") @_set.command(name="listening")
@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"""
Can only be run if the bot is in a server.""" status = ctx.bot.guilds[0].me.status if len(ctx.bot.guilds) > 0 \
if len(ctx.bot.guilds) == 0: else discord.Status.online
await ctx.send_help()
return
status = ctx.bot.guilds[0].me.status
if listening: if listening:
listening = discord.Game(name=listening, type=2) listening = discord.Game(name=listening, type=2)
else: else:
listening = None listening = None
for shard in ctx.bot.shards:
await ctx.bot.change_presence(status=status, game=listening) await ctx.bot.change_presence(status=status, game=listening)
await ctx.send(_("Listening set.")) await ctx.send(_("Listening set."))
@_set.command(name="watching") @_set.command(name="watching")
@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"""
Can only be run if the bot is in a server.""" status = ctx.bot.guilds[0].me.status if len(ctx.bot.guilds) > 0 \
if len(ctx.bot.guilds) == 0: else discord.Status.online
await ctx.send_help()
return
status = ctx.bot.guilds[0].me.status
if watching: if watching:
watching = discord.Game(name=watching, type=3) watching = discord.Game(name=watching, type=3)
else: else:
watching = None watching = None
for shard in ctx.bot.shards:
await ctx.bot.change_presence(status=status, game=watching) await ctx.bot.change_presence(status=status, game=watching)
await ctx.send(_("Watching set.")) await ctx.send(_("Watching set."))
@ -434,8 +428,7 @@ class Core:
idle idle
dnd dnd
invisible invisible
"""
Can only be run if the bot is in a server."""
statuses = { statuses = {
"online": discord.Status.online, "online": discord.Status.online,
@ -444,18 +437,14 @@ class Core:
"invisible": discord.Status.invisible "invisible": discord.Status.invisible
} }
if len(ctx.bot.guilds) == 0: game = ctx.bot.guilds[0].me.game if len(ctx.bot.guilds) > 0 else None
await ctx.send_help()
return
game = ctx.bot.guilds[0].me.game
try: try:
status = statuses[status.lower()] status = statuses[status.lower()]
except KeyError: except KeyError:
await ctx.send_help() await ctx.send_help()
else: else:
await ctx.bot.change_presence(status=status, for shard in ctx.bot.shards:
game=game) await ctx.bot.change_presence(status=status, game=game)
await ctx.send(_("Status changed to %s.") % status) await ctx.send(_("Status changed to %s.") % status)
@_set.command() @_set.command()
@ -464,21 +453,21 @@ class Core:
"""Sets Red's streaming status """Sets Red's streaming status
Leaving both streamer and stream_title empty will clear it.""" Leaving both streamer and stream_title empty will clear it."""
if len(ctx.bot.guilds) == 0: status = ctx.bot.guilds[0].me.status \
await ctx.send_help() if len(ctx.bot.guilds) > 0 else None
return
status = ctx.bot.guilds[0].me.status
if stream_title: if stream_title:
stream_title = stream_title.strip() stream_title = stream_title.strip()
if "twitch.tv/" not in streamer: if "twitch.tv/" not in streamer:
streamer = "https://www.twitch.tv/" + streamer streamer = "https://www.twitch.tv/" + streamer
game = discord.Game(type=1, url=streamer, name=stream_title) game = discord.Game(type=1, url=streamer, name=stream_title)
await ctx.bot.change_presence(game=game, status=status) for shard in ctx.bot.shards:
await ctx.bot.change_presence(status=status, game=game)
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(game=None, status=status) await ctx.bot.change_presence(game=None, status=status)
await ctx.send(_("Done.")) await ctx.send(_("Done."))