[V3 Tools] Account for activity types

command `uinfo` updated to now account for the different activity types
This commit is contained in:
James
2018-10-31 21:17:31 +13:00
committed by GitHub
parent c3ab361396
commit b82e4252cd

View File

@@ -21,6 +21,7 @@ class Tools(BaseCog):
self.bot = bot
async def _Tools__error(self, ctx, error):
return
if error.__cause__:
cause = error.__cause__
print(f"Tools Cog :: Error Occured ::\n{error}\n{cause}\n")
@@ -359,7 +360,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,26 +368,23 @@ 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"])
async def listchannel(self, ctx):
@commands.command(name='listchannel', aliases=['channellist'])
async def listchannels(self, ctx):
"""
List the channels of the current server
"""
@@ -394,17 +392,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,16 +685,20 @@ 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 user.activity.url is None:
if user.activity.type == discord.ActivityType.playing:
data += "[Playing]: {}\n".format(cf.escape(str(user.activity.name)))
elif user.activity.type == discord.ActivityType.listening:
data += "[Listening]: {}\n".format(cf.escape(str(user.activity.name)))
elif user.activity.type == discord.ActivityType.listening:
data += "[Watching]: {}\n".format(cf.escape(str(user.activity.name)))
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 += "[Streaming]: [{}]({})\n".format(
cf.escape(str(user.activity.name)), cf.escape(user.activity.url)
@@ -791,6 +791,7 @@ class Tools(BaseCog):
role = discord.utils.find(lambda r: r.name.lower() == str(rolename).lower(), roles)
return role
def sort_channels(self, channels):
temp = dict()
@@ -806,14 +807,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 []
@@ -825,14 +822,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):
@@ -841,7 +832,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'])