Skip to content

Commit

Permalink
prima prova
Browse files Browse the repository at this point in the history
  • Loading branch information
Burlesco70 committed May 15, 2021
1 parent f609b01 commit 425b75f
Show file tree
Hide file tree
Showing 6 changed files with 342 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
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"
}
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: python3 main.py
7 changes: 7 additions & 0 deletions README.md
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.
78 changes: 78 additions & 0 deletions main.py
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)))
237 changes: 237 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pyproject.toml
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"

0 comments on commit 425b75f

Please sign in to comment.