LoginSignup
3
3

More than 5 years have passed since last update.

Errbotで作るポモドーロタイマー

Posted at

なぜ作ったし

急に作りたくなって、つい(使うか?と言われると、使わないかも?)

中身

pomodoro.py
# -*- coding:utf8 -*-
from __future__ import division, print_function, absolute_import
"""Pomodoro timer
"""
from errbot import BotPlugin, botcmd


class Pomodoro(BotPlugin):
    def __init__(self, bot):
        super().__init__(bot)
        self._timer = [None, None]

    def activate(self):
        super().activate()
        self.start_poller(60, self.pomodoro)

    def pomodoro(self):
        time_counter = self._timer[0]
        target = self._timer[1]
        if time_counter is None:
            return
        time_counter += 1
        if time_counter >= 25:
            time_counter = -5
            self.send(target, "5分間休憩")
        elif time_counter == 0:
            self.send(target, "25分間集中")
        self._timer[0] = time_counter

    @botcmd(name='pomodoro_start')
    def start(self, msg, args):
        self._timer = [0, msg.frm]
        return 'タイマーオン'

    @botcmd(name='pomodoro_stop')
    def stop(self, msg, args):
        self._timer = [None, None]
        return 'タイマーオフ'

インストール用はこちら(公開用にちょっと調整しています)

  • !pomodoro_start でタイマー開始。
    • 約25分後に「休憩しましょう」ポストがErrbotから飛んでくる
    • 休憩が5分経つと、「仕事しましょう」ポストがErrbotから飛んでくる
  • !pomodoro_stop でタイマー終了

こんな挙動メモ

スケジューリングでの機能呼び出し

以前書いたように、Errbotはstart_poller()を用いることで、一定間隔で機能を呼び出すことができる。
タイマーの有効/無効は一旦脇に置いた上で、とりあえず本体ロジックは毎分動くようにする。

本体ロジックはただのカウンターチェック

  • タイマーがオフならNoneになる
  • タイマーがオンになったら-5 〜 24 の整数が入る
  • タイマーがオンの間は、毎分のロジック呼び出しごとに、カウンターを加算
  • カウンターが25になったら−5に戻して休憩ポスト
  • カウンターが0になったら仕事ポスト

その他

どう見ても一人用なので、せっかくだからと多人数版を作成中

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3