Skip to content

Commit

Permalink
Adding in ability for bot to check another bot for functionality in a…
Browse files Browse the repository at this point in the history
…sync
  • Loading branch information
Joshua Luckie committed Feb 21, 2024
1 parent 089e46d commit 8c34e50
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 5 deletions.
Empty file added disc_bot/cli/__init__.py
Empty file.
13 changes: 8 additions & 5 deletions disc_bot/cli/run_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
if not load_dotenv():
raise FileNotFoundError("No .env")

def get_process(token, intents):
return multiprocessing.Process(name='bot_background_process',
target=run,
args=(token, intents))

def main():
background_process = multiprocessing.Process(
name='bot_background_process',
target=run,
args=(os.getenv("BOT_TOKEN"), discord.Intents.all()))
background_process = get_process(
os.getenv("BOT_TOKEN"), discord.Intents.all()
)
background_process.start()
#run(os.getenv("BOT_TOKEN"), discord.Intents.all())
print("hey whats up")
return 0

if __name__ == "__main__":
Expand Down
9 changes: 9 additions & 0 deletions disc_bot/exceptions/handling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from contextlib import contextmanager

@contextmanager
def print_traceback(msg):
try:
yield
except Exception:
print(msg)
traceback.print_exc()
23 changes: 23 additions & 0 deletions disc_bot/tests/bot_tests/test_bot_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
from ...cli.run_bot import main
from ...bot.main import run
import pytest
import discord
import asyncio
from discord.ext import commands

BOT_TOKEN = os.getenv("BOT_TOKEN")
TEST_TOKEN = os.getenv("TEST_TOKEN")
GUILD = os.getenv("GUILD_ID")
CHANNEL = os.getenv("CHANNEL_ID")

main()
test_bot = commands.Bot(
command_prefix = '!',
guild_subscriptions = True,
intents = discord.Intents.all()
)
test_bot.run(TEST_TOKEN)



49 changes: 49 additions & 0 deletions disc_bot/tests/bot_tests/test_bot_translates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
from ...cli.run_bot import get_process
from ...exceptions.handling import print_traceback
from dotenv import load_dotenv
import discord
from contextlib import suppress
from discord.ext import commands

if not load_dotenv():
raise FileNotFoundError("No .env")

BOT_TOKEN = os.getenv("BOT_TOKEN")
TEST_TOKEN = os.getenv("TEST_TOKEN")
DISC_CHANNEL = int(os.getenv("CHANNEL_ID"))

def get_channel(bot_obj):
return bot_obj.get_channel(DISC_CHANNEL)

process = get_process(BOT_TOKEN, discord.Intents.all())
process.start()
bot = commands.Bot(
command_prefix = '!',
guild_subscriptions = True,
intents = discord.Intents.all()
)

@bot.event
async def on_ready():
channel = get_channel(bot)
print(dir(process))
with print_traceback("Bot did not translate"):
assert await assert_bot_translates(bot, get_channel(bot)), "Bot did not translate"
print("Bot translated correctly!")
# fuck dat shit up
process.kill()
await bot.close()


def check(m):
return m.content == 'My love'

async def assert_bot_translates(bot, channel):
_msg = await channel.send("Mi amor")
with suppress(TimeoutError):
thing = await bot.wait_for('message', check=check, timeout=3)
return True
return False

bot.run(TEST_TOKEN)

0 comments on commit 8c34e50

Please sign in to comment.