def rmv_global_admin(user_id): from rowboat.redis import rdb from rowboat.models.user import User init_db(ENV) rdb.srem('global_admins', user_id) User.update(admin=False).where(User.user_id == user_id).execute() print 'Ok, removed {} as a global admin'.format(user_id)
def add_global_admin(user_id): from rowboat.redis import rdb from rowboat.models.user import User init_db(ENV) rdb.sadd('global_admins', user_id) User.update(admin=True).where(User.user_id == user_id).execute() print 'Ok, added {} as a global admin'.format(user_id)
def before_first_request(): init_db(ENV) with open('config.yaml', 'r') as f: data = load(f) rowboat.app.secret_key = data.get('SECRET_KEY') rowboat.app.config.update(data['web'])
def add_global_admin(user_id): from rowboat.redis import rdb from rowboat.models.user import User init_db(ENV) rdb.sadd('global_admins', user_id) user = User.get_id(user_id) user.update(admin=True) print('Ok, added {} as a global admin'.format( str(user))) # Not sure if I need to str here
def before_first_request(): init_db(ENV) # PluginsConfig.force_load_plugin_configs() with open('config.yaml', 'r') as f: data = safe_load(f) rowboat.app.config.update(data['web']) rowboat.app.secret_key = data['web']['SECRET_KEY'] rowboat.app.config['token'] = data.get('token')
def workers(worker_id): from rowboat.tasks import TaskWorker # Log things to file file_handler = logging.FileHandler('worker-%s.log' % worker_id) log = logging.getLogger() file_handler.setFormatter(logging.Formatter(LOG_FORMAT)) log.addHandler(file_handler) for logname in ['peewee', 'requests']: logging.getLogger(logname).setLevel(logging.INFO) init_db(ENV) TaskWorker().run()
def load(self, ctx): init_db(ENV) self.startup = ctx.get('startup', datetime.utcnow()) self.guilds = ctx.get('guilds', {}) super(CorePlugin, self).load(ctx) # Overwrite the main bot instances plugin loader so we can magicfy events self.bot.add_plugin = self.our_add_plugin if ENV != 'prod': self.spawn(self.wait_for_plugin_changes) self._wait_for_actions_greenlet = self.spawn(self.wait_for_actions)
def rmv_whitelist(guild_id, flag): from rowboat.models.guild import Guild init_db(ENV) flag = Guild.WhitelistFlags.get(flag) if not flag: print 'Invalid flag' return try: guild = Guild.get(guild_id=guild_id) except Guild.DoesNotExist: print 'No guild exists with that id' return guild.whitelist.remove(int(flag)) guild.save() guild.emit_update() print 'removed flag'
def add_whitelist(guild_id, flag): from rowboat.models.guild import Guild init_db(ENV) flag = Guild.WhitelistFlags.get(flag) if not flag: print('Flag not found') return try: guild = Guild.get(guild_id=guild_id) except Guild.DoesNotExist: print('No guild exists with that id') return guild.whitelist.append(int(flag)) guild.save() guild.emit_update() print('Added flag')
def load(self, ctx): init_db(ENV) self.startup = ctx.get('startup', datetime.utcnow()) self.guilds = ctx.get('guilds', {}) self.emitter = Emitter(gevent.spawn) super(CorePlugin, self).load(ctx) # Overwrite the main bot instances plugin loader so we can magicfy events self.bot.add_plugin = self.our_add_plugin self.spawn(self.wait_for_plugin_changes) self.global_config = None with open('config.yaml', 'r') as f: self.global_config = load(f) self._wait_for_actions_greenlet = self.spawn(self.wait_for_actions)
def rmv_whitelist(guild_id, flag): from rowboat.models.guild import Guild init_db(ENV) flag = Guild.WhitelistFlags.get(flag) if not flag: print 'Invalid flag' return try: guild = Guild.get(guild_id=guild_id) except Guild.DoesNotExist: print 'No guild exists with that id' return if not guild.is_whitelisted(flag): print 'This guild doesn\'t have this flag' return guild.whitelist.remove(int(flag)) guild.save() guild.emit('GUILD_UPDATE') print 'Removed flag'
def add_whitelist(guild_id, flag): from rowboat.models.guild import Guild init_db(ENV) flag = Guild.WhitelistFlags.get(flag) if not flag: print 'Invalid flag' return try: guild = Guild.get(guild_id=guild_id) except Guild.DoesNotExist: print 'No guild exists with that id' return if guild.is_whitelisted(flag): print 'This guild already has this flag' return guild.whitelist.append(int(flag)) guild.save() guild.emit('GUILD_UPDATE') print 'Added flag'
def add_deletion_admin(user_id): from rowboat.redis import rdb from rowboat.models.user import User init_db(ENV) rdb.sadd('deletion_admins', user_id) print 'Ok, added {} as a deletion admin'.format(user_id)
cursor.execute(GET_NULLABLE_SQL, (table._meta.db_table, field)) return cursor.fetchone()[0] == 'YES' return rule @staticmethod def non_nullable(table, field): def rule(cursor): cursor.execute(GET_NULLABLE_SQL, (table._meta.db_table, field)) return cursor.fetchone()[0] == 'NO' return rule @classmethod def only_if(cls, check, table, *fields): def deco(func): rules = [check(table, i) for i in fields] cls(rules, func).run() return deco @classmethod def always(cls): def deco(func): cls([lambda c: True], func).run() return deco init_db(ENV)
cursor.execute(GET_NULLABLE_SQL, (table._meta.db_table, field)) return cursor.fetchone()[0] == 'YES' return rule @staticmethod def non_nullable(table, field): def rule(cursor): cursor.execute(GET_NULLABLE_SQL, (table._meta.db_table, field)) return cursor.fetchone()[0] == 'NO' return rule @classmethod def only_if(cls, check, table, *fields): def deco(func): rules = [check(table, i) for i in fields] cls(rules, func).run() return deco @classmethod def always(cls): def deco(func): cls([lambda c: True], func).run() return deco init_db()