<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: <NAME> <<EMAIL>>
# @Date:   06-07-2017
# 
# lunch voting telegram bot

from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from datetime import datetime, timedelta, time, date
import logging
import re
import os
import sys

# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                    level=logging.INFO)

logger = logging.getLogger(__name__)

DELAY_RE = re.compile("^\s*\+\s*(\d+)")

vote_start_time = None
vote_in_progress = False
voters = {}

# secret token from BotFather
SECRET_TOKEN_ENV = os.getenv('LUNCH_VOTING_BOT_SECRET_TOKEN', "")

# chat id
CHAT_ID_ENV = os.getenv('LUNCH_VOTING_BOT_CHAT_ID', "")
CHAT_ID = 0

VOTE_BEGIN_TIME = (8,00)
LUNCH_HOUR_TIME = (12,00)
LUNCH_REMIND = 30 #minutes before lunch
LUNCH_WEEK_DAYS = (0, 1, 2, 3, 4)
MAX_DELAY = 30

VOTE_START_MSG = "Обед в %d:%d\nесть время подумать" % (LUNCH_HOUR_TIME[0],LUNCH_HOUR_TIME[1])
VOTE_REMIND_MSG = "Обед через %d минут" % LUNCH_REMIND
VOTE_STOP_MSG = "Кто не успел, тот опоздал...\nИтог такой:\n"

LUNCH_REMIND_TIME = (datetime.combine(date.today(),time(hour=LUNCH_HOUR_TIME[0], minute=LUNCH_HOUR_TIME[1]))-timedelta(minutes=LUNCH_REMIND)).time()
VOTE_START_TIME = time(hour=VOTE_BEGIN_TIME[0], minute=VOTE_BEGIN_TIME[1])
VOTE_STOP_TIME = time(hour=LUNCH_HOUR_TIME[0], minute=LUNCH_HOUR_TIME[1])

class Voter:
    def __init__(self, decision=False, delay=0, name="Anon"):
        self.decision = decision
        self.delay = delay
        self.name = name

def vote(voter,decision,delay=0):
    if voter.id in voters:
        voters[voter.id].decision = decision
        voters[voter.id].delay = delay
    else:
        voters[voter.id] = Voter(decision=decision, delay=delay, name="%s %s" % (voter.first_name,voter.last_name))

def listen_all(bot, update):
    if not vote_in_progress:
        return
    if update.message.chat.id != CHAT_ID:
        return

    if update.message.text.strip() == "-":
        vote(update.message.from_user,False)
    elif update.message.text.strip() == "+":
        vote(update.message.from_user,True)
    else:
        result = DELAY_RE.match(update.message.text)
        if result:
            delay = result.group(1)
            vote(update.message.from_user,True,int(delay))

def error(bot, update, error):
    logger.warn('Update "%s" caused error "%s"' % (update, error))

def vote_start(bot, job):
    global vote_in_progress
    global vote_start_time
    voters.clear()
    vote_in_progress = True
    bot.send_message(chat_id=CHAT_ID,text=VOTE_START_MSG)
<commit_msg>* vote begin silent mode<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: <NAME> <<EMAIL>>
# @Date:   06-07-2017
# 
# lunch voting telegram bot

from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from datetime import datetime, timedelta, time, date
import logging
import re
import os
import sys

# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                    level=logging.INFO)

logger = logging.getLogger(__name__)

DELAY_RE = re.compile("^\s*\+\s*(\d+)")

vote_start_time = None
vote_in_progress = False
voters = {}

# secret token from BotFather
SECRET_TOKEN_ENV = os.getenv('LUNCH_VOTING_BOT_SECRET_TOKEN', "")

# chat id
CHAT_ID_ENV = os.getenv('LUNCH_VOTING_BOT_CHAT_ID', "")
CHAT_ID = 0

VOTE_BEGIN_TIME = (8,00)
LUNCH_HOUR_TIME = (12,00)
LUNCH_REMIND = 30 #minutes before lunch
LUNCH_WEEK_DAYS = (0, 1, 2, 3, 4)
MAX_DELAY = 30
VOTE_BEGIN_SILENT = True

VOTE_START_MSG = "Обед в %d:%d\nесть время подумать" % (LUNCH_HOUR_TIME[0],LUNCH_HOUR_TIME[1])
VOTE_REMIND_MSG = "Обед через %d минут" % LUNCH_REMIND
VOTE_STOP_MSG = "Кто не успел, тот опоздал...\nИтог такой:\n"

LUNCH_REMIND_TIME = (datetime.combine(date.today(),time(hour=LUNCH_HOUR_TIME[0], minute=LUNCH_HOUR_TIME[1]))-timedelta(minutes=LUNCH_REMIND)).time()
VOTE_START_TIME = time(hour=VOTE_BEGIN_TIME[0], minute=VOTE_BEGIN_TIME[1])
VOTE_STOP_TIME = time(hour=LUNCH_HOUR_TIME[0], minute=LUNCH_HOUR_TIME[1])

class Voter:
    def __init__(self, decision=False, delay=0, name="Anon"):
        self.decision = decision
        self.delay = delay
        self.name = name

def vote(voter,decision,delay=0):
    if voter.id in voters:
        voters[voter.id].decision = decision
        voters[voter.id].delay = delay
    else:
        voters[voter.id] = Voter(decision=decision, delay=delay, name="%s %s" % (voter.first_name,voter.last_name))

def listen_all(bot, update):
    if not vote_in_progress:
        return
    if update.message.chat.id != CHAT_ID:
        return

    if update.message.text.strip() == "-":
        vote(update.message.from_user,False)
    elif update.message.text.strip() == "+":
        vote(update.message.from_user,True)
    else:
        result = DELAY_RE.match(update.message.text)
        if result:
            delay = result.group(1)
            vote(update.message.from_user,True,int(delay))

def error(bot, update, error):
    logger.warn('Update "%s" caused error "%s"' % (update, error))

def vote_start(bot, job):
    global vote_in_progress
    global vote_start_time
    voters.clear()
    vote_in_progress = True
    if not VOTE_BEGIN_SILENT:
        bot.send_message(chat_id=CHAT_ID,text=VOTE_START_MSG)

{'fraction_non_alphanumeric': 0.13536221060492906, 'fraction_numerical': 0.013816280806572068, 'mean_word_length': 4.039510818438382, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7348845', 'n_tokens_mistral': 2131, 'n_tokens_neox': 2052, 'n_words': 381}