Bot¶
Contains the discord clients used to run tests.
DiscordBot
contains the logic for running tests and finding the target bot
DiscordInteractiveInterface
is a subclass of DiscordBot
and contains the logic to handle
commands sent from discord to run tests, display stats, and more
DiscordCliInterface
is a subclass of DiscordInteractiveInterface
and simply contains logic to
start the bot when it wakes up
-
class
distest.bot.
DiscordBot
(target_id)[source]¶ Discord bot used to run tests. This class by itself does not provide any useful methods for human interaction, and is just used as a superclass of the two interfaces,
DiscordInteractiveInterface
andDiscordCliInterface
Parameters: target_id (str) – The name of the target bot, used to ensure that the target user is actually present in the server. Good for checking for typos or other simple mistakes. -
run_test
(test: distest.TestInterface.Test, channel: discord.channel.TextChannel, stop_error=False) → distest.TestInterface.TestResult[source]¶ Run a single test in a given channel.
Updates the test with the result and returns it
Parameters: - test (Test) – The
Test
that is to be run - channel (discord.TextChannel) – The
- stop_error – Weather or not to stop the program on error. Not currently in use.
Returns: Result of the test
Return type: - test (Test) – The
-
-
class
distest.bot.
DiscordInteractiveInterface
(target_id, collector: distest.collector.TestCollector, timeout=5)[source]¶ A variant of the discord bot which commands sent in discord to allow a human to run the tests manually.
Does NOT support CLI arguments
Parameters: - target_id (str) – The name of the bot to target (Username, no discriminator)
- collector (TestCollector) – The instance of Test Collector that contains the tests to run
- timeout (int) – The amount of time to wait for responses before failing tests.
-
on_message
(message: discord.message.Message)[source]¶ Handle an incoming message, see
discord.event.on_message()
for event reference.Parse a message, can ignore it or parse the message as a command and run some tests or do one of the alternate functions (stats, list, or help)
Parameters: message (discord.Message) – The message being recieved, passed by discord.py
-
on_ready
()[source]¶ Report when the bot is ready for use and report the available tests to the console
-
run_tests
(channel: discord.channel.TextChannel, name: str)[source]¶ Helper function for choosing and running an appropriate suite of tests Makes sure only tests that still need to be run are run, also prints to the console when a test is run
Parameters: - channel (discord.TextChannel) – The channel in which to run the tests
- name (str) – Selector string used to determine what category of test to run
-
class
distest.bot.
DiscordCliInterface
(target_id, collector, test, channel_id, stats, timeout)[source]¶ A variant of the discord bot which is designed to be run off command line arguments.
Parameters: - target_id (str) – The name of the bot to target (Username, no discriminator)
- collector (TestCollector) – The instance of Test Collector that contains the tests to run
- test (str) – The name of the test option (all, specific test, etc)
- channel_id (int) – The ID of the channel to run the bot in
- stats (bool) – If true, run in hstats mode.
-
on_ready
()[source]¶ Run all the tests sequentially when the bot becomes awake and exit when the tests finish. The CLI should run all by itself without prompting, and this allows it to behave that way.
-
run
(token) → int[source]¶ Override of the default run() that returns failure state after completion. Allows the failure to cascade back up until it is processed into an exit code by
run_command_line_bot()
Parameters: token (str) – The tester bot token Returns: Returns 1 if the any test failed, otherwise returns zero. Return type: int