This commit is contained in:
leander committed 2026-10-29 21:23:26 +01:00
1 parent 02da979ee2
commit 05212c9eb6
14 files changed
+359 -271

No files matched your search

+40 -24
View File
@@ -332,14 +332,16 @@ class Anime(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 5)
@anilist_profile.command(name="generelt", description="Viser informasjon om en Anilistprofil")
async def anilist_profile_general(self, interaction: discord.Interaction, bruker: str):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Anilist-brukernavnet")
async def anilist_profile_general(self, interaction: discord.Interaction, user: str):
"""
Shows general information about a user's Anilist profile
Parameters
----------
interaction (discord.Interaction): Slash command context object
bruker (str): The user to get information about
user (str): The user to get information about
"""
# GraphQL
@@ -415,7 +417,7 @@ class Anime(commands.Cog):
}
}
"""
variables = {"name": bruker}
variables = {"name": user}
data, url = await self.request_anilist(interaction, query, variables, "User")
if not data:
@@ -458,14 +460,16 @@ class Anime(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 5)
@anilist_profile.command(name="anime", description="Se statistikk om animetittingen til en bruker")
async def anilist_profile_anime_stats(self, interaction: discord.Interaction, bruker: str):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Anilist-brukernavnet")
async def anilist_profile_anime_stats(self, interaction: discord.Interaction, user: str):
"""
Shows anime viewing statistics from a user's Anilist profile
Parameters
----------
interaction (discord.Interaction): Slash command context object
bruker (str): The user to get information about
user (str): The user to get information about
"""
# GraphQL
@@ -504,7 +508,7 @@ class Anime(commands.Cog):
}
}
"""
variables = {"name": bruker}
variables = {"name": user}
data, url = await self.request_anilist(interaction, query, variables, "User")
if not data:
@@ -549,14 +553,16 @@ class Anime(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 5)
@anilist_profile.command(name="manga", description="Se statistikk om mangalesingen til en bruker")
async def anilist_profile_manga_stats(self, interaction: discord.Interaction, bruker: str):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Anilist-brukernavnet")
async def anilist_profile_manga_stats(self, interaction: discord.Interaction, user: str):
"""
Shows manga reading statistics from a user's Anilist profile
Parameters
----------
interaction (discord.Interaction): Slash command context object
bruker (str): The user to get information about
user (str): The user to get information about
"""
# GraphQL
@@ -597,7 +603,7 @@ class Anime(commands.Cog):
}
}
"""
variables = {"name": bruker}
variables = {"name": user}
data, url = await self.request_anilist(interaction, query, variables, "User")
if not data:
@@ -642,14 +648,16 @@ class Anime(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 5)
@anilist.command(name="anime", description="Hent informasjon om en anime")
async def anilist_anime(self, interaction: discord.Interaction, navn: str):
@app_commands.rename(search="navn")
@app_commands.describe(search="Navnet på animen")
async def anilist_anime(self, interaction: discord.Interaction, search: str):
"""
Shows information about an anime
Parameters
----------
interaction (discord.Interaction): Slash command context object
navn (str): The name of the anime to fetch information about
search (str): The name of the anime to fetch information about
"""
# GraphQL
@@ -707,7 +715,7 @@ class Anime(commands.Cog):
}
}
"""
variables = {"search": navn, "isMain": True}
variables = {"search": search, "isMain": True}
data, url = await self.request_anilist(interaction, query, variables, "Media")
if not data:
@@ -796,14 +804,16 @@ class Anime(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 5)
@anilist.command(name="manga", description="Hent informasjon om en manga")
async def anilist_manga(self, interaction: discord.Interaction, navn: str):
@app_commands.rename(search="navn")
@app_commands.describe(search="Navnet på mangaen")
async def anilist_manga(self, interaction: discord.Interaction, search: str):
"""
Shows information about a manga
Parameters
----------
interaction (discord.Interaction): Slash command context object
navn (str): The name of the manga to fetch information about
search (str): The name of the manga to fetch information about
"""
query = """
@@ -854,7 +864,7 @@ class Anime(commands.Cog):
}
}
"""
variables = {"search": navn}
variables = {"search": search}
data, url = await self.request_anilist(interaction, query, variables, "Media")
if not data:
@@ -927,14 +937,16 @@ class Anime(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 5)
@anilist.command(name="karakter", description="Hent informasjon om en karakter")
async def anilist_character(self, interaction: discord.Interaction, navn: str):
@app_commands.rename(search="navn")
@app_commands.describe(search="Navnet på karakteren")
async def anilist_character(self, interaction: discord.Interaction, search: str):
"""
Shows information about a character
Parameters
----------
interaction (discord.Interaction): Slash command context object
navn (str): The name of the character to fetch information about
search (str): The name of the character to fetch information about
"""
query = """
@@ -973,7 +985,7 @@ class Anime(commands.Cog):
}
}
"""
variables = {"search": navn}
variables = {"search": search}
data, url = await self.request_anilist(interaction, query, variables, "Character")
if not data:
@@ -1021,14 +1033,16 @@ class Anime(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 5)
@anilist.command(name="skaper", description="Hent informasjon om en skaper")
async def anilist_creator(self, interaction: discord.Interaction, navn: str):
@app_commands.rename(search="navn")
@app_commands.describe(search="Navnet på skaperen")
async def anilist_creator(self, interaction: discord.Interaction, search: str):
"""
Shows information about a creator
Parameters
----------
interaction (discord.Interaction): Slash command context object
navn (str): The name of the creator to fetch information about
search (str): The name of the creator to fetch information about
"""
query = """
@@ -1071,7 +1085,7 @@ class Anime(commands.Cog):
}
}
"""
variables = {"search": navn}
variables = {"search": search}
data, url = await self.request_anilist(interaction, query, variables, "Staff")
if not data:
@@ -1120,14 +1134,16 @@ class Anime(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 5)
@anilist.command(name="studio", description="Hent informasjon om et studio")
async def anilist_studio(self, interaction: discord.Interaction, navn: str):
@app_commands.rename(search="navn")
@app_commands.describe(search="Navnet på studioet")
async def anilist_studio(self, interaction: discord.Interaction, search: str):
"""
Shows information about a studio
Parameters
----------
interaction (discord.Interaction): Slash command context object
navn (str): The name of the studio to fetch information about
search (str): The name of the studio to fetch information about
"""
query = """
@@ -1151,7 +1167,7 @@ class Anime(commands.Cog):
}
}
"""
variables = {"search": navn}
variables = {"search": search}
data, url = await self.request_anilist(interaction, query, variables, "Studio")
if not data:
+23 -21
View File
@@ -256,12 +256,14 @@ class Birthday(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 5)
@birthday_group.command(name="sett", description="Lagrer din bursdag i databasen")
@app_commands.rename(day="dag", month="måned", year="år")
@app_commands.describe(day="Dagen i måneden", month="Måneden", year="Året du ble født")
async def birthday_set(
self,
interaction: discord.Interaction,
dag: app_commands.Range[int, 1, 31],
måned: app_commands.Range[int, 1, 12],
år: int,
day: app_commands.Range[int, 1, 31],
month: app_commands.Range[int, 1, 12],
year: int,
):
"""
Allows the user to set their birthday in the database.
@@ -269,13 +271,13 @@ class Birthday(commands.Cog):
Parameters
----------
interaction (discord.Interaction): Slash command context object
dag (int): Day of the month
måned (int): Month of the year
år (int): Year
day (int): Day of the month
month (int): Month of the year
year (int): Year
"""
try:
date = datetime(år, måned, dag)
date = datetime(year, month, day)
except ValueError:
return await interaction.response.send_message(
embed=embed_templates.error_warning("ikke en gyldig dato, gjøk!"), ephemeral=True
@@ -319,44 +321,44 @@ class Birthday(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 5)
@birthday_group.command(name="se", description="Viser bursdagen til en bruker. Om ingen er gitt, vises din egen")
async def birthday_show(
self, interaction: discord.Interaction, bruker: discord.Member | discord.User | None = None
):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Brukeren du vil se bursdagen til. Standard er deg selv")
async def birthday_show(self, interaction: discord.Interaction, user: discord.Member | discord.User | None = None):
"""
Shows the birthday of a user. If none is given, shows the invoking user's one.
Parameters
----------
interaction (discord.Interaction): Slash command context object
bruker (discord.Member | discord.User | None): The user to show the birthday of. Defaults to None.
user (discord.Member | discord.User | None): The user to show the birthday of. Defaults to None.
"""
if not bruker:
bruker = interaction.user
user = await self.fetch_user_birthday(bruker.id)
if not user:
user = interaction.user
user_birthday = await self.fetch_user_birthday(user.id)
if not user_birthday:
return await interaction.response.send_message(
embed=embed_templates.error_warning("Brukeren har ikke registrert bursdagen sin")
)
# Current age information
today = self.local_today()
birthday = datetime(user.year, user.month, user.day)
birthday = datetime(user_birthday.year, user_birthday.month, user_birthday.day)
days_old = (today - birthday).days
years_old = relativedelta(today, birthday).years
# Next birthday information
next_birthday = await self.fetch_user_next_birthday(bruker.id)
next_birthday = await self.fetch_user_next_birthday(user.id)
next_birthday_days = (next_birthday - today).days
# Japanese era
japanese_era = EraDate.from_date(birthday).strftime("%-K%-y年")
embed = discord.Embed(description=bruker.mention, color=bruker.color)
embed.set_thumbnail(url=bruker.display_avatar)
embed.set_author(name=bruker.name, icon_url=bruker.display_avatar)
embed = discord.Embed(description=user.mention, color=user.color)
embed.set_thumbnail(url=user.display_avatar)
embed.set_author(name=user.name, icon_url=user.display_avatar)
embed.add_field(
name="Bursdag", value=discord.utils.format_dt(misc_utils.localize(birthday, self.bot.timezone), style="D")
)
+17 -8
View File
@@ -50,8 +50,15 @@ class Galtinn(commands.Cog):
@app_commands.checks.cooldown(1, 5)
@galtinn_group.command(name="medlemskap", description="Sjekk medlemskap i Det Norske Studentersamfund")
@app_commands.rename(galtinn_username="brukernavn", discord_user="discordbruker")
@app_commands.describe(
galtinn_username="Galtinn-brukernavnet", discord_user="Discordbrukeren som er koblet til Galtinn"
)
async def medlemskap(
self, interaction: discord.Interaction, brukernavn: str | None = None, discordbruker: discord.User | None = None
self,
interaction: discord.Interaction,
galtinn_username: str | None = None,
discord_user: discord.User | None = None,
):
"""
Check someone's membership status in the norwegian student society
@@ -61,12 +68,12 @@ class Galtinn(commands.Cog):
interaction (discord.Interaction): Slash command context object
"""
if discordbruker and brukernavn:
if discord_user and galtinn_username:
embed = embed_templates.error_fatal("Du kan ikke oppgi både brukernavn og discordbruker")
return await interaction.response.send_message(embed=embed, ephemeral=True)
if not brukernavn and not discordbruker:
discordbruker = interaction.user
if not galtinn_username and not discord_user:
discord_user = interaction.user
# Check if the user has registered their Discord account in Galtinn.
# We do this because we don't want just anyone fetching data
@@ -86,17 +93,19 @@ class Galtinn(commands.Cog):
# Only make new request if given user is different from command invoker
# This is done in order to avoid redundant requests
if (discordbruker and discordbruker.id != data["results"][0]["discord_profile"]["discord_id"]) or brukernavn:
if (
discord_user and discord_user.id != data["results"][0]["discord_profile"]["discord_id"]
) or galtinn_username:
params = {
"discord_profile__discord_id": discordbruker.id if discordbruker else None,
"username": brukernavn,
"discord_profile__discord_id": discord_user.id if discord_user else None,
"username": galtinn_username,
}
if not (data := await self.request_users(params)):
embed = embed_templates.error_fatal("Noe gikk galt under henting av data fra Galtinn")
return await interaction.response.send_message(embed=embed, ephemeral=True)
if not data["results"]:
if discordbruker:
if discord_user:
embed = embed_templates.error_warning(
"Brukeren du forespurte har ikke koblet Discordbrukeren sin til Galtinn"
)
+9 -7
View File
@@ -113,25 +113,27 @@ class Gullkorn(commands.Cog):
@gullkorn_group.command(
name="statistikk", description="Se informasjon om gullkorn for en bruker eller hele serveren"
)
async def gullkorn_stats(self, interaction: discord.Interaction, bruker: discord.Member | None = None):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Brukeren du vil se statistikk for. Standard er deg selv")
async def gullkorn_stats(self, interaction: discord.Interaction, user: discord.Member | None = None):
"""
Fetches gullkorn stats for a user or the whole server
Parameters
----------
interaction (discord.Interaction): Slash command context object
bruker (discord.Member, optional): Discord user to fetch stats for. Defaults to None.
user (discord.Member, optional): Discord user to fetch stats for. Defaults to None.
"""
# This looks kinda ugly, ngl
if bruker:
if user:
result = await self.bot.db.fetchone(
"""
SELECT *
FROM gullkorn
WHERE discord_id = %s;
""",
(bruker.id,),
(user.id,),
)
if not result:
@@ -141,10 +143,10 @@ class Gullkorn(commands.Cog):
)
embed = discord.Embed(
title=f"Gullkornstatistikk for `{bruker.name}`",
color=bruker.color,
title=f"Gullkornstatistikk for `{user.name}`",
color=user.color,
)
embed.set_thumbnail(url=bruker.avatar)
embed.set_thumbnail(url=user.avatar)
embed.add_field(name="Antall gullkorn", value=result[1])
embed.add_field(name="Antall gullkorn postet", value=result[2])
return await interaction.response.send_message(embed=embed, ephemeral=False)
+103 -90
View File
@@ -354,102 +354,108 @@ class Info(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@guild_group.command(name="rolle", description="Hent informasjon om en rolle på serveren")
async def guild_role(self, interaction: discord.Interaction, rolle: discord.Role):
@app_commands.rename(role="rolle")
@app_commands.describe(role="Rollen du vil se informasjon om")
async def guild_role(self, interaction: discord.Interaction, role: discord.Role):
"""
Get information about a role
Parameters
----------
interaction (discord.Interaction): Slash command context object
rolle (discord.Role): Role to fetch information about
role (discord.Role): Role to fetch information about
"""
if rolle.name == "@everyone":
if role.name == "@everyone":
embed = embed_templates.error_warning("Skriv inn en annen rolle enn `@everyone`")
return await interaction.response.send_message(embed=embed)
# Timestamp and days since creation
created_at_timestamp = discord.utils.format_dt(rolle.created_at, style="F")
since_created_days = (interaction.created_at - rolle.created_at).days
created_at_timestamp = discord.utils.format_dt(role.created_at, style="F")
since_created_days = (interaction.created_at - role.created_at).days
# List of members with the role
members = self.construct_member_string(rolle.members)
members = self.construct_member_string(role.members)
members = members if len(members) < 1024 else "For mange medlemmer for å vise her"
# List of permissions
permissions = ", ".join([permission for permission, value in iter(rolle.permissions) if value is True])
permissions = ", ".join([permission for permission, value in iter(role.permissions) if value is True])
embed = discord.Embed(title=rolle.name, description=f"{rolle.mention}\n**ID:** {rolle.id}", color=rolle.color)
embed.set_author(name=rolle.guild.name, icon_url=rolle.guild.icon)
embed.add_field(name="Fargekode", value=str(rolle.color))
embed = discord.Embed(title=role.name, description=f"{role.mention}\n**ID:** {role.id}", color=role.color)
embed.set_author(name=role.guild.name, icon_url=role.guild.icon)
embed.add_field(name="Fargekode", value=str(role.color))
embed.add_field(
name="Opprettet",
value=f"{created_at_timestamp}\n{since_created_days} "
+ f'{"dager" if since_created_days != 1 else "dag"} siden',
)
embed.add_field(name="Posisjon", value=rolle.position)
embed.add_field(name="Nevnbar", value="Ja" if rolle.mentionable else "Nei")
embed.add_field(name="Vises separat i medlemsliste", value="Ja" if rolle.hoist else "Nei")
embed.add_field(name="Posisjon", value=role.position)
embed.add_field(name="Nevnbar", value="Ja" if role.mentionable else "Nei")
embed.add_field(name="Vises separat i medlemsliste", value="Ja" if role.hoist else "Nei")
if permissions:
embed.add_field(name="Tillatelser", value=permissions, inline=False)
embed.add_field(name=f"Brukere med rollen ({len(rolle.members)})", value=members, inline=False)
embed.add_field(name=f"Brukere med rollen ({len(role.members)})", value=members, inline=False)
await interaction.response.send_message(embed=embed)
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@guild_group.command(name="tekstkanal", description="Hent informasjon om en tekstkanal")
async def guild_text_channel(self, interaction: discord.Interaction, kanal: discord.TextChannel):
@app_commands.rename(channel="kanal")
@app_commands.describe(channel="Tekstkanalen du vil se informasjon om")
async def guild_text_channel(self, interaction: discord.Interaction, channel: discord.TextChannel):
"""
Get information about a text channel
Parameters
----------
interaction (discord.Interaction): Slash command context object
kanal (discord.TextChannel): Text channel to fetch information about
channel (discord.TextChannel): Text channel to fetch information about
"""
members = self.construct_member_string(kanal.members)
members = self.construct_member_string(channel.members)
if len(members) > 1024:
members = "For mange for å vise her"
embed = discord.Embed(
color=interaction.guild.me.color, title=kanal.name, description=f"{kanal.mention}\nID: {kanal.id}"
color=interaction.guild.me.color, title=channel.name, description=f"{channel.mention}\nID: {channel.id}"
)
embed.set_author(name=kanal.guild.name, icon_url=kanal.guild.icon)
embed.add_field(name="Beskrivelse", value=kanal.topic if kanal.topic else "**Ingen**", inline=False)
embed.add_field(name="Opprettet", value=discord.utils.format_dt(kanal.created_at, style="F"))
embed.add_field(name="NSFW", value="Ja" if kanal.is_nsfw() else "Nei")
embed.set_author(name=channel.guild.name, icon_url=channel.guild.icon)
embed.add_field(name="Beskrivelse", value=channel.topic if channel.topic else "**Ingen**", inline=False)
embed.add_field(name="Opprettet", value=discord.utils.format_dt(channel.created_at, style="F"))
embed.add_field(name="NSFW", value="Ja" if channel.is_nsfw() else "Nei")
embed.add_field(
name="Saktemodus", value=f"Ja ({kanal.slowmode_delay} sekunder)" if kanal.slowmode_delay else "Nei"
name="Saktemodus", value=f"Ja ({channel.slowmode_delay} sekunder)" if channel.slowmode_delay else "Nei"
)
if kanal.category:
embed.add_field(name="Kategori", value=kanal.category.name)
embed.add_field(name=f"Antall med tilgang ({len(kanal.members)})", value=members)
if channel.category:
embed.add_field(name="Kategori", value=channel.category.name)
embed.add_field(name=f"Antall med tilgang ({len(channel.members)})", value=members)
await interaction.response.send_message(embed=embed)
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@guild_group.command(name="talekanal", description="Hent informasjon om en talekanal")
async def guild_voice_channel(self, interaction: discord.Interaction, kanal: discord.VoiceChannel):
@app_commands.rename(channel="kanal")
@app_commands.describe(channel="Talekanalen du vil se informasjon om")
async def guild_voice_channel(self, interaction: discord.Interaction, channel: discord.VoiceChannel):
"""
Get information about a voice channel
Parameters
----------
interaction (discord.Interaction): Slash command context object
kanal (discord.VoiceChannel): Voice channel to fetch information about
channel (discord.VoiceChannel): Voice channel to fetch information about
"""
embed = discord.Embed(color=interaction.guild.me.color, title=kanal.name, description=f"ID: {kanal.id}")
embed.set_author(name=kanal.guild.name, icon_url=kanal.guild.icon)
embed.add_field(name="Opprettet", value=discord.utils.format_dt(kanal.created_at, style="F"))
embed.add_field(name="Bitrate", value=f"{int(kanal.bitrate / 1000)}kbps")
embed = discord.Embed(color=interaction.guild.me.color, title=channel.name, description=f"ID: {channel.id}")
embed.set_author(name=channel.guild.name, icon_url=channel.guild.icon)
embed.add_field(name="Opprettet", value=discord.utils.format_dt(channel.created_at, style="F"))
embed.add_field(name="Bitrate", value=f"{int(channel.bitrate / 1000)}kbps")
embed.add_field(
name="Maksgrense", value=f"{kanal.user_limit} personer" if kanal.user_limit != 0 else "∞ personer"
name="Maksgrense", value=f"{channel.user_limit} personer" if channel.user_limit != 0 else "∞ personer"
)
if kanal.category:
embed.add_field(name="Kategori", value=kanal.category.name)
embed.add_field(name="Antall koblet til", value=len(kanal.members))
if channel.category:
embed.add_field(name="Kategori", value=channel.category.name)
embed.add_field(name="Antall koblet til", value=len(channel.members))
await interaction.response.send_message(embed=embed)
@app_commands.checks.bot_has_permissions(embed_links=True)
@@ -481,6 +487,7 @@ class Info(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@app_commands.command(name="emoji", description="Hent informasjon om en emoji i serveren")
@app_commands.describe(emoji="Emojien du vil se informasjon om")
async def emoji(self, interaction: discord.Interaction, emoji: str):
"""
Get information about an emoji in the server
@@ -632,49 +639,49 @@ class Info(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True, external_emojis=True)
@app_commands.checks.cooldown(1, 2)
@user_group.command(name="info", description="Hent informasjon om en bruker")
async def user_info(self, interaction: discord.Interaction, *, bruker: discord.Member | None = None):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Brukeren du vil se informasjon om. Standard er deg selv")
async def user_info(self, interaction: discord.Interaction, *, user: discord.Member | None = None):
"""
Get information about a user
Parameters
----------
interaction (discord.Interaction): Slash command context object
bruker (discord.Member, optional): User to get information about. Defaults to None (invoker).
user (discord.Member, optional): User to get information about. Defaults to None (invoker).
"""
if not bruker:
bruker = interaction.user
if not user:
user = interaction.user
# Get device(s) that is currently used by the user
app = ""
if str(bruker.mobile_status) != "offline":
if str(user.mobile_status) != "offline":
app += "📱 "
if str(bruker.web_status) != "offline":
if str(user.web_status) != "offline":
app += "🌐 "
if str(bruker.desktop_status) != "offline":
if str(user.desktop_status) != "offline":
app += "💻"
# Get index of join, creation and/or boost date in comparison to other users in the guild
join_index = sorted(interaction.guild.members, key=lambda m: m.joined_at).index(bruker) + 1
creation_index = sorted(interaction.guild.members, key=lambda m: m.created_at).index(bruker) + 1
if bruker.premium_since:
premium_index = (
sorted(interaction.guild.premium_subscribers, key=lambda m: m.premium_since).index(bruker) + 1
)
join_index = sorted(interaction.guild.members, key=lambda m: m.joined_at).index(user) + 1
creation_index = sorted(interaction.guild.members, key=lambda m: m.created_at).index(user) + 1
if user.premium_since:
premium_index = sorted(interaction.guild.premium_subscribers, key=lambda m: m.premium_since).index(user) + 1
# Creation/join date & days ago
created_timestamp = discord.utils.format_dt(bruker.created_at, style="F")
joined_timestamp = discord.utils.format_dt(bruker.joined_at, style="F")
joined_days = (interaction.created_at - bruker.joined_at).days
created_days = (interaction.created_at - bruker.created_at).days
created_timestamp = discord.utils.format_dt(user.created_at, style="F")
joined_timestamp = discord.utils.format_dt(user.joined_at, style="F")
joined_days = (interaction.created_at - user.joined_at).days
created_days = (interaction.created_at - user.created_at).days
# Boost date & days ago
if bruker.premium_since:
premium_since = discord.utils.format_dt(bruker.premium_since, style="F")
premium_since_days = (interaction.created_at - bruker.premium_since).days
if user.premium_since:
premium_since = discord.utils.format_dt(user.premium_since, style="F")
premium_since_days = (interaction.created_at - user.premium_since).days
# Get user roles
roles = self.construct_role_string(bruker.roles)
roles = self.construct_role_string(user.roles)
roles = (
roles
@@ -688,14 +695,14 @@ class Info(commands.Cog):
"dnd": f'{self.bot.emoji["dnd"]} Ikke forstyrr',
"offline": f'{self.bot.emoji["offline"]} Frakoblet',
}
status = statuses[str(bruker.status)]
status = statuses[str(user.status)]
embed = discord.Embed(color=bruker.color, description=f"{bruker.mention}\nID: {bruker.id}\n{status}\n{app}")
if bruker.display_name == bruker.name:
embed.set_author(name=bruker.name, icon_url=bruker.display_avatar)
embed = discord.Embed(color=user.color, description=f"{user.mention}\nID: {user.id}\n{status}\n{app}")
if user.display_name == user.name:
embed.set_author(name=user.name, icon_url=user.display_avatar)
else:
embed.set_author(name=f"{bruker.name} | {bruker.display_name}", icon_url=bruker.display_avatar)
embed.set_thumbnail(url=bruker.display_avatar)
embed.set_author(name=f"{user.name} | {user.display_name}", icon_url=user.display_avatar)
embed.set_thumbnail(url=user.display_avatar)
embed.add_field(
name="Opprettet",
value=f"{created_timestamp}\n{created_days} " + f'{"dag" if created_days == 1 else "dager"} siden',
@@ -704,7 +711,7 @@ class Info(commands.Cog):
name="Ble med i serveren",
value=f"{joined_timestamp}\n{joined_days} " + f'{"dag" if joined_days == 1 else "dager"} siden',
)
if bruker.premium_since:
if user.premium_since:
embed.add_field(
name="Boost",
value=f"{premium_since}\n{premium_since_days} "
@@ -712,13 +719,13 @@ class Info(commands.Cog):
+ f"Booster #{premium_index} av serveren",
inline=False,
)
embed.add_field(name=f"Roller ({len(bruker.roles)})", value=roles, inline=False)
embed.add_field(name=f"Roller ({len(user.roles)})", value=roles, inline=False)
embed.set_footer(text=f"#{join_index} Medlem av serveren | #{creation_index} Eldste brukeren på serveren")
# Playing activity
if bruker.activities:
if user.activities:
games = ""
for activity in bruker.activities:
for activity in user.activities:
games += f"{activity.name}\n"
if games:
embed.add_field(name="Spiller", value=games, inline=False)
@@ -728,20 +735,22 @@ class Info(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@user_group.command(name="roller", description="Hent roller til en bruker")
async def user_roles(self, interaction: discord.Interaction, bruker: discord.Member | None = None):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Brukeren du vil se rollene til. Standard er deg selv")
async def user_roles(self, interaction: discord.Interaction, user: discord.Member | None = None):
"""
Get roles of a user
Parameters
----------
interaction (discord.Interaction): Slash command context object
bruker (discord.Member, optional): User to get roles of. Defaults to None (invoker).
user (discord.Member, optional): User to get roles of. Defaults to None (invoker).
"""
if not bruker:
bruker = interaction.user
if not user:
user = interaction.user
roles = self.construct_role_string(bruker.roles)
roles = self.construct_role_string(user.roles)
# If the list of roles is too long, send it as a file
if len(roles) > 2048:
@@ -749,28 +758,30 @@ class Info(commands.Cog):
interaction, roles, f"{interaction.guild.id}_{interaction.user.id}_roles.txt"
)
else:
embed = discord.Embed(color=bruker.color, description=roles)
embed.set_author(name=f"Roller ({len(bruker.roles)})", icon_url=bruker.display_avatar)
embed.set_footer(text=bruker.name, icon_url=bruker.display_avatar)
embed = discord.Embed(color=user.color, description=roles)
embed.set_author(name=f"Roller ({len(user.roles)})", icon_url=user.display_avatar)
embed.set_footer(text=user.name, icon_url=user.display_avatar)
await interaction.response.send_message(embed=embed)
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@user_group.command(name="manglenderoller", description="Se hvilke roller en bruker ikke har i en guild")
async def user_missing_roles(self, interaction: discord.Interaction, bruker: discord.Member | None = None):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Brukeren du vil se manglende roller for. Standard er deg selv")
async def user_missing_roles(self, interaction: discord.Interaction, user: discord.Member | None = None):
"""
See which roles a user does not have in a guild
Parameters
----------
interaction (discord.Interaction): Slash command context object
bruker (discord.Member, optional): User to get roles of. Defaults to None (invoker).
user (discord.Member, optional): User to get roles of. Defaults to None (invoker).
"""
if not bruker:
bruker = interaction.user
if not user:
user = interaction.user
missing_roles = set(interaction.guild.roles) - set(bruker.roles)
missing_roles = set(interaction.guild.roles) - set(user.roles)
roles = self.construct_role_string(missing_roles)
@@ -780,30 +791,32 @@ class Info(commands.Cog):
interaction, roles, f"{interaction.guild.id}_{interaction.user.id}_missing_roles.txt"
)
else:
embed = discord.Embed(color=bruker.color, description=roles)
embed.set_author(name=f"Manglende roller ({len(missing_roles)})", icon_url=bruker.display_avatar)
embed.set_footer(text=bruker.name, icon_url=bruker.display_avatar)
embed = discord.Embed(color=user.color, description=roles)
embed.set_author(name=f"Manglende roller ({len(missing_roles)})", icon_url=user.display_avatar)
embed.set_footer(text=user.name, icon_url=user.display_avatar)
await interaction.response.send_message(embed=embed)
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@user_group.command(name="avatar", description="Hent avatar til en bruker")
async def user_avatar(self, interaction: discord.Interaction, bruker: discord.User | discord.Member | None = None):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Brukeren du vil se avataren til. Standard er deg selv")
async def user_avatar(self, interaction: discord.Interaction, user: discord.User | discord.Member | None = None):
"""
Get avatar of a user
Parameters
----------
interaction (discord.Interaction): Slash command context object
bruker (discord.User, optional): User to get avatar of. Defaults to None (invoker).
user (discord.User, optional): User to get avatar of. Defaults to None (invoker).
"""
if not bruker:
bruker = interaction.user
if not user:
user = interaction.user
embed = discord.Embed(color=bruker.color, description=f"[Lenke]({bruker.display_avatar})")
embed.set_author(name=bruker.name, icon_url=bruker.display_avatar)
embed.set_image(url=bruker.display_avatar)
embed = discord.Embed(color=user.color, description=f"[Lenke]({user.display_avatar})")
embed.set_author(name=user.name, icon_url=user.display_avatar)
embed.set_image(url=user.display_avatar)
await interaction.response.send_message(embed=embed)
+6 -4
View File
@@ -44,23 +44,25 @@ class MCWhitelist(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 5)
@whitelist_group.command(name="registrer", description="Whitelist minecraftbrukeren din på serveren vår")
async def whitelist_add(self, interaction: discord.Interaction, minecraftbrukernavn: str):
@app_commands.rename(minecraft_username="minecraftbrukernavn")
@app_commands.describe(minecraft_username="Minecraft-brukernavnet ditt")
async def whitelist_add(self, interaction: discord.Interaction, minecraft_username: str):
"""
Whitelist a minecraft user on the Minecraft server
Parameters
----------
interaction (discord.Interaction): Slash command context object
minecraftbrukernavn (str): Minecraft username
minecraft_username (str): Minecraft username
"""
# Fetch minecraft uuid from api
async with self.bot.http_session.get(
f"https://api.mojang.com/users/profiles/minecraft/{minecraftbrukernavn}"
f"https://api.mojang.com/users/profiles/minecraft/{minecraft_username}"
) as response:
if response.status != 200:
return await interaction.response.send_message(
embed=embed_templates.error_warning(f"Brukeren `{minecraftbrukernavn}` finnes ikke på minecraft"),
embed=embed_templates.error_warning(f"Brukeren `{minecraft_username}` finnes ikke på minecraft"),
ephemeral=True,
)
data = await response.json(content_type=None)
+29 -19
View File
@@ -38,20 +38,22 @@ class Meme(commands.Cog):
@app_commands.checks.bot_has_permissions(attach_files=True)
@app_commands.checks.cooldown(1, 5)
@app_commands.command(name="deepfry", description="Friter et bilde til hundre og helvete")
async def deepfry(self, interaction: discord.Interaction, bilde: discord.Attachment):
@app_commands.rename(attachment="bilde")
@app_commands.describe(attachment="Bildet som skal frityrstekes")
async def deepfry(self, interaction: discord.Interaction, attachment: discord.Attachment):
"""
Deepfries an image
Parameters
----------
interaction (discord.Interaction): The interaction
bilde (discord.Attachment): The image to deepfry
attachment (discord.Attachment): The image to deepfry
"""
await interaction.response.defer()
# Fetch image
input_image = await discord_utils.get_file_bytesio(bilde)
input_image = await discord_utils.get_file_bytesio(attachment)
try:
image = Image.open(input_image)
@@ -99,20 +101,22 @@ class Meme(commands.Cog):
@app_commands.checks.bot_has_permissions(attach_files=True)
@app_commands.checks.cooldown(1, 5)
@app_commands.command(name="preferansemem", description="Generer en drake-aktig mem basert på tekst")
async def prefer_meme(self, interaction: discord.Interaction, dårlig_tekst: str, bra_tekst: str):
@app_commands.rename(bad_text="dårlig_tekst", good_text="bra_tekst")
@app_commands.describe(bad_text="Teksten øverst, det som er dårlig", good_text="Teksten nederst, det som er bra")
async def prefer_meme(self, interaction: discord.Interaction, bad_text: str, good_text: str):
"""
Generates a drake-like meme based on text
Parameters
----------
interaction (discord.Interaction): The interaction
dårlig_tekst (str): The upper text, what's disliked
bra_tekst (str): The lower text, what's liked
bad_text (str): The upper text, what's disliked
good_text (str): The lower text, what's liked
"""
await interaction.response.defer()
output = await asyncio.to_thread(Meme.make_prefer_meme, dårlig_tekst, bra_tekst)
output = await asyncio.to_thread(Meme.make_prefer_meme, bad_text, good_text)
# Send image
await interaction.followup.send(file=discord.File(output, "sivert_goodbad.jpg"))
@@ -151,23 +155,25 @@ class Meme(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True, attach_files=True)
@app_commands.checks.cooldown(1, 5)
@app_commands.command(name="wojakpoint", description="Få UiO Gaming-medlemmer til å peke på et bilde")
async def wojakpoint(self, interaction: discord.Interaction, file: discord.Attachment):
@app_commands.rename(attachment="bilde")
@app_commands.describe(attachment="Bildet som det skal pekes på. Kun PNG og JPG")
async def wojakpoint(self, interaction: discord.Interaction, attachment: discord.Attachment):
"""
Make glorious UiO Gaming members point at your desired picture
Parameters
----------
interaction (discord.Interaction): Slash command context object
file (discord.Attachment): The image to point at. Only supports png and jpg for now
attachment (discord.Attachment): The image to point at. Only supports png and jpg for now
"""
await interaction.response.defer()
if file.content_type not in ["image/png", "image/jpeg"]:
if attachment.content_type not in ["image/png", "image/jpeg"]:
embed = embed_templates.error_warning("Bildet må være i PNG- eller JPEG-format")
return await interaction.followup.send(embed=embed)
provided_image = await discord_utils.get_file_bytesio(file)
provided_image = await discord_utils.get_file_bytesio(attachment)
output = await asyncio.to_thread(Meme.make_wojakpoint, provided_image)
# Send
@@ -213,20 +219,22 @@ class Meme(commands.Cog):
@app_commands.checks.bot_has_permissions(attach_files=True)
@app_commands.checks.cooldown(1, 30)
@app_commands.command(name="nightcore", description="nightcore en gitt lyd")
async def nightcore(self, interaction: discord.Interaction, søk: str = None, url: str = None):
@app_commands.rename(query="søk")
@app_commands.describe(query="Søkeord for å finne lyden på YouTube", url="Lenke til lyden")
async def nightcore(self, interaction: discord.Interaction, query: str = None, url: str = None):
"""
Turn the user passed url or searched media into nightcore
Parameters
----------
interaction (discord.Interaction): The interaction
søk (str|None): Search term to look up the media on YouTube
query (str|None): Search term to look up the media on YouTube
url (str|None): Link to the source media
"""
await interaction.response.defer()
if not url and not søk:
if not url and not query:
return await interaction.followup.send(
embed=embed_templates.error_warning("Du må enten gi meg en link eller noe å søke etter"),
ephemeral=True,
@@ -261,7 +269,7 @@ class Meme(commands.Cog):
"no_warnings": True,
}
prefix = "ytsearch1:" if not url else ""
search_term = søk if not url else url
search_term = query if not url else url
def download():
with yt_dlp.YoutubeDL(options) as ydl:
@@ -325,20 +333,22 @@ class Meme(commands.Cog):
@app_commands.checks.bot_has_permissions(attach_files=True)
@app_commands.checks.cooldown(1, 60)
@app_commands.command(name="crabrave", description="Generer en crab rave video basert på tekst")
async def crab_rave(self, interaction: discord.Interaction, topptekst: str, bunntekst: str):
@app_commands.rename(top_text="topptekst", bottom_text="bunntekst")
@app_commands.describe(top_text="Teksten øverst", bottom_text="Teksten nederst")
async def crab_rave(self, interaction: discord.Interaction, top_text: str, bottom_text: str):
"""
Generates a crab rave video based on text
Parameters
----------
interaction (discord.Interaction): The interaction
topptekst (str): The upper text
bunntekst (str): The lower text
top_text (str): The upper text
bottom_text (str): The lower text
"""
await interaction.response.defer()
generation_task = functools.partial(Meme.make_crab, topptekst, bunntekst, interaction.user.id)
generation_task = functools.partial(Meme.make_crab, top_text, bottom_text, interaction.user.id)
await self.bot.loop.run_in_executor(None, generation_task)
temp_file = f"./src/assets/temp/{interaction.user.id}_crab.mp4"
+70 -52
View File
@@ -46,83 +46,89 @@ class Misc(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@app_commands.command(name="owo", description="Oversetter teksten din til owo (we_eb)")
async def owo(self, interaction: discord.Interaction, tekst: str):
@app_commands.rename(text="tekst")
@app_commands.describe(text="Teksten som skal oversettes")
async def owo(self, interaction: discord.Interaction, text: str):
"""
Translate text into owo (we_eb)
Parameters
----------
interaction (discord.Interaction): Slash command context object
tekst (str): Text to translate
text (str): Text to translate
"""
# Decades of computer sciencetist optimizng every little detail to make
# our computers as fast as possible. Only for me to ruin it by doing this shit.
# I am sorry to our forefathers whose shoulders we stand upon.
# I have sinned
tekst = re.sub(r"[rl]", "w", tekst)
tekst = re.sub(r"[RL]", "W", tekst)
tekst = re.sub(r"n([aeiou])", r"ny\1", tekst, flags=re.IGNORECASE)
tekst = re.sub(r"N([aeiou])", r"Ny\1", tekst)
tekst = re.sub(r"th", "d", tekst, flags=re.IGNORECASE)
tekst = tekst.replace("ove", "uv")
text = re.sub(r"[rl]", "w", text)
text = re.sub(r"[RL]", "W", text)
text = re.sub(r"n([aeiou])", r"ny\1", text, flags=re.IGNORECASE)
text = re.sub(r"N([aeiou])", r"Ny\1", text)
text = re.sub(r"th", "d", text, flags=re.IGNORECASE)
text = text.replace("ove", "uv")
# TODO: add kaomoji? https://kaomoji.moe/
if len(tekst) >= 1000:
if len(text) >= 1000:
embed = embed_templates.error_warning("Teksten er for lang")
return await interaction.response.send_message(embed=embed)
embed = discord.Embed(description=tekst)
embed = discord.Embed(description=text)
await interaction.response.send_message(embed=embed)
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@app_commands.command(name="dicksize", description="Se hvor liten pikk du har")
async def dicksize(self, interaction: discord.Interaction, bruker: discord.Member | discord.User | None = None):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Brukeren du vil måle. Standard er deg selv")
async def dicksize(self, interaction: discord.Interaction, user: discord.Member | discord.User | None = None):
"""
Get a totally accurate meassurement of a user's dick
Parameters
----------
interaction (discord.Interaction): Slash command context object
bruker (discord.Member | discord.User | None): The user you want to see the dicksize of. Defaults to author
user (discord.Member | discord.User | None): The user you want to see the dicksize of. Defaults to author
"""
if not bruker:
bruker = interaction.user
if not user:
user = interaction.user
# Må jo gi meg selv en stor kuk
if bruker.id == self.bot.user_ids.get("dev"):
if user.id == self.bot.user_ids.get("dev"):
dick_size = 69
elif bruker.id == 327207142681608192:
elif user.id == 327207142681608192:
dick_size = 1
else:
dick_hash = md5(str(bruker.id).encode("utf-8")).hexdigest()
dick_hash = md5(str(user.id).encode("utf-8")).hexdigest()
dick_size = (
int(dick_hash[11:13], 16) * (25 - 2) // 255 + 2
) # This is 5 year old code. I have no fucking idea what's going on
dick_drawing = "=" * dick_size
embed = discord.Embed(color=bruker.color)
embed.set_author(name=bruker.global_name, icon_url=bruker.avatar)
embed = discord.Embed(color=user.color)
embed.set_author(name=user.global_name, icon_url=user.avatar)
embed.add_field(name="Kukstørrelse", value=f"{dick_size} cm\n8{dick_drawing}D")
await interaction.response.send_message(embed=embed)
@app_commands.checks.cooldown(1, 5)
@app_commands.command(name="emne", description="For NTNU'ere som ikke kan emnekoder på UiO")
async def course_code(self, interaction: discord.Interaction, emnekode: str):
@app_commands.rename(course_code="emnekode")
@app_commands.describe(course_code="Emnekoden på UiO, f.eks. IN1000")
async def course_code(self, interaction: discord.Interaction, course_code: str):
"""
Translate UiO course codes to their respective course names
Parameters
----------
interaction (discord.Interaction): Slash command context object
emnekode (str): UiO course code
course_code (str): UiO course code
"""
params = {"action": "autocomplete", "service": "emner", "scope": "/studier/emner", "q": emnekode, "limit": 1}
params = {"action": "autocomplete", "service": "emner", "scope": "/studier/emner", "q": course_code, "limit": 1}
async with self.bot.http_session.get("https://www.uio.no/studier/", params=params) as response:
if response.status != 200:
return await interaction.response.send_message(embed=embed_templates.error_fatal("Kunne ikke nå API"))
@@ -134,7 +140,7 @@ class Misc(commands.Cog):
for result in results:
code, name, _ = result.split(";")
if code.lower() == emnekode.lower():
if code.lower() == course_code.lower():
break
await interaction.response.send_message(name)
@@ -142,33 +148,37 @@ class Misc(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@app_commands.command(name="klappifiser", description="Klappifiser tekst")
async def clapify(self, interation: discord.Interaction, tekst: str):
@app_commands.rename(text="tekst")
@app_commands.describe(text="Teksten som skal klappifiseres")
async def clapify(self, interation: discord.Interaction, text: str):
"""
Add clap emoji between every word of a string
Parameters
----------
interaction (discord.Interaction): Slash command context object
tekst (str): Text to clapify
text (str): Text to clapify
"""
if len(tekst) >= 1000:
if len(text) >= 1000:
embed = embed_templates.error_warning("Teksten er for lang")
return await interation.response.send_message(embed=embed)
tekst = tekst.replace(" ", "👏")
text = text.replace(" ", "👏")
embed = discord.Embed(color=interation.client.user.color, description=f"**{tekst.upper()}**")
embed = discord.Embed(color=interation.client.user.color, description=f"**{text.upper()}**")
await interation.response.send_message(embed=embed)
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@app_commands.command(name="mock", description="vEt dU iKkE hVa mOcKtEkSt eR eLlEr?")
@app_commands.rename(text="tekst", user="bruker")
@app_commands.describe(text="Teksten som skal mockes", user="Brukeren som skal mockes")
async def mock(
self,
interation: discord.Interaction,
tekst: app_commands.Range[str, 1, 4096],
bruker: discord.User | None = None,
text: app_commands.Range[str, 1, 4096],
user: discord.User | None = None,
):
"""
dO i rEaLlY nEeD tO eXpLaIn??
@@ -176,11 +186,11 @@ class Misc(commands.Cog):
Parameters
----------
interaction (discord.Interaction): Slash command context object
tekst (str): Text to clapify
text (str): Text to clapify
"""
# TODO: make this not horrible. I can't be botherd to right now
words = tekst.split(" ")
words = text.split(" ")
for i, word in enumerate(words):
karakter = 0
word = list(word)
@@ -194,7 +204,7 @@ class Misc(commands.Cog):
words[i] = "".join(word)
text = " ".join(words)
mention = bruker.mention if bruker else ""
mention = user.mention if user else ""
embed = discord.Embed(color=interation.client.user.color, description=text)
await interation.response.send_message(content=mention, embed=embed)
@@ -202,8 +212,10 @@ class Misc(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 5)
@app_commands.command(name="helligdager", description="Se helligdager i et land for et år")
@app_commands.rename(country_code="land", year="år")
@app_commands.describe(country_code="Landkode med to bokstaver, f.eks. NO", year="Året. Standard er i år")
async def holidays(
self, interaction: discord.Interaction, *, land: app_commands.Range[str, 2, 2] = "NO", år: int = None
self, interaction: discord.Interaction, *, country_code: app_commands.Range[str, 2, 2] = "NO", year: int = None
):
"""
Get holidays for a country for a given year
@@ -211,21 +223,23 @@ class Misc(commands.Cog):
Parameters
----------
interaction (discord.Interaction): Slash command context object
land (str): Country code
år (int): Year
country_code (str): Country code
year (int): Year
"""
land = land.upper()
år = discord.utils.utcnow().astimezone(self.bot.timezone).year if not år else int(år)
country_code = country_code.upper()
year = discord.utils.utcnow().astimezone(self.bot.timezone).year if not year else int(year)
async with self.bot.http_session.get(f"https://date.nager.at/api/v3/publicholidays/{år}/{land}") as response:
async with self.bot.http_session.get(
f"https://date.nager.at/api/v3/publicholidays/{year}/{country_code}"
) as response:
if response.status not in (200, 204):
embed = embed_templates.error_warning("Ugyldig land\nHusk å bruke landskoder\n" + "For eksempel: `NO`")
return await interaction.response.send_message(embed=embed)
data = await response.json(content_type=None) if response.status == 200 else []
if not data:
embed = embed_templates.error_warning(f"Fant ingen helligdager for `{land}` i {år}")
embed = embed_templates.error_warning(f"Fant ingen helligdager for `{country_code}` i {year}")
return await interaction.response.send_message(embed=embed)
country = data[0]["countryCode"].lower()
@@ -238,7 +252,7 @@ class Misc(commands.Cog):
holiday_str += f'* **{date}**: {day["localName"]}\n'
embed = discord.Embed(
color=interaction.client.user.color, title=f":flag_{country}: Helligdager {år} :flag_{country}:"
color=interaction.client.user.color, title=f":flag_{country}: Helligdager {year} :flag_{country}:"
)
embed.description = holiday_str
await interaction.response.send_message(embed=embed)
@@ -246,36 +260,38 @@ class Misc(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True, attach_files=True)
@app_commands.checks.cooldown(1, 5)
@app_commands.command(name="match", description="Se hvor mye du matcher med en annen")
async def match(self, interaction: discord.Interaction, bruker: discord.Member):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Brukeren du vil matche med")
async def match(self, interaction: discord.Interaction, user: discord.Member):
"""
Get dating compatibility with another user
Parameters
----------
interaction (discord.Interaction): Slash command context object
bruker (discord.Member): User to match with
user (discord.Member): User to match with
"""
if bruker == interaction.user:
if user == interaction.user:
embed = embed_templates.error_warning("Jeg vet du er ensom, men du kan ikke matche med deg selv")
return await interaction.response.send_message(embed=embed)
invoker_id = int(str(interaction.user.id)[11:14])
user_id = int(str(bruker.id)[11:14])
user_id = int(str(user.id)[11:14])
match_percent = int((invoker_id + user_id) % 100)
if bruker.id == self.bot.user.id:
if user.id == self.bot.user.id:
match_percent = 100
invoker_avatar = await discord_utils.get_file_bytesio(interaction.user.display_avatar)
user_avatar = await discord_utils.get_file_bytesio(bruker.display_avatar)
user_avatar = await discord_utils.get_file_bytesio(user.display_avatar)
output = await asyncio.to_thread(Misc.make_match_image, invoker_avatar, user_avatar, match_percent)
# Send
f = discord.File(output, filename=f"{interaction.user.id}_{bruker.id}_match.png")
f = discord.File(output, filename=f"{interaction.user.id}_{user.id}_match.png")
embed = discord.Embed()
embed.set_image(url=f"attachment://{interaction.user.id}_{bruker.id}_match.png")
embed.set_image(url=f"attachment://{interaction.user.id}_{user.id}_match.png")
await interaction.response.send_message(embed=embed, file=f)
@staticmethod
@@ -368,18 +384,20 @@ class Misc(commands.Cog):
@app_commands.checks.cooldown(1, 2)
@app_commands.command(name="mennesketid", description="Konverter tid i menneskelig format til dato og klokkeslett")
async def humantime(self, interaction: discord.Interaction, tekst: str):
@app_commands.rename(text="tekst")
@app_commands.describe(text="Tidspunkt i menneskelig format, f.eks. «fredag 18:00»")
async def humantime(self, interaction: discord.Interaction, text: str):
"""
Convert human-readable time to date and time
Parameters
----------
interaction (discord.Interaction): Slash command context object
tekst (str): Human-readable time string
text (str): Human-readable time string
"""
parsed_time = dateparser.parse(
tekst,
text,
languages=["nb", "nn", "en"],
settings={
"TIMEZONE": str(self.bot.timezone) if self.bot.timezone else "local",
+9 -7
View File
@@ -199,35 +199,37 @@ class SocialCredit(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@social_credit_group.command(name="credits", description="Sjekk hvor dårlig menneske du er")
async def credits(self, interaction: discord.Interaction, *, bruker: discord.Member | None = None):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Brukeren du vil se poengsummen til. Standard er deg selv")
async def credits(self, interaction: discord.Interaction, *, user: discord.Member | None = None):
"""
Check the social credit score of a given user
Parameters
----------
interaction (discord.Interaction): The interaction object
bruker (discord.Member | None): The user to check the score of. Defaults to the user who invoked the command
user (discord.Member | None): The user to check the score of. Defaults to the user who invoked the command
"""
if not bruker:
bruker = interaction.user
if not user:
user = interaction.user
result = await self.bot.db.fetchone(
"""
SELECT * FROM social_credit
WHERE user_id = %s
""",
(bruker.id,),
(user.id,),
)
if not result:
return await interaction.response.send_message(
embed=embed_templates.error_warning(f"{bruker.mention} er ikke registrert i databasen")
embed=embed_templates.error_warning(f"{user.mention} er ikke registrert i databasen")
)
db_user = CreditUser(*result)
embed = discord.Embed(description=(f"{bruker.mention} har `{db_user.credit_score}` social credits"))
embed = discord.Embed(description=(f"{user.mention} har `{db_user.credit_score}` social credits"))
await interaction.response.send_message(embed=embed)
@app_commands.checks.bot_has_permissions(embed_links=True)
+9 -7
View File
@@ -225,20 +225,22 @@ class Streak(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@streak_group.command(name="se", description="Se din eller en annen brukers streak")
async def streak_user(self, interaction: discord.Interaction, bruker: discord.Member | discord.User | None = None):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Brukeren du vil se streaken til. Standard er deg selv")
async def streak_user(self, interaction: discord.Interaction, user: discord.Member | discord.User | None = None):
"""
Get the current streak for a user
Parameters
----------
interaction (discord.Interaction): The interaction
bruker (discord.Member | discord.User | None): The user to get the streak for
user (discord.Member | discord.User | None): The user to get the streak for
"""
await interaction.response.defer()
if not bruker:
bruker = interaction.user
if not user:
user = interaction.user
streak = await self.bot.db.fetchone(
"""
@@ -246,7 +248,7 @@ class Streak(commands.Cog):
FROM streak
WHERE discord_id = %s;
""",
(bruker.id,),
(user.id,),
)
if not streak:
@@ -270,8 +272,8 @@ class Streak(commands.Cog):
streak_days = (discord.utils.utcnow() - streak_msg_time).days
streak_msg_timestamp = discord.utils.format_dt(streak_msg_time, "F")
embed = discord.Embed(title="Streak", description=bruker.mention)
embed.set_author(name=bruker.name, icon_url=bruker.avatar)
embed = discord.Embed(title="Streak", description=user.mention)
embed.set_author(name=user.name, icon_url=user.avatar)
embed.add_field(name="Antall dager", value=streak_days)
embed.add_field(name="Startet streaken", value=f"{streak_msg_timestamp}\n{streak_msg_link}")
await interaction.followup.send(embed=embed)
+2
View File
@@ -37,6 +37,8 @@ class TempVoice(commands.Cog):
@app_commands.checks.bot_has_permissions(manage_channels=True, embed_links=True)
@app_commands.checks.cooldown(1, 300)
@app_commands.command(name="tempvoice")
@app_commands.rename(name="navn", limit="grense")
@app_commands.describe(name="Navnet på kanalen", limit="Maks antall brukere. 0 betyr ingen grense")
async def tempvoice(
self,
interaction: discord.Interaction,
+29 -23
View File
@@ -62,25 +62,27 @@ class UserFacts(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@height_group.command(name="se", description="Se høyden til en bruker")
async def height_see(self, interaction: discord.Interaction, bruker: discord.Member = None):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Brukeren du vil se høyden til")
async def height_see(self, interaction: discord.Interaction, user: discord.Member = None):
"""
See the height of a user
Parameters
----------
interaction (discord.Interaction): The interaction object
bruker (discord.Member): The user to see the height of
user (discord.Member): The user to see the height of
"""
if not bruker:
bruker = interaction.user
if not user:
user = interaction.user
height = await self.bot.db.fetchone(
"""
SELECT height FROM user_facts
WHERE discord_id = %s and height IS NOT NULL;
""",
(bruker.id,),
(user.id,),
)
if not height:
@@ -94,10 +96,10 @@ class UserFacts(commands.Cog):
feet = int(inches * (1 / 12))
inches = int(inches - (feet * 12))
embed = discord.Embed(color=bruker.color)
embed = discord.Embed(color=user.color)
embed.add_field(name="Høyde", value=f"{height} cm")
embed.add_field(name="Høyde (🦅🦅🇺🇸🦅🦅)", value=f"{feet}'{inches}\"")
embed.set_author(name=bruker.global_name, icon_url=bruker.avatar)
embed.set_author(name=user.global_name, icon_url=user.avatar)
await interaction.response.send_message(embed=embed)
@@ -105,6 +107,7 @@ class UserFacts(commands.Cog):
@app_commands.checks.cooldown(1, 2)
@height_group.command(name="sett", description="Sett høyden din")
@app_commands.rename(height_cm="høyde_cm")
@app_commands.describe(height_cm="Høyden din i centimeter")
async def height_set(self, interaction: discord.Interaction, height_cm: app_commands.Range[int, 50, 250]):
"""
Set your height
@@ -191,18 +194,20 @@ class UserFacts(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True, attach_files=True)
@app_commands.checks.cooldown(1, 2)
@mbti_group.command(name="se", description="Se MBTI-en til en bruker")
async def mbti_see(self, interaction: discord.Interaction, bruker: discord.Member = None):
@app_commands.rename(user="bruker")
@app_commands.describe(user="Brukeren du vil se MBTI-en til")
async def mbti_see(self, interaction: discord.Interaction, user: discord.Member = None):
"""
See the MBTI of a user
Parameters
----------
interaction (discord.Interaction): The interaction object
bruker (discord.Member): The user to see the MBTI of
user (discord.Member): The user to see the MBTI of
"""
if not bruker:
bruker = interaction.user
if not user:
user = interaction.user
await interaction.response.defer()
@@ -211,7 +216,7 @@ class UserFacts(commands.Cog):
SELECT mbti FROM user_facts
WHERE discord_id = %s AND mbti IS NOT NULL;
""",
(bruker.id,),
(user.id,),
)
if not user_mbti:
@@ -221,15 +226,15 @@ class UserFacts(commands.Cog):
user_mbti = user_mbti[0]
embed = discord.Embed(color=bruker.color, title="MBTI", description=user_mbti)
embed.set_author(name=bruker.global_name, icon_url=bruker.avatar)
embed = discord.Embed(color=user.color, title="MBTI", description=user_mbti)
embed.set_author(name=user.global_name, icon_url=user.avatar)
results = await self.bot.db.fetchall(
"""
SELECT discord_id, mbti FROM user_facts
WHERE mbti IS NOT NULL and discord_id != %s;
""",
(bruker.id,),
(user.id,),
)
if not results:
@@ -237,24 +242,25 @@ class UserFacts(commands.Cog):
others = []
for discord_id, mbti in results:
user = self.bot.get_user(discord_id)
if not user and interaction.guild:
other = self.bot.get_user(discord_id)
if not other and interaction.guild:
try:
user = await interaction.guild.fetch_member(discord_id)
other = await interaction.guild.fetch_member(discord_id)
except discord.NotFound:
pass
if user:
others.append((user, mbti))
if other:
others.append((other, mbti))
graph_png = await asyncio.to_thread(self.create_mbti_graph, (bruker, user_mbti), others)
image = discord.File(BytesIO(graph_png), filename=f"{bruker.id}_mbti.png")
graph_png = await asyncio.to_thread(self.create_mbti_graph, (user, user_mbti), others)
image = discord.File(BytesIO(graph_png), filename=f"{user.id}_mbti.png")
embed.set_image(url=f"attachment://{bruker.id}_mbti.png")
embed.set_image(url=f"attachment://{user.id}_mbti.png")
await interaction.followup.send(embed=embed, file=image)
@app_commands.checks.bot_has_permissions(embed_links=True)
@app_commands.checks.cooldown(1, 2)
@mbti_group.command(name="sett", description="Sett MBTI-en din")
@app_commands.describe(mbti="MBTI-typen din, f.eks. INTJ")
async def mbti_set(self, interaction: discord.Interaction, mbti: str):
"""
Set your MBTI
+7 -5
View File
@@ -108,14 +108,16 @@ class Viteboka(commands.Cog):
@app_commands.checks.bot_has_permissions(embed_links=True, attach_files=True)
@app_commands.checks.cooldown(1, 10)
@viteboka_group.command(name="søk", description="Søk etter en artikkel i Viteboka")
async def search(self, interaction: discord.Interaction, søkestreng: str):
@app_commands.rename(query="søkestreng")
@app_commands.describe(query="Det du vil søke etter")
async def search(self, interaction: discord.Interaction, query: str):
"""
Search for an article in Viteboka
Parameters
----------
interaction (discord.Interaction): Slash command context object
søkestreng (str): The search query
query (str): The search query
"""
await interaction.response.defer()
@@ -124,18 +126,18 @@ class Viteboka(commands.Cog):
"action": "query",
"format": "json",
"list": "search",
"srsearch": søkestreng,
"srsearch": query,
}
async with self.bot.http_session.get(API_URL, params=params) as response:
if response.status != 200:
self.bot.logger.error(f"Failed to search for articles with query {søkestreng}: {response.status}")
self.bot.logger.error(f"Failed to search for articles with query {query}: {response.status}")
embed = embed_templates.error_fatal("Klarte ikke å søke etter artikler")
return await interaction.followup.send(embed=embed)
data = await response.json(content_type=None)
search_results = data["query"]["search"]
if not search_results:
self.bot.logger.info(f"No articles found with query {søkestreng}")
self.bot.logger.info(f"No articles found with query {query}")
embed = embed_templates.error_warning("Fant ingen artikler som matcher søket")
return await interaction.followup.send(embed=embed)
+6 -4
View File
@@ -482,7 +482,9 @@ class WordCloud(commands.Cog):
name="siste",
description="Generer en ordsky basert på dine mest frekvente sagte ord fra de siste meldingene dine",
)
async def generate_last(self, interaction: discord.Interaction, antall: app_commands.Range[int, 100, 2000] = 1000):
@app_commands.rename(amount="antall")
@app_commands.describe(amount="Hvor mange meldinger som skal søkes gjennom. Flere tar lengre tid")
async def generate_last(self, interaction: discord.Interaction, amount: app_commands.Range[int, 100, 2000] = 1000):
"""
Generer en ordsky basert på dine mest frekvente sagte ord fra de siste meldingene dine
@@ -513,7 +515,7 @@ class WordCloud(commands.Cog):
try:
# Limit search to half of requested messages to avoid rate limits
# We assume we can still fetch enough tokens to reach the requested amount
async for message in channel.history(limit=int(antall / 2)):
async for message in channel.history(limit=int(amount / 2)):
if message.author.id != interaction.user.id or not self.can_count_message(message):
continue
@@ -536,8 +538,8 @@ class WordCloud(commands.Cog):
word_cloud_file = discord.File(word_cloud, filename=f"wordcloud_{interaction.user.id}.png")
embed = discord.Embed(title="☁️ Her er ordskyen din! ☁️")
embed.description = (
f"Basert på de {int(antall/2)} siste meldingene i alle kanaler og "
+ f"topp {antall} mest frekvente ord i dine meldinger"
f"Basert på de {int(amount/2)} siste meldingene i alle kanaler og "
+ f"topp {amount} mest frekvente ord i dine meldinger"
)
embed.set_image(url=f"attachment://wordcloud_{interaction.user.id}.png")
await interaction.followup.send(embed=embed, file=word_cloud_file)