Skip to content

Commit

Permalink
update to current bot
Browse files Browse the repository at this point in the history
some major changes are:
- convert to slash only commands
- bug fixes and improvements
- add giveaway mode
- thumbnail option
- export
- remove prefix commands
- fix message cache
  • Loading branch information
RJ1002 authored Aug 13, 2024
1 parent a4473c8 commit fee899e
Show file tree
Hide file tree
Showing 9 changed files with 879 additions and 398 deletions.
23 changes: 12 additions & 11 deletions cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ async def cog_check(self, ctx):
async def cog_command_error(self, ctx, error):
if isinstance(error, commands.CheckFailure):
await ctx.reply("Only the bot owner can use this module. Join the support discord server if you are having "
f"any problems. This usage has been logged.", delete_after=60)
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 in guild: {ctx.author.guild} ({ctx.author.guild.id}). command used: `/reload` or `pm!reload`')
#send a DM to bot owner
warning = await self.bot.fetch_user(self.bot.owner)
await warning.send(f'User {ctx.author} ({ctx.author.id}) has tried to access a restricted '
f'command in guild: {ctx.author.guild} ({ctx.author.guild.id}). command used: `/reload` or `pm!reload`')
elif isinstance(error, commands.MissingRequiredArgument):
await ctx.reply("Missing a required argument for this command.", delete_after=60)
await ctx.reply("Missing a required argument for this command.")
else:
logger.warning(error)

Expand Down Expand Up @@ -67,17 +67,18 @@ async def reload(self, ctx, *, cog):
id='enter guild id to leave',
)
async def guildleave(self, ctx, *, id: id = None):
await ctx.response.defer(thinking=True)
result = await self.bot.db.config.find_one({'_id': id})
if not isinstance(ctx.channel, discord.TextChannel):
await ctx.response.send_message("`/guildleave` can only be used in a server text channel.", delete_after=60)
await ctx.followup.send("`/guildleave` can only be used in a server text channel.")
return
guild = ctx.guild
if not guild:
await ctx.response.send_message("Could not determine your server. Run the command in a server text channel.", delete_after=60)
await ctx.followup.send("Could not determine your server. Run the command in a server text channel.")
return
if not self.bot.owner == ctx.user.id:
await ctx.response.send_message("Only the bot owner can use this module. Join the support discord server if you are having "
f"any problems. This usage has been logged.", delete_after=60)
await ctx.followup.send("Only the bot owner can use this module. Join the support discord server if you are having "
f"any problems. This usage has been logged.")
logger.warning(f'User {ctx.user} ({ctx.user.id}) has tried to access a restricted '
f'command in guild: {ctx.user.guild} ({ctx.user.guild.id}). command used: `/guildleave`')
#send a DM to bot owner
Expand All @@ -86,18 +87,18 @@ async def guildleave(self, ctx, *, id: id = None):
f'command in guild: {ctx.user.guild} ({ctx.user.guild.id}). command used: `/guildleave`')
return
if not id:
await ctx.response.send_message(f'you need to choose a guild id! ', delete_after=60)
await ctx.followup.send(f'you need to choose a guild id! ')
return
if not result:
await ctx.response.send_message(f'guild id `{id}` not found.', delete_after=60)
await ctx.followup.send(f'guild id `{id}` not found.')
return
if id == result.get('_id'):
if id == result.get('_id') and self.bot.owner == ctx.user.id:
guildobject = self.bot.get_guild(int(id))
await ctx.response.send_message(f'bot left {id} {guildobject}', delete_after=60)
await ctx.response.send_message(f'bot left {id} {guildobject}')
await guildobject.leave()
return
else:
await ctx.response.send_message(f'guild id `{id}` not found.', delete_after=60)
await ctx.response.send_message(f'guild id `{id}` not found.')


async def setup(bot):
Expand Down
155 changes: 106 additions & 49 deletions cogs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,105 +8,162 @@
class Config(commands.Cog):
def __init__(self, bot):
self.bot = bot

async def cog_command_error(self, ctx, error):
if ctx.command.name == "adminrole":
print('cog error adminrole!')
await ctx.send(f'You don''t have permission to run this command! you need manage guild permission.', delete_after=60)
if ctx.command.name == "userrole":
print('cog error userrole!')
await ctx.send(f'You don''t have permission to run this command! you need manage guild permission.', delete_after=60)
if ctx.command.name == "prefix":
print('cog error userrole!')
await ctx.send(f'You don''t have permission to run this command! you need manage guild permission.', delete_after=60)

async def cog_app_command_error(self, interaction, error):
await interaction.response.defer(thinking=True)
if interaction.command.name == "settings":
await interaction.followup.send(f'You don''t have permission to run this command! you need manage guild permission.')
if interaction.command.name == "adminrole":
print('cog error adminrole!')
await interaction.followup.send(f'You don''t have permission to run this command! you need manage guild permission.')
if interaction.command.name == "userrole":
print('cog error userrole!')
await interaction.followup.send(f'You don''t have permission to run this command! you need manage guild permission.')

@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):
async def prefix(self, ctx, *, pre:str=None):
"""Set a custom prefix for the server."""
server = ctx.message.guild
if pre.endswith('\w'):
pre = pre[:-2]+' '
if len(pre.strip()) > 0:
msg = f'The server prefix has been set to `{pre}` Use `{pre}prefix <prefix>` to change it again.'
else:
await ctx.send('Invalid prefix.')
return
else:
msg = f'The server prefix has been set to `{pre}` Use `{pre}prefix <prefix>` to change it again. ' \
f'If you would like to add a trailing whitespace to the prefix, use `{pre}prefix {pre}\w`.'
#server = ctx.message.guild
#if pre.endswith('\w'):
# pre = pre[:-2]+' '
# if len(pre.strip()) > 0:
# msg = f'The server prefix has been set to `{pre}` Use `{pre}prefix <prefix>` to change it again.'
# else:
# await ctx.send('Invalid prefix.')
# return
#else:
# msg = f'The server prefix has been set to `{pre}` Use `{pre}prefix <prefix>` to change it again. ' \
# f'If you would like to add a trailing whitespace to the prefix, use `{pre}prefix {pre}\w`.'

await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'prefix': str(pre)}}, upsert=True)
self.bot.pre[str(server.id)] = str(pre)
#await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'prefix': str(pre)}}, upsert=True)
#self.bot.pre[str(server.id)] = str(pre)
msg = f'This command is **disabled** as of 4/24/2024 EST\nJoin the support server for more info or if you have any questions.'
await ctx.send(msg)

@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.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.checks.has_permissions(manage_guild=True)
@app_commands.describe(
role='Choose the role for admin',
)
async def adminrole(self, ctx, *, role: Role = None):
server = ctx.message.guild
server = ctx.guild
await ctx.response.defer(thinking=True)

if not role:
result = await self.bot.db.config.find_one({'_id': str(server.id)})
if result and result.get('admin_role'):
await ctx.send(f'The admin role restricts which users are able to create and manage ALL polls on this server. \n'
await ctx.followup.send(f'The admin role restricts which users are able to create and manage ALL polls on this server. \n'
f'The current admin role is `{result.get("admin_role")}`. '
f'To change it type `{result.get("prefix")}adminrole <role name>`')
else:
await ctx.send(f'The admin role restricts which users are able to create and manage ALL polls on this server. \n'
await ctx.followup.send(f'The admin role restricts which users are able to create and manage ALL polls on this server. \n'
f'No admin role set. '
f'To set one type `{result.get("prefix")}adminrole <role name>`')
elif role.name in [r.name for r in server.roles]:
await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'admin_role': str(role)}}, upsert=True)
await ctx.send(f'Server role `{role}` can now manage all polls.')
await ctx.followup.send(f'Server role `{role}` can now manage all polls.')
else:
await ctx.send(f'Server role `{role}` not found.')
await ctx.followup.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.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.checks.has_permissions(manage_guild=True)
@app_commands.describe(
role='Choose the role for user',
)
async def userrole(self, ctx, *, role: Role=None):
server = ctx.message.guild
server = ctx.guild
await ctx.response.defer(thinking=True)

if not role:
result = await self.bot.db.config.find_one({'_id': str(server.id)})
if result and result.get('user_role'):
await ctx.send(f'The user role restricts which users are able to create and manage their own polls. \n'
await ctx.followup.send(f'The user role restricts which users are able to create and manage their own polls. \n'
f'The current user role is `{result.get("user_role")}`. '
f'To change it type `{result.get("prefix")}userrole <role name>`')
else:
await ctx.send(f'The user role restricts which users are able to create and manage their own polls. \n'
await ctx.followup.send(f'The user role restricts which users are able to create and manage their own polls. \n'
f'No user role set. '
f'To set one type `{result.get("prefix")}userrole <role name>`')
elif role.name in [r.name for r in server.roles]:
await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'user_role': str(role)}}, upsert=True)
await ctx.send(f'Server role `{role}` can now create and manage their own polls.')
await ctx.followup.send(f'Server role `{role}` can now create and manage their own polls.')
else:
await ctx.send(f'Server role `{role}` not found.')
await ctx.followup.send(f'Server role `{role}` not found.')

@app_commands.command(name="errormessage", description="to enable or disable error message (Beta)")
@app_commands.command(name="settings", description="to change settings (Beta)")
@app_commands.checks.has_permissions(manage_guild=True)
async def errormessage(self, ctx):
print('error message ran!')
@app_commands.describe(
change=f'what setting do you want to change the status of',
)
@app_commands.choices(
change=[discord.app_commands.Choice(name='pollclosed message', value=1), discord.app_commands.Choice(name='errormessage', value=2)],
)
async def settings(self, ctx, *, change: discord.app_commands.Choice[int]):
server = ctx.guild
result = await self.bot.db.config.find_one({'_id': str(server.id)},{'_id': 1, 'error_mess': 2})

if result and not result.get('error_mess'):
print('error config not found!', result.get('error_mess'))
await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'error_mess': 'True'}}, upsert=True)
await ctx.response.send_message("error messages was set to `enable`!!", delete_after=60)

elif result and result.get('error_mess'):
print('error resultget!', result.get('error_mess'))
if result.get('error_mess') == 'True':
await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'error_mess': 'False'}}, upsert=True)
await ctx.response.send_message("error messages was set to `disabled`!!", delete_after=60)
print('error result true')
result = await self.bot.db.config.find_one({'_id': str(server.id)},{'_id': 1, 'error_mess': 2, 'closedpoll_mess': 3 })
await ctx.response.defer(thinking=True)
print('settings message ran!')
if change.name == "pollclosed message": #pollclosed message
if result and not result.get('closedpoll_mess'):
print('closed poll config not found!', result.get('closedpoll_mess'))
await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'closedpoll_mess': 'True'}}, upsert=True)
await ctx.followup.send("closed poll message was set to `enable`!!")

elif result and result.get('error_mess') == 'False':
elif result and result.get('closedpoll_mess'):
print('closed poll resultget!', result.get('closedpoll_mess'))
if result.get('closedpoll_mess') == 'True':
await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'closedpoll_mess': 'False'}}, upsert=True)
await ctx.followup.send("closed poll message was set to `disabled`!!")
print('closed poll result true')

elif result and result.get('closedpoll_mess') == 'False':
await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'closedpoll_mess': 'True'}}, upsert=True)
await ctx.followup.send("closed poll message was set to `enable`!!")
print('closed poll result false')
else:
await ctx.followup.send("unknown error has occurred. please report to dev!")
else:
await ctx.followup.send("unknown error has occurred. please report to dev!")
elif change.name == "errormessage": #errormessage
if result and not result.get('error_mess'):
print('error config not found!', result.get('error_mess'))
await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'error_mess': 'True'}}, upsert=True)
await ctx.response.send_message("error messages was set to `enable`!!", delete_after=60)
print('error result false')
await ctx.followup.send("error messages was set to `enable`!!")

elif result and result.get('error_mess'):
print('error resultget!', result.get('error_mess'))
if result.get('error_mess') == 'True':
await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'error_mess': 'False'}}, upsert=True)
await ctx.followup.send("error messages was set to `disabled`!!")
print('error result true')

elif result and result.get('error_mess') == 'False':
await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'error_mess': 'True'}}, upsert=True)
await ctx.followup.send("error messages was set to `enable`!!")
print('error result false')
else:
await ctx.followup.send("unknown error has occurred. please report to dev!")
else:
await ctx.response.send_message("unknown error has occurred. please report to dev!", delete_after=60)
await ctx.followup.send("unknown error has occurred. please report to dev!")
else:
await ctx.response.send_message("unknown error has occurred. please report to dev!", delete_after=60)
await ctx.followup.send("unknown error has occured. please report to Dev!")


async def setup(bot):
Expand Down
Loading

0 comments on commit fee899e

Please sign in to comment.