Minor changes and fixes, re-apply temproles after re-join

This commit is contained in:
Zeva Rose 2023-03-06 17:07:55 +00:00 committed by Zevaryx
parent ec14506634
commit 6c73e0df48
6 changed files with 76 additions and 25 deletions

View file

@ -3,7 +3,7 @@ import asyncio
from aiohttp import ClientSession from aiohttp import ClientSession
from beanie.operators import Set from beanie.operators import Set
from interactions import listen from interactions import listen, Intents
from interactions.ext.prefixed_commands.context import PrefixedContext from interactions.ext.prefixed_commands.context import PrefixedContext
from interactions.models.discord.channel import DMChannel from interactions.models.discord.channel import DMChannel
from interactions.models.discord.embed import EmbedField from interactions.models.discord.embed import EmbedField
@ -28,10 +28,6 @@ class EventMixin(MemberEventMixin, MessageEventMixin, ComponentEventMixin):
async def _chunk_all(self) -> None: async def _chunk_all(self) -> None:
"""Chunk all guilds.""" """Chunk all guilds."""
self.logger.warn("Deprecated function, nothing will happen") self.logger.warn("Deprecated function, nothing will happen")
# for guild in self.guilds:
# if not guild.chunked.is_set():
# self.logger.debug(f"Chunking guild {guild.name} <{guild.id}>")
# await guild.chunk_guild()
async def _sync_domains(self) -> None: async def _sync_domains(self) -> None:
self.logger.debug("Loading phishing domains") self.logger.debug("Loading phishing domains")
@ -176,7 +172,9 @@ class EventMixin(MemberEventMixin, MessageEventMixin, ComponentEventMixin):
embed.set_author( embed.set_author(
name=ctx.author.username, icon_url=ctx.author.display_avatar.url name=ctx.author.username, icon_url=ctx.author.display_avatar.url
) )
embed.set_footer(text=f"{ctx.author.user.username} | {ctx.author.id}") embed.set_footer(
text=f"{ctx.author.user.username}#{ctx.author.discriminator} | {ctx.author.id}"
)
if channel: if channel:
await channel.send(embeds=embed) await channel.send(embeds=embed)
else: else:

View file

@ -7,7 +7,7 @@ from interactions.client.utils.misc_utils import get
from interactions.models.discord.embed import Embed, EmbedField from interactions.models.discord.embed import Embed, EmbedField
from interactions.models.discord.enums import AuditLogEventType from interactions.models.discord.enums import AuditLogEventType
from interactions.models.discord.user import Member from interactions.models.discord.user import Member
from jarvis_core.db.models import Setting from jarvis_core.db.models import Setting, Temprole
from jarvis.utils import build_embed from jarvis.utils import build_embed
@ -20,19 +20,41 @@ class MemberEventMixin:
"""Handle on_member_add event.""" """Handle on_member_add event."""
user = event.member user = event.member
guild = event.guild guild = event.guild
unverified = await Setting.find_one(Setting.guild == guild.id, Setting.setting == "unverified") unverified = await Setting.find_one(
Setting.guild == guild.id, Setting.setting == "unverified"
)
temproles = await Temprole.find(
Temprole.guild == guild.id, Temprole.user == user.id
).to_list()
if unverified: if unverified:
self.logger.debug(f"Applying unverified role to {user.id} in {guild.id}") self.logger.debug(f"Applying unverified role to {user.id} in {guild.id}")
role = await guild.fetch_role(unverified.value) role = await guild.fetch_role(unverified.value)
if role not in user.roles: if not role:
self.logger.warn(
f"Unverified role no longer exists for guild {guild.id}"
)
await settings.delete()
elif role not in user.roles:
await user.add_role(role, reason="User just joined and is unverified") await user.add_role(role, reason="User just joined and is unverified")
if temproles:
self.logger.debug(f"User {user.id} still has temprole(s) in {guild.id}")
for temprole in temproles:
role = await guild.fetch_role(temprole.role)
if not role:
await temprole.delete()
elif role not in user.roles:
await user.add_role(
role, reason="User joined and has existing temprole"
)
@listen() @listen()
async def on_member_remove(self, event: MemberRemove) -> None: async def on_member_remove(self, event: MemberRemove) -> None:
"""Handle on_member_remove event.""" """Handle on_member_remove event."""
user = event.member user = event.member
guild = event.guild guild = event.guild
log = await Setting.find_one(Setting.guild == guild.id, Setting.setting == "activitylog") log = await Setting.find_one(
Setting.guild == guild.id, Setting.setting == "activitylog"
)
if log: if log:
self.logger.debug(f"User {user.id} left {guild.id}") self.logger.debug(f"User {user.id} left {guild.id}")
channel = await guild.fetch_channel(log.value) channel = await guild.fetch_channel(log.value)
@ -103,10 +125,7 @@ class MemberEventMixin:
async def process_rename(self, before: Member, after: Member) -> None: async def process_rename(self, before: Member, after: Member) -> None:
"""Process name change.""" """Process name change."""
if ( if before.nickname == after.nickname and before.username == after.username:
before.nickname == after.nickname
and before.username == after.username
):
return return
fields = ( fields = (
@ -132,21 +151,29 @@ class MemberEventMixin:
before = event.before before = event.before
after = event.after after = event.after
if (before.display_name == after.display_name and before.roles == after.roles) or (not after or not before): if (
before.display_name == after.display_name and before.roles == after.roles
) or (not after or not before):
return return
log = await Setting.find_one(Setting.guild == before.guild.id, Setting.setting == "activitylog") log = await Setting.find_one(
Setting.guild == before.guild.id, Setting.setting == "activitylog"
)
if log: if log:
channel = await before.guild.fetch_channel(log.value) channel = await before.guild.fetch_channel(log.value)
await asyncio.sleep(0.5) # Wait for audit log await asyncio.sleep(0.5) # Wait for audit log
embed = None embed = None
if before._role_ids != after._role_ids: if before._role_ids != after._role_ids:
verified = await Setting.find_one(Setting.guild == before.guild.id, Setting.setting == "verified") verified = await Setting.find_one(
Setting.guild == before.guild.id, Setting.setting == "verified"
)
v_role = None v_role = None
if verified: if verified:
v_role = await before.guild.fetch_role(verified.value) v_role = await before.guild.fetch_role(verified.value)
if not v_role: if not v_role:
self.logger.debug(f"Guild {before.guild.id} verified role no longer exists") self.logger.debug(
f"Guild {before.guild.id} verified role no longer exists"
)
await verified.delete() await verified.delete()
else: else:
if not before.has_role(v_role) and after.has_role(v_role): if not before.has_role(v_role) and after.has_role(v_role):

View file

@ -132,6 +132,8 @@ class MessageEventMixin:
await message.channel.send(embeds=embed) await message.channel.send(embeds=embed)
except Exception: except Exception:
self.logger.warn("Failed to send warning embed") self.logger.warn("Failed to send warning embed")
if re.match("\b(?!dbrand)([Dd][Bb][Rr][Aa][Nn][Dd])\b", message.content):
await message.reply("*dbrand")
async def filters(self, message: Message) -> None: async def filters(self, message: Message) -> None:
"""Handle filter evennts.""" """Handle filter evennts."""
@ -598,7 +600,7 @@ class MessageEventMixin:
not ignore or (ignore and message.channel.id not in ignore.value) not ignore or (ignore and message.channel.id not in ignore.value)
): ):
try: try:
content = message.content or "N/A" content = message.content or message.system_content or "N/A"
except AttributeError: except AttributeError:
content = "N/A" content = "N/A"
fields = [EmbedField("Original Message", content, False)] fields = [EmbedField("Original Message", content, False)]

View file

@ -43,7 +43,7 @@ JARVIS_LOGO = Image.open("jarvis_small.png").convert("RGBA")
RESPONSES = { RESPONSES = {
264072583987593217: "Oh fuck no, go fuck yourself", 264072583987593217: "Oh fuck no, go fuck yourself",
840031256201003008: "https://tenor.com/view/fluffy-gabriel-iglesias-you-need-jesus-thats-what-you-need-pointing-up-gif-16385108", 840031256201003008: "https://tenor.com/view/fluffy-gabriel-iglesias-you-need-jesus-thats-what-you-need-pointing-up-gif-16385108",
215564028615852033: "As flattered as I am, I'm not into bestiality", 215564028615852033: "Last time you offered, we ended up playing board games instead. No thanks",
256110768724901889: "Haven't you broken me enough already?", 256110768724901889: "Haven't you broken me enough already?",
196018858455334912: "https://www.youtube.com/watch?v=ye5BuYf8q4o", 196018858455334912: "https://www.youtube.com/watch?v=ye5BuYf8q4o",
169641326927806464: "I make it a habit to not get involved with people who use robot camoflauge to hide from me", 169641326927806464: "I make it a habit to not get involved with people who use robot camoflauge to hide from me",
@ -77,6 +77,32 @@ class UtilCog(Extension):
bot = SlashCommand(name="bot", description="Bot commands") bot = SlashCommand(name="bot", description="Bot commands")
@bot.subcommand(
sub_cmd_name="donate", sub_cmd_description="Support the development of JARVIS"
)
async def _donate(self, ctx: SlashContext) -> None:
await ctx.send(
"""Want to support JARVIS? Donate here:
https://ko-fi.com/zevaryx
Tips will be used to pay server costs, and any excess will go to local animal shelters.
"""
)
@bot.subcommand(
sub_cmd_name="donate", sub_cmd_description="Support the development of JARVIS"
)
async def _donate(self, ctx: SlashContext) -> None:
await ctx.send(
"""Want to support JARVIS? Donate here:
https://ko-fi.com/zevaryx
Tips will be used to pay server costs, and any excess will go to local animal shelters.
"""
)
# @bot.subcommand(sub_cmd_name="sex", sub_cmd_description="Have sex with JARVIS") # @bot.subcommand(sub_cmd_name="sex", sub_cmd_description="Have sex with JARVIS")
# async def _sex(self, ctx: SlashContext) -> None: # async def _sex(self, ctx: SlashContext) -> None:
# if ctx.author.id == 264072583987593217: # if ctx.author.id == 264072583987593217:

View file

@ -74,7 +74,7 @@ class TagCog(Extension):
placeholder="Content to send here", placeholder="Content to send here",
style=TextStyles.PARAGRAPH, style=TextStyles.PARAGRAPH,
custom_id="content", custom_id="content",
max_length=512, max_length=1024,
), ),
], ],
title="Create a new tag!", title="Create a new tag!",
@ -190,7 +190,7 @@ class TagCog(Extension):
value=tag.content, value=tag.content,
style=TextStyles.PARAGRAPH, style=TextStyles.PARAGRAPH,
custom_id="content", custom_id="content",
max_length=512, max_length=1024,
), ),
], ],
title="Edit a tag!", title="Edit a tag!",

View file

@ -182,9 +182,7 @@ class DbrandCog(Extension):
async def _support(self, ctx: InteractionContext) -> None: async def _support(self, ctx: InteractionContext) -> None:
return await self._db_support_cmd(ctx) return await self._db_support_cmd(ctx)
@db.subcommand( # @db.subcommand(sub_cmd_name="gripcheck", sub_cmd_description="Watch a dbrand grip get thrown")
sub_cmd_name="gripcheck", sub_cmd_description="Watch a dbrand grip get thrown"
)
async def _gripcheck(self, ctx: InteractionContext) -> None: async def _gripcheck(self, ctx: InteractionContext) -> None:
video_url = "https://cdn.discordapp.com/attachments/599068193339736096/890679742263623751/video0.mov" video_url = "https://cdn.discordapp.com/attachments/599068193339736096/890679742263623751/video0.mov"
image_url = "https://cdn.discordapp.com/attachments/599068193339736096/890680198306095104/image0.jpg" image_url = "https://cdn.discordapp.com/attachments/599068193339736096/890680198306095104/image0.jpg"