Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's raining soldini, hallelujah #135

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,4 @@ pydrive
pydrive/*
.vscode
data/json/subjs.json
soldini
2 changes: 2 additions & 0 deletions config/settings.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ test:

dev_group_chatid: 0
representatives_group: 0

easter_eggs_chat: []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

volendo potremmo considerare qualsiasi chatid < 0, quindi gruppi/supergruppi, non per forza un chat id specifico
se no ogni volta che creiamo un nuovo gruppo dovremmo "ottenere" il chat id e poi inserirlo qui, insomma ce la potremmo risparmiare questa cosa

Copy link
Member Author

@TendTo TendTo Nov 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si, si può controllare se si tratta di gruppo/supergruppo caso per caso, ma non ho capito da dove dovremmo procurarci la lista di chat_id se non è hardcoded

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cioè, se non specifichi la lista di chat nei settings, da dove dovrebbe procurarsela il bot?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non mi vengono soluzioni ottimali al problema

6 changes: 5 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from telegram.ext import Updater, CallbackQueryHandler, CommandHandler, Filters, CallbackContext, MessageHandler

# Modules
from module.easter_egg_func import smonta_portoni, santino, prof_sticker, bladrim, lei_che_ne_pensa_signorina
from module.easter_egg_func import smonta_portoni, santino, prof_sticker, bladrim, lei_che_ne_pensa_signorina, tomarchio_schedule, tomarchio_balance, add_soldino
from module.callback_handlers import informative_callback, generic_button_handler, submenu_handler, md_handler, callback, submenu_with_args_handler, none_handler
from module.shared import config_map, TOKEN, give_chat_id, HELP, AULARIO, SEGNALAZIONE, CLOUD
from module.regolamento_didattico import regolamenti, regolamentodidattico, regolamentodidattico_button, triennale, magistrale, regdid
Expand Down Expand Up @@ -67,6 +67,8 @@ def main():
dp.add_handler(CommandHandler('prof_sticker' ,prof_sticker))
dp.add_handler(MessageHandler(Filters.regex('/lezioni cazzeggio'), bladrim))
dp.add_handler(CommandHandler('leiCheNePensaSignorina',lei_che_ne_pensa_signorina))
dp.add_handler(CommandHandler('tomarchio', tomarchio_balance))
dp.add_handler(MessageHandler(Filters.reply & Filters.regex(r"^[Ss][Ii]$"), add_soldino))

#Informative command
dp.add_handler(CommandHandler('sdidattica', informative_callback))
Expand Down Expand Up @@ -141,6 +143,8 @@ def main():

j.run_repeating(updater_lep, interval=86400, first=0) # job_updater_lep (24h)
j.run_daily(updater_schedule, time = time(hour = 1, minute = 5) ) # you need to put 1 hour late cause of the timezone
j.run_daily(tomarchio_schedule, time = time(hour = 1, minute = 5) ) # you need to put 1 hour late cause of the timezone

if (config_map['debug']['disable_drive'] == 0):
dp.add_handler(CommandHandler('drive',drive))

Expand Down
61 changes: 61 additions & 0 deletions module/easter_egg_func.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# -*- coding: utf-8 -*-
# system
import sqlite3
from datetime import time
from random import randint, choice
from time import sleep
from os import path

# Telegram
from telegram import Update
Expand Down Expand Up @@ -44,3 +48,60 @@ def lei_che_ne_pensa_signorina(update: Update, context: CallbackContext) -> None
check_log(update, context, "leiCheNePensaSignorina")
message_text = EasterEgg.get_lei_che_ne_pensa_signorina()
context.bot.sendMessage(chat_id=update.message.chat_id, text=message_text)


def tomarchio_schedule(context: CallbackContext) -> None:
"""Called once a day at 00:00 (ROME)
Schedules the "tomarchio_request" job that will run between 10:00 and 21:00 of the same day
Also, makes sure the file "data/soldini" exists

Args:
context (CallbackContext): context passed by the updater
"""
if not path.exists("data/soldini"):
with open("data/soldini", 'w+') as soldini:
soldini.write("0")
Helias marked this conversation as resolved.
Show resolved Hide resolved
#context.job_queue.run_once(tomarchio_request, when=time(hour=randint(10, 21), minute=randint(0, 59)))
Helias marked this conversation as resolved.
Show resolved Hide resolved
context.job_queue.run_once(tomarchio_request, when=0)


def tomarchio_request(context: CallbackContext) -> None:
"""Called every day between 10:00 and 21:00
Sends a message to a random chat choosen between the ones listed in "easter_eggs_chat" in the settings.yaml file

Args:
context (CallbackContext): context passed by the handler
"""
chat_id = choice(config_map['easter_eggs_chat'])
message = context.bot.sendMessage(chat_id=chat_id, text="Hai un euro per il Signor Tomarchio?")
sleep(30)
Helias marked this conversation as resolved.
Show resolved Hide resolved
context.bot.deleteMessage(chat_id=chat_id, message_id=message.message_id)

def add_soldino(update: Update, context: CallbackContext) -> None:
"""Called when a user replyes to the "tomarchio_request" message with "Si"
Adds a "soldino" to the tomarchio balance

Args:
update (Update): update event
context (CallbackContext): context passed by the handler
"""
if update.message.reply_to_message.text == "Hai un euro per il Signor Tomarchio?":
with open("data/soldini", 'r', encoding="utf8") as in_file:
soldini = int(in_file.read()) + 1
with open("data/soldini", 'w', encoding="utf8") as out_file:
out_file.write(str(soldini))


def tomarchio_balance(update: Update, context: CallbackContext) -> None:
"""Called with the /tomarchio command
Shows the tomarchio balance

Args:
update (Update): update event
context (CallbackContext): context passed by the handler
"""
check_log(update, context, "tomarchioBalance")
with open("data/soldini", 'r', encoding="utf8") as in_file:
soldini = int(in_file.read()) + 1
message_text = "Tomarchio ha {} euro per il caffè.".format(soldini)
context.bot.sendMessage(chat_id=update.message.chat_id, text=message_text)