Ejemplo n.º 1
0
    def enInit(self):
        self.venuetype = self.vars.get("venuetype", "pub")
        if ":" in self.venuetype:
            self.venuetype, self.pluraltype = self.venuetype.split(":")
        else:
            self.pluraltype = self.venuetype + "s"
        com = self.get('endroid.plugins.command')
        com.register_both(self.register, ('register', self.venuetype),
                          '<name>',
                          synonyms=(('register', 'new', self.venuetype),
                                    ('register', 'a', 'new', self.venuetype)))
        com.register_both(self.picker, ('pick', 'a', self.venuetype),
                          synonyms=(('pick', self.venuetype), ))
        com.register_both(self.vote_up, ('vote', self.venuetype, 'up'),
                          '<name>')
        com.register_both(self.vote_down, ('vote', self.venuetype, 'down'),
                          '<name>')
        com.register_both(self.alias, ('alias', self.venuetype),
                          '<name> to <alias>')
        com.register_both(self.list, ('list', self.pluraltype),
                          synonyms=(('list', self.venuetype), ))
        com.register_both(self.list_aliases,
                          ('list', self.venuetype, 'aliases'))
        com.register_both(self.rename, ('rename', self.venuetype),
                          '<oldname> to <newname>')

        self.db = Database(DB_NAME)
        self.setup_db()
        self.load_db()
Ejemplo n.º 2
0
    def endroid_init(self):
        self.db = Database(DB_NAME)
        if not self.db.table_exists(DB_TABLE):
            self.db.create_table(DB_TABLE, ('user', 'kills'))

        # make a local copy of the registration database
        data = self.db.fetch(DB_TABLE, ['user', 'kills'])
        for dct in data:
            self.users[dct['user']] = User(dct['user'], dct['kills'])
Ejemplo n.º 3
0
    def endroid_init(self):
        com = self.get('endroid.plugins.command')

        com.register_chat(self.allow, ('allow', 'remote'))
        com.register_chat(self.deny, ('deny', 'remote'))

        http = self.get('endroid.plugins.httpinterface')
        http.register_path(self, self.http_request_handler, '')

        self.sms = self.get('endroid.plugins.sms')

        self.keys = DatabaseDict(Database(DB_NAME), DB_TABLE, "users", "keys")
Ejemplo n.º 4
0
 def __init__(self):
     self.delayedcall = None
     self.fun_dict = {}
     self.db = Database('Cron')
     # table for tasks which will be called after a certain amount of time
     if not self.db.table_exists('cron_delay'):
         self.db.create_table('cron_delay',
                              ['timestamp', 'reg_name', 'params'])
     # table for tasks which will be called at a specific time
     if not self.db.table_exists('cron_datetime'):
         self.db.create_table(
             'cron_datetime',
             ['datetime', 'locality', 'reg_name', 'params'])
Ejemplo n.º 5
0
 def database(self):
     if self._database is None:
         self._database = Database(self.name)  # Should use place too
     return self._database
Ejemplo n.º 6
0
 def endroid_init(self):
     self.db = Database(DB_NAME)
     if not self.db.table_exists(DB_TABLE):
         self.db.create_table(DB_TABLE, DB_COLUMNS)
Ejemplo n.º 7
0
    def endroid_init(self):
        # set up database, creating it if it doesn't exist
        if not all([
                self.vars["country_code"], self.vars["phone_number"],
                self.vars["auth_token"], self.vars["twilio_sid"]
        ]):
            raise ValueError("Specify country_code, phone_number, auth_token "
                             "and twilio_sid in the Endroid config file.")

        self._config = {
            "time_between_sms_resets": 1,
            "user_bucket_capacity": 3,
            "user_bucket_fillrate": 0.05,
            "global_bucket_capacity": 20,
            "global_bucket_fillrate": 1,
            "period_limit": 30
        }

        for key in self._config:
            user_value = self.vars.get(key, "")
            if user_value:
                # Check user_value is a number
                try:
                    a = user_value / 2
                    self._config[key] = user_value
                except TypeError:
                    logging.info("{} must be a number".format(key))

        self.ratelimit = self.get('endroid.plugins.ratelimit')
        self.user_buckets = defaultdict(lambda: self.ratelimit.create_bucket(
            self._config["user_bucket_capacity"], self._config[
                "user_bucket_fillrate"]))
        self.global_bucket = self.ratelimit.create_bucket(
            self._config["global_bucket_capacity"],
            self._config["global_bucket_fillrate"])

        self.db = Database(DB_NAME)
        # Create a table to store user's phone numbers
        if not self.db.table_exists(DB_TABLE):
            self.db.create_table(DB_TABLE, ("user", "phone"))
        # Create a table to record the number of SMSs sent per user
        if not self.db.table_exists(DB_LIMIT_TABLE):
            self.db.create_table(DB_LIMIT_TABLE,
                                 ("user", "texts_sent_this_period"))
        # Create a table to record any users and a user wants to block
        if not self.db.table_exists(DB_BLOCK_TABLE):
            self.db.create_table(DB_BLOCK_TABLE, ("user", "users_blocked"))

        # logging file stuff
        self.log = logging.getLogger(__name__)
        logfile = os.path.expanduser(
            self.vars.get('logfile', '~/.endroid/sms.log'))
        self.log.info("Logging SMS activity to {}".format(logfile))
        handler = logging.FileHandler(logfile)
        formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
        handler.setFormatter(formatter)
        self.log.addHandler(handler)
        self.log.setLevel(logging.INFO)
        self.cron_name = "SMS_PERIOD_LIMIT"

        self.cron.register(self._sms_reset_number_sent, self.cron_name)
        if self.cron_name not in self.cron.getTimeouts():
            # Set number sent to reset at some time in the future for the first
            # time unless there is already a reset time set.
            # Convert days to seconds
            time_between = 60 * 60 * 24 * self._config[
                "time_between_sms_resets"]
            self.cron.setTimeout(time_between, self.cron_name, None)