Browse Source

Complete bot.py. Add groups to config. Change /post to POST.

Update gitignore.
master
Ceda EI 8 months ago
parent
commit
d7c4f7e14c
4 changed files with 20 additions and 2 deletions
  1. 1
    0
      .gitignore
  2. 15
    1
      bot/bot.py
  3. 3
    0
      bot/sample.config.py
  4. 1
    1
      bot/server.py

+ 1
- 0
.gitignore View File

@@ -114,3 +114,4 @@ dmypy.json
114 114
 # Pyre type checker
115 115
 .pyre/
116 116
 
117
+config.py

+ 15
- 1
bot/bot.py View File

@@ -1,13 +1,27 @@
1 1
 #!/usr/bin/env python3
2 2
 
3 3
 import config
4
+import logging
5
+import requests
4 6
 from telegram.ext import Updater, MessageHandler, Filters
5 7
 
8
+logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - \
9
+                    %(message)s', level=logging.INFO)
10
+
6 11
 
7 12
 def message_handling(bot, update):
8
-    pass
13
+    print("in here")
14
+    if update.message.chat.id in config.groups:
15
+        print("in here")
16
+        for i in update.message.text.split("\n"):
17
+            params = {"message": (f"TG - {update.message.from_user.first_name}"
18
+                                  f": {i}")}
19
+            requests.post("http://localhost:" + str(config.port) + "/post",
20
+                          data=params)
21
+            print(params)
9 22
 
10 23
 
11 24
 updater = Updater(token=config.api_key)
12 25
 dispatcher = updater.dispatcher
13 26
 dispatcher.add_handler(MessageHandler(Filters.text, message_handling))
27
+updater.start_polling()

+ 3
- 0
bot/sample.config.py View File

@@ -4,3 +4,6 @@ api_key = "123456789:xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
4 4
 
5 5
 # Port to connect to server
6 6
 port = 9876
7
+
8
+# Groups to read from
9
+groups = []

+ 1
- 1
bot/server.py View File

@@ -21,4 +21,4 @@ with open('schema.sql') as fp:
21 21
     cursor.executescript(fp.read())
22 22
 
23 23
 app.add_url_rule('/get', 'get', lambda: get(db))
24
-app.add_url_rule('/post', 'post', lambda: post(db))
24
+app.add_url_rule('/post', 'post', lambda: post(db), methods=["POST"])

Loading…
Cancel
Save