import logging

from pajbot.managers.handler import HandlerManager
from pajbot.models.user import User
from pajbot.modules import BaseModule
from pajbot.modules import ModuleSetting

log = logging.getLogger(__name__)


class LineFarmingModule(BaseModule):

    ID = __name__.split(".")[-1]
    NAME = "Line Farming"
    DESCRIPTION = "Keep track on the amount of lines users type in chat"
    ENABLED_DEFAULT = True
    CATEGORY = "Feature"
    SETTINGS = [
        ModuleSetting(
            key="count_offline", label="Count lines in offline chat", type="boolean", required=True, default=False
        )
    ]

    def on_pubmsg(self, source, **rest):
        if self.bot.is_online or self.settings["count_offline"] is True:
            # this funky syntax makes SQLAlchemy increment
            # the num_lines atomically with SET num_lines=("user".num_lines + 1)
            source.num_lines = User.num_lines + 1

    def enable(self, bot):
        HandlerManager.add_handler("on_pubmsg", self.on_pubmsg)

    def disable(self, bot):
        HandlerManager.remove_handler("on_pubmsg", self.on_pubmsg)

import logging

from pajbot.managers.handler import HandlerManager
from pajbot.models.user import User
from pajbot.modules import BaseModule
from pajbot.modules import ModuleSetting

log = logging.getLogger(__name__)


class LineFarmingModule(BaseModule):

    ID = __name__.split(".")[-1]
    NAME = "Line Farming"
    DESCRIPTION = "Keep track on the amount of lines users type in chat"
    ENABLED_DEFAULT = True
    CATEGORY = "Feature"
    SETTINGS = [
        ModuleSetting(
            key="count_offline", label="Count lines in offline chat", type="boolean", required=True, default=False
        )
    ]

    def on_pubmsg(self, source, **rest):
        if self.bot.is_online or self.settings["count_offline"] is True:
            source.num_lines += 1

    def enable(self, bot):
        HandlerManager.add_handler("on_pubmsg", self.on_pubmsg)

    def disable(self, bot):
        HandlerManager.remove_handler("on_pubmsg", self.on_pubmsg)

Revert to using += to increment user's lines Doing it the "atomic" way was causing str(user.num_lines) to become ""user".num_lines + :num_lines_1" which is not intended
Revert to using += to increment user's lines
Doing it the "atomic" way was causing str(user.num_lines) to become ""user".num_lines + :num_lines_1" which is not intended
