示例#1
0
def main():
    """
    Sample application of supbot which takes in commands to run actions,
    and prints incoming events on screen
    made just to tests the library

    starts the bot then waits for input
    """
    args = docopt(__doc__)

    if args["--version"]:
        from supbot import __version__
        print("supbot v{}".format(__version__))
        return

    print("Loading...")

    kwargs = {}
    for k, v in args.items():
        kwargs[k.strip("-").replace("-", "_")] = v

    with Supbot(message_received=print_message,
                group_message_received=print_group_message,
                **kwargs) as supbot:
        start_loop(supbot, args["--no-prompt"])
示例#2
0
    def test_works_properly(self):

        with self.assertLogs(level='DEBUG') as cm:
            with Supbot(config["device_name"]) as supbot:
                supbot.send_message(config["contact_name"], "hi")
            self.assertIn(
                'DEBUG:supbot:sent message hi to {} successfully'.format(
                    config["contact_name"]), cm.output, "log not found")
示例#3
0
def start_loop(supbot: Supbot):
    """
    Waits for input, then processes the input when entered
    loops till supbot is running

    :param supbot: supbot service
    """
    while supbot.is_on():
        request = input(">")
        process(supbot, request)
示例#4
0
def process(supbot: Supbot, request_command: str):
    """
    reads request command string and performs appropriate function
    return response to print

    :param supbot: supbot service
    :param request_command: request string
    :return:
    """
    match = re.findall(r"([^\s\"']+|\"([^\"]*)\"|'([^']*)')", request_command)
    parts = [x[0] if x[1] == "" else x[1] for x in match]
    try:
        if parts[0] == "quit":
            supbot.quit()
        elif parts[0] == "send":
            supbot.send_message(parts[1], parts[2])
        else:
            return "Invalid command"
    except IndexError:
        return "Insufficient Arguments"
示例#5
0
def start_loop(supbot: Supbot, no_prompt: bool):
    """
    Waits for input, then processes the input when entered
    loops till supbot is running

    :param no_prompt:
    :param supbot: supbot service
    """
    while not supbot.has_started():
        time.sleep(0.5)

    print(help_me)

    def get_input():
        with patch_stdout():
            while supbot.is_on():
                yield prompt("> ")

    while supbot.is_on():
        request = input("> ") if no_prompt else next(get_input())
        process(supbot, request)
示例#6
0
def main():
    """
    Sample application of supbot which takes in commands to run actions,
    and prints incoming events on screen
    made just to tests the library

    starts the bot then waits for input
    """
    args = docopt(__doc__)

    if args["--version"]:
        from supbot import __version__
        print("supbot v{}".format(__version__))
        return

    device_name = args["--device"]

    print(help_me)

    with Supbot(device_name=device_name,
                message_received=print_message) as supbot:
        start_loop(supbot)
示例#7
0
def main():
    """
    Sample application of supbot which takes in commands to run actions,
    and prints incoming events on screen
    made just to tests the library

    starts the bot then waits for input
    """
    args = docopt(__doc__)

    if args["--version"]:
        from supbot import __version__
        print("supbot v{}".format(__version__))
        return

    print("Loading...")

    with Supbot(message_received=print_message,
                no_server=args["--no-server"],
                port=args["--port"],
                device_name=args["--device"]) as supbot:
        start_loop(supbot, args["--no-prompt"])
示例#8
0
from supbot import Supbot
from supbot.action import Action

contact = "123456789"


def action_callback(action: Action):
    print(action)


with Supbot() as supbot:
    supbot.send_message(contact,
                        "hi",
                        action_complete_callback=action_callback)
    supbot.quit()
示例#9
0
from supbot import Supbot
from estrutura import aimlbot
import time

bot = aimlbot()


def message_received(contact_name: str, message: str):
    resposta = bot.login(message, contact_name)
    if type(resposta) == list:
        resposta = resposta[::-1]
        for x in resposta:
            supbot.send_message(contact_name, x)
            # time.sleep(300)
    elif resposta:
        supbot.send_message(contact_name, resposta)
    else:
        print("ERRO : ", resposta)


with Supbot(message_received=message_received) as supbot:
    supbot.wait_for_finish()
示例#10
0
"""
Simple example which resends messages sent to the bot
"""

from supbot import Supbot


def repeat_message(contact_name, message):
    """
    Supbot callbacks returns a reference for supbot's interface too
    :param contact_name:
    :param message:
    :return:
    """
    supbot.send_message(contact_name, message)


"""
Supbot requires to initialize before you can use its services, so it should never be used out of its scope,
you can use with-as statement in order to automatically initialize supbot.
After it is created, you can use its services within its block.
"""
with Supbot(message_received=repeat_message) as supbot:
    supbot.wait_for_finish()
示例#11
0
    elif parts[0] == "!help":
        supbot.send_message(
            group_name, """Hello! my name is DafqBot, powered by Supbot2 API
        user commands:
        !dc <message>: will send the message to discord
        @all: will tag everyone in the group
        !help: show this message again
        
        admin commands:
        !add <number> <discord-id>: will add user to the database
        !quit: quit the bot safely
        
        Apart form these commands, I also let my master know if someone hasn't interacted since a long time"""
        )


def forward_message(message):
    supbot.send_message(group_name, message)


def main():
    with supbot:
        supbot.wait_for_finish()


if __name__ == '__main__':
    supbot = Supbot(group_message_received=group_message, no_server=True)
    Thread(target=main).start()
    client = discord_client.MyClient(forward_message)
    client.run(discord_client.token)
示例#12
0
def prepare_consolidated_message(title, linkedin_url, twitter_url,
                                 facebook_url, instagram_url):
    message = title + "\n"
    if linkedin_url:
        message += "\n" + linkedin_template.format(linkedin_url)
    if twitter_url:
        message += "\n" + twitter_template.format(twitter_url)
    if facebook_url:
        message += "\n" + facebook_template.format(facebook_url)
    if instagram_url:
        message += "\n" + instagram_template.format(instagram_url)
    return message


def clear_title():
    global title
    title = ""


def clear_links():
    global linkedin_url, twitter_url, facebook_url, instagram_url
    linkedin_url = ""
    twitter_url = ""
    facebook_url = ""
    instagram_url = ""


if __name__ == "__main__":
    with Supbot(group_message_received=message_received) as supbot:
        supbot.wait_for_finish()