-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding in ability for bot to check another bot for functionality in a…
…sync
- Loading branch information
Joshua Luckie
committed
Feb 21, 2024
1 parent
089e46d
commit 8c34e50
Showing
5 changed files
with
89 additions
and
5 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |