Skip to content

Commit

Permalink
Adding in first implementation of translation commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Luckie committed Feb 20, 2024
1 parent f5d70f2 commit 5dfe9b5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
15 changes: 6 additions & 9 deletions disc_bot/bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
import logging

from discord.ext import commands
from cogs import cogs_list
from dotenv import load_dotenv
if not load_dotenv():
raise FileNotFoundError("No .env")
from ..cogs import cogs_list

logger = logging.getLogger("bot")

def run_bot():
def run(token, intents):
bot = commands.Bot(
command_prefix = '!',
guild_subscriptions = True,
intents = discord.Intents.all()
intents = intents
)

@bot.event
Expand All @@ -23,9 +20,9 @@ async def on_ready():

async def setup(bot):
for cog in cogs_list:
bot.add_cog(cog(bot))
await bot.add_cog(cog(bot))
logger.debug(
f"Successfully registered {', ',join(cogs_list)}"
f"Successfully registered {', '.join([str(x) for x in cogs_list])}"
)

bot.run(os.getenv["BOT_TOKEN"])
bot.run(token)
16 changes: 16 additions & 0 deletions disc_bot/cli/run_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import discord
import os
import logging
logging.basicConfig(level=logging.DEBUG)

from dotenv import load_dotenv
from ..bot.main import run
if not load_dotenv():
raise FileNotFoundError("No .env")

def main():
run(os.getenv("BOT_TOKEN"), discord.Intents.all())
return 0

if __name__ == "__main__":
exit(main())
7 changes: 6 additions & 1 deletion disc_bot/cogs/TranslatorCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class Translation_Commands(commands.Cog):

def __init__(self, bot, translator=None):
self.bot = bot
self.translator = translator if translator is not None else Translator()
self.translator = ( translator
if translator is not None
else Translator(auto_translate = True))

@commands.Cog.listener()
async def on_message(self, message):
Expand All @@ -25,3 +27,6 @@ async def on_message(self, message):

def repr(self):
return f"{self.__class__.__name__}"

def str(self):
return repr(self)
6 changes: 6 additions & 0 deletions disc_bot/cogs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os
from pathlib import Path
from .TranslatorCog import Translation_Commands
cogs_list = [
Translation_Commands
]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name='disc_bot',
version='2.0.0',
entry_points={
'console_scripts': ['hello-world=hello_world:main'],
'console_scripts': ['run-bot=disc_bot.cli.run_bot:main'],
'hello_world.output' : [
'default=hello_world:default_output'
],
Expand Down

0 comments on commit 5dfe9b5

Please sign in to comment.