def init(): from commands import load_commands parser = CommandParser(fromfile_prefix_chars='@') for command in load_commands(): parser.add_command(command) parser.run()
def remote_loader(): # Instantiate invoker class remote_control = RemoteControlWithMethodRefs() # Instantiate receiver classes living_room_light = Light("Living Room") kitchen_light = Light("Kitchen") ceiling_fan = CeilingFan("Living Room") garage_door = GarageDoor() stereo = Stereo("Living Room") # Pass methods reference of receivers to invoker remote_control.set_command(0, living_room_light.on, living_room_light.off) remote_control.set_command(1, kitchen_light.on, kitchen_light.off) remote_control.set_command(2, ceiling_fan.high, ceiling_fan.off) commands = [(stereo.on, []), (stereo.set_cd, []), (stereo.set_volume, [11])] remote_control.set_command(3, load_commands(commands), stereo.off) remote_control.set_command(4, garage_door.open, garage_door.close) remote_control.show_commands() # Invoke commands using hte invoker's methods remote_control.on_button_was_pushed(0) remote_control.off_button_was_pushed(0) remote_control.on_button_was_pushed(1) remote_control.off_button_was_pushed(1) remote_control.on_button_was_pushed(2) remote_control.off_button_was_pushed(2) remote_control.on_button_was_pushed(3) remote_control.off_button_was_pushed(3)
def main(): parser = CommandParser(fromfile_prefix_chars='@') for command in load_commands(): parser.add_command(command) parser.run()
import discord import logging import argparse import commands import datetime from cmd_manager import dispatcher from config import config, help_text from cmd_manager.bot_args import parser, HelpException, UnkownCommandException from handle_messages import private_msg_code, delete_user_message, message_init asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) loop = uvloop.new_event_loop() asyncio.set_event_loop(loop) client = discord.Client() commands.load_commands() @client.event async def on_ready(): logging.info( f'Logged in as\nUsername: {client.user.name}\nID: {client.user.id}\nAPI Version: {discord.__version__}' ) gameplayed = discord.Game( name=config.MAIN.get("gameplayed", "Yuri is Love!")) await client.change_presence(game=gameplayed) @client.event async def on_message(message): for role in message.role_mentions:
def test_negative_loader_of_command(self): commands = load_commands("wrong_path") self.assertEqual(commands, None)
def test_positive_loader_of_command(self): commands = load_commands("commands.json") self.assertNotEqual(commands, None)