-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f609b01
commit 425b75f
Showing
6 changed files
with
342 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"python.pythonPath": "C:\\Users\\Utente\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\pbgbot-TiX7w1Mn-py3.8\\Scripts\\python.exe" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: python3 main.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
# PBGBot | ||
Python Biella Group Telegram Bot | ||
|
||
## Devlog | ||
|
||
Creato Poetry | ||
|
||
Prime prove con il bot così come dal corso di Angelo | ||
Al momento funziona solo in modalità polling (DEBUG), non è stato deployato su Heroku. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import os | ||
|
||
import telebot | ||
from flask import Flask, request | ||
from telebot.types import InlineKeyboardButton, InlineKeyboardMarkup, ReplyKeyboardMarkup, KeyboardButton | ||
|
||
bot = telebot.TeleBot("PUT YOUR TOKEN HERE") | ||
DEBUG = True | ||
app = Flask(__name__) | ||
|
||
|
||
@bot.callback_query_handler(func=lambda call: "id_YouTube" == call.data) | ||
def azione1(message): | ||
bot.send_message(message.message.chat.id, "https://www.youtube.com/c/PythonBiellaGroup") | ||
|
||
|
||
@bot.callback_query_handler(func=lambda call: "id_GitHub" == call.data) | ||
def azione2(message): | ||
bot.send_message(message.message.chat.id, "https://github.com/PythonGroupBiella/") | ||
|
||
|
||
@bot.message_handler(commands=['start', 'help']) | ||
def send_welcome(message): | ||
bot.reply_to(message, "Benvenuto e buon uso del bot PythonBiellaGroup!") | ||
|
||
|
||
@bot.message_handler(commands=['links']) | ||
def keyboard(message): | ||
markup = ReplyKeyboardMarkup(row_width=2) | ||
itembtn1 = KeyboardButton('YouTube') | ||
itembtn2 = KeyboardButton('GitHub') | ||
markup.add(itembtn1, itembtn2) | ||
bot.send_message(message.chat.id, "Quale link vuoi?", reply_markup=markup) | ||
|
||
|
||
@bot.message_handler(func=lambda m: "python" in m.text) | ||
def fun2(message): | ||
markup = InlineKeyboardMarkup() | ||
markup.row_width = 2 | ||
markup.add(InlineKeyboardButton("Link YouTube", callback_data="id_YouTube"), | ||
InlineKeyboardButton("Link GitHub", callback_data="id_GitHub")) | ||
|
||
bot.send_message(message.chat.id, "Hai scritto python?", reply_markup=markup) | ||
|
||
|
||
# Gestione temporanea del comando links | ||
@bot.message_handler(func=lambda m: True) | ||
def fun_generale(message): | ||
if "YouTube" in message.text: | ||
bot.reply_to(message, "https://www.youtube.com/c/PythonBiellaGroup") | ||
else: | ||
bot.reply_to(message, "https://github.com/PythonGroupBiella/") | ||
|
||
|
||
# Webhook con Flask | ||
@app.route("/webhook", methods=['POST']) | ||
def getMessage(): | ||
json_string = request.get_data().decode('utf-8') | ||
update = telebot.types.Update.de_json(json_string) | ||
bot.process_new_updates([update]) | ||
return "!", 200 | ||
|
||
@app.route("/", methods=['GET']) | ||
def get_home(): | ||
return "!", 200 | ||
|
||
def set_webhook(): | ||
bot.remove_webhook() | ||
bot.set_webhook("https://provapythonbiellagroup.herokuapp.com/webhook") | ||
|
||
|
||
if __name__ == '__main__': | ||
if DEBUG: | ||
bot.remove_webhook() | ||
bot.polling() | ||
else: | ||
set_webhook() | ||
app.run(host="0.0.0.0", port=int(os.environ.get('PORT', 5000))) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[tool.poetry] | ||
name = "pbgbot" | ||
version = "0.1.0" | ||
description = "Bot Telegram PBG" | ||
authors = ["PBG"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.8" | ||
pyTelegramBotAPI = "^3.7.8" | ||
Flask = "^2.0.0" | ||
|
||
[tool.poetry.dev-dependencies] | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" |