def dash_index(): if g.user: if g.user.admin: stats = json.loads(rdb.get('web:dashboard:stats') or '{}') if not stats or 'refresh' in request.args: stats['messages'] = pretty_number(Message.select().count()) stats['guilds'] = pretty_number(Guild.select().count()) stats['users'] = pretty_number(User.select().count()) stats['channels'] = pretty_number(Channel.select().count()) rdb.setex('web:dashboard:stats', json.dumps(stats), 300) guilds = Guild.select().order_by(Guild.guild_id) else: stats = {} guilds = Guild.select( Guild, Guild.config['web'][str(g.user.user_id)].alias('role') ).where( (Guild.enabled == 1) & (~(Guild.config['web'][str(g.user.user_id)] >> None)) ) return render_template( 'dashboard.html', stats=stats, guilds=guilds, ) return render_template('login.html')
def users_me_guilds(): if g.user.admin: guilds = list(Guild.select()) else: guilds = list( Guild.select( Guild, Guild.config['web'][str(g.user.user_id)].alias('role')).where( (~(Guild.config['web'][str(g.user.user_id)] >> None)))) return jsonify([guild.serialize() for guild in guilds])
def on_play(self, event, url): g = Guild.select(Guild).where((Guild.guild_id == event.guild.id)).get() if g.premium == False: raise CommandFail('This guild does not have premium enabled, please contact an Airplane global administrator.') # item = YoutubeDLInput(url, command='ffmpeg').pipe(BufferedOpusEncoderPlayable) # self.get_player(event.guild.id).queue.append(item) item = YoutubeDLInput(url) song = item.info if song['extractor'] is 'youtube': if song['is_live']: raise CommandFail('Sorry, live streams are not supported.') if song['duration'] > 7200: raise CommandFail('Sorry you are not allowed to play songs over 2 hours.') if song['duration'] > event.config.max_song_length: raise CommandFail('Sorry, you may not go over the server time limit.') item2 = item.pipe(BufferedOpusEncoderPlayable) self.get_player(event.guild.id).queue.append(item2) song = item.info if song['extractor'] is 'youtube': if song['artist']: return event.msg.reply('Now playing **{songname}** by **{author}**. Song length is `{duration}`'.format(songname=song['alt_title'], author=song['artist'], duration=timedelta(seconds=song['duration']))) else: return event.msg.reply('Now playing **{songname}** uploaded by **{author}**. Song length is `{duration}`'.format(songname=song['title'], author=song['uploader'], duration=timedelta(seconds=song['duration']))) else: return CommandSuccess('You\'re playing a song :D')
def command_about(self, event): embed = MessageEmbed() embed.set_author(name='Rowboat', icon_url=self.client.state.me.avatar_url, url='https://docs.rowboat.party/') embed.description = BOT_INFO embed.add_field(name='Servers', value=str(Guild.select().count()), inline=True) embed.add_field(name='Uptime', value=humanize.naturaltime(datetime.utcnow() - self.startup), inline=True) event.msg.reply('', embed=embed)
def check_subreddits(self): # TODO: sharding # TODO: filter in query subs_raw = list(Guild.select( Guild.guild_id, Guild.config['plugins']['reddit'] ).where( ~(Guild.config['plugins']['reddit'] >> None) ).tuples()) # Group all subreddits, iterate, update channels subs = defaultdict(list) for gid, config in subs_raw: config = json.loads(config) for k, v in config['subs'].items(): subs[k].append((gid, SubRedditConfig(v))) for sub, configs in subs.items(): try: self.update_subreddit(sub, configs) except requests.HTTPError: self.log.exception('Error loading sub %s:', sub)
def func(*args, **kwargs): try: if g.user.admin: guild = Guild.select().where( Guild.guild_id == kwargs.pop('gid')).get() guild.role = 'admin' else: guild = Guild.select( Guild, Guild.config['web'][str(g.user.user_id)].alias('role') ).where((Guild.guild_id == kwargs.pop('gid')) & ( ~(Guild.config['web'][str(g.user.user_id)] >> None)) ).get() return f(guild, *args, **kwargs) except Guild.DoesNotExist: return 'Invalid Guild', 404
def command_about(self, event): embed = MessageEmbed() embed.color = 0x7289da embed.set_author(name='Jetski', icon_url=self.client.state.me.avatar_url, url='https://jetski.ga/') embed.description = BOT_INFO embed.add_field(name='Servers', value=str(Guild.select().count()), inline=True) embed.add_field(name='Uptime', value=humanize_duration(datetime.utcnow() - self.startup), inline=True) event.msg.reply(embed=embed)
def control_sync_bans(self, event): guilds = list(Guild.select().where(Guild.enabled == 1)) msg = event.msg.reply(':timer: pls wait while I sync...') for guild in guilds: guild.sync_bans(self.client.state.guilds.get(guild.guild_id)) msg.edit('synced {} guilds'.format(len(guilds)))
def control_sync_bans(self, event): guilds = list(Guild.select().where(Guild.enabled == 1)) msg = event.msg.reply(':timer: Pls hold...') for guild in guilds: guild.sync_bans(self.client.state.guilds.get(guild.guild_id)) msg.edit('<:{}> synced {} guilds'.format(GREEN_TICK_EMOJI, len(guilds)))
def update_guild_bans(self): to_update = [ guild for guild in Guild.select().where( (Guild.last_ban_sync < (datetime.utcnow() - timedelta(days=1))) | (Guild.last_ban_sync >> None) ) if guild.guild_id in self.client.state.guilds] # Update 10 at a time for guild in to_update[:10]: guild.sync_bans(self.client.state.guilds.get(guild.guild_id))
def update_rowboat_guild_access(self): # if ROWBOAT_GUILD_ID not in self.state.guilds or ENV != 'prod': if ROWBOAT_GUILD_ID not in self.state.guilds or ENV not in ('prod', 'docker'): return rb_guild = self.state.guilds.get(ROWBOAT_GUILD_ID) if not rb_guild: return self.log.info('Updating Jetski guild access') guilds = Guild.select(Guild.guild_id, Guild.config).where( (Guild.enabled == 1)) users_who_should_have_access = set() for guild in guilds: if 'web' not in guild.config: continue for user_id in guild.config['web'].keys(): try: users_who_should_have_access.add(int(user_id)) except: self.log.warning('Guild %s has invalid user ACLs: %s', guild.guild_id, guild.config['web']) # TODO: sharding users_who_have_access = { i.id for i in rb_guild.members.values() if ROWBOAT_USER_ROLE_ID in i.roles } remove_access = set(users_who_have_access) - set( users_who_should_have_access) add_access = set(users_who_should_have_access) - set( users_who_have_access) for user_id in remove_access: member = rb_guild.members.get(user_id) if not member: continue member.remove_role(ROWBOAT_USER_ROLE_ID) for user_id in add_access: member = rb_guild.members.get(user_id) if not member: continue member.add_role(ROWBOAT_USER_ROLE_ID)
def command_about(self, event): embed = MessageEmbed() embed.set_author(name='RoPolice', icon_url=self.client.state.me.avatar_url, url='https://www.youtube.com/watch?v=5wFDWP5JwSM') embed.description = BOT_INFO embed.add_field(name='Servers', value=str(Guild.select().count()), inline=True) embed.add_field(name='Uptime', value=humanize.naturaldelta(datetime.utcnow() - self.startup), inline=True) event.msg.reply(embed=embed)
def stats(): stats = json.loads(rdb.get('web:dashboard:stats') or '{}') if not stats or 'refresh' in request.args: # stats['messages'] = pretty_number(Message.select().count()) # stats['guilds'] = pretty_number(Guild.select().count()) # stats['users'] = pretty_number(User.select().count()) # stats['channels'] = pretty_number(Channel.select().count()) stats['messages'] = Message.select().count() stats['guilds'] = Guild.select().count() stats['users'] = User.select().count() stats['channels'] = Channel.select().count() rdb.setex('web:dashboard:stats', json.dumps(stats), 300) return jsonify(stats)
def on_join(self, event): g = Guild.select(Guild).where((Guild.guild_id == event.guild.id)).get() if g.premium == False: raise CommandFail('This guild does not have premium enabled, please contact an Airplane global administrator.') if event.guild.id in self.guilds: return event.msg.reply("I'm already playing music here.") state = event.guild.get_member(event.author).get_voice_state() if not state: return event.msg.reply('You must be connected to voice to use that command.') try: client = state.channel.connect() except VoiceException as e: return event.msg.reply('Failed to connect to voice: `{}`'.format(e)) self.guilds[event.guild.id] = Player(client) self.guilds[event.guild.id].complete.wait() del self.guilds[event.guild.id]
def command_about(self, event): embed = MessageEmbed() embed.set_author(name='Planeboat', icon_url=self.client.state.me.avatar_url, url='https://rowboat.party/') embed.description = BOT_INFO embed.add_field(name='Servers', value=str(Guild.select().count()), inline=True) embed.add_field(name='Uptime', value=humanize.naturaldelta(datetime.utcnow() - self.startup), inline=True) #global_admin = rdb.sismember('global_admins', event.author.id) #_usr = User.select().where(User.user_id == event.author.id) #if len(_usr) == 1: # global_admin = _usr[0].admin global_admin = self.is_global_admin(event.author.id) if global_admin: embed.add_field(name='Admin', value='You are a rowboat global admin!') event.msg.reply(embed=embed)