Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: V2 #7

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
500ab15
V2
Soapy7261 Dec 5, 2022
c002360
Lint
Soapy7261 Dec 5, 2022
530d55b
Correct stuff
Soapy7261 Dec 5, 2022
f2c596d
I hate pylint
Soapy7261 Dec 5, 2022
83d8b6e
Happy now pylint?
Soapy7261 Dec 5, 2022
a13090b
ange
Soapy7261 Dec 5, 2022
c5741ac
...
Soapy7261 Dec 5, 2022
19163b2
STOP.
Soapy7261 Dec 5, 2022
4559038
Can't stop me now!
Soapy7261 Dec 5, 2022
47b4d2a
V2 is only started.
Soapy7261 Dec 5, 2022
10931d9
no
Soapy7261 Dec 5, 2022
32dbb20
Pylint is right
Soapy7261 Dec 5, 2022
a55c1d0
oops
Soapy7261 Dec 5, 2022
3d36286
ok fine
Soapy7261 Dec 5, 2022
29848dc
New stuff incoming!
Soapy7261 Dec 5, 2022
866efe1
changes to make pylint happy
Soapy7261 Dec 5, 2022
39b5503
smh
Soapy7261 Dec 5, 2022
afe5d5d
shit up pylint
Soapy7261 Dec 5, 2022
8eab471
security (#10)
Soapy7261 Dec 5, 2022
fc1c1a9
Update SECURITY.md
Soapy7261 Dec 6, 2022
d19cf4e
changes
Soapy7261 Dec 16, 2022
d3b0d76
changes
Soapy7261 Dec 16, 2022
77dd7bb
reload is cool
Soapy7261 Dec 16, 2022
60f4976
wait
Soapy7261 Dec 16, 2022
315e74d
we're booting here
Soapy7261 Dec 16, 2022
bf8ee6a
ugh
Soapy7261 Dec 16, 2022
38c8153
Update year in LICENSE, and some other changes (#11)
Soapy7261 Jan 20, 2023
bfac91a
Some changes
Soapy7261 Jan 20, 2023
e7efe5f
Some changes
Soapy7261 Jan 20, 2023
e6749d5
Oops.
Soapy7261 Jan 20, 2023
e16dfde
Pylint hates me
Soapy7261 Jan 20, 2023
ebc8236
Big changes coming soon
Soapy7261 Jan 20, 2023
cd9afec
I wonder how much pylint is gonna scream at me, im predicting a lot
Soapy7261 Feb 19, 2023
019b9e9
please dont yell at me
Soapy7261 Feb 19, 2023
414bb94
stop
Soapy7261 Feb 19, 2023
8d1730d
meh ill fix that in a moment
Soapy7261 Feb 19, 2023
43ab219
noooow?
Soapy7261 Feb 19, 2023
4963794
Update cogs.py
Soapy7261 Feb 19, 2023
fa506d3
2024
Soapy7261 Aug 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Pylint

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
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 pylint
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea
.vscode
cogs/__pycache__
__pycache__
.env
config.json
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[MESSAGES CONTROL]
disable=missing-docstring,missing-module-docstring,line-too-long,no-member,global-statement,no-name-in-module
32 changes: 32 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
@@ -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` |
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion LICENSE.txt → LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 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
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# DobbieBot
Discord fork used: pycord
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, <br>
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 all intents.

## Configuration
Please view the [config file](./CONFIGURATION.md) for more configuration options.
23 changes: 23 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Security Policy

## Supported Versions
Only the latest version of DobbieBot is supported, older versions are not supported.
| Version | Support status |
| ------- | ------------------ |
| 2.LATEST | ✅ Active |
| 1.X | ❌ EOL |

## 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
30 changes: 30 additions & 0 deletions cogs/botinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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):
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 = Embed(
title="DobbieBot",
description = "The Dobbie bot",
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):
bot.add_cog(BotInfo(bot))
21 changes: 21 additions & 0 deletions cogs/branch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import discord
from discord.ext import commands
from discord.ext.commands import slash_command
from utils import Utils
class Branch(commands.Cog):
def __init__(self, bot):
self.bot = bot
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=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)

def setup(bot):
bot.add_cog(Branch(bot))
43 changes: 43 additions & 0 deletions cogs/cogs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import discord
from discord.ext import commands
from discord.ext.commands import slash_command
from discord.errors import ExtensionAlreadyLoaded, ExtensionNotLoaded, ExtensionFailed
from utils import Utils
class Cogs(commands.Cog):
def __init__(self, bot):
self.bot = bot
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=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")]:
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 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)

def setup(bot):
bot.add_cog(Cogs(bot))
16 changes: 16 additions & 0 deletions cogs/examples/cogexample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from discord import slash_command
from discord.ext import 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))
16 changes: 16 additions & 0 deletions cogs/examples/defaultpermissions.txt
Original file line number Diff line number Diff line change
@@ -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))
17 changes: 17 additions & 0 deletions cogs/examples/defaultpermissionsgroup.txt
Original file line number Diff line number Diff line change
@@ -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))
17 changes: 17 additions & 0 deletions cogs/examples/deferexample.txt
Original file line number Diff line number Diff line change
@@ -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))
17 changes: 17 additions & 0 deletions cogs/examples/slashcommandgroup.txt
Original file line number Diff line number Diff line change
@@ -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))
29 changes: 29 additions & 0 deletions cogs/math.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import discord
from discord.ext import commands
from discord.ext.commands import slash_command
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(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
elif operation == '-':
oper = first - second
elif operation == '*':
oper = first * second
elif operation == '/':
if second == 0:
return await ctx.respond("You can't divide by 0!", ephemeral=True)
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))
34 changes: 34 additions & 0 deletions cogs/reload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from asyncio import sleep as asyncsleep
import discord
from discord.ext.commands import slash_command
from discord.ext import commands
from utils import Utils
class Reload(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.info = Utils.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_ids=[955135608228024394])
async def reload(self, ctx):
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)
await asyncsleep(1)
try:
await self.bot.sync_commands()
except Exception as error:
await ctx.respond ("Failed to reload commands!")
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)
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)

def setup(bot):
bot.add_cog(Reload(bot))
Loading
Loading