Skip to content

Commit

Permalink
Merge branch 'refs/heads/rewrite' into extensions-command
Browse files Browse the repository at this point in the history
# Conflicts:
#	cogs/dev.py
  • Loading branch information
n0Oo0Oo0b committed Jul 2, 2024
2 parents b1eb8ad + 6dbc76f commit b629659
Show file tree
Hide file tree
Showing 31 changed files with 1,423 additions and 598 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Ruff
on: [ push, pull_request ]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@ dmypy.json
.pyre/

config.json
config.toml
config.toml
.pdm-python
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ IB.ai, but in Python

## Running the bot

To run this project, you need to have [Docker](https://docs.docker.com/get-docker/) and [Python 3.11](https://www.python.org/downloads/) installed.
To run this project, you need to have [Docker](https://docs.docker.com/get-docker/) and [Python >=3.11](https://www.python.org/downloads/) installed.

1. Clone this repository

Expand Down Expand Up @@ -46,3 +46,36 @@ docker-compose -f docker-compose.postgres.yml up --build
# Contributing

Please read the `CONTRIBUTING.md` file to find out more about contributing towards the project.

## Development
We use [PDM](https://pdm-project.org/en/stable/) to manage dependencies for this project and [Ruff](https://docs.astral.sh/ruff/) to handle linting and code formatting.

### 1. Clone this repository

```
git clone https://github.com/ib-ai/ib.py.git
```

and navigate to the root directory.

```
cd ib.py
```

### 2. [Install pdm](https://pdm-project.org/en/stable/#recommended-installation-method)


### 3. Create virtual environment and install dependencies
(requires either virtualenv, venv, or conda to be installed)

```
pdm install
```

### 4. Using the virtual environment

Either [activate virtual environment](https://pdm-project.org/en/stable/usage/venv/#activate-a-virtualenv) if you are running commands in the terminal

Or

Choose `.venv\Scripts\python.exe` as the interpreter in your IDE.
64 changes: 37 additions & 27 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,52 @@


import logging
logger = logging.getLogger('bot')

logger = logging.getLogger("bot")
logger.setLevel(logging.DEBUG) # TODO: Change back to logging.INFO

cogs_logger = logging.getLogger('cogs')
cogs_logger = logging.getLogger("cogs")
cogs_logger.setLevel(logging.DEBUG) # TODO: Change back to logging.INFO

logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S')
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
datefmt="%d-%b-%y %H:%M:%S",
)


intents = discord.Intents.all()
INITIAL_COGS = (
'dev',
'embeds',
'filter',
# 'help',
'helper',
'moderation',
'monitor',
'public',
'reminder',
'roles',
'tags',
'updates',
'voting',
"dev",
"embeds",
"filter",
# "help",
"helper",
"moderation",
"monitor",
"public",
"reminder",
"roles",
"tags",
"updates",
"voting",
)


class IBpy(commands.Bot):
def __init__(self):
super().__init__(
intents=intents,
intents=intents,
command_prefix=config.prefix,
description=config.description,
application_id=config.application_id
application_id=config.application_id,
)

async def setup_hook(self):
await db_init()

for cog in INITIAL_COGS:
try:
await bot.load_extension(f'cogs.{cog}')
await bot.load_extension(f"cogs.{cog}")
logger.debug(f'Imported cog "{cog}".')
except commands.errors.NoEntryPointError as e:
# ! Remove before push
Expand All @@ -55,26 +61,30 @@ async def setup_hook(self):
except commands.errors.ExtensionFailed as e:
logger.error(e)
logger.info("Loaded all cogs.")

async def on_ready(self):
await bot.change_presence(activity=discord.Game(name=f"{config.prefix}help"), status=discord.Status.do_not_disturb)
await bot.change_presence(
activity=discord.Game(name=f"{config.prefix}help"),
status=discord.Status.do_not_disturb,
)

bot_name = bot.user.name
bot_description = bot.description
guild_number = len(bot.guilds)

logger.info(f"Bot \"{bot_name}\" is now connected.")
logger.info(f'Bot "{bot_name}" is now connected.')
logger.info(f"Currently serving {guild_number} guilds.")
logger.info(f"Described as \"{bot_description}\".")
logger.info(f'Described as "{bot_description}".')

await self.get_cog("Reminder").schedule_existing_reminders()
logger.info("Existing reminders queued.")

await self.get_cog('Reminder').schedule_existing_reminders()
logger.info(f'Existing reminders queued.')

async def on_command_error(self, ctx: commands.Context, exception) -> None:
# sends the error message as a discord message
# uesful for debugging, TODO: remove/edit before pushing to production
await super().on_command_error(ctx, exception)
await ctx.send(exception)


bot = IBpy()
bot.run(config.token)
19 changes: 9 additions & 10 deletions cogs/channelorder.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import discord
from discord.ext import commands


class ChannelOrder(commands.Cog):
def __init__(self, bot: commands.Bot) -> None:
self.bot = bot
@commands.hybrid_group(aliases=['co'])

@commands.hybrid_group(aliases=["co"])
async def channelorder(self, ctx: commands.Context):
"""
Commands for discord channel arrangement within categories.
"""
raise NotImplementedError('Command requires implementation and permission set-up.')
raise NotImplementedError("Command requires implementation and permission set-up.")

@channelorder.command()
async def snapshot(self, ctx: commands.Context):
"""
Save the arrangement of channels in a category.
"""
raise NotImplementedError('Command requires implementation and permission set-up.')
@channelorder.command(aliases=['r'])
raise NotImplementedError("Command requires implementation and permission set-up.")

@channelorder.command(aliases=["r"])
async def rollback(self, ctx: commands.Context):
"""
Revert the arrangement of channels in a category.
"""
raise NotImplementedError('Command requires implementation and permission set-up.')
raise NotImplementedError("Command requires implementation and permission set-up.")


async def setup(bot: commands.Bot):
await bot.add_cog(ChannelOrder(bot))
await bot.add_cog(ChannelOrder(bot))
16 changes: 11 additions & 5 deletions cogs/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ async def guilddata(self, ctx: commands.Context):
"""
Display all guild data.
"""
raise NotImplementedError('Command requires implementation and permission set-up.')
raise NotImplementedError("Command requires implementation and permission set-up.")

@commands.command(name='eval')
@commands.command(name="eval")
async def evaluate(self, ctx: commands.Context, *, code: str):
"""
Run python code.
Expand All @@ -50,15 +50,16 @@ async def evaluate(self, ctx: commands.Context, *, code: str):
"channel": ctx.channel,
"author": ctx.author,
"guild": ctx.guild,
"message": ctx.message
"message": ctx.message,
}

stdout = io.StringIO()

try:
with contextlib.redirect_stdout(stdout):
exec(
f"async def func():\n{textwrap.indent(code, ' ')}", local_variables,
f"async def func():\n{textwrap.indent(code, ' ')}",
local_variables,
)

obj = await local_variables["func"]()
Expand All @@ -69,7 +70,12 @@ async def evaluate(self, ctx: commands.Context, *, code: str):
await ctx.send(result[0:2000])

@commands.command()
async def sync(self, ctx: commands.Context, guilds: commands.Greedy[discord.Object], spec: Optional[Literal["~", "*", "^"]] = None) -> None:
async def sync(
self,
ctx: commands.Context,
guilds: commands.Greedy[discord.Object],
spec: Optional[Literal["~", "*", "^"]] = None,
) -> None:
"""
Syncs app commands to Discord.
"""
Expand Down
11 changes: 5 additions & 6 deletions cogs/embeds.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import discord
from discord.ext import commands


class Embeds(commands.Cog):
def __init__(self, bot: commands.Bot) -> None:
self.bot = bot

@commands.hybrid_command()
async def embed(self, ctx: commands.Context):
"""
Interactively construct a Discord embed.
"""
raise NotImplementedError('Command requires implementation and permission set-up.')
raise NotImplementedError("Command requires implementation and permission set-up.")

@commands.command()
async def embedraw(self, ctx: commands.Context):
"""
Create a Discord embed via raw JSON input.
"""
raise NotImplementedError('Command requires implementation and permission set-up.')
raise NotImplementedError("Command requires implementation and permission set-up.")


async def setup(bot: commands.Bot):
await bot.add_cog(Embeds(bot))
await bot.add_cog(Embeds(bot))
Loading

0 comments on commit b629659

Please sign in to comment.