Skip to content

Commit

Permalink
word set generation refactor, python version bump, ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
KruASe76 committed Aug 30, 2024
1 parent 3b4323f commit f829977
Show file tree
Hide file tree
Showing 19 changed files with 1,297 additions and 828 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11.4-alpine
FROM python:3.12.5-alpine

WORKDIR /bot

Expand All @@ -7,4 +7,4 @@ RUN pip3 install -r requirements.txt

COPY . .

CMD python3 main.py
CMD ["python3", "main.py"]
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ aiofiles = "*"
[dev-packages]

[requires]
python_version = "3.11"
python_version = "3.12"
529 changes: 301 additions & 228 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Codenames-bot

### Bot is down. More info: [#1][issue-1]
<!-- ### Bot is down. More info: [#1][issue-1] -->
[![Invite to server](https://img.shields.io/badge/INVITE%20TO%20SERVER-555555?style=for-the-badge&logo=discord&logoWidth=32&logoColor=ffffff&labelColor=5865f2)](https://discord.com/api/oauth2/authorize?client_id=841776986246348851&permissions=274878015552&scope=bot%20applications.commands)


Expand Down
24 changes: 17 additions & 7 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,32 @@ async def setup_hook(self) -> None:
await self.tree.set_translator(CodenamesTranslator())

for filename in filter(lambda fn: "cog" in fn, os.listdir("handlers")):
await self.load_extension(f"handlers.{filename[:-3]}") # removing ".py" at the end of the filename
await self.load_extension(
f"handlers.{filename[:-3]}"
) # removing ".py" at the end of the filename


async def get_prefix(bot: CodenamesBot, message: Message) -> Iterable[str]:
if message.guild:
request = await bot.db.fetch("SELECT prefix FROM guilds WHERE id = ?", (message.guild.id,))
request = await bot.db.fetch(
"SELECT prefix FROM guilds WHERE id = ?", (message.guild.id,)
)

if not request: # should not normally happen
await bot.db.exec_and_commit("INSERT INTO guilds VALUES (?, ?, ?)", (message.guild.id, "", "en"))
await bot.db.exec_and_commit(
"INSERT INTO guilds VALUES (?, ?, ?)", (message.guild.id, "", "en")
)
else:
request = await bot.db.fetch("SELECT prefix FROM players WHERE id = ?", (message.author.id,))
request = await bot.db.fetch(
"SELECT prefix FROM players WHERE id = ?", (message.author.id,)
)

if not request: # if the user sends a text command to the bot as the first use in DMs
if (
not request
): # if the user sends a text command to the bot as the first use in DMs
await bot.db.exec_and_commit(
"INSERT INTO players VALUES (?, strftime('%d/%m/%Y','now'), ?, ?, ?, ?, ?, ?)",
(message.author.id, "", "en", 0, 0, 0, 0)
(message.author.id, "", "en", 0, 0, 0, 0),
)

prefix = request[0] if request else ""
Expand All @@ -59,7 +69,7 @@ def main() -> None:
help_command=None,
strip_after_prefix=True,
intents=CodenamesBot.custom_intents(),
owner_ids=ADMINS
owner_ids=ADMINS,
)

token = os.environ.get("TOKEN")
Expand Down
6 changes: 5 additions & 1 deletion handlers/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ def is_moderator():
async def predicate(ctx: Context | Interaction) -> bool:
user = ctx.author if isinstance(ctx, Context) else ctx.user

if not ctx.guild or ctx.channel.permissions_for(user).manage_messages or user in ADMINS:
if (
not ctx.guild
or ctx.channel.permissions_for(user).manage_messages
or user in ADMINS
):
return True

if isinstance(ctx, Interaction):
Expand Down
23 changes: 18 additions & 5 deletions handlers/event_cog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from discord import Message, Guild, Activity, ActivityType
from discord.ext.commands import (
Context, Command, Cog,
CommandNotFound, BadArgument, MemberNotFound, NoPrivateMessage, MissingPermissions, NotOwner
Context,
Command,
Cog,
CommandNotFound,
BadArgument,
MemberNotFound,
NoPrivateMessage,
MissingPermissions,
NotOwner,
)

from bot import CodenamesBot
Expand All @@ -14,7 +21,9 @@ def __init__(self, bot: CodenamesBot) -> None:

@Cog.listener()
async def on_ready(self) -> None:
await self.bot.change_presence(activity=Activity(type=ActivityType.watching, name="codenames.me"))
await self.bot.change_presence(
activity=Activity(type=ActivityType.watching, name="codenames.me")
)

@Cog.listener()
async def on_message(self, message: Message) -> None:
Expand Down Expand Up @@ -45,11 +54,15 @@ async def on_command_error(self, ctx: Context, error: Exception) -> None:

@Cog.listener()
async def on_guild_join(self, guild: Guild) -> None:
await self.bot.db.exec_and_commit("INSERT INTO guilds VALUES (?, ?, ?)", (guild.id, "", "en"))
await self.bot.db.exec_and_commit(
"INSERT INTO guilds VALUES (?, ?, ?)", (guild.id, "", "en")
)

@Cog.listener()
async def on_guild_remove(self, guild: Guild) -> None:
await self.bot.db.exec_and_commit("DELETE FROM guilds WHERE id = ?", (guild.id,))
await self.bot.db.exec_and_commit(
"DELETE FROM guilds WHERE id = ?", (guild.id,)
)


async def setup(bot: CodenamesBot) -> None:
Expand Down
Loading

0 comments on commit f829977

Please sign in to comment.