Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@commands.Cog.listener()
async def on_member_join(self, member):
"""Actually adds the autoassign roles."""
autoassign_roles = []
autoassign_role_ids = await \
self.bot.pg_utils.get_autoassign_roles(member.guild.id)
if not autoassign_role_ids:
return
for role in member.guild.roles:
if role.id in autoassign_role_ids:
autoassign_roles.append(role)
await member.add_roles(*autoassign_roles)
@commands.Cog.listener()
async def on_ready(self):
if not os.path.exists('./tmp/'):
os.mkdir('./tmp/', mode=0o755)
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
if message.guild is not None or len(message.content) > 1800 or message.author.id == self.bot.user.id:
return
ctx: commands.Context = await self.bot.get_context(message)
if ctx.command is None:
channel = self.bot.get_channel(Configuration.get_master_var("inbox", 0))
if channel is not None:
await channel.send(f"[`{message.created_at.strftime('%c')}`] {message.author} (`{message.author.id}`) said: {message.clean_content}")
for attachement in message.attachments:
await channel.send(attachement.url)
@Cog.listener()
async def on_message(self, message: Message) -> None:
"""Check new message event for messages to the checkpoint channel & process."""
if message.channel.id != Channels.verification:
return # Only listen for #checkpoint messages
if message.author.bot:
# They're a bot, delete their message after the delay.
# But not the periodic ping; we like that one.
if message.content != PERIODIC_PING:
await message.delete(delay=BOT_MESSAGE_DELETE_DELAY)
return
# if a user mentions a role or guild member
# alert the mods in mod-alerts channel
if message.mentions or message.role_mentions:
log.debug(
@commands.Cog.listener()
async def on_message(self, message):
log.debug("message from {0!r} in channel {1!r}.".format(message.author, message.channel))
a, b, c, d = (
not message.content.startswith('"'),
message.author.id in self.always_speak_users_by_channel[message.channel.id],
message.author.voice is not None and message.author.voice.channel is not None,
message.author != self.bot.user,
)
log.debug("always speak bools are: {} {} {} {}".format(a, b, c, d))
if a and b and c and d:
log.debug("Always speaking for {}".format(message.author))
await self.speak_aloud(message, message.content)
@commands.Cog.listener()
async def on_ready(self):
asyncio.create_task(self._cache_data())
@Cog.listener()
async def on_message_discarded(self, message):
''' Trigger the calculator when the message is prefixed by "==" '''
async def send(*args, **kwargs):
msg = await message.channel.send(*args, **kwargs)
await core.blame.set_blame(self.bot.keystore, msg, message.author)
return msg
arg = message.content
if len(arg) > 2 and \
arg.startswith('==') and \
arg[2] not in '=<>+*/!@#$%^&' and \
'results from bdsmtest.org' not in arg.lower() and \
await self.bot.settings.resolve_message('f-calc-shortcut', message):
if not await self.bot.settings.resolve_message('c-calc', message):
raise core.settings.DisabledCommandByServerOwner
await self.perform_calculation(arg.strip()[2:], message, send)
@commands.Cog.listener()
async def on_unloaded_extension(self, ext):
# Called to shut things down
if not self._is_submodule(ext.__name__, self.__module__):
return
self.is_current = False
for task in self.loop_list:
task.cancel()
@commands.Cog.listener()
async def on_loaded_extension(self, ext):
# See if we were loaded
if not self._is_submodule(ext.__name__, self.__module__):
return
self.bot.loop.create_task(self.start_loading())
@Cog.listener()
async def on_message(self, msg: Message) -> None:
"""
Detect poorly formatted Python code in new messages.
If poorly formatted code is detected, send the user a helpful message explaining how to do
properly formatted Python syntax highlighting codeblocks.
"""
parse_codeblock = (
(
msg.channel.id in self.channel_cooldowns
or msg.channel.id in self.channel_whitelist
)
and not msg.author.bot
and len(msg.content.splitlines()) > 3
)