Esempio n. 1
0
    def start(self, bot, update):
        printlog(update, "start")

        _, chat_id = get_ids(update)  # Ignoraa user_id, tätä käytetään paljon
        count_and_write(self.db, update, "commands")

        bot.send_message(chat_id=chat_id, text="Woof woof")
Esempio n. 2
0
    def darkroom(self, bot, update):
        printlog(update, "darkroom")

        _, chat_id = get_ids(update)
        count_and_write(self.db, update, "commands")

        try:
            with urlopen("https://ttkamerat.fi/darkroom/api/v1/sensors/latest"
                         ) as url:
                sensor_data = json.loads(url.read().decode())

                value_light = 0
                isDarkroomPopulated = False

                # JSON härössä muodossa, sen takia teemme näin. Esimerkki:
                #   {"entries": [{"value": 191, "sensor": "light1", "inserted": "2018-07-27T16:18:43.589Z"}]}
                for sensor in sensor_data["entries"]:
                    if sensor["sensor"] == "light1":
                        value_light = sensor["value"]

                if value_light > 100:
                    isDarkroomPopulated = True

                if isDarkroomPopulated:
                    reply = "Joku on pimiöllä :O\n"
                else:
                    reply = "Pimiö tyhjä :(\n"

                bot.send_message(chat_id=chat_id, text=reply)
        except URLError as e:
            print(e.reason)
            bot.send_message(chat_id=chat_id,
                             text="Ei ny onnistunu (%s)" % e.reason)
Esempio n. 3
0
    def camera_versus(self, bot, update):
        printlog(update, "camera versus")

        _, chat_id = get_ids(update)
        count_and_write(self.db, update, "commands")

        msg = camera_versus_text()
        bot.send_message(chat_id=chat_id, text=msg)
Esempio n. 4
0
    def protip(self, bot, update):
        printlog(update, "protip")

        _, chat_id = get_ids(update)
        count_and_write(self.db, update, "commands")

        protip_list = masterlist.tips

        protip_index = random.randint(0, len(protip_list) - 1)

        bot.send_message(chat_id=chat_id, text=protip_list[protip_index])
Esempio n. 5
0
    def route_command(self, bot, update, args=[]):
        message = update.message.text.split(" ")[0]

        #poistetaan '@<BotUsername>' komennosta jos löytyy
        if "@" in message:
            message = message.split("@", 1)[0]

        printlog(update, message)
        count_and_write(self.db, update, "commands")

        if message in self.commands:
            self.commands[message](bot, update, args)
Esempio n. 6
0
    def noutaja(self, bot, update):
        printlog(update, "noutaja")

        _, chat_id = get_ids(update)
        count_and_write(self.db, update, "commands")

        url = "https://dog.ceo/api/breed/retriever/golden/images/random"

        req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})

        with urlopen(req) as page:
            retriever_data = json.loads(page.read().decode())

            picture_link = retriever_data["message"]

            bot.sendPhoto(chat_id=chat_id, photo=picture_link)
Esempio n. 7
0
    def stats(self, bot, update):
        printlog(update, "stats")

        user_id, chat_id = get_ids(update)

        count_and_write(self.db, update, "commands")

        if self.db.in_blacklist(user_id):
            update.message.reply_text("Markku ei seuraa sinua. Käytä komentoa /unblacklist , jos haluat seurannan käyttöön.\n" \
                                    "Markku does not track you. Use the command /unblacklist to enable tracking.")
            return

        counters = self.db.get_counters()

        user_counters = {}
        counter_sum = 0

        # Haetaan käyttäjän laskurien arvot databaseltä
        for i in counters:
            user_counters[i] = self.db.get_counter_user(user_id, chat_id, i)
            if i != "kiitos":
                counter_sum += user_counters[i]

        # Muodostetaan lähetettävä viesti
        msg = "@{}<code>:".format(update.message.from_user.username)
        msg += "\n{:<10}{:>4}".format("Total:", counter_sum)

        for counter in user_counters:
            if counter == "kiitos":
                msg += "\n└ {}% Kiitosta".format(
                    round(
                        user_counters[counter] / user_counters["messages"] *
                        100, 1))

            else:
                msg += "\n{:<10}{:>4} ({:>4}%)".format(
                    counter.capitalize() + ":", user_counters[counter],
                    round(user_counters[counter] / counter_sum * 100, 1))

        msg += "</code>"

        # Lähetetään viesti. parse_mode mahdollistaa html-muotoilun viestissä
        bot.send_message(chat_id=chat_id, text=msg, parse_mode='HTML')
Esempio n. 8
0
    def help(self, bot, update):
        printlog(update, "help")

        _, chat_id = get_ids(update)
        count_and_write(self.db, update, "commands")

        reply = "Komennot:\n" \
                "/darkroom - Kertoo onko joku pimiöllä.\n" \
                "/stats - Chattikohtaiset statsit.\n" \
                "/topten <i>laskuri</i> - Paljastaa chatin spämmibotit.\n"\
                "/noutaja - Postaa satunnaisen noutajakuvan.\n"\
                "/protip - Antaa ammatti valo kuvaus vinkin!\n"\
                "/blacklist - Poistaa lähettäjän datat tietokannasta ja estää uusien tallentamisen.\n"\
                "/unblacklist - Sallii omien tietojen tallentamisen blacklist-komennon jälkeen.\n"\
                "\n" \
                "Botin koodit: @eltsu7, @kulmajaba ja @anttimoi\n" \
                "https://github.com/eltsu7/MarkkuBot\n" \
                "Valosensorit ja siihen koodit: @anttimoi"

        bot.send_message(chat_id=chat_id, text=reply, parse_mode='HTML')
Esempio n. 9
0
    def msg_text(self, bot, update):
        printlog(update, "text")

        _, chat_id = get_ids(update)
        count_and_write(self.db, update, "messages")

        sticker_list = masterlist.stickers
        message = update.message.text.lower()

        parse_and_count(self.db, update)

        lotto = random.randint(1, 201)

        if "kiitos" in message:
            count_and_write(self.db, update, "kiitos")

            if lotto < 11:
                update.message.reply_text("Kiitos")
            elif lotto < 16:
                sticker_index = random.randint(0, len(sticker_list) - 1)
                bot.send_sticker(chat_id=chat_id,
                                 sticker=sticker_list[sticker_index])

            elif lotto < 17:
                update.message.reply_text("Ole hyvä")

        elif "markku" in message and "istu" in message:
            if lotto < 91:
                bot.send_message(chat_id=chat_id, text="*istuu*")
            else:
                bot.send_message(chat_id=chat_id, text="*paskoo lattialle*")

        elif "huono markku" in message:
            bot.send_message(chat_id=chat_id, text="w00F")

        elif "markku perkele" in message:
            bot.send_message(chat_id=chat_id, text="woof?")

        elif "filmi" in message and lotto < 11:
            bot.send_message(chat_id=chat_id, text="Filmi best")
Esempio n. 10
0
    def topten(self, bot, update, args):
        printlog(update, "topten")

        _, chat_id = get_ids(update)
        count_and_write(self.db, update, "commands")

        # argumenttejä pitää olla vain yksi. ei errorviestiä koska tätä varmaan painetaan vahingossa usein
        if len(args) != 1:
            return

        # db:ltä käytössä olevat laskurit
        valid_counters = self.db.get_counters()

        # errorviesti jos argumentti ei vastaa laskuria
        if args[0] not in valid_counters:
            counters = ", ".join(valid_counters)
            reply = "Väärä laskurin nimi. Käytettävät laskurit: " + counters + "."
            bot.send_message(chat_id=chat_id, text=reply)

            return

        text = toptenlist(self.db, chat_id, args[0])

        bot.send_message(chat_id=chat_id, text=text)
Esempio n. 11
0
 def msg_sticker(self, bot, update):
     count_and_write(self.db, update, "stickers")
Esempio n. 12
0
 def msg_photo(self, bot, update):
     count_and_write(self.db, update, "photos")
Esempio n. 13
0
 def msg_gif(self, bot, update):
     count_and_write(self.db, update, "gifs")
Esempio n. 14
0
 def msg_sticker(self, bot, update):
     printlog(update, "sticker")
     count_and_write(self.db, update, "stickers")
Esempio n. 15
0
 def msg_photo(self, bot, update):
     printlog(update, "photo")
     count_and_write(self.db, update, "photos")
Esempio n. 16
0
 def msg_gif(self, bot, update):
     printlog(update, "gif")
     count_and_write(self.db, update, "gifs")