Merge pull request #29 from Sitryk/patch-2

[V3 Tools] Account for activity types
This commit is contained in:
aikaterna
2018-10-31 21:19:44 -07:00
committed by GitHub

View File

@@ -359,7 +359,7 @@ class Tools(BaseCog):
)
await awaiter.edit(embed=embed)
@commands.command(name="listguilds", aliases=["listservers", "guildlist", "serverlist"])
@commands.command(name='listguilds', aliases=['listservers', 'guildlist', 'serverlist'])
@checks.mod_or_permissions()
async def listguilds(self, ctx):
"""
@@ -367,25 +367,22 @@ class Tools(BaseCog):
"""
asciidoc = lambda m: "```asciidoc\n{}\n```".format(m)
guilds = sorted(self.bot.guilds, key=lambda g: -g.member_count)
header = ("```\n" "The bot is in the following {} server{}:\n" "```").format(
len(guilds), "s" if len(guilds) > 1 else ""
)
header = ("```\n"
"The bot is in the following {} server{}\n"
"```").format(len(guilds), 's' if len(guilds) > 1 else '')
max_zpadding = max([len(str(g.member_count)) for g in guilds])
form = "{gid} :: {mems:0{zpadding}} :: {name}"
all_forms = [
form.format(gid=g.id, mems=g.member_count, name=g.name, zpadding=max_zpadding)
for g in guilds
]
final = "\n".join(all_forms)
all_forms = [form.format(gid=g.id, mems=g.member_count, name=g.name, zpadding=max_zpadding) for g in guilds]
final = '\n'.join(all_forms)
await ctx.send(header)
for page in cf.pagify(final, delims=["\n"], shorten_by=16):
for page in cf.pagify(final, delims=['\n'], shorten_by=16):
await ctx.send(asciidoc(page))
@commands.guild_only()
@checks.mod_or_permissions(manage_channels=True)
@commands.command(name="listchannel", aliases=["channellist"])
@commands.command(name='listchannel', aliases=['channellist'])
async def listchannel(self, ctx):
"""
List the channels of the current server
@@ -394,17 +391,15 @@ class Tools(BaseCog):
channels = ctx.guild.channels
top_channels, category_channels = self.sort_channels(ctx.guild.channels)
topChannels_formed = "\n".join(self.channels_format(top_channels))
categories_formed = "\n\n".join([self.category_format(tup) for tup in category_channels])
topChannels_formed = '\n'.join(self.channels_format(top_channels))
categories_formed = '\n\n'.join([self.category_format(tup) for tup in category_channels])
await ctx.send(
f"{ctx.guild.name} has {len(channels)} channel{'s' if len(channels) > 1 else ''}."
)
await ctx.send(f"{ctx.guild.name} has {len(channels)} channel{'s' if len(channels) > 1 else ''}.")
for page in cf.pagify(topChannels_formed, delims=["\n"], shorten_by=16):
for page in cf.pagify(topChannels_formed, delims=['\n'], shorten_by=16):
await ctx.send(asciidoc(page))
for page in cf.pagify(categories_formed, delims=["\n\n"], shorten_by=16):
for page in cf.pagify(categories_formed, delims=['\n\n'], shorten_by=16):
await ctx.send(asciidoc(page))
@commands.guild_only()
@@ -689,10 +684,24 @@ class Tools(BaseCog):
data += "[ID]: {}\n".format(user.id)
data += "[Status]: {}\n".format(user.status)
data += "[Servers]: {} shared\n".format(seen)
if user.activity is None:
act = user.activity
if act is None:
pass
elif act.type == discord.ActivityType.playing:
data += "[Playing]: {}\n".format(cf.escape(str(act.name)))
elif act.type == discord.ActivityType.listening:
if isinstance(act, discord.Spotify):
_form = act.title
else:
_form = act.name
data += "[Listening]: {}\n".format(cf.escape(_form))
elif act.type == discord.ActivityType.listening:
data += "[Watching]: {}\n".format(cf.escape(str(user.activity.name)))
else:
data += "[Playing]: {}\n".format(cf.escape(str(user.activity.name)))
data += "[Streaming]: [{}]({})\n".format(
cf.escape(str(user.activity.name)), cf.escape(user.activity.url)
)
passed = (ctx.message.created_at - user.created_at).days
data += "[Created]: {}\n".format(self._dynamic_time(user.created_at))
joined_at = self.fetch_joined_at(user, ctx.guild)
@@ -796,14 +805,10 @@ class Tools(BaseCog):
channels.pop(channels.index(c))
temp[c.category].append(c)
category_channels = sorted(
[(cat, sorted(chans, key=lambda c: c.position)) for cat, chans in temp.items()],
key=lambda t: t[0].position,
)
category_channels = sorted([(cat, sorted(chans, key=lambda c: c.position)) for cat, chans in temp.items()], key=lambda t: t[0].position)
return channels, category_channels
def channels_format(self, channels: list):
if channels == []:
return []
@@ -815,14 +820,8 @@ class Tools(BaseCog):
name_justify = max([len(c.name[:24]) for c in channels])
type_justify = max([len(type_name(c)) for c in channels])
return [
channel_form.format(
name=c.name[:24].ljust(name_justify),
ctype=type_name(c).ljust(type_justify),
cid=c.id,
)
for c in channels
]
return [channel_form.format(name=c.name[:24].ljust(name_justify), ctype=type_name(c).ljust(type_justify), cid=c.id) for c in channels]
def category_format(self, cat_chan_tuple: tuple):
@@ -831,7 +830,7 @@ class Tools(BaseCog):
chfs = self.channels_format(chs)
if chfs != []:
ch_forms = ["\t" + f for f in chfs]
return "\n".join([f"{cat.name} :: {cat.id}"] + ch_forms)
ch_forms = ['\t' + f for f in chfs]
return '\n'.join([f'{cat.name} :: {cat.id}'] + ch_forms)
else:
return "\n".join([f"{cat.name} :: {cat.id}"] + ["\tNo Channels"])
return '\n'.join([f'{cat.name} :: {cat.id}'] + ['\tNo Channels'])