Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def help_embed_all(self, prefix, commands):
"""Create an embed message that displays command help"""
help = discord.Embed(title="Available Commands", color=constants.BLUE)
help.description = ("**Note:** don't include the angled brackets\n"
+ "For additional help, join the support server: https://discord.gg/ZqkjJEa")
help.set_footer(text="Use {}help [command] for more info on a command".format(prefix))
for command in commands:
if command.hidden:
continue
signature = self.get_command_signature(prefix, command)
help.add_field(name="{}".format(signature), value="{}".format(command.help.split('\n')[0]), inline=False)
return help
e.set_thumbnail(url=BASE_URL + item['displayProperties']['icon'])
# Set embed color based on item rarity
item_rarity = int(item['inventory']['tierType'])
if item_rarity == 2:
e.color = discord.Color.light_grey()
elif item_rarity == 3:
e.color = discord.Color.dark_green()
elif item_rarity == 4:
e.color = discord.Color.blue()
elif item_rarity == 5:
e.color = discord.Color.dark_purple()
elif item_rarity == 6:
e.color = discord.Color.gold()
else:
e.color = constants.BLUE
# Add armor/weapon specific information
if item['itemType'] == 3:
e = self.embed_weapon(e, item)
e = await self.embed_perks(e, item, 4241085061)
else:
e = self.embed_armor(e, item)
e = await self.embed_perks(e, item, 2518356196)
paginator.add_embed(e)
if not paginator.length:
await manager.send_message("I didn't find any items that match your search.")
return await manager.clean_messages()
func = manager.clean_messages()
def pve_stats_embed(stats, display_name, platform_id):
e = discord.Embed(colour=constants.BLUE)
e.set_author(name="{} | PvE Stats".format(display_name), icon_url=constants.PLATFORM_URLS.get(platform_id))
e.add_field(name='Kills', value=stats.kills, inline=True)
e.add_field(name='Assists', value=stats.assists, inline=True)
e.add_field(name='Deaths', value=stats.deaths, inline=True)
e.add_field(name='Strikes', value=stats.strike_count, inline=True)
e.add_field(name='Nightfalls', value=stats.nightfall_count, inline=True)
e.add_field(name='Fastest Nightfall', value=stats.fastest_nightfall, inline=True)
e.add_field(name='Public Events', value=stats.event_count, inline=True)
e.add_field(name='Heroic Public Events', value=stats.heroic_event_count, inline=True)
e.add_field(name='Favorite Weapon', value=stats.best_weapon, inline=True)
e.add_field(name='Total Raid Time', value=stats.raid_time, inline=True)
e.add_field(name='Raids', value=stats.raid_count, inline=True)
e.add_field(name='Time Played', value=stats.time_played, inline=True)
return e
def display_startup_info(self):
print('Spirit v{}'.format(constants.VERSION))
print('Username: {}'.format(self.bot.user.name))
print('------')
e.description = "Please select your preferred platform. You can always change it by registering again!"
else:
e.description = "As you have only one connected account, it has been set as your preferred platform."
# If a preferred platform is already set, display it in bold
if platform == 4:
bliz_name = "**{}**".format(bliz_name)
elif platform == 1:
xbox_name = "**{}**".format(xbox_name)
elif platform == 2:
psn_name = "**{}**".format(psn_name)
# Display connected accounts
accounts = ""
accounts += "{} {}\n".format(str(self.bot.get_emoji(constants.BNET_ICON)), bliz_name) if bliz_name else ''
accounts += "{} {}\n".format(str(self.bot.get_emoji(constants.XBOX_ICON)), xbox_name) if xbox_name else ''
accounts += "{} {}".format(str(self.bot.get_emoji(constants.PS_ICON)), psn_name) if psn_name else ''
e.add_field(name="Connected Accounts", value=accounts)
if footer:
e.set_footer(text="Your preferred platform has been set!")
return e
def embed_weapon(self, embed, item):
"""Add weapon specific attributes to item embed"""
damage_type = item['defaultDamageType']
if damage_type in (2,3,4):
item_name = item['displayProperties']['name']
embed.set_author(name=item_name, icon_url=constants.ELEMENTS.get(damage_type))
stats = item['stats']['stats']
# Basic info field
info_field = ""
if item.get('itemTypeDisplayName'):
wep_type = item['itemTypeDisplayName']
info_field += "\nType: {}".format(wep_type)
if stats.get('1480404414'):
min_attack = stats['1480404414']['minimum']
max_attack = stats['1480404414']['maximum']
info_field += "\nAttack: {}-{}".format(min_attack, max_attack) if (min_attack and max_attack) else "\u200B"
if stats.get('3871231066'):
magazine = stats['3871231066']['value']
info_field += "\nMagazine: {}".format(magazine)
if stats.get('4284893193'):
async def countdown(self, ctx):
"""Show time until upcoming Destiny 2 releases"""
manager = MessageManager(ctx)
pst_now = datetime.now(tz=pytz.timezone('US/Pacific'))
text = ""
for name, date in constants.RELEASE_DATES:
diff = date - pst_now
days = diff.days + 1
if days == 0:
text += "{}: Today!\n".format(name)
elif days == 1:
text += "{}: Tomorrow!\n".format(name)
elif days > 1:
text += "{}: {} days\n".format(name, days)
if not text:
text = "There are no concrete dates for our next adventure..."
countdown = discord.Embed(title="Destiny 2 Countdown", color=constants.BLUE)
countdown.description = text
await manager.send_embed(countdown)
await manager.clean_messages()
def create_event_embed(self, guild, event):
"""Create and return a Discord Embed object that represents an upcoming event"""
title = event.get('event_title')
description = event.get('description')
time = event.get('start_time')
timezone = event.get('timezone')
creator_id = event.get('user_id')
accepted = event.get('accepted')
declined = event.get('declined')
maybe = event.get('maybe')
max_members = event.get('max_members')
embed_msg = discord.Embed(color=constants.BLUE)
embed_msg.title = title
creator = guild.get_member(creator_id)
if creator:
embed_msg.set_footer(text="Created by {} | React with {} to remove this event".format(creator.display_name, '\U0001f480'))
else:
embed_msg.set_footer(text="React with {} to remove this event".format('\U0001f480'))
if description:
embed_msg.description = description
time_str = time.strftime("%A %b %-d, %Y @ %-I:%M %p")
embed_msg.add_field(name="Time", value=time_str + " " + timezone, inline=False)
if accepted:
accepted_list = None
if max_members:
async def pm(self, ctx, user_id: int, *message):
"""Send a PM via the bot to a user given their ID"""
manager = MessageManager(ctx)
user = self.bot.get_user(user_id)
if ctx.author.id not in constants.MODS:
return
if len(message) == 0:
await manager.send_message("You forgot to include your message!")
return await manager.clean_messages()
response = "You have received a message from my developer:\n\n**"
for word in message:
response += "{} ".format(word)
response += ("**\n\nYour response will not be tracked here. If you wish "
+ "to speak with him further, join the official **{} Support** "
+ "server - https://discord.gg/GXCFpkr").format(self.bot.user.name)
try:
await user.send(response)
except:
"""Register your Destiny 2 account with the bot
This command will let the bot know which Destiny 2 profile to associate with your Discord
profile. Registering is a prerequisite to using any commands that require knowledge of your
Destiny 2 profile.
"""
manager = MessageManager(ctx)
template = "https://www.bungie.net/en/OAuth/Authorize?client_id={}&response_type=code&state={}"
auth_url = template.format(self.bot.bungie_client_id, ctx.author.id)
bliz_name, xbox_name, psn_name, bliz_id, xbox_id, psn_id = (None,)*6
if not isinstance(ctx.channel, discord.abc.PrivateChannel):
await manager.send_message("Registration instructions have been messaged to you.")
# Prompt user with link to Bungie.net OAuth authentication
e = discord.Embed(colour=constants.BLUE)
e.title = "Click Here to Register"
e.url = auth_url
e.description = ("Click the above link to register your Bungie.net account with Spirit. "
+ "Registering will allow Spirit to access your connected Destiny "
+ "2 accounts.")
registration_msg = await manager.send_private_embed(e)
# Wait for user info from the web server via Redis
res = await self.redis.subscribe(ctx.author.id)
tsk = asyncio.ensure_future(self.wait_for_msg(res[0]))
try:
user_info = await asyncio.wait_for(tsk, timeout=120)
except asyncio.TimeoutError:
await manager.send_private_message("I'm not sure where you went. We can try this again later.")
await registration_msg.delete()
return await manager.clean_messages()