Code Monkey home page Code Monkey logo

partitelle-bot's Introduction

** PartitelleBot**

PartitelleBot

PartitelleBot is an Italian Telegram Bot in Python to retrieve participants for the organization of a football game.

Table of contents

Architecture

This is a Python project relying on python-telegram-bot library. Data storage is handled through PostgreSQL. The application and the mentioned database are both hosted on Render.

Project structure

  • database.ini: a configuration file with database credentials
  • config.py: a little function to parse and read database credentials in database.ini
  • requirements.txt: a file to indicate Render which external libraries are necessary to the Python code.
  • main.py: the real heart of PartitelleBot code

Behaviour

Presentation message

By adding PartitelleBot to your Telegram group, you can easily manage those so-hard-to-organize weekly football matches with your friends. You have two ways of interacting with the bot:

  1. by writing a specific set of allowed messages through the conversation
  2. by using standard commands

By default, the bot sets all new matches the next Wednesday at 9 pm but this information is, of course, editable. Once a new match is created through /start command, people can begin to organize the match through the set of allowed messages. The first time the bot detects an adding interaction, it will print a match summary of the current situation whereas from the second time it will edit its previous message (by the way remind that a new explicit summary can be obtained through /participants command). In this way, people can easily and autonomously add, propose, and remove themselves or each other. Once the target number is reached, users enter the final phase; here, the bot states that is the time to play and asks permission to generate /teams. Through this command, the bot randomly generates two groups of players, respectively the black team and the white team. At this point, users can always adjust the teams by swapping players.

Note: if you give PartitelleBot the administrator rights, it will be able to pin its messages in the group.

Match summary

Match summary

In my organizational experience, one of the most annoying tasks is to keep on copying and pasting the same list over and over again each time a new update over participants turns out. This summary aims to change this pattern and let the bot do the dirty work. This message has a specific structure:

GIORNO: <day> | <time>

<participants list from 1 to N

  • added player ✅
  • added player ✅
  • proposed player ❓
  • ...

- free slot ❌ where N is the target number>

<description>

CAMPO: <pitch>

Final phase

Final phase

Swapping players

Swap

Allowed messages

This is the list of current available allowed messages to interact with the bot:

  • proponimi - you want to be added to the list but you are not 100% sure to be present
  • proponi <nome> - you propose someone else who may participate
  • aggiungimi - you want to be added or confirmed to the list of participants
  • aggiungi <nome> - you add someone to the list or someone who had been previously proposed
  • toglimi - you remove yourself from the list in any case
  • togli <nome> - you remove someone else from the list in any case
  • scambia <nome 1> con <nome 2> - you swap two players to balance the teams generated by the bot

Commands

This is the list of current available commands:

  • /start - Create new match
  • /setnumber - Set the number of participants
  • /setday - Set the day of the match
  • /settime - Set the time of the match
  • /setdescription - Set the custom message under the list of participants
  • /setpitch - Set the football pitch
  • /participants - Show the participants of the current match
  • /teams - Show the generated teams for the current match
  • /stop - Remove the match
  • /help - Show the list of available commands

How to contribute

"Can I contribute to this project?"

Hell, yes 😉!

Have a look here.

Sponsorships

The ambitiousness of this project depends on the resources it has available and every little help to contribute to its improvement is appreciated. Nothing mandatory, just do it if you feel like you would offer me a coffee! :) In that case, tap the Sponsor button at the top, or click here 💪.

partitelle-bot's People

Contributors

iamgiolaga avatar piro-97 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

piro-97

partitelle-bot's Issues

Hosting platform migration

Currently, both the application and the db are hosted on Heroku.
After the last announcement where Heroku declares to stop offering free tier plans from November 28th, it is needed to migrate PartitelleBot hosting and its database to a new platform.

These are the options currently considered:

  • Render - it looks suitable but future pricing is always possible
  • Deta - declared to be free forever, but it does not support PostgreSQL, so it has an impact on code

Bug: payment reminder is not working

Bug Report

What

When reaching the target number, a new handler is added to the queue to notify participants if everybody has paid. Currently this mechanism is not working.

How to replicate it

Let people start a new game, reach the target number: the reminder should arrive two hours after the date and the time of the match, but no alert is arriving

GitHub Actions Workflow can be improved

Currently, I am using this GitHub Action which just establishes a connection with Render and deploys a new instance.

There are two problems:

  1. the task is done asynchronously whereas it would be great to have a workflow running and waiting for the response until Render deploy has not finished
  2. the outcome looks always positive and never fails

Refactor needed

When starting this project, the idea was to keep the code simple in a unique main.py file.
Given the many possibilities of this project, a lot of business logic has been added and today the maintenance of the code is of course getting harder and harder.
This implies that a refactor is needed: the main file has to be reduced with the minimal logic concerning the startup of the bot, its handlers registrations plus the new events listening.
All of the remaining logic can be organized in separate folders respecting the Separation of Concerns.

An example of possible folders:

  • queries/: for all the queries that interact with the db
  • handlers/: with all the behaviours that must be triggered by users messages (MessageHandler)
  • commands/: for the behaviours that must be triggered by telegram commands (CommandHandler)
  • utils/: any support method used in the code

Tests needed

Currently, no tests have been written, but they should be added in order to make the software more robust at changes

Bug: starting matches after midnight causes wrong default wednesday computation

Bug Report

What

Wrong default date computation - normally it should compute the first available wednesday on the calendar

How to replicate it

By starting a new match right after midnight

Additional Note

Since this computation is based on the current timestamp at the moment of starting a new match, this is a problem probably related to the shifted timezone (the bug occurred in Italy)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.