Skip to content

Commit

Permalink
Personalized
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewEdgers committed Oct 6, 2023
1 parent e6a344d commit 48a4b4c
Show file tree
Hide file tree
Showing 20 changed files with 1,272 additions and 194 deletions.
1 change: 0 additions & 1 deletion .env.example

This file was deleted.

2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: ['AndrewEdgers']
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: kkrypt0nn # Replace with a single Ko-fi username
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.

**Template Version**
**Roster Version**
The version of the template that you are using.

**Additional context**
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,7 @@ cython_debug/
*.db

# Log file
discord.log
discord.log

# Comfig file
discloud.config
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Python Discord Bot Template
# Python Discord Bot Roster

<p align="center">
<a href="https://discord.gg/mTBrXyWxAF"><img src="https://img.shields.io/discord/739934735387721768?logo=discord"></a>
Expand Down Expand Up @@ -89,7 +89,7 @@ Here is an explanation of what everything is:

### `.env` file

To set up the token you will have to either make use of the [`.env.example`](.env.example) file, either copy or rename it to `.env` and replace `YOUR_BOT_TOKEN_HERE` with your bot's token.
To set up the token you will have to either make use of the [`.env.example`](.env) file, either copy or rename it to `.env` and replace `YOUR_BOT_TOKEN_HERE` with your bot's token.

Alternatively you can simply create an environment variable named `TOKEN`.

Expand Down
45 changes: 32 additions & 13 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Version: 6.1.0
"""

import asyncio
import json
import logging
import os
Expand Down Expand Up @@ -60,19 +60,20 @@
intents.presences = True
"""

intents = discord.Intents.default()
intents = discord.Intents.all()
intents.members = True
intents.message_content = True
intents.presences = True

"""
Uncomment this if you want to use prefix (normal) commands.
It is recommended to use slash commands and therefore not use prefix commands.
If you want to use prefix commands, make sure to also enable the intent below in the Discord developer portal.
"""
# intents.message_content = True

# Setup both of the loggers


# Setup both of the loggers
class LoggingFormatter(logging.Formatter):
# Colors
black = "\x1b[30m"
Expand Down Expand Up @@ -143,10 +144,10 @@ def __init__(self) -> None:

async def init_db(self) -> None:
async with aiosqlite.connect(
f"{os.path.realpath(os.path.dirname(__file__))}/database/database.db"
f"{os.path.realpath(os.path.dirname(__file__))}/database/database.db"
) as db:
with open(
f"{os.path.realpath(os.path.dirname(__file__))}/database/schema.sql"
f"{os.path.realpath(os.path.dirname(__file__))}/database/schema.sql"
) as file:
await db.executescript(file.read())
await db.commit()
Expand All @@ -156,7 +157,7 @@ async def load_cogs(self) -> None:
The code in this function is executed whenever the bot will start.
"""
for file in os.listdir(f"{os.path.realpath(os.path.dirname(__file__))}/cogs"):
if file.endswith(".py"):
if file.endswith(".py") and file[:-3] not in config["disabled_cogs"]:
extension = file[:-3]
try:
await self.load_extension(f"cogs.{extension}")
Expand All @@ -172,7 +173,7 @@ async def status_task(self) -> None:
"""
Setup the game status task of the bot.
"""
statuses = ["with you!", "with Krypton!", "with humans!"]
statuses = config["statuses"]
await self.change_presence(activity=discord.Game(random.choice(statuses)))

@status_task.before_loop
Expand Down Expand Up @@ -201,6 +202,10 @@ async def setup_hook(self) -> None:
f"{os.path.realpath(os.path.dirname(__file__))}/database/database.db"
)
)
if config["sync_commands_globally"]:
self.logger.info("Syncing commands globally...")
await bot.tree.sync()
self.logger.info("Done!")

async def on_message(self, message: discord.Message) -> None:
"""
Expand Down Expand Up @@ -230,6 +235,20 @@ async def on_command_completion(self, context: Context) -> None:
f"Executed {executed_command} command by {context.author} (ID: {context.author.id}) in DMs"
)

# on channel create check if name starts with ┇ and if not rename it
async def on_guild_channel_create(self, channel: discord.abc.GuildChannel) -> None:
"""
The code in this event is executed every time a channel is created.
:param channel: The channel that was created.
"""
if channel.name.startswith("┇"):
return
else:
# wait for the channel to be created
await asyncio.sleep(1)
await channel.edit(name=f"┇{channel.name}")

async def on_command_error(self, context: Context, error) -> None:
"""
The code in this event is executed every time a normal valid command catches an error.
Expand Down Expand Up @@ -262,16 +281,16 @@ async def on_command_error(self, context: Context, error) -> None:
elif isinstance(error, commands.MissingPermissions):
embed = discord.Embed(
description="You are missing the permission(s) `"
+ ", ".join(error.missing_permissions)
+ "` to execute this command!",
+ ", ".join(error.missing_permissions)
+ "` to execute this command!",
color=0xE02B2B,
)
await context.send(embed=embed)
elif isinstance(error, commands.BotMissingPermissions):
embed = discord.Embed(
description="I am missing the permission(s) `"
+ ", ".join(error.missing_permissions)
+ "` to fully perform this command!",
+ ", ".join(error.missing_permissions)
+ "` to fully perform this command!",
color=0xE02B2B,
)
await context.send(embed=embed)
Expand Down
Loading

0 comments on commit 48a4b4c

Please sign in to comment.