This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmanage.py
executable file
·74 lines (56 loc) · 1.78 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
from models.conversation import Conversation
from models.user import User
from models.command import Command
from models.message import Message
from models.hook import Hook
from hangoutsbot import HangoutsBot
from manager import Manager
from colors import red
import settings
import sys
import hangups
import asyncio
import code
manager = Manager()
@manager.command
def create_tables():
"""Create the tables for the models in the database"""
tables = [Conversation, User, Command, Message, Conversation.members.get_through_model(), Hook]
for table in tables:
if table.table_exists():
print("Table already exists for {}".format(table))
else:
table.create_table()
print("Created table for {}".format(table))
@manager.command
def run():
"""Run HangoutsBot"""
bot = HangoutsBot()
bot.run()
@manager.command
def shell():
"""Open python shell with context"""
code.interact(local=globals())
@manager.command
def get_bot_id():
"""Get ID of Bot Account to put in secret.py"""
client = hangups.client.Client(hangups.auth.get_auth_stdin(settings.COOKIES_FILE_PATH))
client.on_connect.add_observer(lambda: asyncio.async(get_id(client)))
loop = asyncio.get_event_loop()
loop.run_until_complete(client.connect())
@asyncio.coroutine
def get_id(client):
request = hangups.hangouts_pb2.GetSelfInfoRequest(
request_header=client.get_request_header(),
)
try:
response = yield from client.get_self_info(request)
print(response.self_entity.id.gaia_id)
finally:
yield from client.disconnect()
if __name__ == '__main__':
if sys.version_info < (3, 4):
print(red("python3.4 is required to use hangoutsbot"))
sys.exit(1)
manager.main()