Skip to main content

A small bot based on twisted

Project description

This a bot based on twisted, mostly a python learning project

Consumers

  • flowdock: read message from flow dock stream API

Responders

  • face

  • whois

  • math

  • wat

  • xkcd

  • ascii

  • 9gag

Installation

Install dependencies:

pip install twisted
pip install twistedhttpstream
pip install requests
pip install sympy
pip install mocker
pip install pyopenssl
pip install python-flowdock
pip install markdown
pip install paramiko
pip install pyyaml
pip install ioc

Running Tests

python tests.py # run all tests
python -m unittest responders.xkcd # run one test

Usage

  • start.py

# vim: set fileencoding=utf-8 :

import twistedhttpstream, yaml, sys, logging
from twisted.internet import reactor
import ioc

logging.basicConfig(level=logging.DEBUG)

container = ioc.build([
    'config.yml',
])

if __name__ == "__main__":

    for flow in container.parameters['consumers']:
        twistedhttpstream.stream(
            reactor,
            "https://stream.flowdock.com/flows/%s/%s" % (container.parameters["flowdock.%s.organisation" % flow], flow),
            container.get("consumer.%s.flowdock" % flow),
            username=container.parameters["flowdock.%s.user.token" % flow],
            password=""
        )


    reactor.run()
  • Configuration file

parameters:
    consumers: [test]
    bot.name: nono
    bot.email: no-reply@shirka.com

    remote.users: [XXX]
    remote.servers:
        # paramiko option - http://www.lag.net/paramiko/docs/paramiko.SSHClient-class.html
        nono: {host: XXXX, username: XXXX, look_for_keys: false, password: XXXX }

    # configure flow parameterstest
    flowdock.test.organisation: shirka
    flowdock.test.flow.name:    FLOW_NAME
    flowdock.test.flow.token:   FLOW_TOKEN
    flowdock.test.user.name:    rande
    flowdock.test.user.token:   USER_TOKEN


services:

    # Configure the bot
    bot:
        class: shirka.consumers.Bot
        arguments: [ '%bot.name%', '%bot.email%']

    # Configure shared responders
    responders.math:        { class: shirka.responders.MathResponder }
    responders.xkcd:        { class: shirka.responders.XkcdResponder }
    responders.big_bro:     { class: shirka.responders.BigbroResponder }
    responders.reminder:    { class: shirka.responders.ReminderResponder }
    responders.status:      { class: shirka.responders.StatusResponder }
    responders.rage_face:   { class: shirka.responders.RagefaceResponder }
    responders.wat:         { class: shirka.responders.WatResponder }
    responders.9gag:        { class: shirka.responders.NineGagResponder }

    responders.remote:
        class: shirka.responders.RemoteResponder
        arguments:
            - '%remote.servers%'
            - '%remote.users%'


    # Configure flowdock push API
    flowdock.test:
        class: flowdock.FlowDock
        kwargs:
            api_key:  '%flowdock.test.flow.token%'
            app_name: '%bot.name%'
            project:  Project test

    consumer.test.flowdock.logger:
        class: logging.getLogger
        arguments:
            - 'flowdock.%flowdock.test.flow.name%'

    # Configure Stream API Consumer with valid responders
    consumer.test.flowdock:
        class: shirka.consumers.FlowDockConsumer
        arguments:
            - '@bot'
            - "%flowdock.test.flow.token%"
            -
                - '@responders.rage_face'
                - '@responders.test.whois'
                - '@responders.math'
                - '@responders.big_bro'
                - '@responders.reminder'
                - '@responders.remote'
                - '@responders.status'
                - '@responders.test.help'
                - '@responders.test.whois'

            - '@flowdock.test'
        kwargs:
            logger: '@consumer.test.flowdock.logger'

    responders.test.whois:
        class: shirka.responders.FlowdockWhoisResponder
        arguments:
            - '%flowdock.test.organisation%'
            - '%flowdock.test.flow.name%'
            - '%flowdock.test.user.token%'

    responders.test.help:
        class: shirka.responders.HelpResponder

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shirka-0.0.3.tar.gz (571.9 kB view details)

Uploaded Source

Built Distribution

shirka-0.0.3.macosx-10.8-x86_64.exe (81.3 kB view details)

Uploaded Source

File details

Details for the file shirka-0.0.3.tar.gz.

File metadata

  • Download URL: shirka-0.0.3.tar.gz
  • Upload date:
  • Size: 571.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for shirka-0.0.3.tar.gz
Algorithm Hash digest
SHA256 731011ea7550a99abbb1857f05524973b8865b1c25f3e93e6db15349e44e3dc1
MD5 8cac069cf9754e7c97763272dda430c3
BLAKE2b-256 984d9881eb0e9b8ad14436f895afab90368f4334b9beb502896ecf20ba77b919

See more details on using hashes here.

File details

Details for the file shirka-0.0.3.macosx-10.8-x86_64.exe.

File metadata

File hashes

Hashes for shirka-0.0.3.macosx-10.8-x86_64.exe
Algorithm Hash digest
SHA256 637a4a54de2c94aff30fc16cc20a4ba37db1f27ee38976c9d729636a89d14f08
MD5 6689d61b3a7cf794557445a679f1caa2
BLAKE2b-256 8f29ebdff83876efb6b9e86ab623802e2fd75c5c0520f607fac9fab1985f9c2f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page