From 73ffaf6730e0f850affa19556ad8a8e825042a2a Mon Sep 17 00:00:00 2001 From: Vikxaker Date: Thu, 11 May 2017 14:03:01 +0300 Subject: [PATCH 01/95] news bots --- .idea/misc.xml | 4 + .idea/modules.xml | 8 ++ .idea/telegram-bot-example.iml | 11 +++ .idea/vcs.xml | 6 ++ .idea/workspace.xml | 163 +++++++++++++++++++++++++++++++++ app/settings.py | 4 +- 6 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/telegram-bot-example.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..c3c95b5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e79cb04 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/telegram-bot-example.iml b/.idea/telegram-bot-example.iml new file mode 100644 index 0000000..6711606 --- /dev/null +++ b/.idea/telegram-bot-example.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..0529d91 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1494499207878 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/settings.py b/app/settings.py index 7adc600..6b64dfe 100644 --- a/app/settings.py +++ b/app/settings.py @@ -1,5 +1,5 @@ import telegram -BOT_TOKEN = '268737221:AAGdNFIz7Bi6lbXx2IZUMIosQnU9_fo77Ug' -WEBHOOK_URL = 'https://mytelegrambot.dokkurapp.com/HOOK' +BOT_TOKEN = '374526741:AAGzUUxN2t9SkMXLHeA2YXuRsQf78cYGyhk' +WEBHOOK_URL = 'https://mybots1.dokkurapp.com/HOOK' bot = telegram.Bot(token=BOT_TOKEN) From 2b9b2b6fa2cc5757bf200305a2c77efae2f5f2a2 Mon Sep 17 00:00:00 2001 From: Vikxaker Date: Thu, 11 May 2017 18:12:58 +0300 Subject: [PATCH 02/95] 1 --- .idea/inspectionProfiles/Project_Default.xml | 22 ++ .idea/workspace.xml | 336 ++++++++++++++++++- app/classes/chat.py | 6 +- 3 files changed, 345 insertions(+), 19 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..b31d808 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,22 @@ + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0529d91..6c55581 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,8 @@ - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -33,6 +132,7 @@ @@ -58,6 +158,7 @@ + @@ -84,10 +185,45 @@ + + + + + + + + + + + + + + + + + + + + - @@ -125,21 +261,21 @@ - + - - + + - + - - + + - - + + @@ -153,8 +289,176 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/classes/chat.py b/app/classes/chat.py index ae811c2..e156da5 100644 --- a/app/classes/chat.py +++ b/app/classes/chat.py @@ -8,6 +8,6 @@ def __init__(self, chat_id, text=''): self.chat_id = chat_id self.text = text - # main process method - def process(self): - bot.sendMessage(chat_id=self.chat_id, text=u"> {}".format(self.text)) +@bot.message_handler(content_types=["text"]) +def repeat_all_messages(message): # Название функции не играет никакой роли, в принципе + bot.send_message(message.chat.id, message.text) \ No newline at end of file From 4fdad1fdd53bea0877d7eef8588103367e692613 Mon Sep 17 00:00:00 2001 From: Vikxaker Date: Thu, 11 May 2017 18:19:25 +0300 Subject: [PATCH 03/95] 1 --- .idea/workspace.xml | 145 ++++++++++++++++++++++++++++++++------------ app/settings.py | 12 +++- 2 files changed, 115 insertions(+), 42 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6c55581..1cc4ba9 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,7 @@ - - + + + + + + + + + + + @@ -375,7 +440,7 @@ - + @@ -383,58 +448,56 @@ - + - + + + - + - + - + - - + + - + - - - - - + + + - + - - - - - + + + - + - - + + - + @@ -447,18 +510,20 @@ - + - + + + - + - - + + diff --git a/app/settings.py b/app/settings.py index 6b64dfe..f324e62 100644 --- a/app/settings.py +++ b/app/settings.py @@ -1,5 +1,13 @@ -import telegram +import telebot BOT_TOKEN = '374526741:AAGzUUxN2t9SkMXLHeA2YXuRsQf78cYGyhk' WEBHOOK_URL = 'https://mybots1.dokkurapp.com/HOOK' -bot = telegram.Bot(token=BOT_TOKEN) +bot = telebot.TeleBot(BOT_TOKEN) + + +@bot.message_handler(content_types=["text"]) +def repeat_all_messages(message): # Название функции не играет никакой роли, в принципе + bot.send_message(message.chat.id, message.text) + +if __name__ == '__main__': + bot.polling(none_stop=True) \ No newline at end of file From a3fc41179432f1673173fcea858d6979b9369ff7 Mon Sep 17 00:00:00 2001 From: Vikxaker Date: Thu, 11 May 2017 18:20:37 +0300 Subject: [PATCH 04/95] 1 --- .idea/workspace.xml | 27 ++++++++++++++------------- requirements.txt | 1 + 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1cc4ba9..d3a681c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,7 @@ - + @@ -484,14 +485,6 @@ - - - - - - - - @@ -528,5 +521,13 @@ + + + + + + + + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index fc50821..94624e2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ python-telegram-bot==4.3.2 six==1.10.0 urllib3==1.16 wheel==0.24.0 +telebot==0.0.3 From 5a79f56525cf3fa570266dee01f348e704534713 Mon Sep 17 00:00:00 2001 From: Vikxaker Date: Thu, 11 May 2017 18:23:25 +0300 Subject: [PATCH 05/95] 1 --- .idea/workspace.xml | 196 +++++------------------------------ app/__init__.py | 0 app/classes/__init__.py | 1 - app/classes/chat.py | 13 --- app/main.py | 18 ++-- app/resources/__init__.py | 3 - app/resources/hook.py | 22 ---- app/resources/main.py | 7 -- app/resources/set_webhook.py | 16 --- app/settings.py | 13 --- 10 files changed, 38 insertions(+), 251 deletions(-) delete mode 100644 app/__init__.py delete mode 100644 app/classes/__init__.py delete mode 100644 app/classes/chat.py delete mode 100644 app/resources/__init__.py delete mode 100644 app/resources/hook.py delete mode 100644 app/resources/main.py delete mode 100644 app/resources/set_webhook.py delete mode 100644 app/settings.py diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d3a681c..d2b9047 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,14 @@ - + + + + + + + + - + + + + + + + + + + + + - + - + @@ -379,8 +400,8 @@ - - + + diff --git a/app/main.py b/app/main.py index f324e62..75cc8b2 100644 --- a/app/main.py +++ b/app/main.py @@ -6,7 +6,7 @@ @bot.message_handler(content_types=["text"]) -def repeat_all_messages(message): # Название функции не играет никакой роли, в принципе +def repeat_all_messages(message): bot.send_message(message.chat.id, message.text) if __name__ == '__main__': From 5b7ab46a0ef427dfaedd69b93c3b59ae17db52b7 Mon Sep 17 00:00:00 2001 From: Vikxaker Date: Thu, 11 May 2017 18:50:16 +0300 Subject: [PATCH 07/95] 1 --- .idea/workspace.xml | 59 ++++++++++++++++++++++++++++++++++++++------- app/config.py | 2 ++ app/main.py | 54 +++++++++++++++++++++++++++++++++++------ requirements.txt | 1 + 4 files changed, 99 insertions(+), 17 deletions(-) create mode 100644 app/config.py diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ce52add..279fc73 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,6 +3,7 @@ + + + + + + @@ -390,19 +421,29 @@ + + + + + + + + - - + + - - - + + + + + diff --git a/app/config.py b/app/config.py new file mode 100644 index 0000000..192cf6d --- /dev/null +++ b/app/config.py @@ -0,0 +1,2 @@ +BOT_TOKEN = '374526741:AAGzUUxN2t9SkMXLHeA2YXuRsQf78cYGyhk' +WEBHOOK_URL = 'https://mybots1.dokkurapp.com/' \ No newline at end of file diff --git a/app/main.py b/app/main.py index 75cc8b2..3b6e785 100644 --- a/app/main.py +++ b/app/main.py @@ -1,13 +1,51 @@ import telebot +import cherrypy +import config -BOT_TOKEN = '374526741:AAGzUUxN2t9SkMXLHeA2YXuRsQf78cYGyhk' -WEBHOOK_URL = 'https://mybots1.dokkurapp.com/HOOK' -bot = telebot.TeleBot(BOT_TOKEN) +WEBHOOK_HOST = '%s' %(config.WEBHOOK_URL) +WEBHOOK_PORT = 443 +WEBHOOK_LISTEN = '0.0.0.0' -@bot.message_handler(content_types=["text"]) -def repeat_all_messages(message): - bot.send_message(message.chat.id, message.text) -if __name__ == '__main__': - bot.polling(none_stop=True) \ No newline at end of file +WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT) +WEBHOOK_URL_PATH = "/%s/" % (config.BOT_TOKEN) + +bot = telebot.TeleBot(config.BOT_TOKEN) + + + +class WebhookServer(object): + @cherrypy.expose + def index(self): + if 'content-length' in cherrypy.request.headers and \ + 'content-type' in cherrypy.request.headers and \ + cherrypy.request.headers['content-type'] == 'application/json': + length = int(cherrypy.request.headers['content-length']) + json_string = cherrypy.request.body.read(length).decode("utf-8") + update = telebot.types.Update.de_json(json_string) + + bot.process_new_updates([update]) + return '' + else: + raise cherrypy.HTTPError(403) + + +@bot.message_handler(func=lambda message: True, content_types=['text']) +def echo_message(message): + bot.reply_to(message, message.text) + + +bot.remove_webhook() + + +bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH, + ) + +cherrypy.config.update({ + 'server.socket_host': WEBHOOK_LISTEN, + 'server.socket_port': WEBHOOK_PORT, +}) + + +cherrypy.quickstart(WebhookServer(), WEBHOOK_URL_PATH, {'/': {}}) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 94624e2..d2be3f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,4 @@ six==1.10.0 urllib3==1.16 wheel==0.24.0 telebot==0.0.3 +cherrypy From 8ed126d2034203e18e631816c82692d72432cdb3 Mon Sep 17 00:00:00 2001 From: Vikxaker Date: Thu, 11 May 2017 19:01:18 +0300 Subject: [PATCH 08/95] 1 --- .idea/workspace.xml | 30 ++++++++++++++++++++---------- app/main.py | 9 ++++++++- app/webhook_cert.pem | 23 +++++++++++++++++++++++ app/webhook_pkey.pem | 27 +++++++++++++++++++++++++++ webhook_cert.pem | 23 +++++++++++++++++++++++ webhook_pkey.pem | 27 +++++++++++++++++++++++++++ 6 files changed, 128 insertions(+), 11 deletions(-) create mode 100644 app/webhook_cert.pem create mode 100644 app/webhook_pkey.pem create mode 100644 webhook_cert.pem create mode 100644 webhook_pkey.pem diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 279fc73..e02deac 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,10 @@ + + + - \ No newline at end of file diff --git a/app/main.py b/app/main.py index a1ce9a6..e3e2b09 100644 --- a/app/main.py +++ b/app/main.py @@ -3,8 +3,8 @@ import config WEBHOOK_HOST = '%s' %(config.WEBHOOK_URL) -WEBHOOK_PORT = 443 -WEBHOOK_LISTEN = '0.0.0.0' +WEBHOOK_PORT = 5000 +WEBHOOK_LISTEN = '%s' %(config.WEBHOOK_URL) WEBHOOK_SSL_CERT = './webhook_cert.pem' From 2b381788a9f564589d98c22d3c72b03a1ebec18f Mon Sep 17 00:00:00 2001 From: Vikxaker Date: Thu, 11 May 2017 19:25:03 +0300 Subject: [PATCH 11/95] 1 --- .idea/workspace.xml | 28 ++++++++++++++------------- 2017-05-11-190925_1024x600_scrot.png | Bin 0 -> 134468 bytes app/config.py | 2 +- app/main.py | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) create mode 100644 2017-05-11-190925_1024x600_scrot.png diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1681b68..a07e422 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,6 +2,8 @@ + +