예제 #1
0
    def test_room_iterators():
        client = chatexchange.Client('stackexchange.com', live_testing.email,
                                     live_testing.password)

        me = client.get_me()
        sandbox = client.get_room(14219)

        my_message = None

        with sandbox.new_messages() as messages:
            sandbox.send_message("hello worl")

            for message in messages:
                if message.owner is me:
                    my_message = message
                    assert my_message.content == "hello worl"
                    break
                else:
                    logger.info("ignoring message: %r", message)

        with sandbox.new_events(MessageEdited) as edits:
            my_message.edit("hello world")

            for edit in edits:
                assert isinstance(edit, MessageEdited)

                if edit.message is my_message:
                    assert my_message.content == "hello world"
                    break
예제 #2
0
    def test_user_info():
        client = chatexchange.Client('stackexchange.com')

        user = client.get_user(-2)
        assert user.id == -2
        assert not user.is_moderator
        assert user.name == "Feeds"
        assert user.room_count >= 18
        assert user.message_count >= 129810
        assert user.reputation == -1

        user = client.get_user(31768)
        assert user.id == 31768
        assert user.is_moderator
        assert user.name == "ManishEarth"
        assert user.room_count >= 222
        assert user.message_count >= 89093
        assert user.reputation > 115000

        user = client.get_user(-5)
        assert user.id == -5
        assert not user.is_moderator
        assert user.last_seen == -1
        assert user.last_message == -1
        assert user.reputation == -1
예제 #3
0
파일: bot.py 프로젝트: erikroyall/Loquitor
def main(username,
         password,
         room,
         config_dir,
         host='stackoverflow.com',
         no_input=False):
    from . import scripts

    client = chatexchange.Client(host, username, password)
    room = skeleton.Room(room, client)
    bot = Bot(room, client, config_dir, no_input)

    for module_name in scripts.__all__:
        module = sys.modules['Loquitor.scripts.{}'.format(module_name)]
        if hasattr(module, 'main') and callable(module.main):
            module.main(room, bot, client)
        elif hasattr(module, 'commands') and hasattr(module.commands, 'items'):
            for com_name, func in module.commands.items():
                bot.register(com_name, func)

            if hasattr(module, 'help') and hasattr(module.help, 'items'):
                for command, help in module.help.items():
                    bot.commands[command].help = help
        else:
            print("Invalid script file: {!r}".format(module_name))

    return client, room, bot
예제 #4
0
def main(port='8462'):
    port = int(port)

    logging.basicConfig(level=logging.INFO)

    room_id = 14219  # Charcoal Chatbot Sandbox

    if 'ChatExchangeU' in os.environ:
        email = os.environ['ChatExchangeU']
    else:
        sys.stderr.write("Username: "******"Password: ")

    client = chatexchange.Client('stackexchange.com')
    client.login(email, password)

    httpd = Server(('127.0.0.1', 8462),
                   Handler,
                   client=client,
                   room_id=room_id)
    webbrowser.open('http://localhost:%s/' % (port, ))
    httpd.serve_forever()
예제 #5
0
    def test_room_info():
        client = chatexchange.Client('stackexchange.com')

        a_feeds_user = client.get_user(-2)
        bot_user = client.get_user(97938)
        sandbox = client.get_room(14219)

        assert bot_user in sandbox.owners
        assert a_feeds_user not in sandbox.owners
        assert sandbox.user_count >= 4
        assert sandbox.message_count >= 10
        assert 'test' in sandbox.tags

        # we aren't checking these result, just that it doesn't blow up
        sandbox.description
        sandbox.text_description
        sandbox.parent_site_name + sandbox.name
예제 #6
0
import os

import chatexchange
from chatexchange.events import MessageEdited

logging.basicConfig(level=logging.DEBUG)

if 'ChatExchangeU' in os.environ:
    email = os.environ['ChatExchangeU']
else:
    email = eval(input("Email: "))
if 'ChatExchangeP' in os.environ:
    password = os.environ['ChatExchangeP']
else:
    password = getpass.getpass("Password: "******"hello worl")

    for message in messages:
        if message.owner is me:
            my_message = message
            assert my_message.content == "hello worl"
            print("message sent successfully")
            break
예제 #7
0
파일: main.py 프로젝트: sri-shree/Thunder
    Utilities.Redunda.sendStatusPing()
    Utilities.location = Utilities.Redunda.location

if 'ThunderEmail' in os.environ:
    email = os.environ['ThunderEmail']
else:
    email = input("Email: ")

if 'ThunderPass' in os.environ:
    password = os.environ['ThunderPass']
else:
    password = getpass.getpass("Password: "******"Logging in...")

client = chatexchange.Client(Utilities.host, email, password)
Utilities.client = client
Utilities.myself = client.get_me()
Utilities.myUserID = Utilities.myself.id

if Utilities.Redunda:
    Utilities.Redunda.downloadFiles()

while BackgroundTasks.shouldShutdown == False or BackgroundTasks.shouldReboot == False:
    if Utilities.Redunda:
        while Utilities.Redunda.shouldStandby:
            Utilities.Redunda.sendStatusPing()
            Utilities.Redunda.downloadFiles()
            time.sleep(45)

    if BackgroundTasks.shouldShutdown or BackgroundTasks.shouldReboot: