Skip to main content

Official Order Python API wrapper

Project description

Official Order Python API Wrapper

Hi!

This repository contains the source code of the Order API wrapper for the Python programming language meant for writing bots. It could be used for typical user accounts as well, and this is not prohibited by the Terms of Service in any way, but not all functions of the API are fully implemented to fulfill every action a human user might take in the app.

Installation

pip3 install order.py

How do I get a bot token?

Head into the app. Open user settings by clicking on you avatar in the bottom-right corner. Navigate to the "Developers" tab

Choose a cool name and hit the "create" button. Below that you will see the list of bot IDs you have created previously.

Once you did that, you should see a big popup. Copy the bot ID and token and save them in a separate file. You will only see this token once!

How do I use my bot?

Bots can only be used in groups. In order to add a bot, you should know its ID.
Head into the app. Choose or create a group you would like to add the bot into. Open its settings by clicking on its title in the top-left corner. Navigate to the "Invites" tab. Paste your bot ID into the "Bot ID" field. Click the "Invite bot" button. You're all set!

Simple bot example

Sends "Hi!" when it receives "hello"

import order
from order import entities
from order.entities import Message
import time

async def on_message(message, text):
    if text.lower() == 'hello':
        await client.put_entities([
            Message.create(sections=[
                Message.TextSection.create('Hi!')
            ], channel=message.channel)
        ])

async def on_entities(packet):
    for e in packet.entities:
        if isinstance(e, Message):
            # find the first text section
            for s in e.sections:
                if isinstance(s, Message.TextSection):
                    await on_message(e, s.text)
                    break

async def on_connected():
    await client.login_with_bot_token('BOT_TOKEN')

async def on_logged_in(user):
    print('Logged in as ' + user.name + '#' + str(user.tag))

client = order.Order(debug_protocol=False)
client.handler('connected', on_connected)
client.handler('logged_in', on_logged_in)
client.handler('entities',  on_entities)

client.run()

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

order.py-0.0.4.tar.gz (9.9 kB view details)

Uploaded Source

File details

Details for the file order.py-0.0.4.tar.gz.

File metadata

  • Download URL: order.py-0.0.4.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for order.py-0.0.4.tar.gz
Algorithm Hash digest
SHA256 73fcb74c4a0155395be3f2a26ecffa30f1acad8c1b6dfc1896436c203760c2b8
MD5 ddfbfb8785b097a6942be5affa192c42
BLAKE2b-256 efd800513238fb0fb303bfb63527fe5b5e013910ad1e43aaa3b8e95c6eedb47a

See more details on using hashes here.

Supported by

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