From 500ab15133529566bcb62393544dd92d36409494 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Sun, 4 Dec 2022 19:01:06 -0500 Subject: [PATCH 01/38] V2 This aims to switch the bot completely to slash commands, fix some bugs, remove unneeded code, fix some grammar issues, and generally make the bot much better --- main.py | 164 +++++++++++++++----------------------------------------- 1 file changed, 44 insertions(+), 120 deletions(-) diff --git a/main.py b/main.py index 716cf04..4c1a82b 100644 --- a/main.py +++ b/main.py @@ -1,24 +1,19 @@ import discord -from discord.ext import commands import os from dotenv import load_dotenv load_dotenv() - intents = discord.Intents.default() intents.message_content = True -bot = commands.Bot(debug_guilds=[955135608228024394], command_prefix="-", status=discord.Status.dnd, +bot = discord.Bot(debug_guilds=[955135608228024394], status=discord.Status.dnd, activity=discord.Activity(type=discord.ActivityType.listening, name="keyboard noises and no errors"), - owner='820255805257023498', intents=intents, ) - -bot = discord.Bot() - + intents=intents) -@bot.listen() +@bot.event async def on_ready(): - embed = discord.Embed(title=":green_circle: Online!\nTime to mess around!", timestamp=discord.utils.utcnow(), - color=0x00ff00, ) + embed = discord.Embed(title="🟢 Online!\nTime to mess around!", timestamp=discord.utils.utcnow(), + color=discord.Color.green()) await bot.get_guild(955135608228024394).get_channel(1011649871511572500).send(embed=embed) print("Now ready!") @@ -26,144 +21,73 @@ async def on_ready(): @bot.slash_command(description="Restart the bot") async def restart(ctx): await ctx.respond("Restarting.") - embed = discord.Embed(title=":arrows_counterclockwise: Restarting...", timestamp=discord.utils.utcnow(), color=0xFFA500) + embed = discord.Embed(title="🔄 Restarting...", timestamp=discord.utils.utcnow(), color=discord.Color.orange()) await bot.get_guild(955135608228024394).get_channel(1048306173071347782).send(embed=embed) quit() -@bot.slash_command(name="cal1", description="run a calculation") -async def cal1(ctx, first: discord.Option(int), mark: discord.Option(description="What operation you want to run", choices=["+", "-", "*", "/"]), second: discord.Option(int)): - if mark == "+": - calcu = f"{first}+{second} = {first + second}" - print('cal done ') - if mark==('-'): - calcu=(f"{first}-{second} = {first - second}") - if mark==('*'): - calcu=(f"{first} {mark} {second} = {first * second}") - if mark== '/': - if first or second !=0: - calcu=(f"{first}/{second} = {first / second}") - embed=discord.Embed(title='calculation',timestamp=discord.utils.utcnow(),color=0x00ff00,) - embed.add_field(name='your calculation is here!', value=calcu) +@bot.slash_command(description="Run a calculation") +async def math(ctx, first: discord.Option(int, description="The first number"), second: discord.Option(int, description="The second number"), operation: discord.Option(description="What operation you want to run", choices=["+", "-", "*", "/"])): + await ctx.defer() + if operation == "+": + output = f"{first}+{second} = {first + second}" + if operation == '-': + output=(f"{first}-{second} = {first - second}") + if operation == '*': + output=(f"{first}*{second} = {first * second}") + if operation == '/': + if second == 0: + output=(f"Can't divide by 0") + if second != 0: + output=(f"{first}/{second} = {first / second}") + embed=discord.Embed(title='Calculation', timestamp=discord.utils.utcnow(), color=discord.Color.green()) + embed.add_field(name='Your calculation is here!', value=output) await ctx.respond(embed=embed) - print(f'command cal runned; {calcu} {discord.user.User}') - + print(f'command math called {output} {ctx.author}') - - - - -@bot.slash_command(name='info', description='get info about the bot') +@bot.slash_command(description='Get info about the bot') async def info(ctx): embed = discord.Embed( title="DobbieBot", description ="The Dobbie bot ", timestamp=discord.utils.utcnow(), color=discord.Color.dark_gray()) - embed.add_field(name="ping",value=(f'ping = {round(bot.latency*1000, 2)}')) - embed.add_field(name="info about the bot", + embed.add_field(name="Ping",value=(round(bot.latency * 1000))) + embed.add_field(name="Info about the bot", value="this bot is made by Soapy7261#8558 and Dobbie#4778. To learn Dobbie how Discord bots work and how py-cord works!") - embed.add_field(name="main commands", value="the /call1 comamnd and the /info command") + embed.add_field(name="Main commands", value="the /math comamnd and the /info command") await ctx.respond(embed=embed) +@bot.slash_command(description='Say hello', guild_ids=[955135608228024394]) +async def hello(ctx): + await ctx.respond(f"Hello {ctx.user.mention}!", ephemeral=True) - - -@bot.slash_command(name="hello", description='say hello', guild=discord.Object(id=955135608228024394)) -async def hello(interaction: discord.Interaction): - await interaction.response.send_message(f"he {interaction.user}", ephemeral=True) - - - - - - - -@bot.slash_command(name="distance-thing", description="change the Mesure ting") - - -@bot.command() +@bot.slash_command(description='Test command') async def test(ctx): await ctx.send("te@st!") print("send command 'test!'") - -@bot.command() -async def add(ctx, add1: int, add2: int): - add.thing='this command is now merged in to the -call command use `-call', add1 , add2, ' and then whitout those stupid marks' - await ctx.send (add.thig) - print("command used 'add'.") - - -@bot.command() -async def multi(ctx, multi1: int, multi2: int): - await ctx.send(f"{multi1} * {multi2} = {multi1 * multi2}") - print("command used 'muti'.") - - -@bot.command() -async def divide(ctx, divide1: int, divide2: int): - if divide2 == 0: - await ctx.send("You fool. :smiling_imp: ") - return - await ctx.send(f"{divide1} / {divide2} = {divide1 / divide2}") - print("command used 'divide'.") - print(f"{divide1} / {divide2} = {divide1 / divide2}") - - -@bot.command() -async def sub(ctx, subt1: int, subt2: int): - await ctx.respond(f"{subt1}-{subt2} = {subt1 - subt2}") - print("command sub is used" + f"{subt1}-{subt2} = {subt1 - subt2}") - - -@bot.command() -async def papa(ctx, *, b1): - await ctx.send(b1) - -@bot.command() -async def cal(ctx,nr1: int, mark, nr2:int ): - - if mark==("+"): - calcu=(f"{nr1}+{nr2} = {nr1 + nr2}") - if mark==('-'): - calcu=(f"{nr1}-{nr2} = {nr1 - nr2}") - if mark==('*', 'x'): - if nr2!= 0: - calcu=(f"{nr1} {mark} {nr2} = {nr1 * nr2}") - if mark== '/': - if nr2 !=0: - calcu=(f"{nr1}/{nr2} = {nr1 / nr2}") - else: - calcu=("you fool!") - embed=discord.Embed(title='calculation',timestamp=discord.utils.utcnow(),color=0x00ff00,) - embed.add_field(name='your calculation is here!', value=calcu) - await ctx.send(embed=embed) - print(f'command cal runned; {calcu} {discord.user.User}') - - - - - +@bot.slash_command(description="Say something through the bot") +async def say(ctx, message: discord.Option(str, description="The message to say")): + await ctx.delete() + await ctx.send(message) @bot.event async def on_command_error(ctx, error): - if isinstance(error, discord.ext.commands.CommandError): - await ctx.reply(f"oh noo! there is an error:```py\n{str(error)}```message the owner for support") - embed = discord.Embed(title="Error :(", timestamp=discord.utils.utcnow(),color=0xff0000, ) - #embed.add_field(name = "Author:", value=message.author) - #embed.add_field(name = "Author ID:", value = message.author.id) - embed.add_field(name = "Error:", value=str(error)) + await ctx.reply(f"An error occurred```py\n{str(error)}\n```Message the owner for support\nThis has been logged.") + embed = discord.Embed(title="Error :(", timestamp=discord.utils.utcnow(),color=discord.Color.red()) + embed.add_field(name = "Error:", value=str(error)) - await bot.get_guild(955135608228024394).get_channel(1017880577506017361).send(embed=embed) + await bot.get_guild(955135608228024394).get_channel(1017880577506017361).send(embed=embed) -@bot.listen() +@bot.event async def on_message(message): print ("message") - print (discord.message.content) + print (message.content) if "dobbie" in message.content.lower(): - print('your got fans') - await discord.PartialMessage.message.add_reaction() + print('you got fans') + #Add an eyes reaction + await message.add_reaction("👀") bot.run(os.getenv('TOKEN')) From c002360faebd09f20a28a11ddd7ec17ef6afcee0 Mon Sep 17 00:00:00 2001 From: Soapy7261 <81933267+Soapy7261@users.noreply.github.com> Date: Sun, 4 Dec 2022 19:31:10 -0600 Subject: [PATCH 02/38] Lint --- .github/workflows/pylint.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/pylint.yml diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 0000000..5abdb30 --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,23 @@ +name: Pylint + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pylint + - name: Analysing the code with pylint + run: | + pylint $(git ls-files '*.py') From 530d55b0b74339f8c97f07c4f8ff8803a0e68e2a Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Sun, 4 Dec 2022 20:55:00 -0500 Subject: [PATCH 03/38] Correct stuff --- launcher.py | 20 +++++++++++--------- main.py | 9 ++++----- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/launcher.py b/launcher.py index 635ea62..04c9f4b 100644 --- a/launcher.py +++ b/launcher.py @@ -1,14 +1,16 @@ -#This is for restarting the python script, before you make a pr to use os.exec() instead, please know that it doesn't run new code, it just restarts the existing script, so you'll have to restart the script manually after making changes -import subprocess, time +import subprocess +import time while True: print ("Starting bot...") - g = subprocess.run("git pull") # Pulls the latest code from GitHub, if you do not have git installed, you can remove this line + g = subprocess.run("git pull", check=True) #Pulls the latest code from GitHub if g.returncode != 0: - print ("Error pulling code from github, this is likely because you don't have git installed, if you do have git installed, please check your configuration for git and try again") - time.sleep(5) - pass - p = subprocess.run('py main.py') + print ("""Error pulling code from github, this is + likely because you don't have git installed, + if you do have git installed, + please check your configuration for git + and try again""") + p = subprocess.run("py main.py", check=True) if p.returncode != 0: - print ("Hmmm, something went wrong, restarting in 8 seconds...") + print ("Hmmm, something went wrong.") print('Restarting bot...') - time.sleep(4) #This is to prevent the script from restarting too fast, which causes discord to get rate limited \ No newline at end of file + time.sleep(4) diff --git a/main.py b/main.py index 4c1a82b..0e3e688 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ -import discord import os +import discord from dotenv import load_dotenv load_dotenv() @@ -7,13 +7,13 @@ intents = discord.Intents.default() intents.message_content = True bot = discord.Bot(debug_guilds=[955135608228024394], status=discord.Status.dnd, - activity=discord.Activity(type=discord.ActivityType.listening, name="keyboard noises and no errors"), - intents=intents) + activity=discord.Activity(type=discord.ActivityType.listening, name="keyboard noises and no errors"), + intents=intents) @bot.event async def on_ready(): embed = discord.Embed(title="🟢 Online!\nTime to mess around!", timestamp=discord.utils.utcnow(), - color=discord.Color.green()) + color=discord.Color.green()) await bot.get_guild(955135608228024394).get_channel(1011649871511572500).send(embed=embed) print("Now ready!") @@ -25,7 +25,6 @@ async def restart(ctx): await bot.get_guild(955135608228024394).get_channel(1048306173071347782).send(embed=embed) quit() - @bot.slash_command(description="Run a calculation") async def math(ctx, first: discord.Option(int, description="The first number"), second: discord.Option(int, description="The second number"), operation: discord.Option(description="What operation you want to run", choices=["+", "-", "*", "/"])): await ctx.defer() From f2c596de1c86edfef8d6d10c95b4b3fcc0564336 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Sun, 4 Dec 2022 20:59:41 -0500 Subject: [PATCH 04/38] I hate pylint --- .github/workflows/pylint.yml | 2 ++ launcher.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 5abdb30..1ee28bb 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -18,6 +18,8 @@ jobs: run: | python -m pip install --upgrade pip pip install pylint + pip install py-cord + pip install python-dotenv - name: Analysing the code with pylint run: | pylint $(git ls-files '*.py') diff --git a/launcher.py b/launcher.py index 04c9f4b..cd76c48 100644 --- a/launcher.py +++ b/launcher.py @@ -4,10 +4,10 @@ print ("Starting bot...") g = subprocess.run("git pull", check=True) #Pulls the latest code from GitHub if g.returncode != 0: - print ("""Error pulling code from github, this is - likely because you don't have git installed, - if you do have git installed, - please check your configuration for git + print ("""Error pulling code from github, this is + likely because you don't have git installed, + if you do have git installed, + please check your configuration for git and try again""") p = subprocess.run("py main.py", check=True) if p.returncode != 0: From 83d8b6e408fd78853a919d073bfec81809f0638a Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Sun, 4 Dec 2022 21:13:05 -0500 Subject: [PATCH 05/38] Happy now pylint? --- main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 0e3e688..702d543 100644 --- a/main.py +++ b/main.py @@ -12,6 +12,7 @@ @bot.event async def on_ready(): + """When the bot is ready, print a message to the console.""" embed = discord.Embed(title="🟢 Online!\nTime to mess around!", timestamp=discord.utils.utcnow(), color=discord.Color.green()) await bot.get_guild(955135608228024394).get_channel(1011649871511572500).send(embed=embed) @@ -20,6 +21,7 @@ async def on_ready(): @bot.slash_command(description="Restart the bot") async def restart(ctx): + """Restart the bot""" await ctx.respond("Restarting.") embed = discord.Embed(title="🔄 Restarting...", timestamp=discord.utils.utcnow(), color=discord.Color.orange()) await bot.get_guild(955135608228024394).get_channel(1048306173071347782).send(embed=embed) @@ -27,6 +29,7 @@ async def restart(ctx): @bot.slash_command(description="Run a calculation") async def math(ctx, first: discord.Option(int, description="The first number"), second: discord.Option(int, description="The second number"), operation: discord.Option(description="What operation you want to run", choices=["+", "-", "*", "/"])): + """Run a calculation""" await ctx.defer() if operation == "+": output = f"{first}+{second} = {first + second}" @@ -36,7 +39,7 @@ async def math(ctx, first: discord.Option(int, description="The first number"), output=(f"{first}*{second} = {first * second}") if operation == '/': if second == 0: - output=(f"Can't divide by 0") + output=("Can't divide by 0") if second != 0: output=(f"{first}/{second} = {first / second}") embed=discord.Embed(title='Calculation', timestamp=discord.utils.utcnow(), color=discord.Color.green()) @@ -46,6 +49,7 @@ async def math(ctx, first: discord.Option(int, description="The first number"), @bot.slash_command(description='Get info about the bot') async def info(ctx): + """Get info about the bot""" embed = discord.Embed( title="DobbieBot", description ="The Dobbie bot ", @@ -60,20 +64,24 @@ async def info(ctx): @bot.slash_command(description='Say hello', guild_ids=[955135608228024394]) async def hello(ctx): + """Say hello""" await ctx.respond(f"Hello {ctx.user.mention}!", ephemeral=True) @bot.slash_command(description='Test command') async def test(ctx): + """Test command""" await ctx.send("te@st!") print("send command 'test!'") @bot.slash_command(description="Say something through the bot") async def say(ctx, message: discord.Option(str, description="The message to say")): + """Say something""" await ctx.delete() await ctx.send(message) @bot.event async def on_command_error(ctx, error): + """When an error occurs""" await ctx.reply(f"An error occurred```py\n{str(error)}\n```Message the owner for support\nThis has been logged.") embed = discord.Embed(title="Error :(", timestamp=discord.utils.utcnow(),color=discord.Color.red()) embed.add_field(name = "Error:", value=str(error)) @@ -82,6 +90,7 @@ async def on_command_error(ctx, error): @bot.event async def on_message(message): + """When a message is sent""" print ("message") print (message.content) if "dobbie" in message.content.lower(): From a13090b1c45375d0f157e94b32d273c2c8f4e4b6 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Sun, 4 Dec 2022 21:18:56 -0500 Subject: [PATCH 06/38] ange --- launcher.py | 2 -- main.py | 33 ++++++++++++++++++++------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/launcher.py b/launcher.py index cd76c48..0c9d619 100644 --- a/launcher.py +++ b/launcher.py @@ -10,7 +10,5 @@ please check your configuration for git and try again""") p = subprocess.run("py main.py", check=True) - if p.returncode != 0: - print ("Hmmm, something went wrong.") print('Restarting bot...') time.sleep(4) diff --git a/main.py b/main.py index 702d543..5bfab2a 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,16 @@ import os +import sys import discord from dotenv import load_dotenv load_dotenv() -intents = discord.Intents.default() -intents.message_content = True -bot = discord.Bot(debug_guilds=[955135608228024394], status=discord.Status.dnd, - activity=discord.Activity(type=discord.ActivityType.listening, name="keyboard noises and no errors"), +intents = discord.Intents.all() +bot = discord.Bot(debug_guilds=[955135608228024394], + status=discord.Status.dnd, + activity=discord.Activity( + type=discord.ActivityType.listening, + name="keyboard noises and no errors"), intents=intents) @bot.event @@ -24,8 +27,10 @@ async def restart(ctx): """Restart the bot""" await ctx.respond("Restarting.") embed = discord.Embed(title="🔄 Restarting...", timestamp=discord.utils.utcnow(), color=discord.Color.orange()) - await bot.get_guild(955135608228024394).get_channel(1048306173071347782).send(embed=embed) - quit() + await bot.get_guild(955135608228024394).get_channel( + 1048306173071347782).send( + embed=embed) + sys.exit() @bot.slash_command(description="Run a calculation") async def math(ctx, first: discord.Option(int, description="The first number"), second: discord.Option(int, description="The second number"), operation: discord.Option(description="What operation you want to run", choices=["+", "-", "*", "/"])): @@ -34,14 +39,14 @@ async def math(ctx, first: discord.Option(int, description="The first number"), if operation == "+": output = f"{first}+{second} = {first + second}" if operation == '-': - output=(f"{first}-{second} = {first - second}") + output= f"{first}-{second} = {first - second}" if operation == '*': - output=(f"{first}*{second} = {first * second}") + output= f"{first}*{second} = {first * second}" if operation == '/': if second == 0: - output=("Can't divide by 0") + output= "Can't divide by 0" if second != 0: - output=(f"{first}/{second} = {first / second}") + output= f"{first}/{second} = {first / second}" embed=discord.Embed(title='Calculation', timestamp=discord.utils.utcnow(), color=discord.Color.green()) embed.add_field(name='Your calculation is here!', value=output) await ctx.respond(embed=embed) @@ -52,14 +57,16 @@ async def info(ctx): """Get info about the bot""" embed = discord.Embed( title="DobbieBot", - description ="The Dobbie bot ", + description = "The Dobbie bot", timestamp=discord.utils.utcnow(), color=discord.Color.dark_gray()) embed.add_field(name="Ping",value=(round(bot.latency * 1000))) embed.add_field(name="Info about the bot", - value="this bot is made by Soapy7261#8558 and Dobbie#4778. To learn Dobbie how Discord bots work and how py-cord works!") + value="""this bot is made by Soapy7261#8558 + and Dobbie#4778. To teach Dobbie how + Discord bots work and how py-cord works!""") - embed.add_field(name="Main commands", value="the /math comamnd and the /info command") + embed.add_field(name="Main commands", value="/math\n/info") await ctx.respond(embed=embed) @bot.slash_command(description='Say hello', guild_ids=[955135608228024394]) From c5741ace7a10c6aad2cd0f8dd82059941e61a0ac Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Sun, 4 Dec 2022 21:23:12 -0500 Subject: [PATCH 07/38] ... --- .pylintrc | 2 ++ main.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..24ffea9 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,2 @@ +[MESSAGES CONTROL] +disable=missing-docstring,missing-module-docstring \ No newline at end of file diff --git a/main.py b/main.py index 5bfab2a..9076446 100644 --- a/main.py +++ b/main.py @@ -6,10 +6,11 @@ load_dotenv() intents = discord.Intents.all() -bot = discord.Bot(debug_guilds=[955135608228024394], +bot = discord.Bot( + debug_guilds=[955135608228024394], status=discord.Status.dnd, activity=discord.Activity( - type=discord.ActivityType.listening, + type=discord.ActivityType.listening, name="keyboard noises and no errors"), intents=intents) From 19163b2c3a12d889dfac96d4fc5a083f080b78a0 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Sun, 4 Dec 2022 21:24:18 -0500 Subject: [PATCH 08/38] STOP. --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 24ffea9..3df2feb 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,2 +1,2 @@ [MESSAGES CONTROL] -disable=missing-docstring,missing-module-docstring \ No newline at end of file +disable=missing-docstring,missing-module-docstring,line-too-long \ No newline at end of file From 4559038b90a7711314e9ebdc7cec33b7bf209b69 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Sun, 4 Dec 2022 23:18:18 -0500 Subject: [PATCH 09/38] Can't stop me now! --- main.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index 9076446..7f5c328 100644 --- a/main.py +++ b/main.py @@ -6,17 +6,14 @@ load_dotenv() intents = discord.Intents.all() -bot = discord.Bot( - debug_guilds=[955135608228024394], +bot = discord.Bot(debug_guilds=[955135608228024394], status=discord.Status.dnd, - activity=discord.Activity( - type=discord.ActivityType.listening, + activity=discord.Activity(type=discord.ActivityType.listening, name="keyboard noises and no errors"), intents=intents) @bot.event async def on_ready(): - """When the bot is ready, print a message to the console.""" embed = discord.Embed(title="🟢 Online!\nTime to mess around!", timestamp=discord.utils.utcnow(), color=discord.Color.green()) await bot.get_guild(955135608228024394).get_channel(1011649871511572500).send(embed=embed) @@ -25,17 +22,13 @@ async def on_ready(): @bot.slash_command(description="Restart the bot") async def restart(ctx): - """Restart the bot""" await ctx.respond("Restarting.") embed = discord.Embed(title="🔄 Restarting...", timestamp=discord.utils.utcnow(), color=discord.Color.orange()) - await bot.get_guild(955135608228024394).get_channel( - 1048306173071347782).send( - embed=embed) + await bot.get_guild(955135608228024394).get_channel(1048306173071347782).send(embed=embed) sys.exit() @bot.slash_command(description="Run a calculation") async def math(ctx, first: discord.Option(int, description="The first number"), second: discord.Option(int, description="The second number"), operation: discord.Option(description="What operation you want to run", choices=["+", "-", "*", "/"])): - """Run a calculation""" await ctx.defer() if operation == "+": output = f"{first}+{second} = {first + second}" @@ -55,7 +48,6 @@ async def math(ctx, first: discord.Option(int, description="The first number"), @bot.slash_command(description='Get info about the bot') async def info(ctx): - """Get info about the bot""" embed = discord.Embed( title="DobbieBot", description = "The Dobbie bot", @@ -72,12 +64,10 @@ async def info(ctx): @bot.slash_command(description='Say hello', guild_ids=[955135608228024394]) async def hello(ctx): - """Say hello""" await ctx.respond(f"Hello {ctx.user.mention}!", ephemeral=True) @bot.slash_command(description='Test command') async def test(ctx): - """Test command""" await ctx.send("te@st!") print("send command 'test!'") @@ -89,7 +79,6 @@ async def say(ctx, message: discord.Option(str, description="The message to say" @bot.event async def on_command_error(ctx, error): - """When an error occurs""" await ctx.reply(f"An error occurred```py\n{str(error)}\n```Message the owner for support\nThis has been logged.") embed = discord.Embed(title="Error :(", timestamp=discord.utils.utcnow(),color=discord.Color.red()) embed.add_field(name = "Error:", value=str(error)) @@ -98,7 +87,6 @@ async def on_command_error(ctx, error): @bot.event async def on_message(message): - """When a message is sent""" print ("message") print (message.content) if "dobbie" in message.content.lower(): From 47b4d2abc53ab7111139e08e5c9ce31674629884 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Mon, 5 Dec 2022 12:43:07 -0500 Subject: [PATCH 10/38] V2 is only started. --- .gitignore | 2 ++ .pylintrc | 2 +- README.md | 2 +- example.config.json | 3 +++ example.env | 1 + main.py | 6 +----- utils/data/getdata.py | 19 +++++++++++++++++++ 7 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100644 example.config.json create mode 100644 example.env create mode 100644 utils/data/getdata.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a72f057 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +config.json \ No newline at end of file diff --git a/.pylintrc b/.pylintrc index 3df2feb..2578923 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,2 +1,2 @@ [MESSAGES CONTROL] -disable=missing-docstring,missing-module-docstring,line-too-long \ No newline at end of file +disable=missing-docstring,missing-module-docstring,line-too-long,snake-case \ No newline at end of file diff --git a/README.md b/README.md index 06ce2ae..01186ff 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # DobbieBot -Discord fork used: pycord +Discord fork used: py-cord Checkout [this to install it](https://docs.pycord.dev/en/master/installing.html). diff --git a/example.config.json b/example.config.json new file mode 100644 index 0000000..e319b5a --- /dev/null +++ b/example.config.json @@ -0,0 +1,3 @@ +{ + "Token": "YourBotTokenHere" +} \ No newline at end of file diff --git a/example.env b/example.env new file mode 100644 index 0000000..e700f06 --- /dev/null +++ b/example.env @@ -0,0 +1 @@ +TOKEN=YOURBOTTOKENHERE \ No newline at end of file diff --git a/main.py b/main.py index 7f5c328..8c5f0ed 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,6 @@ import os import sys import discord -from dotenv import load_dotenv - -load_dotenv() - intents = discord.Intents.all() bot = discord.Bot(debug_guilds=[955135608228024394], status=discord.Status.dnd, @@ -80,7 +76,7 @@ async def say(ctx, message: discord.Option(str, description="The message to say" @bot.event async def on_command_error(ctx, error): await ctx.reply(f"An error occurred```py\n{str(error)}\n```Message the owner for support\nThis has been logged.") - embed = discord.Embed(title="Error :(", timestamp=discord.utils.utcnow(),color=discord.Color.red()) + embed = discord.Embed(title="Error :(", timestamp=discord.utils.utcnow(), color=discord.Color.red()) embed.add_field(name = "Error:", value=str(error)) await bot.get_guild(955135608228024394).get_channel(1017880577506017361).send(embed=embed) diff --git a/utils/data/getdata.py b/utils/data/getdata.py new file mode 100644 index 0000000..fe42f32 --- /dev/null +++ b/utils/data/getdata.py @@ -0,0 +1,19 @@ +def info(use_json: bool = False): + if use_json: + import json, os, sys + if os.path.exists("config.json"): + with open("config.json", "r") as f: + return json.load(f) + else: + print ("config.json not found! Please create it.") + sys.exit() + if not use_json: + from dotenv import load_dotenv + import os + load_dotenv() + if os.getenv("TOKEN") is None: + print("TOKEN not found! Please create it.") + sys.exit() + return { + "Token": os.getenv("TOKEN"), + } From 10931d9085abbfff97276b8c4ce5ff93ceb097ea Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Mon, 5 Dec 2022 12:45:01 -0500 Subject: [PATCH 11/38] no --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 2578923..8bb5f22 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,2 +1,2 @@ [MESSAGES CONTROL] -disable=missing-docstring,missing-module-docstring,line-too-long,snake-case \ No newline at end of file +disable=missing-docstring,missing-module-docstring,line-too-long,invalid-name,multiple-imports,import-outside-toplevel,inconsistent-return-statements \ No newline at end of file From 32dbb20dfaf5309c58f23f68203f1d785cbd785b Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Mon, 5 Dec 2022 12:46:08 -0500 Subject: [PATCH 12/38] Pylint is right --- utils/data/getdata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/data/getdata.py b/utils/data/getdata.py index fe42f32..938bc19 100644 --- a/utils/data/getdata.py +++ b/utils/data/getdata.py @@ -2,7 +2,7 @@ def info(use_json: bool = False): if use_json: import json, os, sys if os.path.exists("config.json"): - with open("config.json", "r") as f: + with open("config.json", "r", encoding="UTF-8") as f: return json.load(f) else: print ("config.json not found! Please create it.") From a55c1d08090163103c5178088e57b911c8679326 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Mon, 5 Dec 2022 12:47:37 -0500 Subject: [PATCH 13/38] oops --- utils/data/getdata.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/data/getdata.py b/utils/data/getdata.py index 938bc19..cfe1afa 100644 --- a/utils/data/getdata.py +++ b/utils/data/getdata.py @@ -9,11 +9,11 @@ def info(use_json: bool = False): sys.exit() if not use_json: from dotenv import load_dotenv - import os + import os, sys load_dotenv() if os.getenv("TOKEN") is None: print("TOKEN not found! Please create it.") sys.exit() return { "Token": os.getenv("TOKEN"), - } + } \ No newline at end of file From 3d36286005110012030dc25faeed04bfe5748769 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Mon, 5 Dec 2022 12:48:30 -0500 Subject: [PATCH 14/38] ok fine --- utils/data/getdata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/data/getdata.py b/utils/data/getdata.py index cfe1afa..75af57a 100644 --- a/utils/data/getdata.py +++ b/utils/data/getdata.py @@ -16,4 +16,4 @@ def info(use_json: bool = False): sys.exit() return { "Token": os.getenv("TOKEN"), - } \ No newline at end of file + } From 29848dc8a3dc6f6e951607467674ca66fab730cc Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Mon, 5 Dec 2022 13:17:41 -0500 Subject: [PATCH 15/38] New stuff incoming! --- cogs/cogs.py | 35 ++++++++++++++++++++++++++++ cogs/examples/cogexample.txt | 15 ++++++++++++ cogs/examples/defaultpermissions.txt | 16 +++++++++++++ cogs/examples/slashcommandgroup.txt | 17 ++++++++++++++ cogs/restart.py | 23 ++++++++++++++++++ example.config.json | 3 ++- example.env | 3 ++- main.py | 16 +++---------- utils/data/getdata.py | 4 ++++ utils/helpers/getcogs.py | 17 ++++++++++++++ 10 files changed, 134 insertions(+), 15 deletions(-) create mode 100644 cogs/cogs.py create mode 100644 cogs/examples/cogexample.txt create mode 100644 cogs/examples/defaultpermissions.txt create mode 100644 cogs/examples/slashcommandgroup.txt create mode 100644 cogs/restart.py create mode 100644 utils/helpers/getcogs.py diff --git a/cogs/cogs.py b/cogs/cogs.py new file mode 100644 index 0000000..8028f29 --- /dev/null +++ b/cogs/cogs.py @@ -0,0 +1,35 @@ +from discord import slash_command, commands +from utils.helpers import getcogs +import discord, os +from utils.data import getdata +info = getdata.info() +class Cogs(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print('Cogs cog loaded!') + + @slash_command(description='Load, unload, or reload cogs', guild_only=True) + async def cogs(self, ctx, action: discord.Option(choices=["Reload", "Load", "Unload"], description='What action to run', required=True), cog: discord.Option(autocomplete=getcogs, description='The cog to run the action on', required=True)): + if ctx.author.id != int(info['OwnerID']): + return await ctx.respond("You don't have permission to use this command!", ephemeral=True) + if cog not in [f"{fn[:-3]}" for fn in os.listdir("commands")]: + await ctx.respond("That cog doesn't exist!", ephemeral=True) + return + await ctx.defer(ephemeral=True) + try: + if action == "Load": + self.bot.load_extension(f"commands.{cog}") + if action == "Unload": + self.bot.unload_extension(f"commands.{cog}") + if action == "Reload": + self.bot.reload_extension(f"commands.{cog}") + except Exception as e: + await ctx.respond(f"```py\n{e}\n```", ephemeral=True) + return + await ctx.respond(f"{action}ed {cog}", ephemeral=True) + +def setup(bot): + bot.add_cog(Cogs(bot)) \ No newline at end of file diff --git a/cogs/examples/cogexample.txt b/cogs/examples/cogexample.txt new file mode 100644 index 0000000..1537e38 --- /dev/null +++ b/cogs/examples/cogexample.txt @@ -0,0 +1,15 @@ +from discord import slash_command, commands +class NAME(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print('BLANK cog loaded!') + + @slash_command(description='Your description') + async def command(self, ctx): + await ctx.respond('Your response') + +def setup(bot): + bot.add_cog(NAME(bot)) \ No newline at end of file diff --git a/cogs/examples/defaultpermissions.txt b/cogs/examples/defaultpermissions.txt new file mode 100644 index 0000000..93cb934 --- /dev/null +++ b/cogs/examples/defaultpermissions.txt @@ -0,0 +1,16 @@ +from discord import slash_command, commands, default_permissions +class NAME(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print('BLANK cog loaded!') + + @slash_command(description='Your description') + @default_permissions(administrator=True) # Tells discord to make the command admin only, so people without the permission can't see it + async def command(self, ctx): + await ctx.respond('Your response') + +def setup(bot): + bot.add_cog(NAME(bot)) \ No newline at end of file diff --git a/cogs/examples/slashcommandgroup.txt b/cogs/examples/slashcommandgroup.txt new file mode 100644 index 0000000..3b1029d --- /dev/null +++ b/cogs/examples/slashcommandgroup.txt @@ -0,0 +1,17 @@ +from discord import slash_command, commands +class NAME(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print('BLANK cog loaded!') + + group = discord.SlashCommandGroup("group", "Group description") + + @group.command(description='Your description') + async def command(self, ctx): + await ctx.respond('Your response') + +def setup(bot): + bot.add_cog(NAME(bot)) \ No newline at end of file diff --git a/cogs/restart.py b/cogs/restart.py new file mode 100644 index 0000000..39d0e5b --- /dev/null +++ b/cogs/restart.py @@ -0,0 +1,23 @@ +from discord import slash_command, commands +from utils.data import getdata +import discord, sys +info = getdata.info() +class Restart(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print('Restart cog loaded!') + + @slash_command(description="Restart the bot", guild_only=True) + async def restart(self, ctx): + if ctx.author.id != int(info['OwnerID']): + return await ctx.respond("You don't have permission to use this command!", ephemeral=True) + await ctx.respond("Restarting.") + embed = discord.Embed(title="🔄 Restarting...", timestamp=discord.utils.utcnow(), color=discord.Color.orange()) + await self.bot.get_guild(955135608228024394).get_channel(1048306173071347782).send(embed=embed) + sys.exit() + +def setup(bot): + bot.add_cog(Restart(bot)) \ No newline at end of file diff --git a/example.config.json b/example.config.json index e319b5a..330581f 100644 --- a/example.config.json +++ b/example.config.json @@ -1,3 +1,4 @@ { - "Token": "YourBotTokenHere" + "Token": "YourBotTokenHere", + "OwnerID": "YourIDHere" } \ No newline at end of file diff --git a/example.env b/example.env index e700f06..d224275 100644 --- a/example.env +++ b/example.env @@ -1 +1,2 @@ -TOKEN=YOURBOTTOKENHERE \ No newline at end of file +TOKEN=YOURBOTTOKENHERE +OWNERID=OWNERIDHERE \ No newline at end of file diff --git a/main.py b/main.py index 8c5f0ed..ac971cc 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,3 @@ -import os -import sys import discord intents = discord.Intents.all() bot = discord.Bot(debug_guilds=[955135608228024394], @@ -15,14 +13,6 @@ async def on_ready(): await bot.get_guild(955135608228024394).get_channel(1011649871511572500).send(embed=embed) print("Now ready!") - -@bot.slash_command(description="Restart the bot") -async def restart(ctx): - await ctx.respond("Restarting.") - embed = discord.Embed(title="🔄 Restarting...", timestamp=discord.utils.utcnow(), color=discord.Color.orange()) - await bot.get_guild(955135608228024394).get_channel(1048306173071347782).send(embed=embed) - sys.exit() - @bot.slash_command(description="Run a calculation") async def math(ctx, first: discord.Option(int, description="The first number"), second: discord.Option(int, description="The second number"), operation: discord.Option(description="What operation you want to run", choices=["+", "-", "*", "/"])): await ctx.defer() @@ -69,7 +59,6 @@ async def test(ctx): @bot.slash_command(description="Say something through the bot") async def say(ctx, message: discord.Option(str, description="The message to say")): - """Say something""" await ctx.delete() await ctx.send(message) @@ -89,5 +78,6 @@ async def on_message(message): print('you got fans') #Add an eyes reaction await message.add_reaction("👀") - -bot.run(os.getenv('TOKEN')) +from utils.data import getdata +info = getdata.info(False) +bot.run(info['Token']) \ No newline at end of file diff --git a/utils/data/getdata.py b/utils/data/getdata.py index 75af57a..63e1d66 100644 --- a/utils/data/getdata.py +++ b/utils/data/getdata.py @@ -14,6 +14,10 @@ def info(use_json: bool = False): if os.getenv("TOKEN") is None: print("TOKEN not found! Please create it.") sys.exit() + if os.getenv("OWNERID") is None: + print("OWNERID not found! Please create it.") + sys.exit() return { "Token": os.getenv("TOKEN"), + "OwnerID": os.getenv("OWNERID"), } diff --git a/utils/helpers/getcogs.py b/utils/helpers/getcogs.py new file mode 100644 index 0000000..e48438c --- /dev/null +++ b/utils/helpers/getcogs.py @@ -0,0 +1,17 @@ +import os +from utils.data import getdata +info = getdata.info() +def getcogs(ctx): + if ctx.interaction.user.id != int(info['OwnerID']): + return ["You don't have permission to use this command!"] + cogs = [] + for fn in os.listdir('cogs'): + if ctx.interaction.data['options'][1]['value'] == "": + cogs.append(fn) + continue + if fn.startswith(ctx.interaction.data['options'][1]['value']): + cogs.append(fn) + continue + if not cogs: + return ["No files found with that name, or none exist"] + return cogs \ No newline at end of file From 866efe1585bd0643872d16653b0cf762ca8c32aa Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Mon, 5 Dec 2022 13:21:16 -0500 Subject: [PATCH 16/38] changes to make pylint happy --- cogs/cogs.py | 12 ++++++------ cogs/restart.py | 6 +++--- main.py | 6 +++--- utils/helpers/getcogs.py | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cogs/cogs.py b/cogs/cogs.py index 8028f29..0660dd5 100644 --- a/cogs/cogs.py +++ b/cogs/cogs.py @@ -1,8 +1,8 @@ -from discord import slash_command, commands -from utils.helpers import getcogs import discord, os -from utils.data import getdata -info = getdata.info() +from discord import slash_command, commands +from utils.helpers.getcogs import getcogs +from utils.data.getdata import info +info = info() class Cogs(commands.Cog): def __init__(self, bot): self.bot = bot @@ -30,6 +30,6 @@ async def cogs(self, ctx, action: discord.Option(choices=["Reload", "Load", "Unl await ctx.respond(f"```py\n{e}\n```", ephemeral=True) return await ctx.respond(f"{action}ed {cog}", ephemeral=True) - + def setup(bot): - bot.add_cog(Cogs(bot)) \ No newline at end of file + bot.add_cog(Cogs(bot)) diff --git a/cogs/restart.py b/cogs/restart.py index 39d0e5b..68f543e 100644 --- a/cogs/restart.py +++ b/cogs/restart.py @@ -1,6 +1,6 @@ +import discord, sys from discord import slash_command, commands from utils.data import getdata -import discord, sys info = getdata.info() class Restart(commands.Cog): def __init__(self, bot): @@ -18,6 +18,6 @@ async def restart(self, ctx): embed = discord.Embed(title="🔄 Restarting...", timestamp=discord.utils.utcnow(), color=discord.Color.orange()) await self.bot.get_guild(955135608228024394).get_channel(1048306173071347782).send(embed=embed) sys.exit() - + def setup(bot): - bot.add_cog(Restart(bot)) \ No newline at end of file + bot.add_cog(Restart(bot)) diff --git a/main.py b/main.py index ac971cc..60a43ec 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,6 @@ import discord +from utils.data.getdata import info +info = info(False) intents = discord.Intents.all() bot = discord.Bot(debug_guilds=[955135608228024394], status=discord.Status.dnd, @@ -78,6 +80,4 @@ async def on_message(message): print('you got fans') #Add an eyes reaction await message.add_reaction("👀") -from utils.data import getdata -info = getdata.info(False) -bot.run(info['Token']) \ No newline at end of file +bot.run(info['Token']) diff --git a/utils/helpers/getcogs.py b/utils/helpers/getcogs.py index e48438c..c1dc048 100644 --- a/utils/helpers/getcogs.py +++ b/utils/helpers/getcogs.py @@ -14,4 +14,4 @@ def getcogs(ctx): continue if not cogs: return ["No files found with that name, or none exist"] - return cogs \ No newline at end of file + return cogs From 39b55038b9589a7da49fa2c6c7f9e4214fa81174 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Mon, 5 Dec 2022 13:22:48 -0500 Subject: [PATCH 17/38] smh --- cogs/cogs.py | 2 +- cogs/restart.py | 2 +- main.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cogs/cogs.py b/cogs/cogs.py index 0660dd5..b06777d 100644 --- a/cogs/cogs.py +++ b/cogs/cogs.py @@ -1,4 +1,4 @@ -import discord, os +import os, discord from discord import slash_command, commands from utils.helpers.getcogs import getcogs from utils.data.getdata import info diff --git a/cogs/restart.py b/cogs/restart.py index 68f543e..dba0b8f 100644 --- a/cogs/restart.py +++ b/cogs/restart.py @@ -1,4 +1,4 @@ -import discord, sys +import sys, discord from discord import slash_command, commands from utils.data import getdata info = getdata.info() diff --git a/main.py b/main.py index 60a43ec..920e496 100644 --- a/main.py +++ b/main.py @@ -35,7 +35,7 @@ async def math(ctx, first: discord.Option(int, description="The first number"), print(f'command math called {output} {ctx.author}') @bot.slash_command(description='Get info about the bot') -async def info(ctx): +async def botinfo(ctx): embed = discord.Embed( title="DobbieBot", description = "The Dobbie bot", From afe5d5d9409bcc6e9c4ada5816525bcc6c63b3dd Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Mon, 5 Dec 2022 13:23:46 -0500 Subject: [PATCH 18/38] shit up pylint --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 8bb5f22..6e97ed1 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,2 +1,2 @@ [MESSAGES CONTROL] -disable=missing-docstring,missing-module-docstring,line-too-long,invalid-name,multiple-imports,import-outside-toplevel,inconsistent-return-statements \ No newline at end of file +disable=missing-docstring,missing-module-docstring,line-too-long,invalid-name,multiple-imports,import-outside-toplevel,inconsistent-return-statements,broad-except \ No newline at end of file From 8eab471326cf418871fb303495e74e4304d502db Mon Sep 17 00:00:00 2001 From: Soapy7261 <81933267+Soapy7261@users.noreply.github.com> Date: Mon, 5 Dec 2022 12:32:21 -0600 Subject: [PATCH 19/38] security (#10) --- SECURITY.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..7bedcef --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,23 @@ +# Security Policy + +## Supported Versions + +| Version | Supported | +| ------- | ------------------ | +| 2.LATEST | :white_check_mark: | +| 1.LATEST | :white_check_mark: | + +## Valid Vulnerabilities +Vulnerabilities in this project mostly fall into one of the following categories: +- Default Permissions that give users access to something that should probably be private +- Injecting custom code into the bot +- Crashing the entire DobbieBot instance +- Overloading the instance and therefore making the bot unusable on other servers + +The following are explicitly not vulnerabilities inside DobbieBot: +- Poorly configured slash command permissions which allow users to execute privileged commands +- Issues otherwise specific to a server for example having a public log of deleted messages, moderations etc. + +## Reporting a Vulnerability +Please do not create a public issue about security vulnerabilities. To prevent abuse of the vulnerability +before a fix is available please create a private report here: https://github.com/Soapy7261/DobbieBot/security/advisories From fc1c1a9d6319fbe6e35d1017ac79c78f4e089080 Mon Sep 17 00:00:00 2001 From: Soapy7261 <81933267+Soapy7261@users.noreply.github.com> Date: Mon, 5 Dec 2022 22:11:49 -0500 Subject: [PATCH 20/38] Update SECURITY.md --- SECURITY.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index 7bedcef..43c7e2c 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -2,10 +2,10 @@ ## Supported Versions -| Version | Supported | +| Version | Support status | | ------- | ------------------ | -| 2.LATEST | :white_check_mark: | -| 1.LATEST | :white_check_mark: | +| 2.LATEST | ✅ Active | +| 1.LATEST | 🟡 Deprecated | ## Valid Vulnerabilities Vulnerabilities in this project mostly fall into one of the following categories: From d19cf4e214fa505e11707fd816c1db9af4cfa315 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Fri, 16 Dec 2022 18:01:18 -0500 Subject: [PATCH 21/38] changes --- .gitignore | 4 ++- CONTRIBUTING.md | 4 +++ LICENSE.txt => LICENSE | 0 README.md | 21 +++++++++-- SECURITY.md | 6 ++-- cogs/botinfo.py | 28 +++++++++++++++ cogs/branch.py | 21 +++++++++++ cogs/cogs.py | 8 ++--- cogs/examples/defaultpermissionsgroup.txt | 17 +++++++++ cogs/examples/deferexample.txt | 17 +++++++++ cogs/math.py | 29 +++++++++++++++ cogs/restart.py | 4 +-- example.config.json | 3 +- example.env | 3 +- main.py | 44 +++-------------------- requirements.txt | 2 ++ utils/data/getdata.py | 26 ++++++++------ utils/helpers/getbranches.py | 21 +++++++++++ 18 files changed, 194 insertions(+), 64 deletions(-) create mode 100644 CONTRIBUTING.md rename LICENSE.txt => LICENSE (100%) create mode 100644 cogs/botinfo.py create mode 100644 cogs/branch.py create mode 100644 cogs/examples/defaultpermissionsgroup.txt create mode 100644 cogs/examples/deferexample.txt create mode 100644 cogs/math.py create mode 100644 requirements.txt create mode 100644 utils/helpers/getbranches.py diff --git a/.gitignore b/.gitignore index a72f057..7bc0894 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .env -config.json \ No newline at end of file +config.json +.idea +.vscode \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..8a47134 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,4 @@ +# Contributing +If you want to contribute, make a [fork](https://github.com/Soapy7261/DobbieBot/fork), make your changes there, and then make a [pull request](https://github.com/Soapy7261/DobbieBot/compare), it must also follow the [licence](https://github.com/Soapy7261/DobbieBot/blob/main/LICENCE) + +If you are contributing to fix a security issue, please see [SECURITY.md](./SECURITY.md) \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE similarity index 100% rename from LICENSE.txt rename to LICENSE diff --git a/README.md b/README.md index 01186ff..ed5901e 100644 --- a/README.md +++ b/README.md @@ -3,5 +3,22 @@ Discord fork used: py-cord Checkout [this to install it](https://docs.pycord.dev/en/master/installing.html). -There are some Id's what you need to change,
-this progam gets the bot tolken by using a .env file +# Self hosting +## Creating a bot +2. Create a [Discord application](https://discord.com/developers/applications/). + You have to enable the Message Content intent. +## Configuration +Dobbiebot supports .json and .env, so you can use either one of them, however, you will need to use json for certain features, mainly the switch branch feature. + +### .env +1. Create a .env file +2. Follow the env.example file and fill in the values + +### .json +1. Create a config.json file +2. Follow the config.example.json file and fill in the values + +## Running +1. Run `python3 -m pip install -r requirements.txt` +2. Run `python3 launcher.py` to have auto-restart, or `python3 bot.py` to not have auto-restart +3. \ No newline at end of file diff --git a/SECURITY.md b/SECURITY.md index 43c7e2c..aca0a40 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -1,11 +1,11 @@ # Security Policy ## Supported Versions - -| Version | Support status | +Only the latest version of DobbieBot is supported, older versions are not supported. +| Version | Support status | | ------- | ------------------ | | 2.LATEST | ✅ Active | -| 1.LATEST | 🟡 Deprecated | +| 1.X | ❌ EOL | ## Valid Vulnerabilities Vulnerabilities in this project mostly fall into one of the following categories: diff --git a/cogs/botinfo.py b/cogs/botinfo.py new file mode 100644 index 0000000..cef47ac --- /dev/null +++ b/cogs/botinfo.py @@ -0,0 +1,28 @@ +import discord +from discord import slash_command, commands +class BotInfo(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print('BotInfo cog loaded!') + + @slash_command(description='Get info about the bot') + async def botinfo(self, ctx): + embed = discord.Embed( + title="DobbieBot", + description = "The Dobbie bot", + timestamp=discord.utils.utcnow(), + color=discord.Color.dark_gray()) + embed.add_field(name="Ping",value=(round(self.bot.latency * 1000))) + embed.add_field(name="Info about the bot", + value="""this bot is made by Soapy7261#8558 + and Dobbie#4778. To teach Dobbie how + Discord bots work and how py-cord works!""") + + embed.add_field(name="Main commands", value="/math\n/info") + await ctx.respond(embed=embed) + +def setup(bot): + bot.add_cog(BotInfo(bot)) \ No newline at end of file diff --git a/cogs/branch.py b/cogs/branch.py new file mode 100644 index 0000000..2a1eee8 --- /dev/null +++ b/cogs/branch.py @@ -0,0 +1,21 @@ +import discord +from discord import slash_command, commands +from utils.helpers.getbranches import GetBranches +from utils.data.getdata import info +info = info() +class Branch(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print('Branch cog loaded!') + + @slash_command(description='Only the owner can use this command', guild_only=True) + async def branch(self, ctx, branch: discord.Option(autocomplete=GetBranches, description='What branch to switch to', required=True)): + if ctx.interaction.user.id != int(info['OwnerID']): + return await ctx.respond("You don't have permission to use this command!", ephemeral=True) + await ctx.respond(f'You selected {branch}', ephemeral=True) + +def setup(bot): + bot.add_cog(Branch(bot)) \ No newline at end of file diff --git a/cogs/cogs.py b/cogs/cogs.py index b06777d..1cac923 100644 --- a/cogs/cogs.py +++ b/cogs/cogs.py @@ -2,18 +2,18 @@ from discord import slash_command, commands from utils.helpers.getcogs import getcogs from utils.data.getdata import info -info = info() class Cogs(commands.Cog): def __init__(self, bot): self.bot = bot + self.info = info() @commands.Cog.listener() async def on_ready(self): print('Cogs cog loaded!') - @slash_command(description='Load, unload, or reload cogs', guild_only=True) + @slash_command(description='Load, unload, or reload cogs', guild_ids=[955135608228024394]) async def cogs(self, ctx, action: discord.Option(choices=["Reload", "Load", "Unload"], description='What action to run', required=True), cog: discord.Option(autocomplete=getcogs, description='The cog to run the action on', required=True)): - if ctx.author.id != int(info['OwnerID']): + if ctx.author.id != int(self.info['OwnerID']): return await ctx.respond("You don't have permission to use this command!", ephemeral=True) if cog not in [f"{fn[:-3]}" for fn in os.listdir("commands")]: await ctx.respond("That cog doesn't exist!", ephemeral=True) @@ -27,7 +27,7 @@ async def cogs(self, ctx, action: discord.Option(choices=["Reload", "Load", "Unl if action == "Reload": self.bot.reload_extension(f"commands.{cog}") except Exception as e: - await ctx.respond(f"```py\n{e}\n```", ephemeral=True) + await ctx.respond(f"```py\n{str(e)}\n```", ephemeral=True) return await ctx.respond(f"{action}ed {cog}", ephemeral=True) diff --git a/cogs/examples/defaultpermissionsgroup.txt b/cogs/examples/defaultpermissionsgroup.txt new file mode 100644 index 0000000..20c8ef0 --- /dev/null +++ b/cogs/examples/defaultpermissionsgroup.txt @@ -0,0 +1,17 @@ +from discord import slash_command, commands, discord +class NAME(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print('BLANK cog loaded!') + + group = discord.SlashCommandGroup("group", "Group description", default_member_permissions=discord.Permissions(PERMISSIONIDHERE)) + + @group.command(description='Your description') + async def command(self, ctx): + await ctx.respond('Your response') + +def setup(bot): + bot.add_cog(NAME(bot)) \ No newline at end of file diff --git a/cogs/examples/deferexample.txt b/cogs/examples/deferexample.txt new file mode 100644 index 0000000..9753e71 --- /dev/null +++ b/cogs/examples/deferexample.txt @@ -0,0 +1,17 @@ +from discord import slash_command, commands +class NAME(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print('BLANK cog loaded!') + + @slash_command(description='Your description') + async def command(self, ctx): + await ctx.defer() #This can also be ephemeral or invisible with parameters, this is mostly useful if what your doing takes a while so discord doesn't think your bot isn't responding + #Some code in here + await ctx.respond('Done!') + +def setup(bot): + bot.add_cog(NAME(bot)) \ No newline at end of file diff --git a/cogs/math.py b/cogs/math.py new file mode 100644 index 0000000..1164964 --- /dev/null +++ b/cogs/math.py @@ -0,0 +1,29 @@ +from discord import slash_command, commands +import discord +class Math(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print('Math cog loaded!') + + @slash_command(description="Run a calculation") + async def math(ctx, first: discord.Option(float, description="The first number"), second: discord.Option(float, description="The second number"), operation: discord.Option(description="What operation you want to run", choices=["+", "-", "*", "/"])): + if operation == '+': + oper = first + second + if operation == '-': + oper = first - second + if operation == '*': + oper = first * second + if operation == '/': + if second == 0: + return await ctx.respond("You can't divide by 0!", ephemeral=True) + else: + oper = first / second + embed=discord.Embed(title='Calculation', timestamp=discord.utils.utcnow(), color=discord.Color.green()) + embed.add_field(name='Your calculation is here!', value=f"{first}{operation}{second} = {oper}") + await ctx.respond(embed=embed) + +def setup(bot): + bot.add_cog(Math(bot)) \ No newline at end of file diff --git a/cogs/restart.py b/cogs/restart.py index dba0b8f..933c9a6 100644 --- a/cogs/restart.py +++ b/cogs/restart.py @@ -1,6 +1,6 @@ import sys, discord from discord import slash_command, commands -from utils.data import getdata +import utils.data.getdata as getdata info = getdata.info() class Restart(commands.Cog): def __init__(self, bot): @@ -17,7 +17,7 @@ async def restart(self, ctx): await ctx.respond("Restarting.") embed = discord.Embed(title="🔄 Restarting...", timestamp=discord.utils.utcnow(), color=discord.Color.orange()) await self.bot.get_guild(955135608228024394).get_channel(1048306173071347782).send(embed=embed) - sys.exit() + await self.bot.close() def setup(bot): bot.add_cog(Restart(bot)) diff --git a/example.config.json b/example.config.json index 330581f..6483979 100644 --- a/example.config.json +++ b/example.config.json @@ -1,4 +1,5 @@ { "Token": "YourBotTokenHere", - "OwnerID": "YourIDHere" + "OwnerID": "YourIDHere", + "Branch": "main" } \ No newline at end of file diff --git a/example.env b/example.env index d224275..ef09ee1 100644 --- a/example.env +++ b/example.env @@ -1,2 +1,3 @@ TOKEN=YOURBOTTOKENHERE -OWNERID=OWNERIDHERE \ No newline at end of file +OWNERID=OWNERIDHERE +BRANCH=main \ No newline at end of file diff --git a/main.py b/main.py index 920e496..1d9a2ca 100644 --- a/main.py +++ b/main.py @@ -1,54 +1,20 @@ import discord from utils.data.getdata import info -info = info(False) -intents = discord.Intents.all() +info = info() +intents = discord.Intents.default() +intents.message_content = True bot = discord.Bot(debug_guilds=[955135608228024394], status=discord.Status.dnd, activity=discord.Activity(type=discord.ActivityType.listening, name="keyboard noises and no errors"), intents=intents) - +bot.load_extensions("cogs") @bot.event async def on_ready(): embed = discord.Embed(title="🟢 Online!\nTime to mess around!", timestamp=discord.utils.utcnow(), color=discord.Color.green()) await bot.get_guild(955135608228024394).get_channel(1011649871511572500).send(embed=embed) - print("Now ready!") - -@bot.slash_command(description="Run a calculation") -async def math(ctx, first: discord.Option(int, description="The first number"), second: discord.Option(int, description="The second number"), operation: discord.Option(description="What operation you want to run", choices=["+", "-", "*", "/"])): - await ctx.defer() - if operation == "+": - output = f"{first}+{second} = {first + second}" - if operation == '-': - output= f"{first}-{second} = {first - second}" - if operation == '*': - output= f"{first}*{second} = {first * second}" - if operation == '/': - if second == 0: - output= "Can't divide by 0" - if second != 0: - output= f"{first}/{second} = {first / second}" - embed=discord.Embed(title='Calculation', timestamp=discord.utils.utcnow(), color=discord.Color.green()) - embed.add_field(name='Your calculation is here!', value=output) - await ctx.respond(embed=embed) - print(f'command math called {output} {ctx.author}') - -@bot.slash_command(description='Get info about the bot') -async def botinfo(ctx): - embed = discord.Embed( - title="DobbieBot", - description = "The Dobbie bot", - timestamp=discord.utils.utcnow(), - color=discord.Color.dark_gray()) - embed.add_field(name="Ping",value=(round(bot.latency * 1000))) - embed.add_field(name="Info about the bot", - value="""this bot is made by Soapy7261#8558 - and Dobbie#4778. To teach Dobbie how - Discord bots work and how py-cord works!""") - - embed.add_field(name="Main commands", value="/math\n/info") - await ctx.respond(embed=embed) + print(f"Ready! Logged in as {bot.user}") @bot.slash_command(description='Say hello', guild_ids=[955135608228024394]) async def hello(ctx): diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..34be5d8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +py-cord==2.3.2 +python-dotenv==0.21.0 \ No newline at end of file diff --git a/utils/data/getdata.py b/utils/data/getdata.py index 63e1d66..cdf5aa4 100644 --- a/utils/data/getdata.py +++ b/utils/data/getdata.py @@ -1,23 +1,27 @@ -def info(use_json: bool = False): +def info(use_json: bool = True): + import os + if not os.path.exists("config.json"): + print ("No config file found! Please create one. Trying .env") + use_json = False if use_json: - import json, os, sys - if os.path.exists("config.json"): - with open("config.json", "r", encoding="UTF-8") as f: - return json.load(f) - else: - print ("config.json not found! Please create it.") - sys.exit() + import json + with open("config.json", "r", encoding="UTF-8") as f: + return json.load(f) if not use_json: + import sys from dotenv import load_dotenv - import os, sys load_dotenv() if os.getenv("TOKEN") is None: - print("TOKEN not found! Please create it.") + print("TOKEN not found in .env! Please create it.") sys.exit() if os.getenv("OWNERID") is None: - print("OWNERID not found! Please create it.") + print("OWNERID not found in .env! Please create it.") + sys.exit() + if os.getenv("BRANCH") is None: + print("BRANCH not found in .env! Please create it.") sys.exit() return { "Token": os.getenv("TOKEN"), "OwnerID": os.getenv("OWNERID"), + "Branch": os.getenv("BRANCH"), } diff --git a/utils/helpers/getbranches.py b/utils/helpers/getbranches.py new file mode 100644 index 0000000..e448022 --- /dev/null +++ b/utils/helpers/getbranches.py @@ -0,0 +1,21 @@ +import aiohttp +from utils.data.getdata import info +info = info() +async def GetBranches(ctx): + if ctx.interaction.user.id != int(info['OwnerID']): + return ["You don't have permission to use this command!"] + branches = [] + async with aiohttp.ClientSession() as session: + async with session.get('https://api.github.com/repos/Soapy7261/DobbieBot/branches') as resp: + if resp.status == 200: + data = await resp.json() + for branch in data: + if ctx.interaction.data['options'][0]['value'] == "": + branches.append(branch['name']) + continue + if branch['name'].startswith(ctx.interaction.data['options'][0]['value']): + branches.append(branch['name']) + continue + else: + branches.append("Error getting branches") + return branches \ No newline at end of file From d3b0d7688166cd439692531341bbaa4f506437b1 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Fri, 16 Dec 2022 18:04:02 -0500 Subject: [PATCH 22/38] changes --- cogs/botinfo.py | 4 ++-- cogs/branch.py | 4 ++-- cogs/math.py | 7 +++---- cogs/restart.py | 4 ++-- utils/helpers/getbranches.py | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cogs/botinfo.py b/cogs/botinfo.py index cef47ac..f9ef205 100644 --- a/cogs/botinfo.py +++ b/cogs/botinfo.py @@ -23,6 +23,6 @@ async def botinfo(self, ctx): embed.add_field(name="Main commands", value="/math\n/info") await ctx.respond(embed=embed) - + def setup(bot): - bot.add_cog(BotInfo(bot)) \ No newline at end of file + bot.add_cog(BotInfo(bot)) diff --git a/cogs/branch.py b/cogs/branch.py index 2a1eee8..4e04802 100644 --- a/cogs/branch.py +++ b/cogs/branch.py @@ -16,6 +16,6 @@ async def branch(self, ctx, branch: discord.Option(autocomplete=GetBranches, des if ctx.interaction.user.id != int(info['OwnerID']): return await ctx.respond("You don't have permission to use this command!", ephemeral=True) await ctx.respond(f'You selected {branch}', ephemeral=True) - + def setup(bot): - bot.add_cog(Branch(bot)) \ No newline at end of file + bot.add_cog(Branch(bot)) diff --git a/cogs/math.py b/cogs/math.py index 1164964..eded7c3 100644 --- a/cogs/math.py +++ b/cogs/math.py @@ -9,7 +9,7 @@ async def on_ready(self): print('Math cog loaded!') @slash_command(description="Run a calculation") - async def math(ctx, first: discord.Option(float, description="The first number"), second: discord.Option(float, description="The second number"), operation: discord.Option(description="What operation you want to run", choices=["+", "-", "*", "/"])): + async def math(self, ctx, first: discord.Option(float, description="The first number"), second: discord.Option(float, description="The second number"), operation: discord.Option(description="What operation you want to run", choices=["+", "-", "*", "/"])): if operation == '+': oper = first + second if operation == '-': @@ -19,11 +19,10 @@ async def math(ctx, first: discord.Option(float, description="The first number") if operation == '/': if second == 0: return await ctx.respond("You can't divide by 0!", ephemeral=True) - else: - oper = first / second + oper = first / second embed=discord.Embed(title='Calculation', timestamp=discord.utils.utcnow(), color=discord.Color.green()) embed.add_field(name='Your calculation is here!', value=f"{first}{operation}{second} = {oper}") await ctx.respond(embed=embed) def setup(bot): - bot.add_cog(Math(bot)) \ No newline at end of file + bot.add_cog(Math(bot)) diff --git a/cogs/restart.py b/cogs/restart.py index 933c9a6..60aa119 100644 --- a/cogs/restart.py +++ b/cogs/restart.py @@ -1,6 +1,6 @@ -import sys, discord +import discord from discord import slash_command, commands -import utils.data.getdata as getdata +from utils.data import getdata info = getdata.info() class Restart(commands.Cog): def __init__(self, bot): diff --git a/utils/helpers/getbranches.py b/utils/helpers/getbranches.py index e448022..49ba242 100644 --- a/utils/helpers/getbranches.py +++ b/utils/helpers/getbranches.py @@ -18,4 +18,4 @@ async def GetBranches(ctx): continue else: branches.append("Error getting branches") - return branches \ No newline at end of file + return branches From 77dd7bb4855504624bb0f7d2aa9c265464b73210 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Fri, 16 Dec 2022 18:06:56 -0500 Subject: [PATCH 23/38] reload is cool --- README.md | 2 +- cogs/branch.py | 2 +- cogs/reload.py | 30 ++++++++++++++++++++++++++++++ main.py | 3 +-- 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 cogs/reload.py diff --git a/README.md b/README.md index ed5901e..839c428 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Checkout [this to install it](https://docs.pycord.dev/en/master/installing.html) # Self hosting ## Creating a bot 2. Create a [Discord application](https://discord.com/developers/applications/). - You have to enable the Message Content intent. + You have to enable all intents. ## Configuration Dobbiebot supports .json and .env, so you can use either one of them, however, you will need to use json for certain features, mainly the switch branch feature. diff --git a/cogs/branch.py b/cogs/branch.py index 4e04802..ffdbc0c 100644 --- a/cogs/branch.py +++ b/cogs/branch.py @@ -11,7 +11,7 @@ def __init__(self, bot): async def on_ready(self): print('Branch cog loaded!') - @slash_command(description='Only the owner can use this command', guild_only=True) + @slash_command(description='Only the owner of the bot can run this command', guild_only=True) async def branch(self, ctx, branch: discord.Option(autocomplete=GetBranches, description='What branch to switch to', required=True)): if ctx.interaction.user.id != int(info['OwnerID']): return await ctx.respond("You don't have permission to use this command!", ephemeral=True) diff --git a/cogs/reload.py b/cogs/reload.py new file mode 100644 index 0000000..0b9120c --- /dev/null +++ b/cogs/reload.py @@ -0,0 +1,30 @@ +import discord +from discord import slash_command, commands, asyncio +from utils.data.getdata import info +info = info() +class Reload(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print('Reload cog loaded!') + + @slash_command(description='Only the owner of the bot can run this command', guild_only=True) + async def reload(self, ctx): + if ctx.author.id != int(info['OwnerID']): + return await ctx.respond("You don't have permission to use this command!", ephemeral=True) + await ctx.defer() + await self.bot.change_presence(activity=discord.Activity(type=discord.ActivityType.playing, name=f"Reloading commands, bot may be unresponsive | In {len(self.bot.guilds)} servers"), status=discord.Status.dnd) + await asyncio.sleep(1) + try: + await self.bot.sync_commands() + except Exception as e: + await ctx.respond ("Failed to reload commands!") + await ctx.respond ("```py\n" + str(e) + "\n```", ephemeral=True) + await asyncio.sleep(3) + await self.bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"my creator's keyboard | In {len(self.bot.guilds)} servers"), status=discord.Status.online) + return await ctx.respond(f"Finished!", ephemeral=True) + +def setup(bot): + bot.add_cog(Reload(bot)) \ No newline at end of file diff --git a/main.py b/main.py index 1d9a2ca..d68639f 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,7 @@ import discord from utils.data.getdata import info info = info() -intents = discord.Intents.default() -intents.message_content = True +intents = discord.Intents.all() bot = discord.Bot(debug_guilds=[955135608228024394], status=discord.Status.dnd, activity=discord.Activity(type=discord.ActivityType.listening, From 60f4976063877bad58ab1ecbfb456bd39a6cb28b Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Fri, 16 Dec 2022 18:07:08 -0500 Subject: [PATCH 24/38] wait --- cogs/reload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/reload.py b/cogs/reload.py index 0b9120c..7006694 100644 --- a/cogs/reload.py +++ b/cogs/reload.py @@ -27,4 +27,4 @@ async def reload(self, ctx): return await ctx.respond(f"Finished!", ephemeral=True) def setup(bot): - bot.add_cog(Reload(bot)) \ No newline at end of file + bot.add_cog(Reload(bot)) From 315e74dc3ebba78161382828c5f5428cf807339c Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Fri, 16 Dec 2022 18:09:53 -0500 Subject: [PATCH 25/38] we're booting here --- cogs/reload.py | 4 ++-- main.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cogs/reload.py b/cogs/reload.py index 7006694..f8e69f6 100644 --- a/cogs/reload.py +++ b/cogs/reload.py @@ -24,7 +24,7 @@ async def reload(self, ctx): await ctx.respond ("```py\n" + str(e) + "\n```", ephemeral=True) await asyncio.sleep(3) await self.bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"my creator's keyboard | In {len(self.bot.guilds)} servers"), status=discord.Status.online) - return await ctx.respond(f"Finished!", ephemeral=True) - + return await ctx.respond("Finished!", ephemeral=True) + def setup(bot): bot.add_cog(Reload(bot)) diff --git a/main.py b/main.py index d68639f..eb2c13b 100644 --- a/main.py +++ b/main.py @@ -4,16 +4,23 @@ intents = discord.Intents.all() bot = discord.Bot(debug_guilds=[955135608228024394], status=discord.Status.dnd, - activity=discord.Activity(type=discord.ActivityType.listening, - name="keyboard noises and no errors"), + activity=discord.Activity(type=discord.ActivityType.playing, + name="Booting..."), intents=intents) bot.load_extensions("cogs") +global first +first = False @bot.event async def on_ready(): + global first embed = discord.Embed(title="🟢 Online!\nTime to mess around!", timestamp=discord.utils.utcnow(), color=discord.Color.green()) await bot.get_guild(955135608228024394).get_channel(1011649871511572500).send(embed=embed) print(f"Ready! Logged in as {bot.user}") + if first == True: + await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, + name=f"my creator's keyboard | In {len(bot.guilds)} servers"), status=discord.Status.online) + first = False @bot.slash_command(description='Say hello', guild_ids=[955135608228024394]) async def hello(ctx): From bf8ee6a0ad5a0050fe1696c355912cf34c32f14d Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Fri, 16 Dec 2022 18:11:47 -0500 Subject: [PATCH 26/38] ugh --- main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index eb2c13b..d5a17c5 100644 --- a/main.py +++ b/main.py @@ -8,17 +8,15 @@ name="Booting..."), intents=intents) bot.load_extensions("cogs") -global first first = False @bot.event async def on_ready(): - global first embed = discord.Embed(title="🟢 Online!\nTime to mess around!", timestamp=discord.utils.utcnow(), color=discord.Color.green()) await bot.get_guild(955135608228024394).get_channel(1011649871511572500).send(embed=embed) print(f"Ready! Logged in as {bot.user}") - if first == True: - await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, + if first is True: + await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"my creator's keyboard | In {len(bot.guilds)} servers"), status=discord.Status.online) first = False From 38c81534017d9b4b50ffd0b050b811c5334c6121 Mon Sep 17 00:00:00 2001 From: Soapy7261 <81933267+Soapy7261@users.noreply.github.com> Date: Fri, 20 Jan 2023 13:23:17 -0600 Subject: [PATCH 27/38] Update year in LICENSE, and some other changes (#11) --- .gitignore | 7 +++++-- .pylintrc | 2 +- LICENSE | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 7bc0894..b445943 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ .env -config.json .idea -.vscode \ No newline at end of file +.vscode +config.json +dyndata.json +example.dyndata.json +things.txt \ No newline at end of file diff --git a/.pylintrc b/.pylintrc index 6e97ed1..8bb5f22 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,2 +1,2 @@ [MESSAGES CONTROL] -disable=missing-docstring,missing-module-docstring,line-too-long,invalid-name,multiple-imports,import-outside-toplevel,inconsistent-return-statements,broad-except \ No newline at end of file +disable=missing-docstring,missing-module-docstring,line-too-long,invalid-name,multiple-imports,import-outside-toplevel,inconsistent-return-statements \ No newline at end of file diff --git a/LICENSE b/LICENSE index d4b1854..8f8b36e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Soapy7261 +Copyright (c) 2023 Soapy7261 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From bfac91a1cdc19c2f70e316808b69b2663ed873d7 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Fri, 20 Jan 2023 14:31:15 -0500 Subject: [PATCH 28/38] Some changes --- .gitignore | 4 +++- cogs/botinfo.py | 2 +- cogs/examples/cogexample.txt | 3 ++- cogs/say.py | 19 +++++++++++++++++++ example.dyndata.json | 5 +++++ launcher.py | 1 + main.py | 5 ----- 7 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 cogs/say.py create mode 100644 example.dyndata.json diff --git a/.gitignore b/.gitignore index 7bc0894..b43e4e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .env config.json .idea -.vscode \ No newline at end of file +.vscode +things.txt +dyndata.json \ No newline at end of file diff --git a/cogs/botinfo.py b/cogs/botinfo.py index f9ef205..77f66e0 100644 --- a/cogs/botinfo.py +++ b/cogs/botinfo.py @@ -17,7 +17,7 @@ async def botinfo(self, ctx): color=discord.Color.dark_gray()) embed.add_field(name="Ping",value=(round(self.bot.latency * 1000))) embed.add_field(name="Info about the bot", - value="""this bot is made by Soapy7261#8558 + value="""this bot is made by Soapy7261#7261 and Dobbie#4778. To teach Dobbie how Discord bots work and how py-cord works!""") diff --git a/cogs/examples/cogexample.txt b/cogs/examples/cogexample.txt index 1537e38..cfc3e1f 100644 --- a/cogs/examples/cogexample.txt +++ b/cogs/examples/cogexample.txt @@ -1,4 +1,5 @@ -from discord import slash_command, commands +from discord import slash_command +from discord.ext import commands class NAME(commands.Cog): def __init__(self, bot): self.bot = bot diff --git a/cogs/say.py b/cogs/say.py new file mode 100644 index 0000000..6b959be --- /dev/null +++ b/cogs/say.py @@ -0,0 +1,19 @@ +from discord import slash_command, Option, Embed, utils, Color +from discord.ext import commands +class Say(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print('Say cog loaded!') + + @slash_command(description="Say something through the bot") + async def say(ctx, message: Option(str, description="The message to say")): + await ctx.delete() + embed = Embed(title="Message from " + ctx.user.name, description=message, timestamp=utils.utcnow(), color=Color.embed_background()) + embed.timestamp = utils.utcnow() + await ctx.send(embed=embed) + +def setup(bot): + bot.add_cog(Say(bot)) \ No newline at end of file diff --git a/example.dyndata.json b/example.dyndata.json new file mode 100644 index 0000000..c505eb6 --- /dev/null +++ b/example.dyndata.json @@ -0,0 +1,5 @@ +{ + "CONFIGURATION": "Please view configuration.md!", + "sharded": false, + "branch": "master" +} \ No newline at end of file diff --git a/launcher.py b/launcher.py index 0c9d619..10ba4b3 100644 --- a/launcher.py +++ b/launcher.py @@ -1,5 +1,6 @@ import subprocess import time +subprocess.run("pip install -r requirements.txt", check=True) #Installs the requirements for the bot while True: print ("Starting bot...") g = subprocess.run("git pull", check=True) #Pulls the latest code from GitHub diff --git a/main.py b/main.py index d5a17c5..f5d63d7 100644 --- a/main.py +++ b/main.py @@ -29,11 +29,6 @@ async def test(ctx): await ctx.send("te@st!") print("send command 'test!'") -@bot.slash_command(description="Say something through the bot") -async def say(ctx, message: discord.Option(str, description="The message to say")): - await ctx.delete() - await ctx.send(message) - @bot.event async def on_command_error(ctx, error): await ctx.reply(f"An error occurred```py\n{str(error)}\n```Message the owner for support\nThis has been logged.") From e6749d56d83224002571c3dc681fd2f2e4774858 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Fri, 20 Jan 2023 14:34:55 -0500 Subject: [PATCH 29/38] Oops. --- cogs/say.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/say.py b/cogs/say.py index 6b959be..e441ce8 100644 --- a/cogs/say.py +++ b/cogs/say.py @@ -9,7 +9,7 @@ async def on_ready(self): print('Say cog loaded!') @slash_command(description="Say something through the bot") - async def say(ctx, message: Option(str, description="The message to say")): + async def say(self, ctx, message: Option(str, description="The message to say")): await ctx.delete() embed = Embed(title="Message from " + ctx.user.name, description=message, timestamp=utils.utcnow(), color=Color.embed_background()) embed.timestamp = utils.utcnow() From e16dfde7409d025ff24e3a306f63e27cc7ad0fc5 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Fri, 20 Jan 2023 14:36:30 -0500 Subject: [PATCH 30/38] Pylint hates me --- cogs/say.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/say.py b/cogs/say.py index e441ce8..76666c9 100644 --- a/cogs/say.py +++ b/cogs/say.py @@ -14,6 +14,6 @@ async def say(self, ctx, message: Option(str, description="The message to say")) embed = Embed(title="Message from " + ctx.user.name, description=message, timestamp=utils.utcnow(), color=Color.embed_background()) embed.timestamp = utils.utcnow() await ctx.send(embed=embed) - + def setup(bot): - bot.add_cog(Say(bot)) \ No newline at end of file + bot.add_cog(Say(bot)) From ebc823616b4b7877bd5b92b927007652f35e5861 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Fri, 20 Jan 2023 17:10:19 -0500 Subject: [PATCH 31/38] Big changes coming soon --- cogs/branch.py | 6 +++--- cogs/reload.py | 11 ++++++----- cogs/restart.py | 11 ++++++----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cogs/branch.py b/cogs/branch.py index ffdbc0c..5c91b59 100644 --- a/cogs/branch.py +++ b/cogs/branch.py @@ -2,18 +2,18 @@ from discord import slash_command, commands from utils.helpers.getbranches import GetBranches from utils.data.getdata import info -info = info() class Branch(commands.Cog): def __init__(self, bot): self.bot = bot + self.info = info() @commands.Cog.listener() async def on_ready(self): print('Branch cog loaded!') - @slash_command(description='Only the owner of the bot can run this command', guild_only=True) + @slash_command(description='Only the owner of the bot can run this command', guild_ids=[955135608228024394]) async def branch(self, ctx, branch: discord.Option(autocomplete=GetBranches, description='What branch to switch to', required=True)): - if ctx.interaction.user.id != int(info['OwnerID']): + if ctx.interaction.user.id != int(self.info['OwnerID']): return await ctx.respond("You don't have permission to use this command!", ephemeral=True) await ctx.respond(f'You selected {branch}', ephemeral=True) diff --git a/cogs/reload.py b/cogs/reload.py index f8e69f6..6f03914 100644 --- a/cogs/reload.py +++ b/cogs/reload.py @@ -1,18 +1,19 @@ -import discord -from discord import slash_command, commands, asyncio +import discord, asyncio +from discord import slash_command +from discord.ext import commands from utils.data.getdata import info -info = info() class Reload(commands.Cog): def __init__(self, bot): self.bot = bot + self.info = info() @commands.Cog.listener() async def on_ready(self): print('Reload cog loaded!') - @slash_command(description='Only the owner of the bot can run this command', guild_only=True) + @slash_command(description='Only the owner of the bot can run this command', guild_ids=[955135608228024394]) async def reload(self, ctx): - if ctx.author.id != int(info['OwnerID']): + if ctx.author.id != int(self.info['OwnerID']): return await ctx.respond("You don't have permission to use this command!", ephemeral=True) await ctx.defer() await self.bot.change_presence(activity=discord.Activity(type=discord.ActivityType.playing, name=f"Reloading commands, bot may be unresponsive | In {len(self.bot.guilds)} servers"), status=discord.Status.dnd) diff --git a/cogs/restart.py b/cogs/restart.py index 60aa119..60f59fc 100644 --- a/cogs/restart.py +++ b/cogs/restart.py @@ -1,18 +1,19 @@ import discord -from discord import slash_command, commands -from utils.data import getdata -info = getdata.info() +from discord import slash_command +from discord.ext import commands +from utils.data.getdata import info class Restart(commands.Cog): def __init__(self, bot): self.bot = bot + self.info = info() @commands.Cog.listener() async def on_ready(self): print('Restart cog loaded!') - @slash_command(description="Restart the bot", guild_only=True) + @slash_command(description="Restart the bot", guild_ids=[955135608228024394]) async def restart(self, ctx): - if ctx.author.id != int(info['OwnerID']): + if ctx.author.id != int(self.info['OwnerID']): return await ctx.respond("You don't have permission to use this command!", ephemeral=True) await ctx.respond("Restarting.") embed = discord.Embed(title="🔄 Restarting...", timestamp=discord.utils.utcnow(), color=discord.Color.orange()) From cd9afec55288329bca213fc330756f1a691ffa91 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Sat, 18 Feb 2023 19:16:55 -0500 Subject: [PATCH 32/38] I wonder how much pylint is gonna scream at me, im predicting a lot --- .github/workflows/pylint.yml | 9 ++--- .gitignore | 6 ++-- .pylintrc | 2 +- CONFIGURATION.md | 32 ++++++++++++++++++ README.md | 17 ++-------- cogs/botinfo.py | 13 ++++---- cogs/branch.py | 7 ++-- cogs/cogs.py | 10 +++--- cogs/math.py | 8 ++--- cogs/reload.py | 9 +++-- cogs/restart.py | 4 +-- example.config.json | 4 ++- example.dyndata.json | 5 --- example.env | 3 +- main.py | 45 ++++++++++++------------- requirements.txt | 4 +-- utils.py | 64 ++++++++++++++++++++++++++++++++++++ utils/data/getdata.py | 27 --------------- utils/helpers/getbranches.py | 21 ------------ utils/helpers/getcogs.py | 17 ---------- 20 files changed, 165 insertions(+), 142 deletions(-) create mode 100644 CONFIGURATION.md delete mode 100644 example.dyndata.json create mode 100644 utils.py delete mode 100644 utils/data/getdata.py delete mode 100644 utils/helpers/getbranches.py delete mode 100644 utils/helpers/getcogs.py diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 1ee28bb..668789a 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -7,19 +7,20 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.10"] + python-version: ["3.10.6", "3.11.1"] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} - - name: Install dependencies + - name: Install pylint run: | python -m pip install --upgrade pip pip install pylint - pip install py-cord - pip install python-dotenv + - name: Install dependencies + run: | + pip install -r requirements.txt - name: Analysing the code with pylint run: | pylint $(git ls-files '*.py') diff --git a/.gitignore b/.gitignore index 196aa53..517217c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -.env .idea .vscode -things.txt -dyndata.json +cogs/__pycache__ +__pycache__ +.env config.json \ No newline at end of file diff --git a/.pylintrc b/.pylintrc index 8bb5f22..3df2feb 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,2 +1,2 @@ [MESSAGES CONTROL] -disable=missing-docstring,missing-module-docstring,line-too-long,invalid-name,multiple-imports,import-outside-toplevel,inconsistent-return-statements \ No newline at end of file +disable=missing-docstring,missing-module-docstring,line-too-long \ No newline at end of file diff --git a/CONFIGURATION.md b/CONFIGURATION.md new file mode 100644 index 0000000..84c3a29 --- /dev/null +++ b/CONFIGURATION.md @@ -0,0 +1,32 @@ +# Configuration + +## File locations +If set to use a JSON file, the file must be in the root directory, if set to use environment variables, the environment variables must be set in the environment the bot is running in. + +## Token +Discord bot authentication token, can be generated in the [Developer Portal](https://discord.com/developers/applications/) + +| type | JSON file | environment | +|--------|-------------|---------------------| +| string | `Token` | `TOKEN` | + +## Owner ID +The owner ID of the bot, this is used for owner only commands. + +| type | JSON file | environment | +|--------|-------------|---------------------| +| string | `OwnerID` | `OWNERID` | + +## Sharded +Whether the bot is sharded or not, only enable this if your bot is in more then 1000 servers. + +| type | JSON file | environment | +|--------|-------------|---------------------| +| boolean | `Sharded` | `SHARDED` | + +## Branch +The branch of the bot, this is used for the `pull` command to pull from the correct branch + +| type | JSON file | environment | +|--------|-------------|---------------------| +| string | `Branch` | `BRANCH` | diff --git a/README.md b/README.md index 839c428..668004a 100644 --- a/README.md +++ b/README.md @@ -4,21 +4,10 @@ Discord fork used: py-cord Checkout [this to install it](https://docs.pycord.dev/en/master/installing.html). # Self hosting + ## Creating a bot 2. Create a [Discord application](https://discord.com/developers/applications/). You have to enable all intents. -## Configuration -Dobbiebot supports .json and .env, so you can use either one of them, however, you will need to use json for certain features, mainly the switch branch feature. - -### .env -1. Create a .env file -2. Follow the env.example file and fill in the values -### .json -1. Create a config.json file -2. Follow the config.example.json file and fill in the values - -## Running -1. Run `python3 -m pip install -r requirements.txt` -2. Run `python3 launcher.py` to have auto-restart, or `python3 bot.py` to not have auto-restart -3. \ No newline at end of file +## Configuration +Please view the [config file](./CONFIGURATION.md) for more configuration options. \ No newline at end of file diff --git a/cogs/botinfo.py b/cogs/botinfo.py index 77f66e0..aad5d6b 100644 --- a/cogs/botinfo.py +++ b/cogs/botinfo.py @@ -1,5 +1,5 @@ -import discord -from discord import slash_command, commands +from discord import slash_command, Embed, utils, Color +from discord.ext import commands class BotInfo(commands.Cog): def __init__(self, bot): self.bot = bot @@ -10,18 +10,19 @@ async def on_ready(self): @slash_command(description='Get info about the bot') async def botinfo(self, ctx): - embed = discord.Embed( + embed = Embed( title="DobbieBot", description = "The Dobbie bot", - timestamp=discord.utils.utcnow(), - color=discord.Color.dark_gray()) - embed.add_field(name="Ping",value=(round(self.bot.latency * 1000))) + timestamp=utils.utcnow(), + color=Color.embed_background()) + embed.add_field(name="Ping:",value=round(self.bot.latency * 1000, 2) + "ms") embed.add_field(name="Info about the bot", value="""this bot is made by Soapy7261#7261 and Dobbie#4778. To teach Dobbie how Discord bots work and how py-cord works!""") embed.add_field(name="Main commands", value="/math\n/info") + embed.add_field(name="Github", value="https://github.com/Soapy7261/DobbieBot") await ctx.respond(embed=embed) def setup(bot): diff --git a/cogs/branch.py b/cogs/branch.py index 5c91b59..6cd64f4 100644 --- a/cogs/branch.py +++ b/cogs/branch.py @@ -1,18 +1,17 @@ import discord from discord import slash_command, commands -from utils.helpers.getbranches import GetBranches -from utils.data.getdata import info +from utils import Utils class Branch(commands.Cog): def __init__(self, bot): self.bot = bot - self.info = info() + self.info = Utils.info() @commands.Cog.listener() async def on_ready(self): print('Branch cog loaded!') @slash_command(description='Only the owner of the bot can run this command', guild_ids=[955135608228024394]) - async def branch(self, ctx, branch: discord.Option(autocomplete=GetBranches, description='What branch to switch to', required=True)): + async def branch(self, ctx, branch: discord.Option(autocomplete=Utils.GetBranches, description='What branch to switch to', required=True)): if ctx.interaction.user.id != int(self.info['OwnerID']): return await ctx.respond("You don't have permission to use this command!", ephemeral=True) await ctx.respond(f'You selected {branch}', ephemeral=True) diff --git a/cogs/cogs.py b/cogs/cogs.py index 1cac923..894ea8e 100644 --- a/cogs/cogs.py +++ b/cogs/cogs.py @@ -1,18 +1,18 @@ -import os, discord +import os +import discord from discord import slash_command, commands -from utils.helpers.getcogs import getcogs -from utils.data.getdata import info +from utils import Utils class Cogs(commands.Cog): def __init__(self, bot): self.bot = bot - self.info = info() + self.info = Utils.info() @commands.Cog.listener() async def on_ready(self): print('Cogs cog loaded!') @slash_command(description='Load, unload, or reload cogs', guild_ids=[955135608228024394]) - async def cogs(self, ctx, action: discord.Option(choices=["Reload", "Load", "Unload"], description='What action to run', required=True), cog: discord.Option(autocomplete=getcogs, description='The cog to run the action on', required=True)): + async def cogs(self, ctx, action: discord.Option(choices=["Reload", "Load", "Unload"], description='What action to run', required=True), cog: discord.Option(autocomplete=Utils.getcogs, description='The cog to run the action on', required=True)): if ctx.author.id != int(self.info['OwnerID']): return await ctx.respond("You don't have permission to use this command!", ephemeral=True) if cog not in [f"{fn[:-3]}" for fn in os.listdir("commands")]: diff --git a/cogs/math.py b/cogs/math.py index eded7c3..a658512 100644 --- a/cogs/math.py +++ b/cogs/math.py @@ -1,5 +1,5 @@ -from discord import slash_command, commands import discord +from discord import slash_command, commands class Math(commands.Cog): def __init__(self, bot): self.bot = bot @@ -12,11 +12,11 @@ async def on_ready(self): async def math(self, ctx, first: discord.Option(float, description="The first number"), second: discord.Option(float, description="The second number"), operation: discord.Option(description="What operation you want to run", choices=["+", "-", "*", "/"])): if operation == '+': oper = first + second - if operation == '-': + elif operation == '-': oper = first - second - if operation == '*': + elif operation == '*': oper = first * second - if operation == '/': + elif operation == '/': if second == 0: return await ctx.respond("You can't divide by 0!", ephemeral=True) oper = first / second diff --git a/cogs/reload.py b/cogs/reload.py index 6f03914..d82b274 100644 --- a/cogs/reload.py +++ b/cogs/reload.py @@ -1,11 +1,12 @@ -import discord, asyncio +import discord +import asyncio from discord import slash_command from discord.ext import commands -from utils.data.getdata import info +from utils import Utils class Reload(commands.Cog): def __init__(self, bot): self.bot = bot - self.info = info() + self.info = Utils.info() @commands.Cog.listener() async def on_ready(self): @@ -23,6 +24,8 @@ async def reload(self, ctx): except Exception as e: await ctx.respond ("Failed to reload commands!") await ctx.respond ("```py\n" + str(e) + "\n```", ephemeral=True) + await asyncio.sleep(3) + return await self.bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"my creator's keyboard | In {len(self.bot.guilds)} servers"), status=discord.Status.online) await asyncio.sleep(3) await self.bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"my creator's keyboard | In {len(self.bot.guilds)} servers"), status=discord.Status.online) return await ctx.respond("Finished!", ephemeral=True) diff --git a/cogs/restart.py b/cogs/restart.py index 60f59fc..e77c624 100644 --- a/cogs/restart.py +++ b/cogs/restart.py @@ -1,11 +1,11 @@ import discord from discord import slash_command from discord.ext import commands -from utils.data.getdata import info +from utils import Utils class Restart(commands.Cog): def __init__(self, bot): self.bot = bot - self.info = info() + self.info = Utils.info() @commands.Cog.listener() async def on_ready(self): diff --git a/example.config.json b/example.config.json index 6483979..7daad84 100644 --- a/example.config.json +++ b/example.config.json @@ -1,5 +1,7 @@ { + "CONFIGURATION": "Please view configuration.md!", "Token": "YourBotTokenHere", "OwnerID": "YourIDHere", - "Branch": "main" + "Sharded": false, + "Branch": "master" } \ No newline at end of file diff --git a/example.dyndata.json b/example.dyndata.json deleted file mode 100644 index c505eb6..0000000 --- a/example.dyndata.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "CONFIGURATION": "Please view configuration.md!", - "sharded": false, - "branch": "master" -} \ No newline at end of file diff --git a/example.env b/example.env index ef09ee1..2f484af 100644 --- a/example.env +++ b/example.env @@ -1,3 +1,4 @@ TOKEN=YOURBOTTOKENHERE OWNERID=OWNERIDHERE -BRANCH=main \ No newline at end of file +SHARDED=FALSE +BRANCH=MASTER \ No newline at end of file diff --git a/main.py b/main.py index f5d63d7..235440b 100644 --- a/main.py +++ b/main.py @@ -1,24 +1,25 @@ -import discord -from utils.data.getdata import info -info = info() -intents = discord.Intents.all() -bot = discord.Bot(debug_guilds=[955135608228024394], - status=discord.Status.dnd, - activity=discord.Activity(type=discord.ActivityType.playing, - name="Booting..."), - intents=intents) +from discord import Bot, Intents, Status, Activity, ActivityType, Embed, Color, utils +from utils import Utils +info = Utils.info() +intents = Intents.all() +bot = Bot(debug_guilds=[955135608228024394], status=Status.dnd, activity=Activity(type=ActivityType.playing, name="Booting..."), intents=intents) bot.load_extensions("cogs") -first = False -@bot.event +global BOOTED +BOOTED = True + +@bot.listen() async def on_ready(): - embed = discord.Embed(title="🟢 Online!\nTime to mess around!", timestamp=discord.utils.utcnow(), - color=discord.Color.green()) - await bot.get_guild(955135608228024394).get_channel(1011649871511572500).send(embed=embed) - print(f"Ready! Logged in as {bot.user}") - if first is True: - await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, - name=f"my creator's keyboard | In {len(bot.guilds)} servers"), status=discord.Status.online) - first = False + global BOOTED + if BOOTED is False: + print ("Reconnected(?)") + if BOOTED is True: + embed = Embed(title="🟢 Online!\nTime to mess around!", timestamp=utils.utcnow(), + color=Color.green()) + await bot.get_guild(955135608228024394).get_channel(1011649871511572500).send(embed=embed) + await bot.change_presence(activity=Activity(type=ActivityType.listening, + name=f"my creator's keyboard | In {len(bot.guilds)} servers"), status=Status.online) + print(f"Ready! Logged in as {bot.user}") + BOOTED = False @bot.slash_command(description='Say hello', guild_ids=[955135608228024394]) async def hello(ctx): @@ -29,15 +30,15 @@ async def test(ctx): await ctx.send("te@st!") print("send command 'test!'") -@bot.event +@bot.listen() async def on_command_error(ctx, error): await ctx.reply(f"An error occurred```py\n{str(error)}\n```Message the owner for support\nThis has been logged.") - embed = discord.Embed(title="Error :(", timestamp=discord.utils.utcnow(), color=discord.Color.red()) + embed = Embed(title="Error :(", timestamp=utils.utcnow(), color=Color.red()) embed.add_field(name = "Error:", value=str(error)) await bot.get_guild(955135608228024394).get_channel(1017880577506017361).send(embed=embed) -@bot.event +@bot.listen() async def on_message(message): print ("message") print (message.content) diff --git a/requirements.txt b/requirements.txt index 34be5d8..275baf6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -py-cord==2.3.2 -python-dotenv==0.21.0 \ No newline at end of file +py-cord==2.4.0 +python-dotenv==0.21.1 \ No newline at end of file diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..19aa639 --- /dev/null +++ b/utils.py @@ -0,0 +1,64 @@ +from os import listdir +from aiohttp import ClientSession +class Utils: + @staticmethod # This is a static method, which means you don't need to create an instance of the class to use it + def info(): + use_json = True # Change this to False if you want to use environment variables instead of a config.json file + if use_json: + import json + try: + with open("config.json", "r", encoding="UTF-8") as f: + return json.load(f) + except FileNotFoundError: + print("config.json file not found! Please create it.") + exit() + except json.decoder.JSONDecodeError: + print("config.json file is invalid! Please fix it.") + exit() + if not use_json: + import os + try: + from dotenv import load_dotenv + load_dotenv() + except ImportError: + print("dotenv module not found! You will not be able to use a .env file.") + return { + "Token": os.getenv("TOKEN"), + "OwnerID": os.getenv("OWNERID") + } + @staticmethod + def getcogs(ctx): + info = Utils.info() + if ctx.interaction.user.id != int(info['OwnerID']): + return ["You don't have permission to use this command!"] + cogs = [] + for fn in listdir('cogs'): + if ctx.interaction.data['options'][1]['value'] == "": + cogs.append(fn) + continue + if fn.startswith(ctx.interaction.data['options'][1]['value']): + cogs.append(fn) + continue + if not cogs: + return ["No files found with that name, or none exist"] + return cogs + @staticmethod + async def GetBranches(ctx): + info = Utils.info() + if ctx.interaction.user.id != int(info['OwnerID']): + return ["You don't have permission to use this command!"] + branches = [] + async with ClientSession() as session: + async with session.get('https://api.github.com/repos/Soapy7261/DobbieBot/branches') as resp: + if resp.status == 200: + data = await resp.json() + for branch in data: + if ctx.interaction.data['options'][0]['value'] == "": + branches.append(branch['name']) + continue + if branch['name'].startswith(ctx.interaction.data['options'][0]['value']): + branches.append(branch['name']) + continue + else: + branches.append("Error getting branches") + return branches \ No newline at end of file diff --git a/utils/data/getdata.py b/utils/data/getdata.py deleted file mode 100644 index cdf5aa4..0000000 --- a/utils/data/getdata.py +++ /dev/null @@ -1,27 +0,0 @@ -def info(use_json: bool = True): - import os - if not os.path.exists("config.json"): - print ("No config file found! Please create one. Trying .env") - use_json = False - if use_json: - import json - with open("config.json", "r", encoding="UTF-8") as f: - return json.load(f) - if not use_json: - import sys - from dotenv import load_dotenv - load_dotenv() - if os.getenv("TOKEN") is None: - print("TOKEN not found in .env! Please create it.") - sys.exit() - if os.getenv("OWNERID") is None: - print("OWNERID not found in .env! Please create it.") - sys.exit() - if os.getenv("BRANCH") is None: - print("BRANCH not found in .env! Please create it.") - sys.exit() - return { - "Token": os.getenv("TOKEN"), - "OwnerID": os.getenv("OWNERID"), - "Branch": os.getenv("BRANCH"), - } diff --git a/utils/helpers/getbranches.py b/utils/helpers/getbranches.py deleted file mode 100644 index 49ba242..0000000 --- a/utils/helpers/getbranches.py +++ /dev/null @@ -1,21 +0,0 @@ -import aiohttp -from utils.data.getdata import info -info = info() -async def GetBranches(ctx): - if ctx.interaction.user.id != int(info['OwnerID']): - return ["You don't have permission to use this command!"] - branches = [] - async with aiohttp.ClientSession() as session: - async with session.get('https://api.github.com/repos/Soapy7261/DobbieBot/branches') as resp: - if resp.status == 200: - data = await resp.json() - for branch in data: - if ctx.interaction.data['options'][0]['value'] == "": - branches.append(branch['name']) - continue - if branch['name'].startswith(ctx.interaction.data['options'][0]['value']): - branches.append(branch['name']) - continue - else: - branches.append("Error getting branches") - return branches diff --git a/utils/helpers/getcogs.py b/utils/helpers/getcogs.py deleted file mode 100644 index c1dc048..0000000 --- a/utils/helpers/getcogs.py +++ /dev/null @@ -1,17 +0,0 @@ -import os -from utils.data import getdata -info = getdata.info() -def getcogs(ctx): - if ctx.interaction.user.id != int(info['OwnerID']): - return ["You don't have permission to use this command!"] - cogs = [] - for fn in os.listdir('cogs'): - if ctx.interaction.data['options'][1]['value'] == "": - cogs.append(fn) - continue - if fn.startswith(ctx.interaction.data['options'][1]['value']): - cogs.append(fn) - continue - if not cogs: - return ["No files found with that name, or none exist"] - return cogs From 019b9e9d9749fab7171d0d86dc8b194c7769253b Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Sat, 18 Feb 2023 19:27:51 -0500 Subject: [PATCH 33/38] please dont yell at me --- .pylintrc | 2 +- cogs/botinfo.py | 3 ++- cogs/branch.py | 3 ++- cogs/cogs.py | 5 +++-- cogs/math.py | 3 ++- cogs/reload.py | 12 +++++----- cogs/restart.py | 2 +- cogs/say.py | 3 ++- utils.py | 58 +++++++++++++++++++++++++++---------------------- 9 files changed, 51 insertions(+), 40 deletions(-) diff --git a/.pylintrc b/.pylintrc index 3df2feb..505367d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,2 +1,2 @@ [MESSAGES CONTROL] -disable=missing-docstring,missing-module-docstring,line-too-long \ No newline at end of file +disable=missing-docstring,missing-module-docstring,line-too-long,no-member,global-statement \ No newline at end of file diff --git a/cogs/botinfo.py b/cogs/botinfo.py index aad5d6b..8e0edb3 100644 --- a/cogs/botinfo.py +++ b/cogs/botinfo.py @@ -1,4 +1,5 @@ -from discord import slash_command, Embed, utils, Color +from discord import Embed, utils, Color +from discord.ext.commands import slash_command from discord.ext import commands class BotInfo(commands.Cog): def __init__(self, bot): diff --git a/cogs/branch.py b/cogs/branch.py index 6cd64f4..4ddc18f 100644 --- a/cogs/branch.py +++ b/cogs/branch.py @@ -1,5 +1,6 @@ import discord -from discord import slash_command, commands +from discord.ext import commands +from discord.ext.commands import slash_command from utils import Utils class Branch(commands.Cog): def __init__(self, bot): diff --git a/cogs/cogs.py b/cogs/cogs.py index 894ea8e..c886115 100644 --- a/cogs/cogs.py +++ b/cogs/cogs.py @@ -1,6 +1,7 @@ import os import discord -from discord import slash_command, commands +from discord.ext import commands +from discord.ext.commands import slash_command from utils import Utils class Cogs(commands.Cog): def __init__(self, bot): @@ -12,7 +13,7 @@ async def on_ready(self): print('Cogs cog loaded!') @slash_command(description='Load, unload, or reload cogs', guild_ids=[955135608228024394]) - async def cogs(self, ctx, action: discord.Option(choices=["Reload", "Load", "Unload"], description='What action to run', required=True), cog: discord.Option(autocomplete=Utils.getcogs, description='The cog to run the action on', required=True)): + async def cogs(self, ctx, action: discord.Option(choices=["Reload", "Load", "Unload"], description='What action to run', required=True), cog: discord.Option(autocomplete=Utils.get_cogs, description='The cog to run the action on', required=True)): if ctx.author.id != int(self.info['OwnerID']): return await ctx.respond("You don't have permission to use this command!", ephemeral=True) if cog not in [f"{fn[:-3]}" for fn in os.listdir("commands")]: diff --git a/cogs/math.py b/cogs/math.py index a658512..837efdd 100644 --- a/cogs/math.py +++ b/cogs/math.py @@ -1,5 +1,6 @@ import discord -from discord import slash_command, commands +from discord.ext import commands +from discord.ext.commands import slash_command class Math(commands.Cog): def __init__(self, bot): self.bot = bot diff --git a/cogs/reload.py b/cogs/reload.py index d82b274..937bbd7 100644 --- a/cogs/reload.py +++ b/cogs/reload.py @@ -1,6 +1,6 @@ import discord -import asyncio -from discord import slash_command +from asyncio import sleep as asyncsleep +from discord.ext.commands import slash_command from discord.ext import commands from utils import Utils class Reload(commands.Cog): @@ -18,15 +18,15 @@ async def reload(self, ctx): return await ctx.respond("You don't have permission to use this command!", ephemeral=True) await ctx.defer() await self.bot.change_presence(activity=discord.Activity(type=discord.ActivityType.playing, name=f"Reloading commands, bot may be unresponsive | In {len(self.bot.guilds)} servers"), status=discord.Status.dnd) - await asyncio.sleep(1) + await asyncsleep(1) try: await self.bot.sync_commands() except Exception as e: await ctx.respond ("Failed to reload commands!") await ctx.respond ("```py\n" + str(e) + "\n```", ephemeral=True) - await asyncio.sleep(3) - return await self.bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"my creator's keyboard | In {len(self.bot.guilds)} servers"), status=discord.Status.online) - await asyncio.sleep(3) + await asyncsleep(3) + return await self.bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"my creator's keyboard | In {len(self.bot.guilds)} servers"), status=discord.Status.online) + await asyncsleep(3) await self.bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"my creator's keyboard | In {len(self.bot.guilds)} servers"), status=discord.Status.online) return await ctx.respond("Finished!", ephemeral=True) diff --git a/cogs/restart.py b/cogs/restart.py index e77c624..b74084f 100644 --- a/cogs/restart.py +++ b/cogs/restart.py @@ -1,5 +1,5 @@ import discord -from discord import slash_command +from discord.ext.commands import slash_command from discord.ext import commands from utils import Utils class Restart(commands.Cog): diff --git a/cogs/say.py b/cogs/say.py index 76666c9..08fe466 100644 --- a/cogs/say.py +++ b/cogs/say.py @@ -1,4 +1,5 @@ -from discord import slash_command, Option, Embed, utils, Color +from discord import Option, Embed, utils, Color +from discord.ext.commands import slash_command from discord.ext import commands class Say(commands.Cog): def __init__(self, bot): diff --git a/utils.py b/utils.py index 19aa639..8788965 100644 --- a/utils.py +++ b/utils.py @@ -1,49 +1,55 @@ -from os import listdir +from os import listdir, getenv from aiohttp import ClientSession +from json import load as jsonload +from json.decoder import JSONDecodeError +from sys import exit as sysexit +try: + from dotenv import load_dotenv +except ImportError: + print("dotenv module not found! You will not be able to use a .env file.") class Utils: @staticmethod # This is a static method, which means you don't need to create an instance of the class to use it - def info(): + def info() -> dict: use_json = True # Change this to False if you want to use environment variables instead of a config.json file + response = {} if use_json: - import json try: - with open("config.json", "r", encoding="UTF-8") as f: - return json.load(f) + with open("config.json", "r", encoding="UTF-8") as file: + response = jsonload(file) except FileNotFoundError: print("config.json file not found! Please create it.") - exit() - except json.decoder.JSONDecodeError: + sysexit() + except JSONDecodeError: print("config.json file is invalid! Please fix it.") - exit() + sysexit() + except EncodingWarning: + print("config.json file is not encoded in UTF-8! Please fix it.") + sysexit() if not use_json: - import os - try: - from dotenv import load_dotenv - load_dotenv() - except ImportError: - print("dotenv module not found! You will not be able to use a .env file.") - return { - "Token": os.getenv("TOKEN"), - "OwnerID": os.getenv("OWNERID") + load_dotenv() + response = { + "Token": getenv("TOKEN"), + "OwnerID": getenv("OWNERID") } + return response @staticmethod - def getcogs(ctx): + def get_cogs(ctx) -> list: info = Utils.info() if ctx.interaction.user.id != int(info['OwnerID']): return ["You don't have permission to use this command!"] cogs = [] - for fn in listdir('cogs'): + for file in listdir('cogs'): if ctx.interaction.data['options'][1]['value'] == "": - cogs.append(fn) + cogs.append(file) continue - if fn.startswith(ctx.interaction.data['options'][1]['value']): - cogs.append(fn) + if file.startswith(ctx.interaction.data['options'][1]['value']): + cogs.append(file) continue - if not cogs: - return ["No files found with that name, or none exist"] + if cogs == []: + return ["No cogs found(!?)"] return cogs @staticmethod - async def GetBranches(ctx): + async def get_branches(ctx) -> list: info = Utils.info() if ctx.interaction.user.id != int(info['OwnerID']): return ["You don't have permission to use this command!"] @@ -61,4 +67,4 @@ async def GetBranches(ctx): continue else: branches.append("Error getting branches") - return branches \ No newline at end of file + return branches From 414bb949de9b7e49a0882ff4d1ecaa634b5522cb Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Sat, 18 Feb 2023 19:30:13 -0500 Subject: [PATCH 34/38] stop --- cogs/cogs.py | 4 ++-- cogs/reload.py | 6 +++--- utils.py | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cogs/cogs.py b/cogs/cogs.py index c886115..adc800b 100644 --- a/cogs/cogs.py +++ b/cogs/cogs.py @@ -27,8 +27,8 @@ async def cogs(self, ctx, action: discord.Option(choices=["Reload", "Load", "Unl self.bot.unload_extension(f"commands.{cog}") if action == "Reload": self.bot.reload_extension(f"commands.{cog}") - except Exception as e: - await ctx.respond(f"```py\n{str(e)}\n```", ephemeral=True) + except Exception as error: + await ctx.respond(f"```py\n{str(error)}\n```", ephemeral=True) return await ctx.respond(f"{action}ed {cog}", ephemeral=True) diff --git a/cogs/reload.py b/cogs/reload.py index 937bbd7..31e07e3 100644 --- a/cogs/reload.py +++ b/cogs/reload.py @@ -1,5 +1,5 @@ -import discord from asyncio import sleep as asyncsleep +import discord from discord.ext.commands import slash_command from discord.ext import commands from utils import Utils @@ -21,9 +21,9 @@ async def reload(self, ctx): await asyncsleep(1) try: await self.bot.sync_commands() - except Exception as e: + except Exception as error: await ctx.respond ("Failed to reload commands!") - await ctx.respond ("```py\n" + str(e) + "\n```", ephemeral=True) + await ctx.respond ("```py\n" + str(error) + "\n```", ephemeral=True) await asyncsleep(3) return await self.bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"my creator's keyboard | In {len(self.bot.guilds)} servers"), status=discord.Status.online) await asyncsleep(3) diff --git a/utils.py b/utils.py index 8788965..d10cc4c 100644 --- a/utils.py +++ b/utils.py @@ -1,8 +1,8 @@ from os import listdir, getenv -from aiohttp import ClientSession from json import load as jsonload from json.decoder import JSONDecodeError from sys import exit as sysexit +from aiohttp import ClientSession try: from dotenv import load_dotenv except ImportError: @@ -45,7 +45,7 @@ def get_cogs(ctx) -> list: if file.startswith(ctx.interaction.data['options'][1]['value']): cogs.append(file) continue - if cogs == []: + if not cogs: return ["No cogs found(!?)"] return cogs @staticmethod @@ -67,4 +67,6 @@ async def get_branches(ctx) -> list: continue else: branches.append("Error getting branches") + if not branches: + return ["No branches found(!?)"] return branches From 8d1730dca8ba433286b6502a4e717f2bd0374860 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Sat, 18 Feb 2023 19:31:59 -0500 Subject: [PATCH 35/38] meh ill fix that in a moment --- .pylintrc | 2 +- main.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index 505367d..8318b6c 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,2 +1,2 @@ [MESSAGES CONTROL] -disable=missing-docstring,missing-module-docstring,line-too-long,no-member,global-statement \ No newline at end of file +disable=missing-docstring,missing-module-docstring,line-too-long,no-member,global-statement,no-name-in-module \ No newline at end of file diff --git a/main.py b/main.py index 235440b..86a4f84 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,6 @@ intents = Intents.all() bot = Bot(debug_guilds=[955135608228024394], status=Status.dnd, activity=Activity(type=ActivityType.playing, name="Booting..."), intents=intents) bot.load_extensions("cogs") -global BOOTED BOOTED = True @bot.listen() From 43ab219b57daa35208534746bd0217ee7bf38e7c Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Sat, 18 Feb 2023 19:34:29 -0500 Subject: [PATCH 36/38] noooow? --- cogs/cogs.py | 11 +++++++++-- main.py | 8 +++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cogs/cogs.py b/cogs/cogs.py index adc800b..0aa97fa 100644 --- a/cogs/cogs.py +++ b/cogs/cogs.py @@ -3,6 +3,7 @@ from discord.ext import commands from discord.ext.commands import slash_command from utils import Utils +from discord.errors import ExtensionAlreadyLoaded, ExtensionNotLoaded, ExtensionFailed class Cogs(commands.Cog): def __init__(self, bot): self.bot = bot @@ -27,8 +28,14 @@ async def cogs(self, ctx, action: discord.Option(choices=["Reload", "Load", "Unl self.bot.unload_extension(f"commands.{cog}") if action == "Reload": self.bot.reload_extension(f"commands.{cog}") - except Exception as error: - await ctx.respond(f"```py\n{str(error)}\n```", ephemeral=True) + except ExtensionAlreadyLoaded: + await ctx.respond("Extension already loaded!", ephemeral=True) + return + except ExtensionNotLoaded: + await ctx.respond("Extension not loaded!", ephemeral=True) + return + except ExtensionFailed as error: + await ctx.respond(f"Extension failed to load!```py\n{str(error)}\n```", ephemeral=True) return await ctx.respond(f"{action}ed {cog}", ephemeral=True) diff --git a/main.py b/main.py index 86a4f84..271cebb 100644 --- a/main.py +++ b/main.py @@ -9,11 +9,10 @@ @bot.listen() async def on_ready(): global BOOTED - if BOOTED is False: + if not BOOTED: print ("Reconnected(?)") - if BOOTED is True: - embed = Embed(title="🟢 Online!\nTime to mess around!", timestamp=utils.utcnow(), - color=Color.green()) + if BOOTED: + embed = Embed(title="🟢 Online!\nTime to mess around!", timestamp=utils.utcnow(), color=Color.green()) await bot.get_guild(955135608228024394).get_channel(1011649871511572500).send(embed=embed) await bot.change_presence(activity=Activity(type=ActivityType.listening, name=f"my creator's keyboard | In {len(bot.guilds)} servers"), status=Status.online) @@ -34,7 +33,6 @@ async def on_command_error(ctx, error): await ctx.reply(f"An error occurred```py\n{str(error)}\n```Message the owner for support\nThis has been logged.") embed = Embed(title="Error :(", timestamp=utils.utcnow(), color=Color.red()) embed.add_field(name = "Error:", value=str(error)) - await bot.get_guild(955135608228024394).get_channel(1017880577506017361).send(embed=embed) @bot.listen() From 4963794a34d3f677aab45426b5b19494b4b48a52 Mon Sep 17 00:00:00 2001 From: Soapy7261 Official <81933267+Soapy7261@users.noreply.github.com> Date: Sat, 18 Feb 2023 19:36:18 -0500 Subject: [PATCH 37/38] Update cogs.py --- cogs/cogs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/cogs.py b/cogs/cogs.py index 0aa97fa..7278220 100644 --- a/cogs/cogs.py +++ b/cogs/cogs.py @@ -2,8 +2,8 @@ import discord from discord.ext import commands from discord.ext.commands import slash_command -from utils import Utils from discord.errors import ExtensionAlreadyLoaded, ExtensionNotLoaded, ExtensionFailed +from utils import Utils class Cogs(commands.Cog): def __init__(self, bot): self.bot = bot From fa506d37b4b4928a3a6d9f623ba2d7c5c83434ff Mon Sep 17 00:00:00 2001 From: Soapy7261 <81933267+Soapy7261@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:23:04 -0400 Subject: [PATCH 38/38] 2024 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 8f8b36e..78f7e6a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Soapy7261 +Copyright (c) 2024 Soapy7261 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal