Skip to content

Commit

Permalink
Merge pull request #179 from UnifierHQ/dev
Browse files Browse the repository at this point in the history
3.5.0: Slash commands
  • Loading branch information
greeeen-dev authored Oct 24, 2024
2 parents 821aa21 + 5f2017b commit 4010fb8
Show file tree
Hide file tree
Showing 19 changed files with 3,694 additions and 2,402 deletions.
5 changes: 3 additions & 2 deletions boot/internal.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"maintainer": "UnifierHQ",
"maintainer_profile": "https://github.com/UnifierHQ",
"product": "unifier",
"product_name": "Unifier",
"base_bootfile": "unifier.py",
Expand All @@ -19,7 +20,7 @@
{
"id": "balanced",
"name": "\u26a1 Balanced",
"description": "Uses the latest stable Nextcord and performance optimizations for balanced performance and stability. Recommended for most users.",
"description": "Uses performance optimizations for balanced performance and stability. Recommended for most users.",
"default": false,
"prefix": "balanced",
"required_py_version": 12,
Expand All @@ -28,7 +29,7 @@
{
"id": "stable",
"name": "\ud83d\udc8e Stable",
"description": "Uses the latest stable Nextcord for best stability.",
"description": "Uses no performance optimizations. May be slower, but has best stability.",
"default": false,
"prefix": "stable",
"required_py_version": 9,
Expand Down
37 changes: 21 additions & 16 deletions cogs/badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

import nextcord
from nextcord.ext import commands
from utils import log, langmgr, restrictions as r
from typing import Optional
from utils import log, langmgr, restrictions_legacy as r_legacy, slash as slash_handler
from enum import Enum

restrictions = r.Restrictions()
restrictions_legacy = r_legacy.Restrictions()
language = langmgr.partial()
language.load()
slash = slash_handler.SlashHelper(language)

class UserRole(Enum):
# let values be None until set by langmgr
Expand Down Expand Up @@ -54,18 +56,21 @@ def __init__(self, bot):
UserRole.BANNED: nextcord.Color.red(),
UserRole.USER: nextcord.Color.blurple()
}
restrictions.attach_bot(self.bot)

@commands.command(description=language.desc('badge.badge'))
async def badge(self, ctx, *, user=None):
restrictions_legacy.attach_bot(self.bot)

@nextcord.slash_command(
description=language.desc('badge.badge'),
description_localizations=language.slash_desc('badge.badge'),
contexts=[nextcord.InteractionContextType.guild, nextcord.InteractionContextType.bot_dm],
integration_types=[nextcord.IntegrationType.guild_install]
)
async def badge(
self, ctx: nextcord.Interaction,
user: Optional[nextcord.User] = slash.option('badge.badge.user', required=False)
):
selector = language.get_selector(ctx)
if user:
try:
user = self.bot.get_user(int(user.replace('<@','',1).replace('>','',1).replace('!','',1)))
except:
user = ctx.author
else:
user = ctx.author
if not user:
user = ctx.user
user_role = self.get_user_role(user.id)
embed = nextcord.Embed(
description=selector.fget("body", values={
Expand All @@ -83,7 +88,7 @@ async def badge(self, ctx, *, user=None):
await ctx.send(embed=embed)

@commands.command(hidden=True,aliases=['trust'],description=language.desc('badge.verify'))
@restrictions.admin()
@restrictions_legacy.admin()
async def verify(self, ctx, user: nextcord.User):
selector = language.get_selector(ctx)

Expand All @@ -98,7 +103,7 @@ async def verify(self, ctx, user: nextcord.User):
await ctx.send(f'{self.bot.ui_emojis.success} '+selector.fget("success", values={'user': user.name}))

@commands.command(hidden=True, aliases=['untrust'], description=language.desc('badge.unverify'))
@restrictions.admin()
@restrictions_legacy.admin()
async def unverify(self, ctx, user: nextcord.User):
selector = language.get_selector(ctx)

Expand All @@ -113,7 +118,7 @@ async def unverify(self, ctx, user: nextcord.User):
await ctx.send(f'{self.bot.ui_emojis.success} '+selector.fget("success", values={'user': user.name}))

def get_user_role(self, user_id):
if user_id == self.bot.config['owner']:
if user_id == self.bot.owner or user_id in self.bot.other_owners:
return UserRole.OWNER
elif user_id in self.bot.admins:
return UserRole.ADMIN
Expand Down
Loading

0 comments on commit 4010fb8

Please sign in to comment.