Skip to content

Commit

Permalink
for v2.5.3-slash update (#5)
Browse files Browse the repository at this point in the history
* updated /help
* updated /debug
* updated /mention
* added /ping
* added description to slash commands

* other things i can't remember lol
  • Loading branch information
RJ1002 authored Apr 30, 2023
2 parents 3876302 + c687a29 commit 0fb6566
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 94 deletions.
11 changes: 5 additions & 6 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
from essentials.multi_server import get_pre
from essentials.settings import SETTINGS


class ClusterBot(commands.AutoShardedBot):
def __init__(self, **kwargs):
self.pipe = kwargs.pop('pipe')
self.cluster_name = kwargs.pop('cluster_name')
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
intents = discord.Intents.default()
intents = discord.Intents.all()
intents.messages = True
intents.members = True
intents.reactions = True
Expand All @@ -36,7 +35,7 @@ def __init__(self, **kwargs):
self._last_result = None
self.ws_task = None
self.responses = asyncio.Queue()
self.eval_wait = True
self.eval_wait = False
log = logging.getLogger(f"Cluster#{self.cluster_name}")
log.setLevel(logging.DEBUG)
log.handlers = [logging.FileHandler(f'cluster-{self.cluster_name}.log', encoding='utf-8', mode='a')]
Expand All @@ -51,8 +50,8 @@ def __init__(self, **kwargs):
self.pre = None

self.remove_command('help')
extensions = ['cogs.config', 'cogs.poll_controls', 'cogs.help', 'cogs.db_api', 'cogs.admin']
self.load_extension("cogs.eval")
extensions = ['cogs.config', 'cogs.poll_controls', 'cogs.help', 'cogs.db_api', 'cogs.admin']
self.loop.create_task(self.ensure_ipc())
for ext in extensions:
self.load_extension(ext)
Expand Down Expand Up @@ -89,7 +88,7 @@ async def on_ready(self):
self.emoji_dict = json.load(emojson)
self.pre = {entry['_id']: entry.get('prefix', 'pm!') async for entry in
self.db.config.find({}, {'_id', 'prefix'})}
await self.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="pm!help"))
await self.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="pm!help and /help"))

self.log.info(f'[Cluster#{self.cluster_name}] Ready called.')
self.pipe.send(1)
Expand Down Expand Up @@ -210,4 +209,4 @@ async def ensure_ipc(self):
except websockets.ConnectionClosed as exc:
self.log.warning(f"! couldnt connect to ws: {exc.code} {exc.reason}")
self.websocket = None
raise
raise
10 changes: 7 additions & 3 deletions cogs/admin.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import logging

import discord
from discord.ext import commands

from discord import app_commands

class Admin(commands.Cog):
def __init__(self, bot):
self.bot = bot

# every commands needs owner permissions
async def cog_check(self, ctx):
return self.bot.owner == ctx.author
return self.bot.owner == ctx.author.id

async def cog_command_error(self, ctx, error):
if isinstance(error, commands.CheckFailure):
await ctx.send("Only the owner can use this module. Join the support discord server if you are having "
"any problems. This usage has been logged.")
f"any problems. This usage has been logged.")
logger.warning(f'User {ctx.author} ({ctx.author.id}) has tried to access a restricted '
f'command via {ctx.message.content}.')
elif isinstance(error, commands.MissingRequiredArgument):
Expand All @@ -23,6 +24,9 @@ async def cog_command_error(self, ctx, error):
logger.warning(error)

@commands.hybrid_command(aliases=['r'], description="Reloads cogs")
@app_commands.describe(
cog='options: config, poll_controls, help, db_api, admin',
)
async def reload(self, ctx, *, cog):
if cog == 'c':
cog = 'poll_controls'
Expand Down
18 changes: 12 additions & 6 deletions cogs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ def __init__(self, bot):

@commands.hybrid_command(name="prefix", description="""Set a custom prefix for the server.""")
@commands.has_permissions(manage_guild=True)
@app_commands.describe(
pre='Choose the new prefix you want',
)
async def prefix(self, ctx, *, pre:str):
"""Set a custom prefix for the server."""
server = ctx.message.guild
Expand All @@ -29,10 +32,12 @@ async def prefix(self, ctx, *, pre:str):

@commands.hybrid_command(name="adminrole", description="Set or show the Admin Role. Members with this role can create polls and manage ALL polls.")
@commands.has_permissions(manage_guild=True)
@app_commands.describe(
role='Choose the role for admin',
)
async def adminrole(self, ctx, *, role: Role = None):
"""Set or show the Admin Role. Members with this role can create polls and manage ALL polls. Parameter: <role> (optional)"""
server = ctx.message.guild

if not role:
result = await self.bot.db.config.find_one({'_id': str(server.id)})
if result and result.get('admin_role'):
Expand All @@ -48,12 +53,13 @@ async def adminrole(self, ctx, *, role: Role = None):
await ctx.send(f'Server role `{role}` can now manage all polls.')
else:
await ctx.send(f'Server role `{role}` not found.')

@commands.hybrid_command(name="userrole", description="Set or show the User Role. Members with this role can create polls and manage their own polls.")
@commands.has_permissions(manage_guild=True)
@app_commands.describe(
role='Choose the role for user',
)
async def userrole(self, ctx, *, role: Role=None):
"""Set or show the User Role. Members with this role can create polls and manage their own polls.
Parameter: <role> (optional)"""
server = ctx.message.guild

if not role:
Expand All @@ -76,4 +82,4 @@ async def userrole(self, ctx, *, role: Role=None):
async def setup(bot):
global logger
logger = logging.getLogger('discord')
await bot.add_cog(Config(bot))
await bot.add_cog(Config(bot))
Loading

0 comments on commit 0fb6566

Please sign in to comment.