jarvis-bot/jarvis/cogs/settings.py

158 lines
4.9 KiB
Python

import discord
from discord import Role, TextChannel
from discord.ext import commands
from discord_slash import cog_ext
from discord_slash.utils.manage_commands import create_option
import jarvis
from jarvis.config import get_config
from jarvis.utils import db
from jarvis.utils.permissions import admin_or_permissions
class SettingsCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
config = get_config()
self.db = db.DBManager(config.mongo).mongo
self.cache = {}
def update_settings(self, setting, value, guild):
settings = {"setting": setting, "value": value, "guild": guild}
updated = self.db.jarvis.settings.update_one(
{"setting": setting, "guild": guild},
{"$set": settings},
upsert=True,
)
return updated is not None
@cog_ext.cog_subcommand(
base="settings",
name="mute",
description="Set mute role",
guild_ids=[418094694325813248, 578757004059738142],
options=[
create_option(
name="role",
description="Mute role",
option_type=8,
required=True,
)
],
)
@admin_or_permissions(mute_members=True)
async def _mute(self, ctx, role: Role):
await ctx.defer()
self.update_settings("mute", role.id, ctx.guild.id)
await ctx.send(f"Settings applied. New mute role is `{role.name}`")
@cog_ext.cog_subcommand(
base="settings",
name="modlog",
description="Set modlog channel",
guild_ids=[418094694325813248, 578757004059738142],
options=[
create_option(
name="channel",
description="Modlog channel",
option_type=7,
required=True,
)
],
)
@commands.has_permissions(administrator=True)
async def _modlog(self, ctx, channel: TextChannel):
await ctx.defer()
self.update_settings("modlog", channel.id, ctx.guild.id)
await ctx.send(
f"Settings applied. New modlog channel is {channel.mention}"
)
@cog_ext.cog_subcommand(
base="settings",
name="userlog",
description="Set userlog channel",
guild_ids=[418094694325813248, 578757004059738142],
options=[
create_option(
name="channel",
description="Userlog channel",
option_type=7,
required=True,
)
],
)
@commands.has_permissions(administrator=True)
async def _userlog(self, ctx, channel: TextChannel):
await ctx.defer()
self.update_settings("userlog", channel.id, ctx.guild.id)
await ctx.send(
f"Settings applied. New userlog channel is {channel.mention}"
)
@cog_ext.cog_subcommand(
base="settings",
name="massmention",
description="Set massmention amount",
guild_ids=[418094694325813248, 578757004059738142],
options=[
create_option(
name="amount",
description="Amount of mentions (0 to disable)",
option_type=4,
required=True,
)
],
)
@commands.has_permissions(administrator=True)
async def _massmention(self, ctx, amount: int):
await ctx.defer()
self.update_settings("massmention", amount, ctx.guild.id)
await ctx.send(f"Settings applied. New massmention limit is {amount}")
@cog_ext.cog_subcommand(
base="settings",
name="verified",
description="Set verified role",
guild_ids=[418094694325813248, 578757004059738142],
options=[
create_option(
name="role",
description="verified role",
option_type=8,
required=True,
)
],
)
@admin_or_permissions(kick_members=True, ban_members=True)
async def _verified(self, ctx, role: Role):
await ctx.defer()
self.update_settings("verified", role.id, ctx.guild.id)
await ctx.send(f"Settings applied. New verified role is `{role.name}`")
@cog_ext.cog_subcommand(
base="settings",
name="unverified",
description="Set unverified role",
guild_ids=[418094694325813248, 578757004059738142],
options=[
create_option(
name="role",
description="Unverified role role",
option_type=8,
required=True,
)
],
)
@admin_or_permissions(kick_members=True, ban_members=True)
async def _unverified(self, ctx, role: Role):
await ctx.defer()
self.update_settings("unverified", role.id, ctx.guild.id)
await ctx.send(
f"Settings applied. New unverified role is `{role.name}`"
)
def setup(bot):
bot.add_cog(SettingsCog(bot))