Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, bot):
self.bot = bot
self.splat2_data = config.Config('splatoon2.json', loop=bot.loop,
object_hook=splatoon2_decoder, encoder=Splatoon2Encoder)
self.map_data = []
self._splatnet2 = bot.loop.create_task(self.splatnet2())
self._authenticator = bot.loop.create_task(self.splatnet2_authenticator())
self._is_authenticated = asyncio.Event(loop=bot.loop)
# mode: List[Rotation]
self.sp2_map_data = {}
self.sp2_shop = []
self.sp2_festival = None
self.sp2_salmonrun = []
self.prefixes = defaultdict(lambda: list(config.command_prefix))
def get_voc_emoji(vocation: str) -> str:
"""Given a vocation name, returns a emoji representing it"""
vocation = str(vocation)
emoji = {"none": config.novoc_emoji, "druid": config.druid_emoji, "sorcerer": config.sorcerer_emoji,
"paladin": config.paladin_emoji, "knight": config.knight_emoji, "elder druid": config.druid_emoji,
"master sorcerer": config.sorcerer_emoji, "royal paladin": config.paladin_emoji,
"elite knight": config.knight_emoji}
try:
return emoji[vocation.lower()]
except KeyError:
return "❓"
server in [s.id for s in user_guilds]]
else:
display_name = f'@{user.display_name}'
embed.colour = user.colour
if ctx.world:
user_tibia_worlds = [ctx.world]
embed.set_thumbnail(url=user.avatar_url)
characters = await DbChar.get_chars_by_user(ctx.pool, user.id, worlds=user_tibia_worlds)
if not characters:
embed.description = f"**{display_name}** has no registered characters here."
return embed
characters.sort(key=lambda c: c.level, reverse=True)
online_list = [x.name for k, v in online_characters.items() if k in user_tibia_worlds for x in v]
char_list = []
for char in characters:
online = config.online_emoji if char.name in online_list else ""
voc_abb = get_voc_abb(char.vocation)
if len(characters) <= 10:
char_list.append(f"[{char.name}]({char.url}){online} (Lvl {abs(char.level)} {voc_abb})")
else:
char_list.append(f"**{char.name}**{online} (Lvl {abs(char.level)} {voc_abb})")
plural = "s are" if len(char_list) > 1 else " is"
embed.description = f"**{display_name}**'s character{plural}: {join_list(char_list, ', ', ' and ')}"
return embed
def get_voc_emoji(vocation: str) -> str:
"""Given a vocation name, returns a emoji representing it"""
vocation = str(vocation)
emoji = {"none": config.novoc_emoji, "druid": config.druid_emoji, "sorcerer": config.sorcerer_emoji,
"paladin": config.paladin_emoji, "knight": config.knight_emoji, "elder druid": config.druid_emoji,
"master sorcerer": config.sorcerer_emoji, "royal paladin": config.paladin_emoji,
"elite knight": config.knight_emoji}
try:
return emoji[vocation.lower()]
except KeyError:
return "❓"
"world": {"title": "🌐 World", "check": lambda ctx: ctx.guild.id not in config.lite_servers},
"newschannel": {"title": "📰 News channel"},
def __init__(self):
super().__init__(command_prefix=_prefix_callable, case_insensitive=True, fetch_offline_members=True,
description="Discord bot with functions for the MMORPG Tibia.")
# Remove default help command to implement custom one
self.remove_command("help")
self.users_servers = defaultdict(list)
self.config: config.Config = None
self.pool: asyncpg.pool.Pool = None
self.start_time = dt.datetime.utcnow()
self.session = aiohttp.ClientSession(loop=self.loop)
# Dictionary of worlds tracked by nabbot, key:value = server_id:world
# Dictionary is populated from database
# A list version is created from the dictionary
self.tracked_worlds = {}
self.tracked_worlds_list = []
self.prefixes = defaultdict()
self.__version__ = "2.4.0"
for member in guild.members:
if member.id in self.bot.users_servers:
self.bot.users_servers[member.id].append(guild.id)
else:
self.bot.users_servers[member.id] = [guild.id]
# Update database member list
async with self.bot.pool.acquire() as conn:
async with conn.transaction():
# Make sure there's no leftover data that will make the copy query fail
await conn.execute("DELETE FROM user_server WHERE server_id = $1", guild.id)
records = [(user.id, guild.id) for user in guild.members]
await conn.copy_records_to_table("user_server", columns=["user_id", "server_id"], records=records)
await conn.execute("INSERT INTO server_history(server_id, server_count, event_type) VALUES($1, $2, $3)",
guild.id, len(self.bot.guilds), "add")
# Show opening message
message = f"Hi, I've been added to this server. Some things you should know:\n" \
f"‣ My command prefix is: `{config.command_prefix[0]}` (it is customizable)\n" \
f"‣ You can see all my commands with: `{config.command_prefix[0]}help` or " \
f"`{config.command_prefix[0]}commands`\n" \
f"‣ You can configure me using: `{config.command_prefix[0]}settings`\n" \
f"‣ You can set a world for me to track by using `{config.command_prefix[0]}settings world`\n" \
f"‣ If you want a logging channel, create a channel named `{config.log_channel_name}`\n" \
f"‣ If you need help, join my support server: ****\n" \
f"‣ For more information and links in: `{config.command_prefix[0]}about`"
try:
channel = self.bot.get_top_channel(guild)
if channel is None:
log.warning(f"{self.tag} Could not send join message on server: {guild.name}."
f"No allowed channel found.")
return
await channel.send(message)
except discord.HTTPException:
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.pool: asyncpg.pool.Pool = self.bot.pool
self.session: aiohttp.ClientSession = self.bot.session
self.yes_no_reactions = ("🇾", "🇳")
self.check_reactions = (config.true_emoji, config.false_emoji)